@mcp-ts/sdk 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +20 -27
  2. package/dist/adapters/agui-adapter.d.mts +16 -0
  3. package/dist/adapters/agui-adapter.d.ts +16 -0
  4. package/dist/adapters/agui-adapter.js +185 -0
  5. package/dist/adapters/agui-adapter.js.map +1 -1
  6. package/dist/adapters/agui-adapter.mjs +185 -0
  7. package/dist/adapters/agui-adapter.mjs.map +1 -1
  8. package/dist/adapters/agui-middleware.d.mts +2 -0
  9. package/dist/adapters/agui-middleware.d.ts +2 -0
  10. package/dist/adapters/agui-middleware.js.map +1 -1
  11. package/dist/adapters/agui-middleware.mjs.map +1 -1
  12. package/dist/adapters/ai-adapter.d.mts +21 -0
  13. package/dist/adapters/ai-adapter.d.ts +21 -0
  14. package/dist/adapters/ai-adapter.js +175 -0
  15. package/dist/adapters/ai-adapter.js.map +1 -1
  16. package/dist/adapters/ai-adapter.mjs +175 -0
  17. package/dist/adapters/ai-adapter.mjs.map +1 -1
  18. package/dist/adapters/langchain-adapter.d.mts +16 -0
  19. package/dist/adapters/langchain-adapter.d.ts +16 -0
  20. package/dist/adapters/langchain-adapter.js +179 -0
  21. package/dist/adapters/langchain-adapter.js.map +1 -1
  22. package/dist/adapters/langchain-adapter.mjs +179 -0
  23. package/dist/adapters/langchain-adapter.mjs.map +1 -1
  24. package/dist/client/index.d.mts +2 -2
  25. package/dist/client/index.d.ts +2 -2
  26. package/dist/client/react.d.mts +14 -7
  27. package/dist/client/react.d.ts +14 -7
  28. package/dist/client/react.js +48 -23
  29. package/dist/client/react.js.map +1 -1
  30. package/dist/client/react.mjs +47 -24
  31. package/dist/client/react.mjs.map +1 -1
  32. package/dist/client/vue.d.mts +4 -4
  33. package/dist/client/vue.d.ts +4 -4
  34. package/dist/{index-CQr9q0bF.d.mts → index-DcYfpY3H.d.mts} +1 -1
  35. package/dist/{index-nE_7Io0I.d.ts → index-GfC_eNEv.d.ts} +1 -1
  36. package/dist/index.d.mts +4 -3
  37. package/dist/index.d.ts +4 -3
  38. package/dist/index.js +883 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +868 -2
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/server/index.d.mts +2 -2
  43. package/dist/server/index.d.ts +2 -2
  44. package/dist/server/index.js +3 -1
  45. package/dist/server/index.js.map +1 -1
  46. package/dist/server/index.mjs +3 -1
  47. package/dist/server/index.mjs.map +1 -1
  48. package/dist/shared/index.d.mts +86 -4
  49. package/dist/shared/index.d.ts +86 -4
  50. package/dist/shared/index.js +874 -0
  51. package/dist/shared/index.js.map +1 -1
  52. package/dist/shared/index.mjs +865 -1
  53. package/dist/shared/index.mjs.map +1 -1
  54. package/dist/tool-router-Bo8qZbsD.d.ts +325 -0
  55. package/dist/tool-router-XnWVxPzv.d.mts +325 -0
  56. package/dist/{types-CW6lghof.d.mts → types-CfCoIsWI.d.mts} +27 -1
  57. package/dist/{types-CW6lghof.d.ts → types-CfCoIsWI.d.ts} +27 -1
  58. package/package.json +3 -2
  59. package/src/adapters/agui-adapter.ts +79 -0
  60. package/src/adapters/ai-adapter.ts +75 -0
  61. package/src/adapters/langchain-adapter.ts +74 -0
  62. package/src/client/react/index.ts +2 -0
  63. package/src/client/react/use-mcp-apps.tsx +50 -32
  64. package/src/server/index.ts +2 -0
  65. package/src/server/mcp/oauth-client.ts +3 -1
  66. package/src/shared/index.ts +36 -0
  67. package/src/shared/meta-tools.ts +387 -0
  68. package/src/shared/schema-compressor.ts +124 -0
  69. package/src/shared/tool-index.ts +499 -0
  70. package/src/shared/tool-router.ts +469 -0
  71. package/src/shared/types.ts +30 -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,EACJ;AAAA,EAEA,MAAc,eAAe,MAAA,EAA8C;AACvE,IAAA,IAAI,CAAC,MAAA,CAAO,WAAA,EAAY,EAAG;AACvB,MAAA,OAAO,EAAC;AAAA,IACZ;AAEA,IAAA,MAAM,KAAK,kBAAA,EAAmB;AAE9B,IAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,SAAA,EAAU;AACtC,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK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A,CAAQ,IAAA,CAAK,4EAA4E,KAAK,CAAA;AAC9F,MAAA,OAAO,IAAA,CAAK,CAAA,CAAG,MAAA,CAAO,IAAA,CAAK,CAAA,CAAG,GAAA,EAAK,CAAA,CAAE,QAAA,EAAS,CAAE,QAAA,CAAS,eAAe,CAAA;AAAA,IAC5E;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAA,GAAsC;AAExC,IAAA,MAAM,cAAA,GAAiB,OAAQ,IAAA,CAAK,MAAA,CAAe,UAAA,KAAe,UAAA;AAClE,IAAA,MAAM,OAAA,GAAU,iBACT,IAAA,CAAK,MAAA,CAA8B,YAAW,GAC/C,CAAC,KAAK,MAAmB,CAAA;AAE/B,IAAA,MAAM,OAAA,GAAU,MAAM,OAAA,CAAQ,GAAA;AAAA,MAC1B,OAAA,CAAQ,GAAA,CAAI,OAAO,MAAA,KAAW;AAC1B,QAAA,IAAI;AACA,UAAA,OAAO,MAAM,IAAA,CAAK,cAAA,CAAe,MAAM,CAAA;AAAA,QAC3C,SAAS,KAAA,EAAO;AACZ,UAAA,OAAA,CAAQ,MAAM,CAAA,8CAAA,EAAiD,MAAA,CAAO,WAAA,EAAa,KAAK,KAAK,CAAA;AAC7F,UAAA,OAAO,EAAC;AAAA,QACZ;AAAA,MACJ,CAAC;AAAA,KACL;AACA,IAAA,OAAO,QAAQ,IAAA,EAAK;AAAA,EACxB;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":["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,MAAA,MAAM,eAAe,GAAA,YAAe,KAAA,GAAQ,GAAA,CAAI,OAAA,GAAU,OAAO,GAAG,CAAA;AACpE,MAAA,OAAO;AAAA,QACL,KAAA,EAAO;AAAA,UACL,SAAS,CAAC,EAAE,MAAM,MAAA,EAAQ,IAAA,EAAM,cAAc,CAAA;AAAA,UAC9C,OAAA,EAAS;AAAA;AACX,OACF;AAAA,IACF;AAAA,EACF,CAAA;AAEA,EAAA,Q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AS;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"]}
