diff --git a/.changeset/mcp-legacy-tool-input-defs.md b/.changeset/mcp-legacy-tool-input-defs.md new file mode 100644 index 00000000000..f72ef9f7d23 --- /dev/null +++ b/.changeset/mcp-legacy-tool-input-defs.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Fix `McpServer` omitting referenced definitions from tool input schemas on protocol revisions 2024-11-05 and 2025-03-26. diff --git a/packages/effect/src/ai/internal/mcpSchema/v2024_11_05.ts b/packages/effect/src/ai/internal/mcpSchema/v2024_11_05.ts index 5caae4f687a..7a663549040 100644 --- a/packages/effect/src/ai/internal/mcpSchema/v2024_11_05.ts +++ b/packages/effect/src/ai/internal/mcpSchema/v2024_11_05.ts @@ -289,6 +289,7 @@ export const PromptMessage = Schema.Struct({ */ export const ToolInputSchema = Schema.Struct({ type: Schema.Literal("object"), + $defs: optional(Schema.Record(Schema.String, Schema.Union([UnknownObject, Schema.Boolean]))), properties: optional(Schema.Record(Schema.String, UnknownObject)), required: optional(Schema.Array(Schema.String)) }) diff --git a/packages/effect/test/ai/McpServer/ProtocolAdapters.test.ts b/packages/effect/test/ai/McpServer/ProtocolAdapters.test.ts index d02d9072b07..61376fe4f22 100644 --- a/packages/effect/test/ai/McpServer/ProtocolAdapters.test.ts +++ b/packages/effect/test/ai/McpServer/ProtocolAdapters.test.ts @@ -59,6 +59,13 @@ const IdentifiedResultTool = Tool.make("identified-result", { success: Schema.Struct({ value: Schema.String }).annotate({ identifier: "IdentifiedResult" }) }) +class Address extends Schema.Class
("Address")({ street: Schema.String }) {} + +const AddressTool = Tool.make("address", { + parameters: Schema.Struct({ address: Address }), + success: Schema.String +}) + const ValidatedTool = Tool.make("validated", { parameters: Schema.Struct({ value: Schema.String @@ -128,6 +135,7 @@ const TestToolkit = Toolkit.make( StructuredOnlyTool, UnionResultTool, IdentifiedResultTool, + AddressTool, ValidatedTool, CapabilityTool, InitializeMetadataTool, @@ -256,6 +264,7 @@ const makeFixture = Effect.fnUntraced(function*( }), "union-result": () => Effect.succeed({ _tag: "a" as const, a: 1 }), "identified-result": () => Effect.succeed({ value: "identified" }), + address: ({ address }) => Effect.succeed(address.street), validated: ({ value }) => Effect.succeed(value), capability: () => McpServer.clientCapabilities.pipe( @@ -1560,6 +1569,19 @@ describe("McpServer protocol adapters", () => { } })) + for (const protocolVersion of ["2024-11-05", "2025-03-26"] as const) { + it.effect(`should preserve referenced tool input definitions on ${protocolVersion}`, () => + Effect.gen(function*() { + const fixture = yield* makeFixture() + const client = yield* initialize(fixture.post, protocolVersion) + const tool = listedTools(yield* client.request("tools/list")).find((tool) => tool.name === "address") + + assert.isDefined(tool) + assert.deepNestedPropertyVal(tool.inputSchema, "properties.address", { $ref: "#/$defs/AddressEncoded" }) + assert.deepNestedPropertyVal(tool.inputSchema, "$defs.AddressEncoded.properties.street", { type: "string" }) + })) + } + it.effect("should omit June fields when projecting a March tool descriptor", () => Effect.gen(function*() { const fixture = yield* makeFixture()