@decocms/bindings 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
10
10
|
import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
11
11
|
import {
|
|
12
|
-
CallToolRequest,
|
|
13
12
|
Implementation,
|
|
14
13
|
ListToolsRequest,
|
|
15
14
|
ListToolsResult,
|
|
@@ -43,15 +42,15 @@ class Client extends BaseClient {
|
|
|
43
42
|
return result;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
type CallToolResponse = Awaited<ReturnType<Client["callTool"]>>;
|
|
47
45
|
export interface ServerClient {
|
|
48
46
|
client: {
|
|
49
|
-
callTool:
|
|
47
|
+
callTool: Client["callTool"];
|
|
50
48
|
listTools: () => Promise<ListToolsResult>;
|
|
51
49
|
};
|
|
52
50
|
callStreamableTool: (
|
|
53
51
|
tool: string,
|
|
54
52
|
args: Record<string, unknown>,
|
|
53
|
+
signal?: AbortSignal,
|
|
55
54
|
) => Promise<Response>;
|
|
56
55
|
}
|
|
57
56
|
export const createServerClient = async (
|
|
@@ -74,7 +73,7 @@ export const createServerClient = async (
|
|
|
74
73
|
|
|
75
74
|
return {
|
|
76
75
|
client,
|
|
77
|
-
callStreamableTool: (tool, args) => {
|
|
76
|
+
callStreamableTool: (tool, args, signal) => {
|
|
78
77
|
if (mcpServer.connection.type !== "HTTP") {
|
|
79
78
|
throw new Error("HTTP connection required");
|
|
80
79
|
}
|
|
@@ -101,6 +100,7 @@ export const createServerClient = async (
|
|
|
101
100
|
redirect: "manual",
|
|
102
101
|
body: JSON.stringify(args),
|
|
103
102
|
headers,
|
|
103
|
+
signal,
|
|
104
104
|
});
|
|
105
105
|
},
|
|
106
106
|
};
|
package/src/core/client/proxy.ts
CHANGED
|
@@ -67,8 +67,16 @@ export function createMCPClientProxy<T extends Record<string, unknown>>(
|
|
|
67
67
|
}
|
|
68
68
|
async function callToolFn(
|
|
69
69
|
args: Record<string, unknown>,
|
|
70
|
-
|
|
70
|
+
toolNameOrRequestInit?: string | symbol | RequestInit,
|
|
71
71
|
) {
|
|
72
|
+
let toolName: string | symbol;
|
|
73
|
+
let requestInit: RequestInit | undefined;
|
|
74
|
+
if (typeof toolNameOrRequestInit === "object") {
|
|
75
|
+
toolName = name;
|
|
76
|
+
requestInit = toolNameOrRequestInit;
|
|
77
|
+
} else {
|
|
78
|
+
toolName ??= name;
|
|
79
|
+
}
|
|
72
80
|
const debugId = options?.debugId?.();
|
|
73
81
|
const extraHeaders = debugId
|
|
74
82
|
? { "x-trace-debug-id": debugId }
|
|
@@ -77,13 +85,21 @@ export function createMCPClientProxy<T extends Record<string, unknown>>(
|
|
|
77
85
|
const { client, callStreamableTool } = await createClient(extraHeaders);
|
|
78
86
|
|
|
79
87
|
if (options?.streamable?.[String(toolName)]) {
|
|
80
|
-
return callStreamableTool(
|
|
88
|
+
return callStreamableTool(
|
|
89
|
+
String(toolName),
|
|
90
|
+
args,
|
|
91
|
+
requestInit?.signal ?? undefined,
|
|
92
|
+
);
|
|
81
93
|
}
|
|
82
94
|
|
|
83
|
-
const { structuredContent, isError, content } = await client.callTool(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
const { structuredContent, isError, content } = await client.callTool(
|
|
96
|
+
{
|
|
97
|
+
name: String(toolName),
|
|
98
|
+
arguments: args as Record<string, unknown>,
|
|
99
|
+
},
|
|
100
|
+
undefined,
|
|
101
|
+
{ signal: requestInit?.signal ?? undefined },
|
|
102
|
+
);
|
|
87
103
|
|
|
88
104
|
if (isError) {
|
|
89
105
|
const maybeErrorMessage = (content as { text: string }[])?.[0]?.text;
|