@@ -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-CQr9q0bF.mjs';
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, T as ToolInfo } from '../types-CW6lghof.mjs';
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';
@@ -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-nE_7Io0I.js';
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, T as ToolInfo } from '../types-CW6lghof.js';
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';
@@ -1,9 +1,9 @@
1
- import { c as SSEClient, e as AppHostOptions, f as AppHostClient, a as AppHost } from '../index-CQr9q0bF.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-CQr9q0bF.mjs';
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 { T as ToolInfo, k as FinishAuthResult, n as ListToolsRpcResult, L as ListPromptsResult, l as ListResourcesResult } from '../types-CW6lghof.mjs';
6
- export { p as McpRpcRequest, q as McpRpcResponse } from '../types-CW6lghof.mjs';
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
7
  import React$1 from 'react';
8
8
  import '@modelcontextprotocol/ext-apps/app-bridge';
9
9
  import '@modelcontextprotocol/sdk/types.js';
@@ -229,9 +229,10 @@ interface McpAppRendererHandle {
229
229
  /** Props for {@link useMcpApps}'s `McpAppRenderer` (client is supplied via the hook). */
230
230
  interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostContext' | 'onCallTool' | 'onReadResource' | 'onFallbackRequest' | 'onMessage' | 'onOpenLink' | 'onLoggingMessage' | 'onSizeChanged' | 'onError'> {
231
231
  name: string;
232
+ client?: McpClient | null;
232
233
  toolResourceUri?: string;
233
234
  html?: string;
234
- input?: Record<string, unknown>;
235
+ input?: Record<string, unknown> | null;
235
236
  result?: unknown;
236
237
  status?: 'executing' | 'inProgress' | 'complete' | 'idle';
237
238
  toolInputPartial?: any;
@@ -239,14 +240,20 @@ interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostC
239
240
  className?: string;
240
241
  loader?: React$1.ReactNode;
241
242
  }
