v2 refactor!: remove Zod schema parameter from public-facing APIs#1606
Conversation
Remove the Zod result schema argument from Protocol.request(), BaseContext.mcpReq.send(), Client.callTool(), and ExperimentalServerTasks.requestStream(). The SDK now resolves the correct result schema internally based on the method name via a new getResultSchema() function. This simplifies the public API surface — callers no longer need to import and pass result schemas like CallToolResultSchema or ElicitResultSchema when making requests. BREAKING CHANGE: Protocol.request(), ctx.mcpReq.send(), Client.callTool(), and ExperimentalServerTasks.requestStream() no longer accept a schema parameter. Internal SDK methods use the new protected _requestWithSchema()/_requestStreamWithSchema() escape hatches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
Add type casts and narrowing in example files where code accesses result.content after client.request() or client.callTool(), since the return type is now a union that includes CreateTaskResult. Also fix formatting with prettier. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
v2 refactor!: remove Zod schema parameter from public-facing APIs
|
|
||
| console.log('Calling notification tool...'); | ||
| const result = await client.request(request, CallToolResultSchema); | ||
| const result = (await client.request(request)) as CallToolResult; |
There was a problem hiding this comment.
can we make this typing work natively or pass a generic to avoid the cast
There was a problem hiding this comment.
Believe this is because of tasks (as it returns Promise<CallToolResult | CreateTaskResult>) - we could fix this as part of the tasks refactor?
But also, in this specific scenario/example here, we could simply do .callTool() instead of .request
There was a problem hiding this comment.
Follow up PR
mattzcarey
left a comment
There was a problem hiding this comment.
question but non blocking
Remove the Zod result schema argument from Protocol.request(), BaseContext.mcpReq.send(), Client.callTool(), and
ExperimentalServerTasks.requestStream(). The SDK now resolves the correct result schema internally based on the method name via a new getResultSchema() function.
This simplifies the public API surface — callers no longer need to import and pass result schemas like CallToolResultSchema or ElicitResultSchema when making requests.
BREAKING CHANGE: Protocol.request(), ctx.mcpReq.send(), Client.callTool(), and ExperimentalServerTasks.requestStream() no longer accept a schema parameter. Internal SDK methods use the new protected _requestWithSchema()/_requestStreamWithSchema() escape hatches.
Motivation and Context
How Has This Been Tested?
Breaking Changes
Types of changes
Checklist
Additional context