@decocms/bindings 0.2.4 → 1.0.0-test.1
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/README.md +3 -3
- package/package.json +9 -35
- package/src/core/binder.ts +241 -0
- package/src/core/client/README.md +3 -0
- package/{dist/core/client/http-client-transport.js → src/core/client/http-client-transport.ts} +24 -12
- package/src/core/client/index.ts +1 -0
- package/src/core/client/mcp-client.ts +149 -0
- package/src/core/client/mcp.ts +93 -0
- package/src/core/client/proxy.ts +151 -0
- package/src/core/connection.ts +38 -0
- package/src/core/subset.ts +514 -0
- package/src/index.ts +15 -0
- package/src/well-known/agent.ts +60 -0
- package/src/well-known/collections.ts +416 -0
- package/src/well-known/language-model.ts +383 -0
- package/test/index.test.ts +942 -0
- package/tsconfig.json +11 -0
- package/vitest.config.ts +8 -0
- package/dist/core/binder.d.ts +0 -3
- package/dist/core/binder.js +0 -77
- package/dist/core/binder.js.map +0 -1
- package/dist/core/client/http-client-transport.d.ts +0 -12
- package/dist/core/client/http-client-transport.js.map +0 -1
- package/dist/core/client/index.d.ts +0 -3
- package/dist/core/client/index.js +0 -5
- package/dist/core/client/index.js.map +0 -1
- package/dist/core/client/mcp-client.d.ts +0 -233
- package/dist/core/client/mcp-client.js +0 -99
- package/dist/core/client/mcp-client.js.map +0 -1
- package/dist/core/client/mcp.d.ts +0 -3
- package/dist/core/client/mcp.js +0 -29
- package/dist/core/client/mcp.js.map +0 -1
- package/dist/core/client/proxy.d.ts +0 -10
- package/dist/core/client/proxy.js +0 -104
- package/dist/core/client/proxy.js.map +0 -1
- package/dist/core/connection.d.ts +0 -30
- package/dist/core/connection.js +0 -1
- package/dist/core/connection.js.map +0 -1
- package/dist/core/subset.d.ts +0 -17
- package/dist/core/subset.js +0 -319
- package/dist/core/subset.js.map +0 -1
- package/dist/index-D0aUdNls.d.ts +0 -153
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/well-known/agent.d.ts +0 -903
- package/dist/well-known/agent.js +0 -27
- package/dist/well-known/agent.js.map +0 -1
- package/dist/well-known/collections.d.ts +0 -537
- package/dist/well-known/collections.js +0 -134
- package/dist/well-known/collections.js.map +0 -1
- package/dist/well-known/language-model.d.ts +0 -2836
- package/dist/well-known/language-model.js +0 -209
- package/dist/well-known/language-model.js.map +0 -1
package/tsconfig.json
ADDED
package/vitest.config.ts
ADDED
package/dist/core/binder.d.ts
DELETED
package/dist/core/binder.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
-
import { createMCPFetchStub } from "./client/mcp";
|
|
3
|
-
import { isSubset } from "./subset";
|
|
4
|
-
function isZodSchema(value) {
|
|
5
|
-
return value !== null && typeof value === "object" && "_def" in value && typeof value._def === "object";
|
|
6
|
-
}
|
|
7
|
-
function normalizeToJsonSchema(schema) {
|
|
8
|
-
if (schema == null) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
if (isZodSchema(schema)) {
|
|
12
|
-
return zodToJsonSchema(schema);
|
|
13
|
-
}
|
|
14
|
-
return schema;
|
|
15
|
-
}
|
|
16
|
-
const bindingClient = (binder) => {
|
|
17
|
-
return {
|
|
18
|
-
...createBindingChecker(binder),
|
|
19
|
-
forConnection: (mcpConnection) => {
|
|
20
|
-
return createMCPFetchStub({
|
|
21
|
-
connection: mcpConnection,
|
|
22
|
-
streamable: binder.reduce(
|
|
23
|
-
(acc, tool) => {
|
|
24
|
-
acc[tool.name] = tool.streamable === true;
|
|
25
|
-
return acc;
|
|
26
|
-
},
|
|
27
|
-
{}
|
|
28
|
-
)
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
function createBindingChecker(binderTools) {
|
|
34
|
-
return {
|
|
35
|
-
isImplementedBy: (tools) => {
|
|
36
|
-
for (const binderTool of binderTools) {
|
|
37
|
-
const pattern = typeof binderTool.name === "string" ? new RegExp(`^${binderTool.name}$`) : binderTool.name;
|
|
38
|
-
const matchedTool = tools.find((t) => pattern.test(t.name));
|
|
39
|
-
if (!matchedTool && binderTool.opt) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (!matchedTool) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const binderInputSchema = normalizeToJsonSchema(binderTool.inputSchema);
|
|
46
|
-
const toolInputSchema = normalizeToJsonSchema(matchedTool.inputSchema);
|
|
47
|
-
if (binderInputSchema && toolInputSchema) {
|
|
48
|
-
if (!isSubset(binderInputSchema, toolInputSchema)) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
} else if (binderInputSchema && !toolInputSchema) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
const binderOutputSchema = normalizeToJsonSchema(
|
|
55
|
-
binderTool.outputSchema
|
|
56
|
-
);
|
|
57
|
-
const toolOutputSchema = normalizeToJsonSchema(
|
|
58
|
-
matchedTool.outputSchema
|
|
59
|
-
);
|
|
60
|
-
if (binderOutputSchema && toolOutputSchema) {
|
|
61
|
-
if (!isSubset(binderOutputSchema, toolOutputSchema)) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
} else if (binderOutputSchema && !toolOutputSchema) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
export {
|
|
73
|
-
bindingClient,
|
|
74
|
-
createBindingChecker,
|
|
75
|
-
normalizeToJsonSchema
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=binder.js.map
|
package/dist/core/binder.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/binder.ts"],"sourcesContent":["/**\n * Core Binder Types and Utilities\n *\n * This module provides the core types and utilities for the bindings system.\n * Bindings define standardized interfaces that integrations (MCPs) can implement.\n */\n\nimport type { ZodType } from \"zod/v3\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { createMCPFetchStub, MCPClientFetchStub } from \"./client/mcp\";\nimport { MCPConnection } from \"./connection\";\nimport { isSubset } from \"./subset\";\n\ntype JsonSchema = Record<string, unknown>;\n\n/**\n * Checks if a value is a Zod schema by looking for the _def property\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isZodSchema(value: unknown): value is ZodType<any> {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"_def\" in value &&\n typeof (value as Record<string, unknown>)._def === \"object\"\n );\n}\n\n/**\n * Normalizes a schema to JSON Schema format.\n * Accepts either a Zod schema or a JSON schema and returns a JSON schema.\n *\n * @param schema - A Zod schema or JSON schema\n * @returns The JSON schema representation, or null if input is null/undefined\n */\nexport function normalizeToJsonSchema(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: ZodType<any> | JsonSchema | null | undefined,\n): JsonSchema | null {\n if (schema == null) {\n return null;\n }\n\n if (isZodSchema(schema)) {\n return zodToJsonSchema(schema) as JsonSchema;\n }\n\n // Already a JSON schema\n return schema as JsonSchema;\n}\n\n/**\n * ToolBinder defines a single tool within a binding.\n * It specifies the tool name, input/output schemas, and whether it's optional.\n *\n * @template TName - The tool name (can be a string or RegExp for pattern matching)\n * @template TInput - The input type (inferred from inputSchema)\n * @template TReturn - The return type (inferred from outputSchema)\n */\nexport interface ToolBinder<\n TName extends string | RegExp = string,\n // biome-ignore lint/suspicious/noExplicitAny: Generic type parameter\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TInput = any,\n TReturn extends object | null | boolean = object,\n TStreamable extends boolean = boolean,\n> {\n /** The name of the tool (e.g., \"DECO_CHAT_CHANNELS_JOIN\") */\n name: TName;\n\n /** Zod schema for validating tool input */\n inputSchema: ZodType<TInput>;\n\n /** Optional Zod schema for validating tool output */\n outputSchema?: TStreamable extends true ? never : ZodType<TReturn>;\n\n /**\n * Whether this tool is streamable.\n */\n streamable?: TStreamable;\n\n /**\n * Whether this tool is optional in the binding.\n * If true, an implementation doesn't need to provide this tool.\n */\n opt?: true;\n}\n\n/**\n * Binder represents a collection of tool definitions that form a binding.\n * A binding is like a TypeScript interface - it defines what tools must be implemented.\n *\n * @template TDefinition - Array of ToolBinder definitions\n *\n * @example\n * ```ts\n * const MY_BINDING = [{\n * name: \"MY_TOOL\" as const,\n * inputSchema: z.object({ id: z.string() }),\n * outputSchema: z.object({ success: z.boolean() }),\n * }] as const satisfies Binder;\n * ```\n */\nexport type Binder<\n TDefinition extends readonly ToolBinder[] = readonly ToolBinder[],\n> = TDefinition;\n\n/**\n * Tool with schemas for validation\n */\nexport interface ToolWithSchemas {\n name: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputSchema?: ZodType<any> | Record<string, unknown>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputSchema?: ZodType<any> | Record<string, unknown>;\n}\n\n/**\n * Binding checker interface\n */\nexport interface BindingChecker {\n /**\n * Check if a set of tools implements the binding with full schema validation.\n *\n * Validates:\n * - Tool name matches (exact or regex)\n * - Input schema: Tool accepts what binder requires (no removals from binder to tool)\n * - Output schema: Tool provides what binder expects (no removals from tool to binder)\n *\n * @param tools - Array of tools with names and schemas\n * @returns Promise<boolean> - true if all tools implement the binding correctly\n */\n isImplementedBy: (tools: ToolWithSchemas[]) => boolean;\n}\n\nexport const bindingClient = <TDefinition extends readonly ToolBinder[]>(\n binder: TDefinition,\n) => {\n return {\n ...createBindingChecker(binder),\n forConnection: (\n mcpConnection: MCPConnection,\n ): MCPClientFetchStub<TDefinition> => {\n return createMCPFetchStub<TDefinition>({\n connection: mcpConnection,\n streamable: binder.reduce(\n (acc, tool) => {\n acc[tool.name] = tool.streamable === true;\n return acc;\n },\n {} as Record<string, boolean>,\n ),\n });\n },\n };\n};\n\nexport type MCPBindingClient<T extends ReturnType<typeof bindingClient>> =\n ReturnType<T[\"forConnection\"]>;\n\n/**\n * Creates a binding checker with full schema validation using structural subset checking.\n *\n * This performs strict compatibility checking:\n * - For input schemas: Validates that the tool can accept what the binder requires (binder ⊆ tool)\n * - For output schemas: Validates that the tool provides what the binder expects (binder ⊆ tool)\n *\n * @param binderTools - The binding definition to check against\n * @returns A binding checker with an async isImplementedBy method\n *\n * @example\n * ```ts\n * const checker = createBindingChecker(MY_BINDING);\n * const isCompatible = await checker.isImplementedBy(availableTools);\n * ```\n */\nexport function createBindingChecker<TDefinition extends readonly ToolBinder[]>(\n binderTools: TDefinition,\n): BindingChecker {\n return {\n isImplementedBy: (tools: ToolWithSchemas[]): boolean => {\n for (const binderTool of binderTools) {\n // Find matching tool by name (exact or regex)\n const pattern =\n typeof binderTool.name === \"string\"\n ? new RegExp(`^${binderTool.name}$`)\n : binderTool.name;\n\n const matchedTool = tools.find((t) => pattern.test(t.name));\n\n // Skip optional tools that aren't present\n if (!matchedTool && binderTool.opt) {\n continue;\n }\n\n // Required tool not found\n if (!matchedTool) {\n return false;\n }\n\n // === INPUT SCHEMA VALIDATION ===\n // Tool must accept what binder requires\n // Check: isSubset(binder, tool) - every value valid under binder is valid under tool\n const binderInputSchema = normalizeToJsonSchema(binderTool.inputSchema);\n const toolInputSchema = normalizeToJsonSchema(matchedTool.inputSchema);\n\n if (binderInputSchema && toolInputSchema) {\n // Check if binder input is a subset of tool input (tool accepts what binder requires)\n if (!isSubset(binderInputSchema, toolInputSchema)) {\n return false;\n }\n } else if (binderInputSchema && !toolInputSchema) {\n // Binder requires input schema but tool doesn't have one\n return false;\n }\n\n // === OUTPUT SCHEMA VALIDATION ===\n // Tool must provide what binder expects (but can provide more)\n // Check: isSubset(binder, tool) - tool provides at least what binder expects\n const binderOutputSchema = normalizeToJsonSchema(\n binderTool.outputSchema,\n );\n const toolOutputSchema = normalizeToJsonSchema(\n matchedTool.outputSchema,\n );\n\n if (binderOutputSchema && toolOutputSchema) {\n // Check if binder output is a subset of tool output (tool provides what binder expects)\n if (!isSubset(binderOutputSchema, toolOutputSchema)) {\n return false;\n }\n } else if (binderOutputSchema && !toolOutputSchema) {\n // Binder expects output schema but tool doesn't have one\n return false;\n }\n }\n return true;\n },\n };\n}\n"],"mappings":"AAQA,SAAS,uBAAuB;AAChC,SAAS,0BAA8C;AAEvD,SAAS,gBAAgB;AAQzB,SAAS,YAAY,OAAuC;AAC1D,SACE,UAAU,QACV,OAAO,UAAU,YACjB,UAAU,SACV,OAAQ,MAAkC,SAAS;AAEvD;AASO,SAAS,sBAEd,QACmB;AACnB,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,MAAM,GAAG;AACvB,WAAO,gBAAgB,MAAM;AAAA,EAC/B;AAGA,SAAO;AACT;AAuFO,MAAM,gBAAgB,CAC3B,WACG;AACH,SAAO;AAAA,IACL,GAAG,qBAAqB,MAAM;AAAA,IAC9B,eAAe,CACb,kBACoC;AACpC,aAAO,mBAAgC;AAAA,QACrC,YAAY;AAAA,QACZ,YAAY,OAAO;AAAA,UACjB,CAAC,KAAK,SAAS;AACb,gBAAI,KAAK,IAAI,IAAI,KAAK,eAAe;AACrC,mBAAO;AAAA,UACT;AAAA,UACA,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAqBO,SAAS,qBACd,aACgB;AAChB,SAAO;AAAA,IACL,iBAAiB,CAAC,UAAsC;AACtD,iBAAW,cAAc,aAAa;AAEpC,cAAM,UACJ,OAAO,WAAW,SAAS,WACvB,IAAI,OAAO,IAAI,WAAW,IAAI,GAAG,IACjC,WAAW;AAEjB,cAAM,cAAc,MAAM,KAAK,CAAC,MAAM,QAAQ,KAAK,EAAE,IAAI,CAAC;AAG1D,YAAI,CAAC,eAAe,WAAW,KAAK;AAClC;AAAA,QACF;AAGA,YAAI,CAAC,aAAa;AAChB,iBAAO;AAAA,QACT;AAKA,cAAM,oBAAoB,sBAAsB,WAAW,WAAW;AACtE,cAAM,kBAAkB,sBAAsB,YAAY,WAAW;AAErE,YAAI,qBAAqB,iBAAiB;AAExC,cAAI,CAAC,SAAS,mBAAmB,eAAe,GAAG;AACjD,mBAAO;AAAA,UACT;AAAA,QACF,WAAW,qBAAqB,CAAC,iBAAiB;AAEhD,iBAAO;AAAA,QACT;AAKA,cAAM,qBAAqB;AAAA,UACzB,WAAW;AAAA,QACb;AACA,cAAM,mBAAmB;AAAA,UACvB,YAAY;AAAA,QACd;AAEA,YAAI,sBAAsB,kBAAkB;AAE1C,cAAI,CAAC,SAAS,oBAAoB,gBAAgB,GAAG;AACnD,mBAAO;AAAA,UACT;AAAA,QACF,WAAW,sBAAsB,CAAC,kBAAkB;AAElD,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
3
|
-
|
|
4
|
-
declare class HTTPClientTransport extends StreamableHTTPClientTransport {
|
|
5
|
-
constructor(url: URL, opts?: StreamableHTTPClientTransportOptions);
|
|
6
|
-
send(message: JSONRPCMessage, options?: {
|
|
7
|
-
resumptionToken?: string;
|
|
8
|
-
onresumptiontoken?: (token: string) => void;
|
|
9
|
-
}): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { HTTPClientTransport };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/client/http-client-transport.ts"],"sourcesContent":["import type { JSONRPCMessage } from \"@modelcontextprotocol/sdk/types.js\";\nimport {\n StreamableHTTPClientTransport,\n type StreamableHTTPClientTransportOptions,\n} from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\n\nexport class HTTPClientTransport extends StreamableHTTPClientTransport {\n constructor(url: URL, opts?: StreamableHTTPClientTransportOptions) {\n super(url, opts);\n }\n\n override send(\n message: JSONRPCMessage,\n options?: {\n resumptionToken?: string;\n onresumptiontoken?: (token: string) => void;\n },\n ): Promise<void> {\n const mockAction = getMockActionFor(message);\n if (mockAction?.type === \"emit\") {\n this.onmessage?.(mockAction.message);\n return Promise.resolve();\n }\n if (mockAction?.type === \"suppress\") {\n return Promise.resolve();\n }\n return super.send(message, options);\n }\n}\n\ntype MockAction =\n | { type: \"emit\"; message: JSONRPCMessage }\n | { type: \"suppress\" };\n\nfunction getMockActionFor(message: JSONRPCMessage): MockAction | null {\n const m = message;\n if (!m || typeof m !== \"object\" || !(\"method\" in m)) return null;\n\n switch (m.method) {\n case \"initialize\": {\n const protocolVersion = m?.params?.protocolVersion;\n if (!protocolVersion) return null;\n return {\n type: \"emit\",\n message: {\n result: {\n protocolVersion,\n capabilities: { tools: {} },\n serverInfo: { name: \"deco-chat-server\", version: \"1.0.0\" },\n },\n jsonrpc: m.jsonrpc ?? \"2.0\",\n // @ts-expect-error - id is not typed\n id: m.id,\n } as JSONRPCMessage,\n };\n }\n case \"notifications/roots/list_changed\":\n case \"notifications/initialized\":\n case \"notifications/cancelled\":\n case \"notifications/progress\": {\n return { type: \"suppress\" };\n }\n default:\n return null;\n }\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,OAEK;AAEA,MAAM,4BAA4B,8BAA8B;AAAA,EACrE,YAAY,KAAU,MAA6C;AACjE,UAAM,KAAK,IAAI;AAAA,EACjB;AAAA,EAES,KACP,SACA,SAIe;AACf,UAAM,aAAa,iBAAiB,OAAO;AAC3C,QAAI,YAAY,SAAS,QAAQ;AAC/B,WAAK,YAAY,WAAW,OAAO;AACnC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AACA,QAAI,YAAY,SAAS,YAAY;AACnC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AACA,WAAO,MAAM,KAAK,SAAS,OAAO;AAAA,EACpC;AACF;AAMA,SAAS,iBAAiB,SAA4C;AACpE,QAAM,IAAI;AACV,MAAI,CAAC,KAAK,OAAO,MAAM,YAAY,EAAE,YAAY,GAAI,QAAO;AAE5D,UAAQ,EAAE,QAAQ;AAAA,IAChB,KAAK,cAAc;AACjB,YAAM,kBAAkB,GAAG,QAAQ;AACnC,UAAI,CAAC,gBAAiB,QAAO;AAC7B,aAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS;AAAA,UACP,QAAQ;AAAA,YACN;AAAA,YACA,cAAc,EAAE,OAAO,CAAC,EAAE;AAAA,YAC1B,YAAY,EAAE,MAAM,oBAAoB,SAAS,QAAQ;AAAA,UAC3D;AAAA,UACA,SAAS,EAAE,WAAW;AAAA;AAAA,UAEtB,IAAI,EAAE;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,0BAA0B;AAC7B,aAAO,EAAE,MAAM,WAAW;AAAA,IAC5B;AAAA,IACA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/client/index.ts"],"sourcesContent":["export { HTTPClientTransport } from \"./http-client-transport\";\n"],"mappings":"AAAA,SAAS,2BAA2B;","names":[]}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import * as zod from 'zod';
|
|
2
|
-
import { Client as Client$1, ClientOptions } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
4
|
-
import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js';
|
|
5
|
-
import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
6
|
-
import { Implementation, ListToolsRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
-
import { MCPConnection } from '../connection.js';
|
|
8
|
-
import { HTTPClientTransport } from './http-client-transport.js';
|
|
9
|
-
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* WARNNING: This is a hack to prevent schema compilation errors.
|
|
13
|
-
* More info at: https://github.com/modelcontextprotocol/typescript-sdk/issues/923
|
|
14
|
-
*
|
|
15
|
-
* Make sure to keep this updated with the right version of the SDK.
|
|
16
|
-
* https://github.com/modelcontextprotocol/typescript-sdk/blob/bf817939917277a4c59f2e19e7b44b8dd7ff140c/src/client/index.ts#L480
|
|
17
|
-
*/
|
|
18
|
-
declare class Client extends Client$1 {
|
|
19
|
-
constructor(_clientInfo: Implementation, options?: ClientOptions);
|
|
20
|
-
listTools(params?: ListToolsRequest["params"], options?: RequestOptions): Promise<zod.objectOutputType<{
|
|
21
|
-
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
22
|
-
} & {
|
|
23
|
-
nextCursor: zod.ZodOptional<zod.ZodString>;
|
|
24
|
-
} & {
|
|
25
|
-
tools: zod.ZodArray<zod.ZodObject<zod.objectUtil.extendShape<zod.objectUtil.extendShape<{
|
|
26
|
-
name: zod.ZodString;
|
|
27
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
28
|
-
}, {
|
|
29
|
-
description: zod.ZodOptional<zod.ZodString>;
|
|
30
|
-
inputSchema: zod.ZodObject<{
|
|
31
|
-
type: zod.ZodLiteral<"object">;
|
|
32
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
33
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
34
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
35
|
-
type: zod.ZodLiteral<"object">;
|
|
36
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
37
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
38
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
39
|
-
type: zod.ZodLiteral<"object">;
|
|
40
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
41
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
42
|
-
}, zod.ZodTypeAny, "passthrough">>;
|
|
43
|
-
outputSchema: zod.ZodOptional<zod.ZodObject<{
|
|
44
|
-
type: zod.ZodLiteral<"object">;
|
|
45
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
46
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
47
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
48
|
-
type: zod.ZodLiteral<"object">;
|
|
49
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
50
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
51
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
52
|
-
type: zod.ZodLiteral<"object">;
|
|
53
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
54
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
55
|
-
}, zod.ZodTypeAny, "passthrough">>>;
|
|
56
|
-
annotations: zod.ZodOptional<zod.ZodObject<{
|
|
57
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
58
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
59
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
60
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
61
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
62
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
63
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
64
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
65
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
66
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
67
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
68
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
69
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
70
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
71
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
72
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
73
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
74
|
-
}, zod.ZodTypeAny, "passthrough">>>;
|
|
75
|
-
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
76
|
-
}>, {
|
|
77
|
-
icons: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
|
|
78
|
-
src: zod.ZodString;
|
|
79
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
80
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
81
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
82
|
-
src: zod.ZodString;
|
|
83
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
84
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
85
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
86
|
-
src: zod.ZodString;
|
|
87
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
88
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
89
|
-
}, zod.ZodTypeAny, "passthrough">>, "many">>;
|
|
90
|
-
}>, "passthrough", zod.ZodTypeAny, zod.objectOutputType<zod.objectUtil.extendShape<zod.objectUtil.extendShape<{
|
|
91
|
-
name: zod.ZodString;
|
|
92
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
93
|
-
}, {
|
|
94
|
-
description: zod.ZodOptional<zod.ZodString>;
|
|
95
|
-
inputSchema: zod.ZodObject<{
|
|
96
|
-
type: zod.ZodLiteral<"object">;
|
|
97
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
98
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
99
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
100
|
-
type: zod.ZodLiteral<"object">;
|
|
101
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
102
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
103
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
104
|
-
type: zod.ZodLiteral<"object">;
|
|
105
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
106
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
107
|
-
}, zod.ZodTypeAny, "passthrough">>;
|
|
108
|
-
outputSchema: zod.ZodOptional<zod.ZodObject<{
|
|
109
|
-
type: zod.ZodLiteral<"object">;
|
|
110
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
111
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
112
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
113
|
-
type: zod.ZodLiteral<"object">;
|
|
114
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
115
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
116
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
117
|
-
type: zod.ZodLiteral<"object">;
|
|
118
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
119
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
120
|
-
}, zod.ZodTypeAny, "passthrough">>>;
|
|
121
|
-
annotations: zod.ZodOptional<zod.ZodObject<{
|
|
122
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
123
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
124
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
125
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
126
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
127
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
128
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
129
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
130
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
131
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
132
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
133
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
134
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
135
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
136
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
137
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
138
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
139
|
-
}, zod.ZodTypeAny, "passthrough">>>;
|
|
140
|
-
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
141
|
-
}>, {
|
|
142
|
-
icons: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
|
|
143
|
-
src: zod.ZodString;
|
|
144
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
145
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
146
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
147
|
-
src: zod.ZodString;
|
|
148
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
149
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
150
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
151
|
-
src: zod.ZodString;
|
|
152
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
153
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
154
|
-
}, zod.ZodTypeAny, "passthrough">>, "many">>;
|
|
155
|
-
}>, zod.ZodTypeAny, "passthrough">, zod.objectInputType<zod.objectUtil.extendShape<zod.objectUtil.extendShape<{
|
|
156
|
-
name: zod.ZodString;
|
|
157
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
158
|
-
}, {
|
|
159
|
-
description: zod.ZodOptional<zod.ZodString>;
|
|
160
|
-
inputSchema: zod.ZodObject<{
|
|
161
|
-
type: zod.ZodLiteral<"object">;
|
|
162
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
163
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
164
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
165
|
-
type: zod.ZodLiteral<"object">;
|
|
166
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
167
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
168
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
169
|
-
type: zod.ZodLiteral<"object">;
|
|
170
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
171
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
172
|
-
}, zod.ZodTypeAny, "passthrough">>;
|
|
173
|
-
outputSchema: zod.ZodOptional<zod.ZodObject<{
|
|
174
|
-
type: zod.ZodLiteral<"object">;
|
|
175
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
176
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
177
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
178
|
-
type: zod.ZodLiteral<"object">;
|
|
179
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
180
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
181
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
182
|
-
type: zod.ZodLiteral<"object">;
|
|
183
|
-
properties: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
184
|
-
required: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
185
|
-
}, zod.ZodTypeAny, "passthrough">>>;
|
|
186
|
-
annotations: zod.ZodOptional<zod.ZodObject<{
|
|
187
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
188
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
189
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
190
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
191
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
192
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
193
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
194
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
195
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
196
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
197
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
198
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
199
|
-
title: zod.ZodOptional<zod.ZodString>;
|
|
200
|
-
readOnlyHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
201
|
-
destructiveHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
202
|
-
idempotentHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
203
|
-
openWorldHint: zod.ZodOptional<zod.ZodBoolean>;
|
|
204
|
-
}, zod.ZodTypeAny, "passthrough">>>;
|
|
205
|
-
_meta: zod.ZodOptional<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
206
|
-
}>, {
|
|
207
|
-
icons: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
|
|
208
|
-
src: zod.ZodString;
|
|
209
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
210
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
211
|
-
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
212
|
-
src: zod.ZodString;
|
|
213
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
214
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
215
|
-
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
216
|
-
src: zod.ZodString;
|
|
217
|
-
mimeType: zod.ZodOptional<zod.ZodString>;
|
|
218
|
-
sizes: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
219
|
-
}, zod.ZodTypeAny, "passthrough">>, "many">>;
|
|
220
|
-
}>, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
221
|
-
}, zod.ZodTypeAny, "passthrough">>;
|
|
222
|
-
}
|
|
223
|
-
interface ServerClient {
|
|
224
|
-
client: Client;
|
|
225
|
-
callStreamableTool: (tool: string, args: unknown) => Promise<Response>;
|
|
226
|
-
}
|
|
227
|
-
declare const createServerClient: (mcpServer: {
|
|
228
|
-
connection: MCPConnection;
|
|
229
|
-
name?: string;
|
|
230
|
-
}, signal?: AbortSignal, extraHeaders?: Record<string, string>) => Promise<ServerClient>;
|
|
231
|
-
declare const createTransport: (connection: MCPConnection, signal?: AbortSignal, extraHeaders?: Record<string, string>) => HTTPClientTransport | WebSocketClientTransport | SSEClientTransport | null;
|
|
232
|
-
|
|
233
|
-
export { type ServerClient, createServerClient, createTransport };
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Client as BaseClient
|
|
3
|
-
} from "@modelcontextprotocol/sdk/client/index.js";
|
|
4
|
-
import {
|
|
5
|
-
SSEClientTransport
|
|
6
|
-
} from "@modelcontextprotocol/sdk/client/sse.js";
|
|
7
|
-
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
8
|
-
import {
|
|
9
|
-
ListToolsResultSchema
|
|
10
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
-
import { HTTPClientTransport } from "./http-client-transport";
|
|
12
|
-
class Client extends BaseClient {
|
|
13
|
-
constructor(_clientInfo, options) {
|
|
14
|
-
super(_clientInfo, options);
|
|
15
|
-
}
|
|
16
|
-
async listTools(params, options) {
|
|
17
|
-
const result = await this.request(
|
|
18
|
-
{ method: "tools/list", params },
|
|
19
|
-
ListToolsResultSchema,
|
|
20
|
-
options
|
|
21
|
-
);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const createServerClient = async (mcpServer, signal, extraHeaders) => {
|
|
26
|
-
const transport = createTransport(mcpServer.connection, signal, extraHeaders);
|
|
27
|
-
if (!transport) {
|
|
28
|
-
throw new Error("Unknown MCP connection type");
|
|
29
|
-
}
|
|
30
|
-
const client = new Client({
|
|
31
|
-
name: mcpServer?.name ?? "MCP Client",
|
|
32
|
-
version: "1.0.0"
|
|
33
|
-
});
|
|
34
|
-
await client.connect(transport);
|
|
35
|
-
return {
|
|
36
|
-
client,
|
|
37
|
-
callStreamableTool: (tool, args) => {
|
|
38
|
-
if (mcpServer.connection.type !== "HTTP") {
|
|
39
|
-
throw new Error("HTTP connection required");
|
|
40
|
-
}
|
|
41
|
-
return fetch(mcpServer.connection.url + `/call-tool/${tool}`, {
|
|
42
|
-
method: "POST",
|
|
43
|
-
redirect: "manual",
|
|
44
|
-
body: JSON.stringify(args),
|
|
45
|
-
headers: {
|
|
46
|
-
...extraHeaders,
|
|
47
|
-
Authorization: `Bearer ${mcpServer.connection.token}`
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
const createTransport = (connection, signal, extraHeaders) => {
|
|
54
|
-
if (connection.type === "Websocket") {
|
|
55
|
-
return new WebSocketClientTransport(new URL(connection.url));
|
|
56
|
-
}
|
|
57
|
-
if (connection.type !== "SSE" && connection.type !== "HTTP") {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const authHeaders = connection.token ? { authorization: `Bearer ${connection.token}` } : {};
|
|
61
|
-
const headers = {
|
|
62
|
-
...authHeaders,
|
|
63
|
-
...extraHeaders ?? {},
|
|
64
|
-
..."headers" in connection ? connection.headers || {} : {}
|
|
65
|
-
};
|
|
66
|
-
if (connection.type === "SSE") {
|
|
67
|
-
const config = {
|
|
68
|
-
requestInit: { headers, signal }
|
|
69
|
-
};
|
|
70
|
-
if (connection.token) {
|
|
71
|
-
config.eventSourceInit = {
|
|
72
|
-
fetch: (req, init) => {
|
|
73
|
-
return fetch(req, {
|
|
74
|
-
...init,
|
|
75
|
-
headers: {
|
|
76
|
-
...headers,
|
|
77
|
-
Accept: "text/event-stream"
|
|
78
|
-
},
|
|
79
|
-
signal
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return new SSEClientTransport(new URL(connection.url), config);
|
|
85
|
-
}
|
|
86
|
-
return new HTTPClientTransport(new URL(connection.url), {
|
|
87
|
-
requestInit: {
|
|
88
|
-
headers,
|
|
89
|
-
signal,
|
|
90
|
-
// @ts-ignore - this is a valid option for fetch
|
|
91
|
-
credentials: "include"
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
export {
|
|
96
|
-
createServerClient,
|
|
97
|
-
createTransport
|
|
98
|
-
};
|
|
99
|
-
//# sourceMappingURL=mcp-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/client/mcp-client.ts"],"sourcesContent":["import {\n Client as BaseClient,\n ClientOptions,\n} from \"@modelcontextprotocol/sdk/client/index.js\";\nimport {\n SSEClientTransport,\n SSEClientTransportOptions,\n} from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { WebSocketClientTransport } from \"@modelcontextprotocol/sdk/client/websocket.js\";\nimport { RequestOptions } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport {\n Implementation,\n ListToolsRequest,\n ListToolsResultSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { MCPConnection } from \"../connection\";\nimport { HTTPClientTransport } from \"./http-client-transport\";\n\n/**\n * WARNNING: This is a hack to prevent schema compilation errors.\n * More info at: https://github.com/modelcontextprotocol/typescript-sdk/issues/923\n *\n * Make sure to keep this updated with the right version of the SDK.\n * https://github.com/modelcontextprotocol/typescript-sdk/blob/bf817939917277a4c59f2e19e7b44b8dd7ff140c/src/client/index.ts#L480\n */\nclass Client extends BaseClient {\n constructor(_clientInfo: Implementation, options?: ClientOptions) {\n super(_clientInfo, options);\n }\n\n override async listTools(\n params?: ListToolsRequest[\"params\"],\n options?: RequestOptions,\n ) {\n const result = await this.request(\n { method: \"tools/list\", params },\n ListToolsResultSchema,\n options,\n );\n\n return result;\n }\n}\n\nexport interface ServerClient {\n client: Client;\n callStreamableTool: (tool: string, args: unknown) => Promise<Response>;\n}\nexport const createServerClient = async (\n mcpServer: { connection: MCPConnection; name?: string },\n signal?: AbortSignal,\n extraHeaders?: Record<string, string>,\n): Promise<ServerClient> => {\n const transport = createTransport(mcpServer.connection, signal, extraHeaders);\n\n if (!transport) {\n throw new Error(\"Unknown MCP connection type\");\n }\n\n const client = new Client({\n name: mcpServer?.name ?? \"MCP Client\",\n version: \"1.0.0\",\n });\n\n await client.connect(transport);\n\n return {\n client,\n callStreamableTool: (tool, args) => {\n if (mcpServer.connection.type !== \"HTTP\") {\n throw new Error(\"HTTP connection required\");\n }\n return fetch(mcpServer.connection.url + `/call-tool/${tool}`, {\n method: \"POST\",\n redirect: \"manual\",\n body: JSON.stringify(args),\n headers: {\n ...extraHeaders,\n Authorization: `Bearer ${mcpServer.connection.token}`,\n },\n });\n },\n };\n};\n\nexport const createTransport = (\n connection: MCPConnection,\n signal?: AbortSignal,\n extraHeaders?: Record<string, string>,\n) => {\n if (connection.type === \"Websocket\") {\n return new WebSocketClientTransport(new URL(connection.url));\n }\n\n if (connection.type !== \"SSE\" && connection.type !== \"HTTP\") {\n return null;\n }\n\n const authHeaders: Record<string, string> = connection.token\n ? { authorization: `Bearer ${connection.token}` }\n : {};\n\n const headers: Record<string, string> = {\n ...authHeaders,\n ...(extraHeaders ?? {}),\n ...(\"headers\" in connection ? connection.headers || {} : {}),\n };\n\n if (connection.type === \"SSE\") {\n const config: SSEClientTransportOptions = {\n requestInit: { headers, signal },\n };\n\n if (connection.token) {\n config.eventSourceInit = {\n fetch: (req, init) => {\n return fetch(req, {\n ...init,\n headers: {\n ...headers,\n Accept: \"text/event-stream\",\n },\n signal,\n });\n },\n };\n }\n\n return new SSEClientTransport(new URL(connection.url), config);\n }\n return new HTTPClientTransport(new URL(connection.url), {\n requestInit: {\n headers,\n signal,\n // @ts-ignore - this is a valid option for fetch\n credentials: \"include\",\n },\n });\n};\n"],"mappings":"AAAA;AAAA,EACE,UAAU;AAAA,OAEL;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,gCAAgC;AAEzC;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,2BAA2B;AASpC,MAAM,eAAe,WAAW;AAAA,EAC9B,YAAY,aAA6B,SAAyB;AAChE,UAAM,aAAa,OAAO;AAAA,EAC5B;AAAA,EAEA,MAAe,UACb,QACA,SACA;AACA,UAAM,SAAS,MAAM,KAAK;AAAA,MACxB,EAAE,QAAQ,cAAc,OAAO;AAAA,MAC/B;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAMO,MAAM,qBAAqB,OAChC,WACA,QACA,iBAC0B;AAC1B,QAAM,YAAY,gBAAgB,UAAU,YAAY,QAAQ,YAAY;AAE5E,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AAEA,QAAM,SAAS,IAAI,OAAO;AAAA,IACxB,MAAM,WAAW,QAAQ;AAAA,IACzB,SAAS;AAAA,EACX,CAAC;AAED,QAAM,OAAO,QAAQ,SAAS;AAE9B,SAAO;AAAA,IACL;AAAA,IACA,oBAAoB,CAAC,MAAM,SAAS;AAClC,UAAI,UAAU,WAAW,SAAS,QAAQ;AACxC,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AACA,aAAO,MAAM,UAAU,WAAW,MAAM,cAAc,IAAI,IAAI;AAAA,QAC5D,QAAQ;AAAA,QACR,UAAU;AAAA,QACV,MAAM,KAAK,UAAU,IAAI;AAAA,QACzB,SAAS;AAAA,UACP,GAAG;AAAA,UACH,eAAe,UAAU,UAAU,WAAW,KAAK;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,MAAM,kBAAkB,CAC7B,YACA,QACA,iBACG;AACH,MAAI,WAAW,SAAS,aAAa;AACnC,WAAO,IAAI,yBAAyB,IAAI,IAAI,WAAW,GAAG,CAAC;AAAA,EAC7D;AAEA,MAAI,WAAW,SAAS,SAAS,WAAW,SAAS,QAAQ;AAC3D,WAAO;AAAA,EACT;AAEA,QAAM,cAAsC,WAAW,QACnD,EAAE,eAAe,UAAU,WAAW,KAAK,GAAG,IAC9C,CAAC;AAEL,QAAM,UAAkC;AAAA,IACtC,GAAG;AAAA,IACH,GAAI,gBAAgB,CAAC;AAAA,IACrB,GAAI,aAAa,aAAa,WAAW,WAAW,CAAC,IAAI,CAAC;AAAA,EAC5D;AAEA,MAAI,WAAW,SAAS,OAAO;AAC7B,UAAM,SAAoC;AAAA,MACxC,aAAa,EAAE,SAAS,OAAO;AAAA,IACjC;AAEA,QAAI,WAAW,OAAO;AACpB,aAAO,kBAAkB;AAAA,QACvB,OAAO,CAAC,KAAK,SAAS;AACpB,iBAAO,MAAM,KAAK;AAAA,YAChB,GAAG;AAAA,YACH,SAAS;AAAA,cACP,GAAG;AAAA,cACH,QAAQ;AAAA,YACV;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,IAAI,mBAAmB,IAAI,IAAI,WAAW,GAAG,GAAG,MAAM;AAAA,EAC/D;AACA,SAAO,IAAI,oBAAoB,IAAI,IAAI,WAAW,GAAG,GAAG;AAAA,IACtD,aAAa;AAAA,MACX;AAAA,MACA;AAAA;AAAA,MAEA,aAAa;AAAA,IACf;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import 'zod/v3';
|
|
2
|
-
import '../connection.js';
|
|
3
|
-
export { C as CreateStubAPIOptions, F as FetchOptions, J as JSONSchemaToZodConverter, b as MCPClient, M as MCPClientFetchStub, d as MCPClientRaw, c as MCPClientStub, a as ToolBinder, e as createMCPFetchStub, i as isStreamableToolBinder } from '../../index-D0aUdNls.js';
|
package/dist/core/client/mcp.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createMCPClientProxy } from "./proxy";
|
|
2
|
-
const MCPClient = new Proxy(
|
|
3
|
-
{},
|
|
4
|
-
{
|
|
5
|
-
get(_, name) {
|
|
6
|
-
if (name === "toJSON") {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
if (name === "forConnection") {
|
|
10
|
-
return (connection) => createMCPFetchStub({
|
|
11
|
-
connection
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return global[name];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
const isStreamableToolBinder = (toolBinder) => {
|
|
19
|
-
return toolBinder.streamable === true;
|
|
20
|
-
};
|
|
21
|
-
function createMCPFetchStub(options) {
|
|
22
|
-
return createMCPClientProxy(options);
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
MCPClient,
|
|
26
|
-
createMCPFetchStub,
|
|
27
|
-
isStreamableToolBinder
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=mcp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/client/mcp.ts"],"sourcesContent":["/* oxlint-disable no-explicit-any */\nimport { z } from \"zod/v3\";\nimport type { MCPConnection } from \"../connection\";\nimport { createMCPClientProxy } from \"./proxy\";\n\nexport interface FetchOptions extends RequestInit {\n path?: string;\n segments?: string[];\n}\n\n// Default fetcher instance with API_SERVER_URL and API_HEADERS\nexport const MCPClient = new Proxy(\n {} as {\n forConnection: <TDefinition extends readonly ToolBinder[]>(\n connection: MCPConnection,\n ) => MCPClientFetchStub<TDefinition>;\n },\n {\n get(_, name) {\n if (name === \"toJSON\") {\n return null;\n }\n\n if (name === \"forConnection\") {\n return <TDefinition extends readonly ToolBinder[]>(\n connection: MCPConnection,\n ) =>\n createMCPFetchStub<TDefinition>({\n connection,\n });\n }\n return global[name as keyof typeof global];\n },\n },\n);\n\nimport type { ToolBinder } from \"../binder\";\nexport type { ToolBinder };\n\nexport const isStreamableToolBinder = (\n toolBinder: ToolBinder,\n): toolBinder is ToolBinder<string, any, any, true> => {\n return toolBinder.streamable === true;\n};\nexport type MCPClientStub<TDefinition extends readonly ToolBinder[]> = {\n [K in TDefinition[number] as K[\"name\"]]: K extends ToolBinder<\n string,\n infer TInput,\n infer TReturn\n >\n ? (params: TInput, init?: RequestInit) => Promise<TReturn>\n : never;\n};\n\nexport type MCPClientFetchStub<TDefinition extends readonly ToolBinder[]> = {\n [K in TDefinition[number] as K[\"name\"]]: K[\"streamable\"] extends true\n ? K extends ToolBinder<string, infer TInput, any, true>\n ? (params: TInput, init?: RequestInit) => Promise<Response>\n : never\n : K extends ToolBinder<string, infer TInput, infer TReturn, any>\n ? (params: TInput, init?: RequestInit) => Promise<Awaited<TReturn>>\n : never;\n};\n\nexport interface MCPClientRaw {\n callTool: (tool: string, args: unknown) => Promise<unknown>;\n listTools: () => Promise<\n {\n name: string;\n inputSchema: any;\n outputSchema?: any;\n description: string;\n }[]\n >;\n}\nexport type JSONSchemaToZodConverter = (jsonSchema: any) => z.ZodTypeAny;\nexport interface CreateStubAPIOptions {\n connection: MCPConnection;\n streamable?: Record<string, boolean>;\n debugId?: () => string;\n getErrorByStatusCode?: (\n statusCode: number,\n message?: string,\n traceId?: string,\n errorObject?: unknown,\n ) => Error;\n}\n\nexport function createMCPFetchStub<TDefinition extends readonly ToolBinder[]>(\n options: CreateStubAPIOptions,\n): MCPClientFetchStub<TDefinition> {\n return createMCPClientProxy<MCPClientFetchStub<TDefinition>>(options);\n}\n"],"mappings":"AAGA,SAAS,4BAA4B;AAQ9B,MAAM,YAAY,IAAI;AAAA,EAC3B,CAAC;AAAA,EAKD;AAAA,IACE,IAAI,GAAG,MAAM;AACX,UAAI,SAAS,UAAU;AACrB,eAAO;AAAA,MACT;AAEA,UAAI,SAAS,iBAAiB;AAC5B,eAAO,CACL,eAEA,mBAAgC;AAAA,UAC9B;AAAA,QACF,CAAC;AAAA,MACL;AACA,aAAO,OAAO,IAA2B;AAAA,IAC3C;AAAA,EACF;AACF;AAKO,MAAM,yBAAyB,CACpC,eACqD;AACrD,SAAO,WAAW,eAAe;AACnC;AA6CO,SAAS,mBACd,SACiC;AACjC,SAAO,qBAAsD,OAAO;AACtE;","names":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { C as CreateStubAPIOptions } from '../../index-D0aUdNls.js';
|
|
2
|
-
import 'zod/v3';
|
|
3
|
-
import '../connection.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The base fetcher used to fetch the MCP from API.
|
|
7
|
-
*/
|
|
8
|
-
declare function createMCPClientProxy<T extends Record<string, unknown>>(options: CreateStubAPIOptions): T;
|
|
9
|
-
|
|
10
|
-
export { createMCPClientProxy };
|