243
+ /**
244
+ * Renders an interactive MCP application inside a sandboxed iframe.
245
+ */
246
+ declare const McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
242
247
  /**
243
248
  * Helpers scoped to one `mcpClient`. Pass the client here once; `McpAppRenderer` only needs per-tool props (`name`, `input`, `result`, `status`).
244
249
  *
245
250
  * @param mcpClient - From `useMcp()` or context (for example `useMcpContext()`).
251
+ * @deprecated Use the standalone `<McpAppRenderer>` component and `getMcpAppMetadata` utility directly.
246
252
  */
247
253
  declare function useMcpApps(mcpClient: McpClient | null): {
248
254
  getAppMetadata: (toolName: string) => McpAppMetadata | undefined;
249
- McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
255
+ McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<Omit<McpAppRendererProps, "client"> & React$1.RefAttributes<McpAppRendererHandle>>>;
250
256
  };
257
+ declare function getMcpAppMetadata(mcpClient: McpClient | null, toolName: string, input?: Record<string, unknown> | null): McpAppMetadata | undefined;
251
258
 
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 };
259
+ export { AppHost, type McpAppMetadata, McpAppRenderer, type McpAppRendererHandle, type McpAppRendererProps, type McpClient$1 as McpClient, type McpConnection, McpConnectionEvent, McpConnectionState, SSEClient, ToolInfo, type UseMcpOptions, getMcpAppMetadata, useAppHost, useMcp, useMcpApps };
@@ -1,9 +1,9 @@
1
- import { c as SSEClient, e as AppHostOptions, f as AppHostClient, a as AppHost } from '../index-nE_7Io0I.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-nE_7Io0I.js';
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 { T as ToolInfo, k as FinishAuthResult, n as ListToolsRpcResult, L as ListPromptsResult, l as ListResourcesResult } from '../types-CW6lghof.js';
6
- export { p as McpRpcRequest, q as McpRpcResponse } from '../types-CW6lghof.js';
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
7
  import React$1 from 'react';
8
8
  import '@modelcontextprotocol/ext-apps/app-bridge';
9
9
  import '@modelcontextprotocol/sdk/types.js';
@@ -229,9 +229,10 @@ interface McpAppRendererHandle {
229
229
  /** Props for {@link useMcpApps}'s `McpAppRenderer` (client is supplied via the hook). */
230
230
  interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostContext' | 'onCallTool' | 'onReadResource' | 'onFallbackRequest' | 'onMessage' | 'onOpenLink' | 'onLoggingMessage' | 'onSizeChanged' | 'onError'> {
231
231
  name: string;
232
+ client?: McpClient | null;
232
233
  toolResourceUri?: string;
233
234
  html?: string;
234
- input?: Record<string, unknown>;
235
+ input?: Record<string, unknown> | null;
235
236
  result?: unknown;
236
237
  status?: 'executing' | 'inProgress' | 'complete' | 'idle';
237
238
  toolInputPartial?: any;
@@ -239,14 +240,20 @@ interface McpAppRendererProps extends Pick<UseAppHostOptions, 'sandbox' | 'hostC
239
240
  className?: string;
240
241
  loader?: React$1.ReactNode;
241
242
  }
243
+ /**
244
+ * Renders an interactive MCP application inside a sandboxed iframe.
245
+ */
246
+ declare const McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
242
247
  /**
243
248
  * Helpers scoped to one `mcpClient`. Pass the client here once; `McpAppRenderer` only needs per-tool props (`name`, `input`, `result`, `status`).
244
249
  *
245
250
  * @param mcpClient - From `useMcp()` or context (for example `useMcpContext()`).
251
+ * @deprecated Use the standalone `<McpAppRenderer>` component and `getMcpAppMetadata` utility directly.
246
252
  */
247
253
  declare function useMcpApps(mcpClient: McpClient | null): {
248
254
  getAppMetadata: (toolName: string) => McpAppMetadata | undefined;
249
- McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<McpAppRendererProps & React$1.RefAttributes<McpAppRendererHandle>>>;
255
+ McpAppRenderer: React$1.MemoExoticComponent<React$1.ForwardRefExoticComponent<Omit<McpAppRendererProps, "client"> & React$1.RefAttributes<McpAppRendererHandle>>>;
250
256
  };
