Skip to content

Commit 1f3dbef

Browse files
committed
Support old tools/call result structure, if explicitly opted in
1 parent b618157 commit 1f3dbef

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/client/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ClientNotification,
77
ClientRequest,
88
ClientResult,
9+
CompatibilityCallToolResultSchema,
910
CompleteRequest,
1011
CompleteResultSchema,
1112
EmptyResultSchema,
@@ -218,11 +219,12 @@ export class Client<
218219

219220
async callTool(
220221
params: CallToolRequest["params"],
222+
resultSchema: typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema = CallToolResultSchema,
221223
onprogress?: ProgressCallback,
222224
) {
223225
return this.request(
224226
{ method: "tools/call", params },
225-
CallToolResultSchema,
227+
resultSchema,
226228
onprogress,
227229
);
228230
}

src/shared/protocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AnyZodObject, ZodLiteral, ZodObject, z } from "zod";
1+
import { ZodLiteral, ZodObject, ZodType, z } from "zod";
22
import {
33
ErrorCode,
44
JSONRPCError,
@@ -250,7 +250,7 @@ export class Protocol<
250250
*
251251
* Do not use this method to emit notifications! Use notification() instead.
252252
*/
253-
request<T extends AnyZodObject>(
253+
request<T extends ZodType<object>>(
254254
request: SendRequestT,
255255
resultSchema: T,
256256
onprogress?: ProgressCallback,

src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,13 @@ export const CallToolResultSchema = ResultSchema.extend({
722722
isError: z.boolean(),
723723
});
724724

725+
/**
726+
* CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07.
727+
*/
728+
export const CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
729+
toolResult: z.unknown(),
730+
}));
731+
725732
/**
726733
* Used by the client to invoke a tool provided by the server.
727734
*/
@@ -1054,6 +1061,7 @@ export const ServerResultSchema = z.union([
10541061
ListResourceTemplatesResultSchema,
10551062
ReadResourceResultSchema,
10561063
CallToolResultSchema,
1064+
CompatibilityCallToolResultSchema,
10571065
ListToolsResultSchema,
10581066
]);
10591067

@@ -1148,6 +1156,7 @@ export type Tool = z.infer<typeof ToolSchema>;
11481156
export type ListToolsRequest = z.infer<typeof ListToolsRequestSchema>;
11491157
export type ListToolsResult = z.infer<typeof ListToolsResultSchema>;
11501158
export type CallToolResult = z.infer<typeof CallToolResultSchema>;
1159+
export type CompatibilityCallToolResult = z.infer<typeof CompatibilityCallToolResultSchema>;
11511160
export type CallToolRequest = z.infer<typeof CallToolRequestSchema>;
11521161
export type ToolListChangedNotification = z.infer<
11531162
typeof ToolListChangedNotificationSchema

0 commit comments

Comments
 (0)