forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog.test.ts
More file actions
47 lines (38 loc) · 1.55 KB
/
Copy pathcatalog.test.ts
File metadata and controls
47 lines (38 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, expect, test } from "bun:test"
import type { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { McpCatalog } from "@/mcp/catalog"
const options = { toolCallId: "call_mcp", abortSignal: new AbortController().signal } as any
function clientReturning(result: unknown) {
return {
callTool: async () => result,
} as unknown as Client
}
function mcpTool() {
return {
name: "screenshot",
description: "Take a screenshot",
inputSchema: {
type: "object",
properties: {},
additionalProperties: false,
},
} as any
}
describe("McpCatalog.convertTool", () => {
test("preserves content when structuredContent is also present", async () => {
const content = [{ type: "image" as const, mimeType: "image/png", data: "AAAA" }]
const structuredContent = { image: { mimeType: "image/png", data: "AAAA" } }
const converted = McpCatalog.convertTool(mcpTool(), clientReturning({ content, structuredContent }))
const output = await converted.execute?.({}, options)
expect(output).toMatchObject({ content, structuredContent })
})
test("falls back to structuredContent only when content is absent", async () => {
const structuredContent = { results: [{ title: "one" }] }
const converted = McpCatalog.convertTool(mcpTool(), clientReturning({ content: [], structuredContent }))
const output = await converted.execute?.({}, options)
expect(output).toMatchObject({
structuredContent,
content: [{ type: "text", text: JSON.stringify(structuredContent) }],
})
})
})