257
+ declare function getMcpAppMetadata(mcpClient: McpClient | null, toolName: string, input?: Record<string, unknown> | null): McpAppMetadata | undefined;
251
258
 
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 };
259
+ export { AppHost, type McpAppMetadata, McpAppRenderer, type McpAppRendererHandle, type McpAppRendererProps, type McpClient$1 as McpClient, type McpConnection, McpConnectionEvent, McpConnectionState, SSEClient, ToolInfo, type UseMcpOptions, getMcpAppMetadata, useAppHost, useMcp, useMcpApps };
@@ -1080,6 +1080,21 @@ function useAppHost(client, iframeRef, options) {
1080
1080
  }, [client, iframeRef]);
1081
1081
  return { host, error };
1082
1082
  }
1083
+
1084
+ // src/shared/meta-tools.ts
1085
+ function resolveMetaToolProxy(toolName, args) {
1086
+ if (toolName === "mcp_execute_tool") {
1087
+ const innerName = args?.toolName;
1088
+ const innerArgs = args?.args;
1089
+ return {
1090
+ toolName: typeof innerName === "string" && innerName ? innerName : toolName,
1091
+ args: innerArgs && typeof innerArgs === "object" && !Array.isArray(innerArgs) ? innerArgs : {}
1092
+ };
1093
+ }
1094
+ const match = toolName.match(/(?:tool_[^_]+_)?(.+)$/);
1095
+ const resolvedName = match?.[1] ?? toolName;
1096
+ return { toolName: resolvedName, args: args ?? {} };
1097
+ }
1083
1098
  var McpAppViewInner = react.forwardRef(function McpAppView({
1084
1099
  clientRef,
1085
1100
  name,
@@ -1104,7 +1119,8 @@ var McpAppViewInner = react.forwardRef(function McpAppView({
1104
1119
  loader
1105
1120
  }, ref) {
1106
1121
  const mcpClient = clientRef.current;
1107
- const metadata = getMcpAppMetadata(mcpClient, name);
1122
+ const { toolName: resolvedToolName, args: resolvedInput } = resolveMetaToolProxy(name, input);
1123
+ const metadata = getMcpAppMetadata(mcpClient, resolvedToolName, resolvedInput);
1108
1124
  const sseClient = mcpClient?.sseClient ?? null;
1109
1125
  const resourceUri = toolResourceUri || metadata?.resourceUri;
1110
1126
  const appSessionId = metadata?.sessionId;
@@ -1184,7 +1200,7 @@ var McpAppViewInner = react.forwardRef(function McpAppView({
1184
1200
  const [error, setError] = react.useState(null);
1185
1201
  const sentInputRef = react.useRef(false);
1186
1202
  const sentResultRef = react.useRef(false);
1187
- const lastInputRef = react.useRef(input);
1203
+ const lastInputRef = react.useRef(resolvedInput);
1188
1204
  const lastResultRef = react.useRef(result);
1189
1205
  const lastStatusRef = react.useRef(status);
1190
1206
  react.useEffect(() => {
@@ -1214,13 +1230,13 @@ var McpAppViewInner = react.forwardRef(function McpAppView({
1214
1230
  host.launch({ uri: resourceUri, html }, appSessionId).then(() => setIsLaunched(true)).catch((err) => setError(err instanceof Error ? err : new Error(String(err))));
1215
1231
  }, [host, resourceUri, html, appSessionId]);
1216
1232
  react.useEffect(() => {
1217
- if (!host || !isLaunched || !resourceUri || !appSessionId || !input) return;
1218
- if (!sentInputRef.current || JSON.stringify(input) !== JSON.stringify(lastInputRef.current)) {
1233
+ if (!host || !isLaunched || !resourceUri || !appSessionId || !resolvedInput) return;
1234
+ if (!sentInputRef.current || JSON.stringify(resolvedInput) !== JSON.stringify(lastInputRef.current)) {
1219
1235
  sentInputRef.current = true;
1220
- lastInputRef.current = input;
1221
- host.sendToolInput(input);
1236
+ lastInputRef.current = resolvedInput;
1237
+ host.sendToolInput(resolvedInput);
1222
1238
  }
1223
- }, [host, isLaunched, input, resourceUri, appSessionId, name]);
1239
+ }, [host, isLaunched, resolvedInput, resourceUri, appSessionId, resolvedToolName]);
1224
1240
  react.useEffect(() => {
1225
1241
  if (!host || !isLaunched || !resourceUri || !appSessionId || result === void 0) return;
1226
1242
  if (status !== "complete") return;
@@ -1230,7 +1246,7 @@ var McpAppViewInner = react.forwardRef(function McpAppView({
1230
1246
  const formattedResult = typeof result === "string" ? { content: [{ type: "text", text: result }] } : result;
1231
1247
  host.sendToolResult(formattedResult);
1232
1248
  }
1233
- }, [host, isLaunched, result, status, resourceUri, appSessionId, name]);
1249
+ }, [host, isLaunched, result, status, resourceUri, appSessionId, resolvedToolName]);
1234
1250
  react.useEffect(() => {
1235
1251
  if (status === "executing" && lastStatusRef.current !== "executing") {
1236
1252
  sentInputRef.current = false;
@@ -1306,30 +1322,37 @@ var McpAppViewInner = react.forwardRef(function McpAppView({
1306
1322
  });
1307
1323
  var McpAppView2 = react.memo(McpAppViewInner);
1308
1324
  McpAppView2.displayName = "McpAppView";
1325
+ var McpAppRenderer = react.memo(
1326
+ react.forwardRef(function McpAppRenderer2({ client, ...props }, ref) {
1327
+ const clientRef = react.useRef(client || null);
1328
+ clientRef.current = client || null;
1329
+ return /* @__PURE__ */ jsxRuntime.jsx(McpAppView2, { ref, clientRef, ...props });
1330
+ })
1331
+ );
1309
1332
  function useMcpApps(mcpClient) {
1310
- const clientRef = react.useRef(mcpClient);
1311
- clientRef.current = mcpClient;
1312
1333
  const getAppMetadata = react.useCallback(
1313
- (toolName) => getMcpAppMetadata(clientRef.current, toolName),
1314
- []
1334
+ (toolName) => getMcpAppMetadata(mcpClient, toolName),
1335
+ [mcpClient]
1315
1336
  );
1316
- const McpAppRenderer = react.useMemo(() => {
1317
- const Inner = react.forwardRef(function McpAppRenderer2(props, ref) {
1318
- return /* @__PURE__ */ jsxRuntime.jsx(McpAppView2, { ref, clientRef, ...props });
1319
- });
1320
- const Renderer = react.memo(Inner);
1321
- Renderer.displayName = "McpAppRenderer";
1322
- return Renderer;
1323
- }, []);
1324
- return { getAppMetadata, McpAppRenderer };
1337
+ const BoundMcpAppRenderer = react.useMemo(() => {
1338
+ const Renderer = react.forwardRef(
1339
+ function BoundMcpAppRenderer2(props, ref) {
1340
+ return /* @__PURE__ */ jsxRuntime.jsx(McpAppRenderer, { ref, client: mcpClient, ...props });
1341
+ }
1342
+ );
1343
+ Renderer.displayName = "BoundMcpAppRenderer";
1344
+ return react.memo(Renderer);
1345
+ }, [mcpClient]);
1346
+ return { getAppMetadata, McpAppRenderer: BoundMcpAppRenderer };
1325
1347
  }
1326
1348
  function extractToolName(fullName) {
1327
1349
  const match = fullName.match(/(?:tool_[^_]+_)?(.+)$/);
1328
1350
  return match?.[1] || fullName;
1329
1351
  }
1330
- function getMcpAppMetadata(mcpClient, toolName) {
1352
+ function getMcpAppMetadata(mcpClient, toolName, input) {
1331
1353
  if (!mcpClient) return void 0;
1332
- const extractedName = extractToolName(toolName);
1354
+ const { toolName: proxyToolName } = resolveMetaToolProxy(toolName, input);
1355
+ const extractedName = extractToolName(proxyToolName);
1333
1356
  for (const conn of mcpClient.connections) {
1334
1357
  for (const tool of conn.tools) {
1335
1358
  const candidateName = extractToolName(tool.name);
@@ -1349,9 +1372,11 @@ function getMcpAppMetadata(mcpClient, toolName) {
1349
1372
  exports.APP_HOST_DEFAULTS = APP_HOST_DEFAULTS;
1350
1373
  exports.AppHost = AppHost;
1351
1374
  exports.DEFAULT_MCP_APP_CSP = DEFAULT_MCP_APP_CSP;
1375
+ exports.McpAppRenderer = McpAppRenderer;
1352
1376
  exports.SANDBOX_PROXY_READY_METHOD = SANDBOX_PROXY_READY_METHOD;
1353
1377
  exports.SANDBOX_RESOURCE_READY_METHOD = SANDBOX_RESOURCE_READY_METHOD;
1354
1378
  exports.SSEClient = SSEClient;
1379
+ exports.getMcpAppMetadata = getMcpAppMetadata;
1355
1380
  exports.useAppHost = useAppHost;
1356
1381
  exports.useMcp = useMcp;
1357
1382
  exports.useMcpApps = useMcpApps;