Repository navigation
Description
What version of Effect is running?
main at ce9e99905 (checked source and wire output there). Node 24.20.0.
What steps can reproduce the bug?
A toolkit tool fails tools/call when its success value contains a field whose schema encoding is not JSON: a Schema.Void field, a Schema.Date field, or a Schema.optional field set to undefined.
import { Effect, Layer, Schema } from "effect"
import { McpProtocol, McpServer, Tool, Toolkit } from "effect/ai"
import { HttpRouter } from "effect/http"
const Kit = Toolkit.make(
Tool.make("VoidField", { success: Schema.Struct({ reply: Schema.Void, version: Schema.Number }) }),
Tool.make("DateField", { success: Schema.Struct({ at: Schema.Date }) }),
Tool.make("OptionalField", { success: Schema.Struct({ note: Schema.optional(Schema.String) }) })
)
const App = McpServer.toolkit(Kit).pipe(
Layer.provide(Kit.toLayer({
VoidField: () => Effect.succeed({ reply: undefined, version: 1 }),
DateField: () => Effect.succeed({ at: new Date(0) }),
OptionalField: () => Effect.succeed({ note: undefined })
})),
Layer.provideMerge(McpServer.layerHttp({
name: "repro",
version: "1.0.0",
path: "/mcp",
protocols: [McpProtocol.v2026_07_28]
}))
)
const { dispose, handler } = HttpRouter.toWebHandler(App, { disableLogger: true })
for (const name of ["VoidField", "DateField", "OptionalField"]) {
const response = await handler(
new Request("http://localhost/mcp", {
method: "POST",
headers: {
"content-type": "application/json",
accept: "application/json, text/event-stream",
"mcp-protocol-version": "2026-07-28",
"mcp-method": "tools/call",
"mcp-name": name
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name,
arguments: {},
_meta: {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": { name: "repro", version: "1.0.0" },
"io.modelcontextprotocol/clientCapabilities": {}
}
}
})
})
)
console.log(name, await response.text())
}
await dispose()What is the expected behavior?
Each call succeeds, and structuredContent has the JSON form that the tool's advertised outputSchema describes:
VoidField {"reply":null,"version":1}
DateField {"at":"1970-01-01T00:00:00.000Z"}
OptionalField {"note":null}
What do you see instead?
All three calls return:
{"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"Internal error"}}
The same happens on 2025-11-25 after initialize. A tool whose whole result is Schema.Void still works and returns content: [].
Additional information
registerToolkit sets structuredContent: result.encodedResult (packages/effect/src/ai/McpServer.ts:3126 on main). encodedResult comes from Schema.encodeUnknownEffect(tool.successSchema) (Toolkit.ts:527), which is the schema encoding, not the JSON encoding. It keeps undefined and Date values. When the RPC layer serializes the tools/call result with Schema.toCodecJson, structuredContent: Schema.optional(Schema.Unknown) rejects them:
Schema.encodeUnknownSync(Schema.toCodecJson(Schema.Struct({ structuredContent: Schema.optional(Schema.Unknown) })))(
{ structuredContent: { reply: undefined } }
)
// throws: Expected JSON value at ["structuredContent"]The advertised outputSchema is built from the JSON codec (toolJsonSchema). For Struct({ reply: Void, version: Number }) it lists reply: { type: "null" } as required. So even a value that serializes can contradict the schema, for example NaN, which the schema lists as the string "NaN".
Schema.encodeUnknownSync(Schema.toCodecJson(successSchema)) produces exactly the values listed above. Encoding the result with it would fix both problems.
Related: #7072 (a root void result), #7494 and #7495 (structuredContent only for objects), #6780 (outputSchema).
I have a fix with regression tests on both protocol revisions, and can open a PR.
Activity