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
5 changes: 5 additions & 0 deletions .changeset/mcp-legacy-tool-input-defs.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions packages/effect/src/ai/internal/mcpSchema/v2024_11_05.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
22 changes: 22 additions & 0 deletions packages/effect/test/ai/McpServer/ProtocolAdapters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>("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
Expand Down Expand Up @@ -128,6 +135,7 @@ const TestToolkit = Toolkit.make(
StructuredOnlyTool,
UnionResultTool,
IdentifiedResultTool,
AddressTool,
ValidatedTool,
CapabilityTool,
InitializeMetadataTool,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
Loading