Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/mcp/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function convertTool(mcpTool: MCPToolDef, client: Client, timeout?: numbe
...(mcpTool.inputSchema as JSONSchema7),
type: "object",
properties: (mcpTool.inputSchema.properties ?? {}) as JSONSchema7["properties"],
additionalProperties: false,
additionalProperties: (mcpTool.inputSchema as JSONSchema7).additionalProperties ?? false,
}

return dynamicTool({
Expand Down
71 changes: 71 additions & 0 deletions packages/opencode/test/mcp/catalog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, expect, test } from "bun:test"
import type { Tool as MCPToolDef } from "@modelcontextprotocol/sdk/types.js"
import type { Schema } from "ai"
import { convertTool } from "../../src/mcp/catalog"

const mockClient = {} as any

function makeMCPTool(inputSchema: Record<string, unknown>): MCPToolDef {
return {
name: "test_tool",
inputSchema: inputSchema as MCPToolDef["inputSchema"],
}
}

function getJsonSchema(tool: ReturnType<typeof convertTool>): Record<string, unknown> {
return (tool.inputSchema as Schema<unknown>).jsonSchema as Record<string, unknown>
}

describe("convertTool additionalProperties", () => {
test("defaults to false when server omits additionalProperties", () => {
const mcpTool = makeMCPTool({
type: "object",
properties: { name: { type: "string" } },
})

const tool = convertTool(mcpTool, mockClient)
const schema = getJsonSchema(tool)

expect(schema.additionalProperties).toBe(false)
})

test("preserves additionalProperties: true from server schema", () => {
const mcpTool = makeMCPTool({
type: "object",
properties: { name: { type: "string" } },
additionalProperties: true,
})

const tool = convertTool(mcpTool, mockClient)
const schema = getJsonSchema(tool)

expect(schema.additionalProperties).toBe(true)
})

test("preserves additionalProperties object sub-schema from server", () => {
const subSchema = { type: "string" as const }
const mcpTool = makeMCPTool({
type: "object",
properties: { name: { type: "string" } },
additionalProperties: subSchema,
})

const tool = convertTool(mcpTool, mockClient)
const schema = getJsonSchema(tool)

expect(schema.additionalProperties).toEqual(subSchema)
})

test("preserves explicit additionalProperties: false from server", () => {
const mcpTool = makeMCPTool({
type: "object",
properties: { name: { type: "string" } },
additionalProperties: false,
})

const tool = convertTool(mcpTool, mockClient)
const schema = getJsonSchema(tool)

expect(schema.additionalProperties).toBe(false)
})
})
Loading