@@ -40,12 +40,36 @@ 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+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
65+ const CallToolResultSchema_forward = z . union ( [
66+ CallToolUnstructuredResultSchema ,
67+ CallToolStructuredResultSchema_forward ,
68+ ] ) ;
69+
70+ type CallToolResult_forward = Infer < typeof CallToolResultSchema_forward > ;
71+
72+
4973/**
5074 * High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
5175 * For advanced usage (like sending notifications or setting custom request handlers), use the underlying
@@ -153,7 +177,7 @@ export class McpServer {
153177 ) ;
154178 }
155179
156- let result : CallToolResult ;
180+ let result : CallToolResult_forward ;
157181
158182 if ( tool . inputSchema ) {
159183 const parseResult = await tool . inputSchema . safeParseAsync (
@@ -236,7 +260,7 @@ export class McpServer {
236260 }
237261 }
238262
239- return result ;
263+ return result as CallToolResult ;
240264 } ,
241265 ) ;
242266
@@ -1009,8 +1033,8 @@ export type ToolCallback<Args extends undefined | ZodRawShape = undefined> =
10091033 ? (
10101034 args : z . objectOutputType < Args , ZodTypeAny > ,
10111035 extra : RequestHandlerExtra < ServerRequest , ServerNotification > ,
1012- ) => CallToolResult | Promise < CallToolResult >
1013- : ( extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => CallToolResult | Promise < CallToolResult > ;
1036+ ) => CallToolResult_forward | Promise < CallToolResult_forward >
1037+ : ( extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => CallToolResult_forward | Promise < CallToolResult_forward > ;
10141038
10151039export type RegisteredTool = {
10161040 description ?: string ;
0 commit comments