Skip to content

Commit dbd9945

Browse files
committed
call tool result reuse type, add tsdoc comments
1 parent 47f569e commit dbd9945

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/server/mcp.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,25 +1163,27 @@ export class ResourceTemplate {
11631163
* Parameters will include tool arguments, if applicable, as well as other request handler context.
11641164
*
11651165
* The callback should return:
1166-
* - `structuredContent` if the tool has an outputSchema defined
1167-
* - `content` if the tool does not have an outputSchema
1166+
* - `structuredContent` if the tool has an outputSchema defined.
1167+
* - `content` if the tool does not have an outputSchema OR if an outputSchema is defined, content *SHOULD* have the serialized JSON structuredContent in a text content for backwards compatibility
11681168
* - Both fields are optional but typically one should be provided
11691169
*/
11701170
export type ToolCallback<InputArgs extends undefined | ZodRawShape = undefined, OutputArgs extends undefined | ZodRawShape = undefined> =
11711171
InputArgs extends ZodRawShape
11721172
? (
11731173
args: z.objectOutputType<InputArgs, ZodTypeAny>,
11741174
extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
1175-
) => OutputArgs extends ZodRawShape
1176-
? CallToolResultStructured<OutputArgs> | Promise<CallToolResultStructured<OutputArgs>>
1177-
: OutputArgs extends undefined
1178-
? CallToolResultUnstructured | Promise<CallToolResultUnstructured>
1179-
: never
1180-
: (extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => OutputArgs extends ZodRawShape
1181-
? CallToolResultStructured<OutputArgs> | Promise<CallToolResultStructured<OutputArgs>>
1182-
: OutputArgs extends undefined
1183-
? CallToolResultUnstructured | Promise<CallToolResultUnstructured>
1184-
: never;
1175+
) => CallToolResultByOutputArgsType<OutputArgs>
1176+
: (extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => CallToolResultByOutputArgsType<OutputArgs>;
1177+
1178+
/**
1179+
* CallToolResult type generated based on OutputArgs.
1180+
*/
1181+
export type CallToolResultByOutputArgsType<OutputArgs extends undefined | ZodRawShape = undefined> =
1182+
OutputArgs extends ZodRawShape
1183+
? CallToolResultStructured<OutputArgs> | Promise<CallToolResultStructured<OutputArgs>>
1184+
: OutputArgs extends undefined
1185+
? CallToolResultUnstructured | Promise<CallToolResultUnstructured>
1186+
: never;
11851187

11861188
export type RegisteredTool = {
11871189
title?: string;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ export type ListToolsResult = Infer<typeof ListToolsResultSchema>;
16471647
export type CallToolResult = Infer<typeof CallToolResultSchema>;
16481648
export type CallToolResultUnstructured = Infer<typeof CallToolResultUnstructuredSchema>;
16491649
export type CallToolResultStructured<OArgs extends ZodRawShape> = Infer<typeof CallToolResultStructuredSchema> & {
1650-
structuredContent: z.infer<z.ZodObject<OArgs, 'strip'>>;
1650+
structuredContent: z.infer<z.ZodObject<OArgs>>;
16511651
}
16521652
export type CompatibilityCallToolResult = Infer<typeof CompatibilityCallToolResultSchema>;
16531653
export type CallToolRequest = Infer<typeof CallToolRequestSchema>;

0 commit comments

Comments
 (0)