@mcp-ts/sdk 1.4.0 → 1.5.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 +20 -27
- package/dist/adapters/agui-adapter.d.mts +16 -0
- package/dist/adapters/agui-adapter.d.ts +16 -0
- package/dist/adapters/agui-adapter.js +185 -0
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs +185 -0
- package/dist/adapters/agui-adapter.mjs.map +1 -1
- package/dist/adapters/agui-middleware.d.mts +2 -0
- package/dist/adapters/agui-middleware.d.ts +2 -0
- package/dist/adapters/agui-middleware.js.map +1 -1
- package/dist/adapters/agui-middleware.mjs.map +1 -1
- package/dist/adapters/ai-adapter.d.mts +21 -0
- package/dist/adapters/ai-adapter.d.ts +21 -0
- package/dist/adapters/ai-adapter.js +175 -0
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs +175 -0
- package/dist/adapters/ai-adapter.mjs.map +1 -1
- package/dist/adapters/langchain-adapter.d.mts +16 -0
- package/dist/adapters/langchain-adapter.d.ts +16 -0
- package/dist/adapters/langchain-adapter.js +179 -0
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +179 -0
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/react.d.mts +94 -8
- package/dist/client/react.d.ts +94 -8
- package/dist/client/react.js +364 -26
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +358 -27
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +4 -4
- package/dist/client/vue.d.ts +4 -4
- package/dist/client/vue.js +11 -2
- package/dist/client/vue.js.map +1 -1
- package/dist/client/vue.mjs +11 -2
- package/dist/client/vue.mjs.map +1 -1
- package/dist/{index-CQr9q0bF.d.mts → index-DcYfpY3H.d.mts} +1 -1
- package/dist/{index-nE_7Io0I.d.ts → index-GfC_eNEv.d.ts} +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +938 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +923 -13
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.d.mts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +58 -12
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +58 -12
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.d.mts +86 -4
- package/dist/shared/index.d.ts +86 -4
- package/dist/shared/index.js +874 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +865 -1
- package/dist/shared/index.mjs.map +1 -1
- package/dist/tool-router-Bo8qZbsD.d.ts +325 -0
- package/dist/tool-router-XnWVxPzv.d.mts +325 -0
- package/dist/{types-CW6lghof.d.mts → types-CfCoIsWI.d.mts} +27 -1
- package/dist/{types-CW6lghof.d.ts → types-CfCoIsWI.d.ts} +27 -1
- package/package.json +3 -2
- package/src/adapters/agui-adapter.ts +79 -0
- package/src/adapters/ai-adapter.ts +75 -0
- package/src/adapters/langchain-adapter.ts +74 -0
- package/src/client/react/index.ts +16 -0
- package/src/client/react/oauth-popup.tsx +446 -0
- package/src/client/react/use-mcp-apps.tsx +50 -32
- package/src/client/react/use-mcp.ts +36 -3
- package/src/client/vue/use-mcp.ts +38 -3
- package/src/server/handlers/sse-handler.ts +39 -0
- package/src/server/index.ts +2 -0
- package/src/server/mcp/oauth-client.ts +35 -15
- package/src/shared/index.ts +36 -0
- package/src/shared/meta-tools.ts +387 -0
- package/src/shared/schema-compressor.ts +124 -0
- package/src/shared/tool-index.ts +499 -0
- package/src/shared/tool-router.ts +469 -0
- package/src/shared/types.ts +30 -0
- package/supabase/migrations/20260421010000_add_session_cleanup_cron.sql +32 -0
|
@@ -8,6 +8,135 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
});
|
|
9
9
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
10
|
|
|
11
|
+
// src/shared/meta-tools.ts
|
|
12
|
+
async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
13
|
+
const resolveToolSchema = (name, namespace) => {
|
|
14
|
+
try {
|
|
15
|
+
return { tool: router.getToolSchema(name, namespace) };
|
|
16
|
+
} catch (err) {
|
|
17
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
18
|
+
return {
|
|
19
|
+
error: {
|
|
20
|
+
content: [{ type: "text", text: errorMessage }],
|
|
21
|
+
isError: true
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
switch (toolName) {
|
|
27
|
+
case "mcp_search_tool_bm25": {
|
|
28
|
+
const query = String(args.query ?? "");
|
|
29
|
+
const limit = Math.min(Number(args.limit) || 5, 20);
|
|
30
|
+
const results = await router.searchTools(query, limit);
|
|
31
|
+
const text = results.length === 0 ? "No tools found matching your query. Try different keywords." : results.map(
|
|
32
|
+
(t, i) => `${i + 1}. **${t.name}** (server: ${t.serverName})
|
|
33
|
+
${t.description}
|
|
34
|
+
Estimated tokens: ${t.estimatedTokens}`
|
|
35
|
+
).join("\n");
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: "text", text }],
|
|
38
|
+
isError: false
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
case "mcp_search_tool_regex": {
|
|
42
|
+
const pattern = String(args.query ?? "");
|
|
43
|
+
const limit = Math.min(Number(args.limit) || 5, 20);
|
|
44
|
+
const results = await router.searchToolsRegex(pattern, limit);
|
|
45
|
+
const text = results.length === 0 ? "No tools matched your regex pattern. Try a broader pattern." : results.map(
|
|
46
|
+
(t, i) => `${i + 1}. **${t.name}** (server: ${t.serverName})
|
|
47
|
+
${t.description}
|
|
48
|
+
Estimated tokens: ${t.estimatedTokens}`
|
|
49
|
+
).join("\n");
|
|
50
|
+
return {
|
|
51
|
+
content: [{ type: "text", text }],
|
|
52
|
+
isError: false
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
case "mcp_get_tool_schema": {
|
|
56
|
+
const name = String(args.toolName ?? "");
|
|
57
|
+
const namespace = String(args.serverName ?? "") || void 0;
|
|
58
|
+
const { tool, error } = resolveToolSchema(name, namespace);
|
|
59
|
+
if (error) {
|
|
60
|
+
return error;
|
|
61
|
+
}
|
|
62
|
+
if (!tool) {
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: "text",
|
|
67
|
+
text: `Tool "${name}" not found. Use mcp_search_tool_bm25 to find available tools first.`
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
isError: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const schema = {
|
|
74
|
+
name: tool.name,
|
|
75
|
+
description: tool.description,
|
|
76
|
+
inputSchema: tool.inputSchema
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
content: [{ type: "text", text: JSON.stringify(schema, null, 2) }],
|
|
80
|
+
isError: false
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
case "mcp_execute_tool": {
|
|
84
|
+
const targetToolName = String(args.toolName ?? "");
|
|
85
|
+
const namespace = String(args.serverName ?? "") || void 0;
|
|
86
|
+
const toolArgs = args.args ?? {};
|
|
87
|
+
if (!targetToolName) {
|
|
88
|
+
return {
|
|
89
|
+
content: [{ type: "text", text: 'Missing required parameter "toolName". Specify which tool to execute.' }],
|
|
90
|
+
isError: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const { tool, error } = resolveToolSchema(targetToolName, namespace);
|
|
94
|
+
if (error) {
|
|
95
|
+
return error;
|
|
96
|
+
}
|
|
97
|
+
if (!tool) {
|
|
98
|
+
return {
|
|
99
|
+
content: [
|
|
100
|
+
{
|
|
101
|
+
type: "text",
|
|
102
|
+
text: `Tool "${targetToolName}" not found. Use mcp_search_tool_bm25 to discover available tools first.`
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
isError: true
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (!callToolFn) {
|
|
109
|
+
return {
|
|
110
|
+
content: [{ type: "text", text: "Tool execution is not available. No callToolFn was configured." }],
|
|
111
|
+
isError: true
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const result = await callToolFn(targetToolName, toolArgs, namespace);
|
|
116
|
+
if (result && typeof result === "object" && "content" in result) {
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
const text = typeof result === "string" ? result : JSON.stringify(result, null, 2);
|
|
120
|
+
return {
|
|
121
|
+
content: [{ type: "text", text }],
|
|
122
|
+
isError: false
|
|
123
|
+
};
|
|
124
|
+
} catch (err) {
|
|
125
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
126
|
+
return {
|
|
127
|
+
content: [{ type: "text", text: `Tool execution failed: ${errorMessage}` }],
|
|
128
|
+
isError: true
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
default:
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function isMetaTool(toolName) {
|
|
137
|
+
return toolName === "mcp_search_tool_bm25" || toolName === "mcp_search_tool_regex" || toolName === "mcp_get_tool_schema" || toolName === "mcp_execute_tool";
|
|
138
|
+
}
|
|
139
|
+
|
|
11
140
|
// src/adapters/langchain-adapter.ts
|
|
12
141
|
var LangChainAdapter = class _LangChainAdapter {
|
|
13
142
|
constructor(client, options = {}) {
|
|
@@ -73,6 +202,9 @@ var LangChainAdapter = class _LangChainAdapter {
|
|
|
73
202
|
* Fetches tools from the MCP server and converts them to LangChain StructuredTools.
|
|
74
203
|
*/
|
|
75
204
|
async getTools() {
|
|
205
|
+
if (this.options.toolRouter) {
|
|
206
|
+
return this.getToolsViaRouter(this.options.toolRouter);
|
|
207
|
+
}
|
|
76
208
|
const isMultiSession = typeof this.client.getClients === "function";
|
|
77
209
|
const clients = isMultiSession ? this.client.getClients() : [this.client];
|
|
78
210
|
const results = await Promise.all(
|
|
@@ -87,6 +219,53 @@ var LangChainAdapter = class _LangChainAdapter {
|
|
|
87
219
|
);
|
|
88
220
|
return results.flat();
|
|
89
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Build StructuredTools from a ToolRouter's filtered output.
|
|
224
|
+
*
|
|
225
|
+
* In `search` strategy, only meta-tools are registered with the framework.
|
|
226
|
+
* Real tool execution is proxied through `mcp_execute_tool` which uses
|
|
227
|
+
* `router.callTool()` to route to the correct MCP client.
|
|
228
|
+
*/
|
|
229
|
+
async getToolsViaRouter(router) {
|
|
230
|
+
await this.ensureDependencies();
|
|
231
|
+
const filteredTools = await router.getFilteredTools();
|
|
232
|
+
return filteredTools.map((tool) => {
|
|
233
|
+
const routedTool = tool;
|
|
234
|
+
const namespace = routedTool.serverName ?? routedTool.sessionId;
|
|
235
|
+
const schema = this.jsonSchemaToZod(tool.inputSchema);
|
|
236
|
+
return new this.DynamicStructuredTool({
|
|
237
|
+
name: isMetaTool(tool.name) ? tool.name : this.getRouterToolKey(tool.name, routedTool.sessionId, routedTool.serverName),
|
|
238
|
+
description: tool.description || `Tool ${tool.name}`,
|
|
239
|
+
schema,
|
|
240
|
+
func: async (args) => {
|
|
241
|
+
try {
|
|
242
|
+
if (isMetaTool(tool.name)) {
|
|
243
|
+
const result = await executeMetaTool(
|
|
244
|
+
tool.name,
|
|
245
|
+
args,
|
|
246
|
+
router,
|
|
247
|
+
(name, toolArgs, namespace2) => router.callTool(name, toolArgs, namespace2)
|
|
248
|
+
);
|
|
249
|
+
if (result) {
|
|
250
|
+
return result.content.map((c) => c.text ?? "").join("\n");
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return await router.callTool(tool.name, args, namespace);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (this.options.simplifyErrors) {
|
|
256
|
+
return `Error: ${error.message}`;
|
|
257
|
+
}
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
getRouterToolKey(toolName, sessionId, serverName) {
|
|
265
|
+
const namespace = sessionId ?? serverName ?? "mcp";
|
|
266
|
+
const normalized = namespace.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "mcp";
|
|
267
|
+
return `tool_${normalized}_${toolName}`;
|
|
268
|
+
}
|
|
90
269
|
/**
|
|
91
270
|
* Convenience static method to fetch tools in a single line.
|
|
92
271
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapters/langchain-adapter.ts"],"names":[],"mappings":";;;;;;;;;;;AAuBO,IAAM,gBAAA,GAAN,MAAM,iBAAA,CAAiB;AAAA,EAI1B,WAAA,CACY,MAAA,EACA,OAAA,GAAmC,EAAC,EAC9C;AAFU,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AALZ,IAAA,aAAA,CAAA,IAAA,EAAQ,uBAAA,CAAA;AACR,IAAA,aAAA,CAAA,IAAA,EAAQ,GAAA,CAAA;AAAA,EAKJ;AAAA;AAAA;AAAA;AAAA,EAKJ,MAAc,kBAAA,GAAqB;AAC/B,IAAA,IAAI,CAAC,KAAK,qBAAA,EAAuB;AAC7B,MAAA,IAAI;AACA,QAAA,MAAM,SAAA,GAAY,MAAM,OAAO,uBAAuB,CAAA;AACtD,QAAA,IAAA,CAAK,wBAAwB,SAAA,CAAU,qBAAA;AAEvC,QAAA,MAAM,GAAA,GAAM,MAAM,OAAO,KAAK,CAAA;AAC9B,QAAA,IAAA,CAAK,IAAI,GAAA,CAAI,CAAA;AAAA,MACjB,SAAS,KAAA,EAAO;AACZ,QAAA,MAAM,IAAI,KAAA;AAAA,UACN;AAAA,SAEJ;AAAA,MACJ;AAAA,IACJ;AAAA,EAC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;AAC5H,IAAA,OAAO,IAAI,iBAAA,CAAiB,MAAA,EAAQ,OAAO,EAAE,QAAA,EAAS;AAAA,EAC1D;AACJ","file":"langchain-adapter.mjs","sourcesContent":["import { MCPClient } from '../server/mcp/oauth-client';\nimport { MultiSessionClient } from '../server/mcp/multi-session-client';\nimport type { DynamicStructuredTool, StructuredTool } from '@langchain/core/tools';\nimport type { z } from 'zod';\n\nexport interface LangChainAdapterOptions {\n /** \n * Prefix for tool names to avoid collision with other tools.\n * Defaults to the client's serverId.\n */\n prefix?: string;\n\n /**\n * Whether to simplify error messages returned to the LLM.\n * If true, returns \"Error: <message>\" string instead of throwing.\n * @default false\n */\n simplifyErrors?: boolean;\n}\n\n/**\n * Adapter to use MCP tools within LangChain/LangGraph agents.\n */\nexport class LangChainAdapter {\n private DynamicStructuredTool: typeof DynamicStructuredTool | undefined;\n private z: typeof z | undefined;\n\n constructor(\n private client: MCPClient | MultiSessionClient,\n private options: LangChainAdapterOptions = {}\n ) { }\n\n /**\n * Lazy-loads LangChain and Zod dependencies\n */\n private async ensureDependencies() {\n if (!this.DynamicStructuredTool) {\n try {\n const langchain = await import('@langchain/core/tools');\n this.DynamicStructuredTool = langchain.DynamicStructuredTool as any;\n\n const zod = await import('zod');\n this.z = zod.z;\n } catch (error) {\n throw new Error(\n 'LangChain dependencies not installed. Install with:\\n' +\n ' npm install @langchain/core zod'\n );\n }\n }\n }\n\n private async transformTools(client: MCPClient): Promise<StructuredTool[]> {\n if (!client.isConnected()) {\n return [];\n }\n\n await this.ensureDependencies();\n\n const result = await client.listTools();\n const prefix = this.options.prefix ?? client.getServerId()?.replace(/-/g, '').substring(0, 8) ?? 'mcp';\n\n return result.tools.map((tool) => {\n // In a real implementation, you would use a library like 'json-schema-to-zod'\n const schema = this.jsonSchemaToZod(tool.inputSchema);\n\n return new this.DynamicStructuredTool!({\n name: `${prefix}_${tool.name}`,\n description: tool.description || `Tool ${tool.name}`,\n schema: schema,\n func: async (args: any) => {\n try {\n return await client.callTool(tool.name, args);\n } catch (error: any) {\n if (this.options.simplifyErrors) {\n return `Error: ${error.message}`;\n }\n throw error;\n }\n },\n });\n });\n }\n\n private jsonSchemaToZod(schema: any): z.ZodType<any> {\n try {\n const { parseSchema } = require('json-schema-to-zod');\n const zodSchemaString = parseSchema(schema);\n // eslint-disable-next-line\n return new Function('z', 'return ' + zodSchemaString)(this.z);\n } catch (error) {\n // Fallback: Accept any object if conversion fails\n console.warn('[LangChainAdapter] Failed to convert JSON Schema to Zod, using fallback:', error);\n return this.z!.record(this.z!.any()).optional().describe(\"Dynamic Input\");\n }\n }\n\n /**\n * Fetches tools from the MCP server and converts them to LangChain StructuredTools.\n */\n async getTools(): Promise<StructuredTool[]> {\n // Use duck typing instead of instanceof to handle module bundling issues\n const isMultiSession = typeof (this.client as any).getClients === 'function';\n const clients = isMultiSession\n ? (this.client as MultiSessionClient).getClients()\n : [this.client as MCPClient];\n\n const results = await Promise.all(\n clients.map(async (client) => {\n try {\n return await this.transformTools(client);\n } catch (error) {\n console.error(`[LangChainAdapter] Failed to fetch tools from ${client.getServerId()}:`, error);\n return [];\n }\n })\n );\n return results.flat();\n }\n\n /**\n * Convenience static method to fetch tools in a single line.\n */\n static async getTools(client: MCPClient | MultiSessionClient, options: LangChainAdapterOptions = {}): Promise<StructuredTool[]> {\n return new LangChainAdapter(client, options).getTools();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/shared/meta-tools.ts","../../src/adapters/langchain-adapter.ts"],"names":["namespace"],"mappings":";;;;;;;;;;;AAuLA,eAAsB,eAAA,CACpB,QAAA,EACA,IAAA,EACA,MAAA,EACA,UAAA,EACgC;AAChC,EAAA,MAAM,iBAAA,GAAoB,CAAC,IAAA,EAAc,SAAA,KAAgE;AACvG,IAAA,IAAI;AACF,MAAA,OAAO,EAAE,IAAA,EAAM,MAAA,CAAO,aAAA,CAAc,IAAA,EAAM,SAAS,CAAA,EAAE;AAAA,IACvD,SAAS,GAAA,EAAK;AACZ,M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,EAAE,CAAA,IAAK,KAAA;AAChC,IAAA,OAAO,CAAA,KAAA,EAAQ,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,QAAA,CAAS,MAAA,EAAwC,OAAA,GAAmC,EAAC,EAA8B;AAC5H,IAAA,OAAO,IAAI,iBAAA,CAAiB,MAAA,EAAQ,OAAO,EAAE,QAAA,EAAS;AAAA,EAC1D;AACJ","file":"langchain-adapter.mjs","sourcesContent":["/**\n * Meta-tools — Injectable tool definitions that let the LLM discover and\n * load MCP tools on-demand, following Anthropic's Tool Search pattern.\n *\n * Instead of injecting 50+ full tool schemas into the context window, you\n * inject just these 4 meta-tools. The LLM calls them to find and load\n * only the tools it actually needs.\n *\n * Meta-tools:\n * • `mcp_search_tool_bm25` — BM25 natural language search\n * • `mcp_search_tool_regex` — Regex pattern search\n * • `mcp_get_tool_schema` — Get full inputSchema for a discovered tool\n * • `mcp_execute_tool` — Execute a discovered tool\n *\n * @packageDocumentation\n */\n\nimport type { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport type { ToolRouter } from './tool-router.js';\n\n// ---------------------------------------------------------------------------\n// Tool Definitions\n// ---------------------------------------------------------------------------\n\n/**\n * Creates the `mcp_search_tool_bm25` tool definition.\n *\n * This tool lets the LLM search the full catalog of available MCP tools\n * using a BM25 natural-language query. Returns tool names and descriptions\n * without the full inputSchema to save context space.\n */\nexport function createSearchToolDefinition(): Tool {\n return {\n name: 'mcp_search_tool_bm25',\n description:\n 'Search the catalog of available tools using BM25 natural language ranking. ' +\n 'Returns tool names, descriptions, and server info. ' +\n 'Use this FIRST to find relevant tools before calling them. ' +\n 'Example queries: \"database query\", \"send email\", \"github pull request\".',\n inputSchema: {\n type: 'object' as const,\n properties: {\n query: {\n type: 'string',\n description: 'Natural language description of the capability you need.',\n },\n limit: {\n type: 'number',\n description: 'Maximum number of results to return (default: 5, max: 20).',\n },\n },\n required: ['query'],\n },\n };\n}\n\n/**\n * Creates the `mcp_search_tool_regex` tool definition.\n * \n * Matches Anthropic's tool_search_tool_regex exactly (takes a 'query' regex pattern).\n */\nexport function createRegexSearchToolDefinition(): Tool {\n return {\n name: 'mcp_search_tool_regex',\n description:\n 'Search the catalog of available tools using a Python-style regex pattern. ' +\n 'Matches against tool names, descriptions, and parameter descriptions. ' +\n 'Example patterns: \"^github_\", \"weather\", \"(?i)slack\".',\n inputSchema: {\n type: 'object' as const,\n properties: {\n query: {\n type: 'string',\n description: 'Regex pattern to search for (e.g., \"^get_.*_data\", \"database\").',\n },\n limit: {\n type: 'number',\n description: 'Maximum number of results to return (default: 5, max: 20).',\n },\n },\n required: ['query'],\n },\n };\n}\n\n/**\n * Creates the `mcp_get_tool_schema` tool definition.\n *\n * After discovering tools via `mcp_search_tool_bm25` or\n * `mcp_search_tool_regex`, the LLM calls this to load the full\n * inputSchema for a specific tool so it can construct the correct\n * arguments.\n */\nexport function createGetSchemaToolDefinition(): Tool {\n return {\n name: 'mcp_get_tool_schema',\n description:\n 'Get the full input schema (parameters) for a specific tool. ' +\n 'Call this after mcp_search_tool_bm25 to get the parameter details ' +\n 'needed to call a tool correctly.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n toolName: {\n type: 'string',\n description: 'The exact tool name returned by mcp_search_tool_bm25.',\n },\n serverName: {\n type: 'string',\n description:\n 'Optional: The server name provided in mcp_search_tool_bm25. Required if multiple tools have the same name.',\n },\n },\n required: ['toolName'],\n },\n };\n}\n\n/**\n * Creates the `mcp_execute_tool` tool definition.\n *\n * This is the execution meta-tool — the LLM calls this to execute any\n * tool discovered via `mcp_search_tool_bm25` or `mcp_search_tool_regex`.\n * The LLM should first call `mcp_get_tool_schema` to know the correct\n * arguments.\n *\n * Instead of registering every real tool with the framework, we proxy\n * all execution through a single meta-tool.\n */\nexport function createExecuteToolDefinition(): Tool {\n return {\n name: 'mcp_execute_tool',\n description:\n 'Execute a tool that was discovered via mcp_search_tool_bm25. ' +\n 'You MUST call mcp_get_tool_schema first to know the correct parameters. ' +\n 'Pass the exact tool name and its arguments.',\n inputSchema: {\n type: 'object' as const,\n properties: {\n toolName: {\n type: 'string',\n description: 'The exact tool name from mcp_search_tool_bm25 results.',\n },\n serverName: {\n type: 'string',\n description:\n 'Optional: The server name provided in mcp_search_tool_bm25. Required if multiple tools have the same name.',\n },\n args: {\n type: 'object',\n description:\n \"Arguments matching the tool's inputSchema. Omit or pass {} if the tool takes no parameters.\",\n additionalProperties: true,\n },\n },\n required: ['toolName'],\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Meta-tool Executors\n// ---------------------------------------------------------------------------\n\n/**\n * Callback for executing a real MCP tool via the correct client.\n * Provided by adapters that wire up client routing.\n */\nexport type CallToolFn = (\n toolName: string,\n args: Record<string, unknown>,\n namespace?: string\n) => Promise<any>;\n\n/**\n * Execute a meta-tool call and return the result in MCP CallToolResult format.\n *\n * @param toolName - One of the meta-tool names (mcp_search_tool_bm25, mcp_search_tool_regex, etc.)\n * @param args - The arguments from the LLM's tool call\n * @param router - The ToolRouter to query\n * @param callToolFn - Optional callback for executing real tools (required for mcp_execute_tool)\n * @returns MCP-compatible CallToolResult, or null if this isn't a meta-tool\n */\nexport async function executeMetaTool(\n toolName: string,\n args: Record<string, unknown>,\n router: ToolRouter,\n callToolFn?: CallToolFn\n): Promise<CallToolResult | null> {\n const resolveToolSchema = (name: string, namespace?: string): { tool?: Tool; error?: CallToolResult } => {\n try {\n return { tool: router.getToolSchema(name, namespace) };\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n return {\n error: {\n content: [{ type: 'text', text: errorMessage }],\n isError: true,\n },\n };\n }\n };\n\n switch (toolName) {\n case 'mcp_search_tool_bm25': {\n const query = String(args.query ?? '');\n const limit = Math.min(Number(args.limit) || 5, 20);\n\n const results = await router.searchTools(query, limit);\n\n const text = results.length === 0\n ? 'No tools found matching your query. Try different keywords.'\n : results\n .map(\n (t, i) =>\n `${i + 1}. **${t.name}** (server: ${t.serverName})\\n` +\n ` ${t.description}\\n` +\n ` Estimated tokens: ${t.estimatedTokens}`\n )\n .join('\\n');\n\n return {\n content: [{ type: 'text', text }],\n isError: false,\n };\n }\n\n case 'mcp_search_tool_regex': {\n const pattern = String(args.query ?? '');\n const limit = Math.min(Number(args.limit) || 5, 20);\n\n const results = await router.searchToolsRegex(pattern, limit);\n\n const text = results.length === 0\n ? 'No tools matched your regex pattern. Try a broader pattern.'\n : results\n .map(\n (t, i) =>\n `${i + 1}. **${t.name}** (server: ${t.serverName})\\n` +\n ` ${t.description}\\n` +\n ` Estimated tokens: ${t.estimatedTokens}`\n )\n .join('\\n');\n\n return {\n content: [{ type: 'text', text }],\n isError: false,\n };\n }\n\n case 'mcp_get_tool_schema': {\n const name = String(args.toolName ?? '');\n const namespace = String(args.serverName ?? '') || undefined;\n const { tool, error } = resolveToolSchema(name, namespace);\n\n if (error) {\n return error;\n }\n\n if (!tool) {\n return {\n content: [\n {\n type: 'text',\n text: `Tool \"${name}\" not found. Use mcp_search_tool_bm25 to find available tools first.`,\n },\n ],\n isError: true,\n };\n }\n\n const schema = {\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema,\n };\n\n return {\n content: [{ type: 'text', text: JSON.stringify(schema, null, 2) }],\n isError: false,\n };\n }\n\n case 'mcp_execute_tool': {\n const targetToolName = String(args.toolName ?? '');\n const namespace = String(args.serverName ?? '') || undefined;\n const toolArgs = (args.args as Record<string, unknown>) ?? {};\n\n if (!targetToolName) {\n return {\n content: [{ type: 'text', text: 'Missing required parameter \"toolName\". Specify which tool to execute.' }],\n isError: true,\n };\n }\n\n // Verify the tool exists in our index\n const { tool, error } = resolveToolSchema(targetToolName, namespace);\n if (error) {\n return error;\n }\n\n if (!tool) {\n return {\n content: [\n {\n type: 'text',\n text: `Tool \"${targetToolName}\" not found. Use mcp_search_tool_bm25 to discover available tools first.`,\n },\n ],\n isError: true,\n };\n }\n\n if (!callToolFn) {\n return {\n content: [{ type: 'text', text: 'Tool execution is not available. No callToolFn was configured.' }],\n isError: true,\n };\n }\n\n try {\n const result = await callToolFn(targetToolName, toolArgs, namespace);\n\n // Normalize result to text\n if (result && typeof result === 'object' && 'content' in result) {\n // Already MCP CallToolResult format\n return result as CallToolResult;\n }\n\n const text = typeof result === 'string' ? result : JSON.stringify(result, null, 2);\n return {\n content: [{ type: 'text', text }],\n isError: false,\n };\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n return {\n content: [{ type: 'text', text: `Tool execution failed: ${errorMessage}` }],\n isError: true,\n };\n }\n }\n\n default:\n return null;\n }\n}\n\n/** Check if a tool name is one of the meta-tools. */\nexport function isMetaTool(toolName: string): boolean {\n return (\n toolName === 'mcp_search_tool_bm25' ||\n toolName === 'mcp_search_tool_regex' ||\n toolName === 'mcp_get_tool_schema' ||\n toolName === 'mcp_execute_tool'\n );\n}\n\n/**\n * Unwraps a meta-tool proxy call (like mcp_execute_tool) to find the real target tool name and arguments.\n * Also automatically strips routing prefixes like tool_{serverId}_.\n * \n * Useful for frontend components that need to determine the actual tool being executed by an AI agent.\n */\nexport function resolveMetaToolProxy(\n toolName: string,\n args: Record<string, unknown> | null | undefined\n): { toolName: string; args: Record<string, unknown> } {\n // Unwrap mcp_execute_tool proxy arguments\n if (toolName === 'mcp_execute_tool') {\n const innerName = args?.toolName;\n const innerArgs = args?.args;\n return {\n toolName: typeof innerName === 'string' && innerName ? innerName : toolName,\n args: innerArgs && typeof innerArgs === 'object' && !Array.isArray(innerArgs)\n ? (innerArgs as Record<string, unknown>)\n : {},\n };\n }\n\n // Strip tool_<serverId>_ prefix used by AIAdapter\n const match = toolName.match(/(?:tool_[^_]+_)?(.+)$/);\n const resolvedName = match?.[1] ?? toolName;\n\n return { toolName: resolvedName, args: args ?? {} };\n}\n\n","import { MCPClient } from '../server/mcp/oauth-client';\nimport { MultiSessionClient } from '../server/mcp/multi-session-client';\nimport type { DynamicStructuredTool, StructuredTool } from '@langchain/core/tools';\nimport type { z } from 'zod';\nimport { ToolRouter } from '../shared/tool-router.js';\nimport { executeMetaTool, isMetaTool } from '../shared/meta-tools.js';\n\nexport interface LangChainAdapterOptions {\n /** \n * Prefix for tool names to avoid collision with other tools.\n * Defaults to the client's serverId.\n */\n prefix?: string;\n\n /**\n * Whether to simplify error messages returned to the LLM.\n * If true, returns \"Error: <message>\" string instead of throwing.\n * @default false\n */\n simplifyErrors?: boolean;\n\n /**\n * Optional ToolRouter for intelligent tool selection.\n * See AIAdapterOptions.toolRouter for details.\n */\n toolRouter?: ToolRouter;\n}\n\n/**\n * Adapter to use MCP tools within LangChain/LangGraph agents.\n */\nexport class LangChainAdapter {\n private DynamicStructuredTool: typeof DynamicStructuredTool | undefined;\n private z: typeof z | undefined;\n\n constructor(\n private client: MCPClient | MultiSessionClient,\n private options: LangChainAdapterOptions = {}\n ) { }\n\n /**\n * Lazy-loads LangChain and Zod dependencies\n */\n private async ensureDependencies() {\n if (!this.DynamicStructuredTool) {\n try {\n const langchain = await import('@langchain/core/tools');\n this.DynamicStructuredTool = langchain.DynamicStructuredTool as any;\n\n const zod = await import('zod');\n this.z = zod.z;\n } catch (error) {\n throw new Error(\n 'LangChain dependencies not installed. Install with:\\n' +\n ' npm install @langchain/core zod'\n );\n }\n }\n }\n\n private async transformTools(client: MCPClient): Promise<StructuredTool[]> {\n if (!client.isConnected()) {\n return [];\n }\n\n await this.ensureDependencies();\n\n const result = await client.listTools();\n const prefix = this.options.prefix ?? client.getServerId()?.replace(/-/g, '').substring(0, 8) ?? 'mcp';\n\n return result.tools.map((tool) => {\n // In a real implementation, you would use a library like 'json-schema-to-zod'\n const schema = this.jsonSchemaToZod(tool.inputSchema);\n\n return new this.DynamicStructuredTool!({\n name: `${prefix}_${tool.name}`,\n description: tool.description || `Tool ${tool.name}`,\n schema: schema,\n func: async (args: any) => {\n try {\n return await client.callTool(tool.name, args);\n } catch (error: any) {\n if (this.options.simplifyErrors) {\n return `Error: ${error.message}`;\n }\n throw error;\n }\n },\n });\n });\n }\n\n private jsonSchemaToZod(schema: any): z.ZodType<any> {\n try {\n const { parseSchema } = require('json-schema-to-zod');\n const zodSchemaString = parseSchema(schema);\n // eslint-disable-next-line\n return new Function('z', 'return ' + zodSchemaString)(this.z);\n } catch (error) {\n // Fallback: Accept any object if conversion fails\n console.warn('[LangChainAdapter] Failed to convert JSON Schema to Zod, using fallback:', error);\n return this.z!.record(this.z!.any()).optional().describe(\"Dynamic Input\");\n }\n }\n\n /**\n * Fetches tools from the MCP server and converts them to LangChain StructuredTools.\n */\n async getTools(): Promise<StructuredTool[]> {\n // If a ToolRouter is provided, use its filtered output\n if (this.options.toolRouter) {\n return this.getToolsViaRouter(this.options.toolRouter);\n }\n\n // Use duck typing instead of instanceof to handle module bundling issues\n const isMultiSession = typeof (this.client as any).getClients === 'function';\n const clients = isMultiSession\n ? (this.client as MultiSessionClient).getClients()\n : [this.client as MCPClient];\n\n const results = await Promise.all(\n clients.map(async (client) => {\n try {\n return await this.transformTools(client);\n } catch (error) {\n console.error(`[LangChainAdapter] Failed to fetch tools from ${client.getServerId()}:`, error);\n return [];\n }\n })\n );\n return results.flat();\n }\n\n /**\n * Build StructuredTools from a ToolRouter's filtered output.\n *\n * In `search` strategy, only meta-tools are registered with the framework.\n * Real tool execution is proxied through `mcp_execute_tool` which uses\n * `router.callTool()` to route to the correct MCP client.\n */\n private async getToolsViaRouter(router: ToolRouter): Promise<StructuredTool[]> {\n await this.ensureDependencies();\n\n const filteredTools = await router.getFilteredTools();\n\n return filteredTools.map((tool) => {\n const routedTool = tool as typeof tool & { sessionId?: string; serverName?: string };\n const namespace = routedTool.serverName ?? routedTool.sessionId;\n const schema = this.jsonSchemaToZod(tool.inputSchema);\n\n return new this.DynamicStructuredTool!({\n name: isMetaTool(tool.name)\n ? tool.name\n : this.getRouterToolKey(tool.name, routedTool.sessionId, routedTool.serverName),\n description: tool.description || `Tool ${tool.name}`,\n schema: schema,\n func: async (args: any) => {\n try {\n // Handle meta-tool calls via the router\n if (isMetaTool(tool.name)) {\n const result = await executeMetaTool(\n tool.name,\n args,\n router,\n (name, toolArgs, namespace) => router.callTool(name, toolArgs, namespace)\n );\n if (result) {\n return result.content.map((c: any) => c.text ?? '').join('\\n');\n }\n }\n\n // For non-meta tools in 'all' or 'groups' strategy,\n // route directly to the correct MCP client\n return await router.callTool(tool.name, args, namespace);\n } catch (error: any) {\n if (this.options.simplifyErrors) {\n return `Error: ${error.message}`;\n }\n throw error;\n }\n },\n });\n });\n }\n\n private getRouterToolKey(toolName: string, sessionId?: string, serverName?: string): string {\n const namespace = sessionId ?? serverName ?? 'mcp';\n const normalized = namespace\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '_')\n .replace(/^_+|_+$/g, '') || 'mcp';\n return `tool_${normalized}_${toolName}`;\n }\n\n /**\n * Convenience static method to fetch tools in a single line.\n */\n static async getTools(client: MCPClient | MultiSessionClient, options: LangChainAdapterOptions = {}): Promise<StructuredTool[]> {\n return new LangChainAdapter(client, options).getTools();\n }\n}\n"]}
|
package/dist/client/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as APP_HOST_DEFAULTS, a as AppHost, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, c as SSEClient, d as SSEClientOptions } from '../index-
|
|
1
|
+
export { A as APP_HOST_DEFAULTS, a as AppHost, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, c as SSEClient, d as SSEClientOptions } from '../index-DcYfpY3H.mjs';
|
|
2
2
|
export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, M as McpConnectionEvent, c as McpConnectionState, d as McpObservabilityEvent } from '../events-CK3N--3g.mjs';
|
|
3
|
-
export { p as McpRpcRequest, q as McpRpcResponse,
|
|
3
|
+
export { p as McpRpcRequest, q as McpRpcResponse, v as ToolInfo } from '../types-CfCoIsWI.mjs';
|
|
4
4
|
import '@modelcontextprotocol/ext-apps/app-bridge';
|
|
5
5
|
import '@modelcontextprotocol/sdk/types.js';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as APP_HOST_DEFAULTS, a as AppHost, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, c as SSEClient, d as SSEClientOptions } from '../index-
|
|
1
|
+
export { A as APP_HOST_DEFAULTS, a as AppHost, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, c as SSEClient, d as SSEClientOptions } from '../index-GfC_eNEv.js';
|
|
2
2
|
export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, M as McpConnectionEvent, c as McpConnectionState, d as McpObservabilityEvent } from '../events-CK3N--3g.js';
|
|
3
|
-
export { p as McpRpcRequest, q as McpRpcResponse,
|
|
3
|
+
export { p as McpRpcRequest, q as McpRpcResponse, v as ToolInfo } from '../types-CfCoIsWI.js';
|
|
4
4
|
import '@modelcontextprotocol/ext-apps/app-bridge';
|
|
5
5
|
import '@modelcontextprotocol/sdk/types.js';
|
package/dist/client/react.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as SSEClient, e as AppHostOptions, f as AppHostClient, a as AppHost } from '../index-
|
|
2
|
-
export { A as APP_HOST_DEFAULTS, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, d as SSEClientOptions } from '../index-
|
|
1
|
+
import { c as SSEClient, e as AppHostOptions, f as AppHostClient, a as AppHost } from '../index-DcYfpY3H.mjs';
|
|
2
|
+
export { A as APP_HOST_DEFAULTS, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, d as SSEClientOptions } from '../index-DcYfpY3H.mjs';
|
|
3
3
|
import { c as McpConnectionState, M as McpConnectionEvent } from '../events-CK3N--3g.mjs';
|
|
4
4
|
export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, d as McpObservabilityEvent } from '../events-CK3N--3g.mjs';
|
|
5
|
-
import {
|
|
6
|
-
export { p as McpRpcRequest, q as McpRpcResponse } from '../types-
|
|
7
|
-
import React$1 from 'react';
|
|
5
|
+
import { v as ToolInfo, k as FinishAuthResult, n as ListToolsRpcResult, L as ListPromptsResult, l as ListResourcesResult } from '../types-CfCoIsWI.mjs';
|
|
6
|
+
export { p as McpRpcRequest, q as McpRpcResponse } from '../types-CfCoIsWI.mjs';
|
|
7
|
+
import React$1, { ReactNode, CSSProperties } from 'react';
|
|
8
8
|
import '@modelcontextprotocol/ext-apps/app-bridge';
|
|
9
9
|
import '@modelcontextprotocol/sdk/types.js';
|
|
10
10
|
|
|
@@ -170,6 +170,85 @@ interface McpClient$1 {
|
|
|
170
170
|
*/
|
|
171
171
|
declare function useMcp(options: UseMcpOptions): McpClient$1;
|
|
172
172
|
|
|
173
|
+
interface OAuthPopupConnectionLike {
|
|
174
|
+
sessionId: string;
|
|
175
|
+
state: string;
|
|
176
|
+
error?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Optional helpers for popup-based OAuth UX.
|
|
180
|
+
*
|
|
181
|
+
* These utilities sit on top of the core MCP auth primitives:
|
|
182
|
+
* - `useMcp({ onRedirect })` to decide how auth navigation happens
|
|
183
|
+
* - `finishAuth(sessionId, code)` to complete code exchange
|
|
184
|
+
*
|
|
185
|
+
* Consumers are free to:
|
|
186
|
+
* - use these helpers as-is for a turnkey popup flow
|
|
187
|
+
* - build their own popup UI/message bridge
|
|
188
|
+
* - skip popups entirely and handle auth in a normal callback page
|
|
189
|
+
*/
|
|
190
|
+
interface OAuthPopupRedirectOptions {
|
|
191
|
+
width?: number;
|
|
192
|
+
height?: number;
|
|
193
|
+
windowName?: string;
|
|
194
|
+
features?: string[];
|
|
195
|
+
onBlocked?: (url: string) => void;
|
|
196
|
+
}
|
|
197
|
+
interface McpOAuthCallbackContentProps {
|
|
198
|
+
code?: string | null;
|
|
199
|
+
sessionId?: string | null;
|
|
200
|
+
title?: ReactNode;
|
|
201
|
+
initialStatus?: string;
|
|
202
|
+
loadingFallback?: ReactNode;
|
|
203
|
+
rootStyle?: CSSProperties;
|
|
204
|
+
cardStyle?: CSSProperties;
|
|
205
|
+
titleStyle?: CSSProperties;
|
|
206
|
+
messageStyle?: CSSProperties;
|
|
207
|
+
renderContainer?: (content: ReactNode) => ReactNode;
|
|
208
|
+
debugPhase?: 'loading' | 'success' | 'error';
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Opens a centered popup window for OAuth.
|
|
212
|
+
*
|
|
213
|
+
* Convenience only: callers can replace this entirely with their own popup,
|
|
214
|
+
* modal, redirect, or router-based navigation strategy.
|
|
215
|
+
*/
|
|
216
|
+
declare function openCenteredPopup(url: string, options?: OAuthPopupRedirectOptions): Window | null;
|
|
217
|
+
/**
|
|
218
|
+
* Creates an `onRedirect` handler suitable for `useMcp({ onRedirect })`.
|
|
219
|
+
*
|
|
220
|
+
* This is the simplest popup entry point, but it is intentionally optional.
|
|
221
|
+
* Applications can provide any redirect handler they want, including full-page
|
|
222
|
+
* navigation or a completely custom popup implementation.
|
|
223
|
+
*/
|
|
224
|
+
declare function createOAuthPopupRedirectHandler(options?: OAuthPopupRedirectOptions): (url: string) => void;
|
|
225
|
+
/**
|
|
226
|
+
* Handles opener-side popup coordination for OAuth code exchange.
|
|
227
|
+
*
|
|
228
|
+
* Use this when you want popup auth but do not want to reimplement the
|
|
229
|
+
* postMessage wiring between the main app window and the popup callback page.
|
|
230
|
+
*
|
|
231
|
+
* If you are not using a popup flow, you do not need this hook.
|
|
232
|
+
*/
|
|
233
|
+
declare function useMcpOAuthPopup<TConnection extends OAuthPopupConnectionLike>(connections: TConnection[], finishAuth: (sessionId: string, code: string) => Promise<unknown>): void;
|
|
234
|
+
/**
|
|
235
|
+
* Default popup callback UI for popup-based OAuth flows.
|
|
236
|
+
*
|
|
237
|
+
* This component reads the OAuth `code` and `state/sessionId`, notifies the
|
|
238
|
+
* opener window, waits for success/failure, and closes the popup on success.
|
|
239
|
+
*
|
|
240
|
+
* It is intentionally optional: apps can replace it with their own callback
|
|
241
|
+
* page UI or skip popup auth entirely and call `finishAuth(sessionId, code)`
|
|
242
|
+
* from any callback route they control.
|
|
243
|
+
*/
|
|
244
|
+
declare function McpOAuthCallbackContent({ code, sessionId, title, initialStatus, loadingFallback, rootStyle, cardStyle, titleStyle, messageStyle, renderContainer, debugPhase, }: McpOAuthCallbackContentProps): JSX.Element;
|
|
245
|
+
/**
|
|
246
|
+
* Tiny fallback component for Suspense-wrapped callback pages.
|
|
247
|
+
*/
|
|
248
|
+
declare function McpOAuthCallbackFallback({ children, }: {
|
|
249
|
+
children?: ReactNode;
|
|
250
|
+
}): JSX.Element;
|
|
251
|
+
|
|
173
252
|
/**
|
|
174
253
|
* Hook to host an MCP App in a React component
|
|
175
254
|
*
|
|
@@ -229,9 +308,10 @@ interface McpAppRendererHandle {
|
|
|
229
308
|
/** Props for {@link useMcpApps}'s `McpAppRenderer` (client is supplied via the hook). */
|
|
230
309
|
interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostContext' | 'onCallTool' | 'onReadResource' | 'onFallbackRequest' | 'onMessage' | 'onOpenLink' | 'onLoggingMessage' | 'onSizeChanged' | 'onError'> {
|
|
231
310
|
name: string;
|
|
311
|
+
client?: McpClient | null;
|
|
232
312
|
toolResourceUri?: string;
|
|
233
313
|
html?: string;
|
|
234
|
-
input?: Record<string, unknown
|
|
314
|
+
input?: Record<string, unknown> | null;
|
|
235
315
|
result?: unknown;
|
|
236
316
|
status?: 'executing' | 'inProgress' | 'complete' | 'idle';
|
|
237
317
|
toolInputPartial?: any;
|
|
@@ -239,14 +319,20 @@ interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostC
|
|
|
239
319
|
className?: string;
|
|
240
320
|
loader?: React$1.ReactNode;
|
|
241
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Renders an interactive MCP application inside a sandboxed iframe.
|
|
324
|
+
*/
|
|
325
|
+
declare const McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
|
|
242
326
|
/**
|
|
243
327
|
* Helpers scoped to one `mcpClient`. Pass the client here once; `McpAppRenderer` only needs per-tool props (`name`, `input`, `result`, `status`).
|
|
244
328
|
*
|
|
245
329
|
* @param mcpClient - From `useMcp()` or context (for example `useMcpContext()`).
|
|
330
|
+
* @deprecated Use the standalone `<McpAppRenderer>` component and `getMcpAppMetadata` utility directly.
|
|
246
331
|
*/
|
|
247
332
|
declare function useMcpApps(mcpClient: McpClient | null): {
|
|
248
333
|
getAppMetadata: (toolName: string) => McpAppMetadata | undefined;
|
|
249
|
-
McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
|
|
334
|
+
McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<Omit<McpAppRendererProps, "client"> & React$1.RefAttributes<McpAppRendererHandle>>>;
|
|
250
335
|
};
|
|
336
|
+
declare function getMcpAppMetadata(mcpClient: McpClient | null, toolName: string, input?: Record<string, unknown> | null): McpAppMetadata | undefined;
|
|
251
337
|
|
|
252
|
-
export { AppHost, type McpAppMetadata, type McpAppRendererHandle, type McpAppRendererProps, type McpClient$1 as McpClient, type McpConnection, McpConnectionEvent, McpConnectionState, SSEClient, ToolInfo, type UseMcpOptions, useAppHost, useMcp, useMcpApps };
|
|
338
|
+
export { AppHost, type McpAppMetadata, McpAppRenderer, type McpAppRendererHandle, type McpAppRendererProps, type McpClient$1 as McpClient, type McpConnection, McpConnectionEvent, McpConnectionState, McpOAuthCallbackContent, type McpOAuthCallbackContentProps, McpOAuthCallbackFallback, type OAuthPopupConnectionLike, type OAuthPopupRedirectOptions, SSEClient, ToolInfo, type UseMcpOptions, createOAuthPopupRedirectHandler, getMcpAppMetadata, openCenteredPopup, useAppHost, useMcp, useMcpApps, useMcpOAuthPopup };
|
package/dist/client/react.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as SSEClient, e as AppHostOptions, f as AppHostClient, a as AppHost } from '../index-
|
|
2
|
-
export { A as APP_HOST_DEFAULTS, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, d as SSEClientOptions } from '../index-
|
|
1
|
+
import { c as SSEClient, e as AppHostOptions, f as AppHostClient, a as AppHost } from '../index-GfC_eNEv.js';
|
|
2
|
+
export { A as APP_HOST_DEFAULTS, D as DEFAULT_MCP_APP_CSP, S as SANDBOX_PROXY_READY_METHOD, b as SANDBOX_RESOURCE_READY_METHOD, d as SSEClientOptions } from '../index-GfC_eNEv.js';
|
|
3
3
|
import { c as McpConnectionState, M as McpConnectionEvent } from '../events-CK3N--3g.js';
|
|
4
4
|
export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, d as McpObservabilityEvent } from '../events-CK3N--3g.js';
|
|
5
|
-
import {
|
|
6
|
-
export { p as McpRpcRequest, q as McpRpcResponse } from '../types-
|
|
7
|
-
import React$1 from 'react';
|
|
5
|
+
import { v as ToolInfo, k as FinishAuthResult, n as ListToolsRpcResult, L as ListPromptsResult, l as ListResourcesResult } from '../types-CfCoIsWI.js';
|
|
6
|
+
export { p as McpRpcRequest, q as McpRpcResponse } from '../types-CfCoIsWI.js';
|
|
7
|
+
import React$1, { ReactNode, CSSProperties } from 'react';
|
|
8
8
|
import '@modelcontextprotocol/ext-apps/app-bridge';
|
|
9
9
|
import '@modelcontextprotocol/sdk/types.js';
|
|
10
10
|
|
|
@@ -170,6 +170,85 @@ interface McpClient$1 {
|
|
|
170
170
|
*/
|
|
171
171
|
declare function useMcp(options: UseMcpOptions): McpClient$1;
|
|
172
172
|
|
|
173
|
+
interface OAuthPopupConnectionLike {
|
|
174
|
+
sessionId: string;
|
|
175
|
+
state: string;
|
|
176
|
+
error?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Optional helpers for popup-based OAuth UX.
|
|
180
|
+
*
|
|
181
|
+
* These utilities sit on top of the core MCP auth primitives:
|
|
182
|
+
* - `useMcp({ onRedirect })` to decide how auth navigation happens
|
|
183
|
+
* - `finishAuth(sessionId, code)` to complete code exchange
|
|
184
|
+
*
|
|
185
|
+
* Consumers are free to:
|
|
186
|
+
* - use these helpers as-is for a turnkey popup flow
|
|
187
|
+
* - build their own popup UI/message bridge
|
|
188
|
+
* - skip popups entirely and handle auth in a normal callback page
|
|
189
|
+
*/
|
|
190
|
+
interface OAuthPopupRedirectOptions {
|
|
191
|
+
width?: number;
|
|
192
|
+
height?: number;
|
|
193
|
+
windowName?: string;
|
|
194
|
+
features?: string[];
|
|
195
|
+
onBlocked?: (url: string) => void;
|
|
196
|
+
}
|
|
197
|
+
interface McpOAuthCallbackContentProps {
|
|
198
|
+
code?: string | null;
|
|
199
|
+
sessionId?: string | null;
|
|
200
|
+
title?: ReactNode;
|
|
201
|
+
initialStatus?: string;
|
|
202
|
+
loadingFallback?: ReactNode;
|
|
203
|
+
rootStyle?: CSSProperties;
|
|
204
|
+
cardStyle?: CSSProperties;
|
|
205
|
+
titleStyle?: CSSProperties;
|
|
206
|
+
messageStyle?: CSSProperties;
|
|
207
|
+
renderContainer?: (content: ReactNode) => ReactNode;
|
|
208
|
+
debugPhase?: 'loading' | 'success' | 'error';
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Opens a centered popup window for OAuth.
|
|
212
|
+
*
|
|
213
|
+
* Convenience only: callers can replace this entirely with their own popup,
|
|
214
|
+
* modal, redirect, or router-based navigation strategy.
|
|
215
|
+
*/
|
|
216
|
+
declare function openCenteredPopup(url: string, options?: OAuthPopupRedirectOptions): Window | null;
|
|
217
|
+
/**
|
|
218
|
+
* Creates an `onRedirect` handler suitable for `useMcp({ onRedirect })`.
|
|
219
|
+
*
|
|
220
|
+
* This is the simplest popup entry point, but it is intentionally optional.
|
|
221
|
+
* Applications can provide any redirect handler they want, including full-page
|
|
222
|
+
* navigation or a completely custom popup implementation.
|
|
223
|
+
*/
|
|
224
|
+
declare function createOAuthPopupRedirectHandler(options?: OAuthPopupRedirectOptions): (url: string) => void;
|
|
225
|
+
/**
|
|
226
|
+
* Handles opener-side popup coordination for OAuth code exchange.
|
|
227
|
+
*
|
|
228
|
+
* Use this when you want popup auth but do not want to reimplement the
|
|
229
|
+
* postMessage wiring between the main app window and the popup callback page.
|
|
230
|
+
*
|
|
231
|
+
* If you are not using a popup flow, you do not need this hook.
|
|
232
|
+
*/
|
|
233
|
+
declare function useMcpOAuthPopup<TConnection extends OAuthPopupConnectionLike>(connections: TConnection[], finishAuth: (sessionId: string, code: string) => Promise<unknown>): void;
|
|
234
|
+
/**
|
|
235
|
+
* Default popup callback UI for popup-based OAuth flows.
|
|
236
|
+
*
|
|
237
|
+
* This component reads the OAuth `code` and `state/sessionId`, notifies the
|
|
238
|
+
* opener window, waits for success/failure, and closes the popup on success.
|
|
239
|
+
*
|
|
240
|
+
* It is intentionally optional: apps can replace it with their own callback
|
|
241
|
+
* page UI or skip popup auth entirely and call `finishAuth(sessionId, code)`
|
|
242
|
+
* from any callback route they control.
|
|
243
|
+
*/
|
|
244
|
+
declare function McpOAuthCallbackContent({ code, sessionId, title, initialStatus, loadingFallback, rootStyle, cardStyle, titleStyle, messageStyle, renderContainer, debugPhase, }: McpOAuthCallbackContentProps): JSX.Element;
|
|
245
|
+
/**
|
|
246
|
+
* Tiny fallback component for Suspense-wrapped callback pages.
|
|
247
|
+
*/
|
|
248
|
+
declare function McpOAuthCallbackFallback({ children, }: {
|
|
249
|
+
children?: ReactNode;
|
|
250
|
+
}): JSX.Element;
|
|
251
|
+
|
|
173
252
|
/**
|
|
174
253
|
* Hook to host an MCP App in a React component
|
|
175
254
|
*
|
|
@@ -229,9 +308,10 @@ interface McpAppRendererHandle {
|
|
|
229
308
|
/** Props for {@link useMcpApps}'s `McpAppRenderer` (client is supplied via the hook). */
|
|
230
309
|
interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostContext' | 'onCallTool' | 'onReadResource' | 'onFallbackRequest' | 'onMessage' | 'onOpenLink' | 'onLoggingMessage' | 'onSizeChanged' | 'onError'> {
|
|
231
310
|
name: string;
|
|
311
|
+
client?: McpClient | null;
|
|
232
312
|
toolResourceUri?: string;
|
|
233
313
|
html?: string;
|
|
234
|
-
input?: Record<string, unknown
|
|
314
|
+
input?: Record<string, unknown> | null;
|
|
235
315
|
result?: unknown;
|
|
236
316
|
status?: 'executing' | 'inProgress' | 'complete' | 'idle';
|
|
237
317
|
toolInputPartial?: any;
|
|
@@ -239,14 +319,20 @@ interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostC
|
|
|
239
319
|
className?: string;
|
|
240
320
|
loader?: React$1.ReactNode;
|
|
241
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Renders an interactive MCP application inside a sandboxed iframe.
|
|
324
|
+
*/
|
|
325
|
+
declare const McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
|
|
242
326
|
/**
|
|
243
327
|
* Helpers scoped to one `mcpClient`. Pass the client here once; `McpAppRenderer` only needs per-tool props (`name`, `input`, `result`, `status`).
|
|
244
328
|
*
|
|
245
329
|
* @param mcpClient - From `useMcp()` or context (for example `useMcpContext()`).
|
|
330
|
+
* @deprecated Use the standalone `<McpAppRenderer>` component and `getMcpAppMetadata` utility directly.
|
|
246
331
|
*/
|
|
247
332
|
declare function useMcpApps(mcpClient: McpClient | null): {
|
|
248
333
|
getAppMetadata: (toolName: string) => McpAppMetadata | undefined;
|
|
249
|
-
McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
|
|
334
|
+
McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<Omit<McpAppRendererProps, "client"> & React$1.RefAttributes<McpAppRendererHandle>>>;
|
|
250
335
|
};
|
|
336
|
+
declare function getMcpAppMetadata(mcpClient: McpClient | null, toolName: string, input?: Record<string, unknown> | null): McpAppMetadata | undefined;
|
|
251
337
|
|
|
252
|
-
export { AppHost, type McpAppMetadata, type McpAppRendererHandle, type McpAppRendererProps, type McpClient$1 as McpClient, type McpConnection, McpConnectionEvent, McpConnectionState, SSEClient, ToolInfo, type UseMcpOptions, useAppHost, useMcp, useMcpApps };
|
|
338
|
+
export { AppHost, type McpAppMetadata, McpAppRenderer, type McpAppRendererHandle, type McpAppRendererProps, type McpClient$1 as McpClient, type McpConnection, McpConnectionEvent, McpConnectionState, McpOAuthCallbackContent, type McpOAuthCallbackContentProps, McpOAuthCallbackFallback, type OAuthPopupConnectionLike, type OAuthPopupRedirectOptions, SSEClient, ToolInfo, type UseMcpOptions, createOAuthPopupRedirectHandler, getMcpAppMetadata, openCenteredPopup, useAppHost, useMcp, useMcpApps, useMcpOAuthPopup };
|