@@ -40,12 +40,35 @@ import {
4040 ServerRequest ,
4141 ServerNotification ,
4242 ToolAnnotations ,
43+ ResultSchema ,
44+ ContentListSchema ,
45+ CallToolUnstructuredResultSchema ,
46+ Infer ,
4347} from "../types.js" ;
4448import { Completable , CompletableDef } from "./completable.js" ;
4549import { UriTemplate , Variables } from "../shared/uriTemplate.js" ;
4650import { RequestHandlerExtra } from "../shared/protocol.js" ;
4751import { Transport } from "../shared/transport.js" ;
4852
53+ /**
54+ * In SDK versions 1.12 and forward, the `content` array will be optional for structured
55+ * tool call results. For convenience we use this type for defining tool callbacks on the
56+ * server side, but provide a backward-compatible schema for the client in 1.11.
57+ */
58+ const CallToolStructuredResultSchema_forward = ResultSchema . extend ( {
59+ structuredContent : z . object ( { } ) . passthrough ( ) ,
60+ content : z . optional ( ContentListSchema ) ,
61+ isError : z . optional ( z . boolean ( ) ) ,
62+ } ) ;
63+
64+ const CallToolResultSchema_forward = z . union ( [
65+ CallToolUnstructuredResultSchema ,
66+ CallToolStructuredResultSchema_forward ,
67+ ] ) ;
68+
69+ type CallToolResult_forward = Infer < typeof CallToolResultSchema_forward > ;
70+
71+
4972/**
5073 * High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
5174 * For advanced usage (like sending notifications or setting custom request handlers), use the underlying
@@ -153,7 +176,7 @@ export class McpServer {
153176 ) ;
154177 }
155178
156- let result : CallToolResult ;
179+ let result : CallToolResult_forward ;
157180
158181 if ( tool . inputSchema ) {
159182 const parseResult = await tool . inputSchema . safeParseAsync (
@@ -236,7 +259,7 @@ export class McpServer {
236259 }
237260 }
238261
239- return result ;
262+ return result as CallToolResult ;
240263 } ,
241264 ) ;
242265
@@ -1009,8 +1032,8 @@ export type ToolCallback<Args extends undefined | ZodRawShape = undefined> =
10091032 ? (
10101033 args : z . objectOutputType < Args , ZodTypeAny > ,
10111034 extra : RequestHandlerExtra < ServerRequest , ServerNotification > ,
1012- ) => CallToolResult | Promise < CallToolResult >
1013- : ( extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => CallToolResult | Promise < CallToolResult > ;
1035+ ) => CallToolResult_forward | Promise < CallToolResult_forward >
1036+ : ( extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => CallToolResult_forward | Promise < CallToolResult_forward > ;
10141037
10151038export type RegisteredTool = {
10161039 description ?: string ;
0 commit comments