@tambo-ai/react 0.59.0 → 0.60.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 (83) hide show
  1. package/dist/hooks/react-query-hooks.d.ts +14 -1
  2. package/dist/hooks/react-query-hooks.d.ts.map +1 -1
  3. package/dist/hooks/react-query-hooks.js +13 -0
  4. package/dist/hooks/react-query-hooks.js.map +1 -1
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/mcp/__tests__/elicitation.test.d.ts +2 -0
  8. package/dist/mcp/__tests__/elicitation.test.d.ts.map +1 -0
  9. package/dist/mcp/__tests__/elicitation.test.js +261 -0
  10. package/dist/mcp/__tests__/elicitation.test.js.map +1 -0
  11. package/dist/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
  12. package/dist/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
  13. package/dist/mcp/__tests__/mcp-hooks.test.js +504 -0
  14. package/dist/mcp/__tests__/mcp-hooks.test.js.map +1 -0
  15. package/dist/mcp/__tests__/tambo-mcp-provider.test.js +151 -12
  16. package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
  17. package/dist/mcp/elicitation.d.ts +80 -0
  18. package/dist/mcp/elicitation.d.ts.map +1 -0
  19. package/dist/mcp/elicitation.js +55 -0
  20. package/dist/mcp/elicitation.js.map +1 -0
  21. package/dist/mcp/index.d.ts +3 -2
  22. package/dist/mcp/index.d.ts.map +1 -1
  23. package/dist/mcp/index.js +2 -1
  24. package/dist/mcp/index.js.map +1 -1
  25. package/dist/mcp/mcp-client.d.ts +41 -9
  26. package/dist/mcp/mcp-client.d.ts.map +1 -1
  27. package/dist/mcp/mcp-client.js.map +1 -1
  28. package/dist/mcp/mcp-hooks.d.ts +20 -6
  29. package/dist/mcp/mcp-hooks.d.ts.map +1 -1
  30. package/dist/mcp/mcp-hooks.js +71 -24
  31. package/dist/mcp/mcp-hooks.js.map +1 -1
  32. package/dist/mcp/tambo-mcp-provider.d.ts +60 -6
  33. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  34. package/dist/mcp/tambo-mcp-provider.js +231 -172
  35. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  36. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  37. package/dist/providers/tambo-interactable-provider.js +11 -4
  38. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  39. package/dist/providers/tambo-provider.d.ts.map +1 -1
  40. package/dist/providers/tambo-provider.js +0 -4
  41. package/dist/providers/tambo-provider.js.map +1 -1
  42. package/esm/hooks/react-query-hooks.d.ts +14 -1
  43. package/esm/hooks/react-query-hooks.d.ts.map +1 -1
  44. package/esm/hooks/react-query-hooks.js +13 -1
  45. package/esm/hooks/react-query-hooks.js.map +1 -1
  46. package/esm/index.js +2 -0
  47. package/esm/index.js.map +1 -1
  48. package/esm/mcp/__tests__/elicitation.test.d.ts +2 -0
  49. package/esm/mcp/__tests__/elicitation.test.d.ts.map +1 -0
  50. package/esm/mcp/__tests__/elicitation.test.js +259 -0
  51. package/esm/mcp/__tests__/elicitation.test.js.map +1 -0
  52. package/esm/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
  53. package/esm/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
  54. package/esm/mcp/__tests__/mcp-hooks.test.js +469 -0
  55. package/esm/mcp/__tests__/mcp-hooks.test.js.map +1 -0
  56. package/esm/mcp/__tests__/tambo-mcp-provider.test.js +151 -12
  57. package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
  58. package/esm/mcp/elicitation.d.ts +80 -0
  59. package/esm/mcp/elicitation.d.ts.map +1 -0
  60. package/esm/mcp/elicitation.js +52 -0
  61. package/esm/mcp/elicitation.js.map +1 -0
  62. package/esm/mcp/index.d.ts +3 -2
  63. package/esm/mcp/index.d.ts.map +1 -1
  64. package/esm/mcp/index.js +1 -1
  65. package/esm/mcp/index.js.map +1 -1
  66. package/esm/mcp/mcp-client.d.ts +41 -9
  67. package/esm/mcp/mcp-client.d.ts.map +1 -1
  68. package/esm/mcp/mcp-client.js.map +1 -1
  69. package/esm/mcp/mcp-hooks.d.ts +20 -6
  70. package/esm/mcp/mcp-hooks.d.ts.map +1 -1
  71. package/esm/mcp/mcp-hooks.js +73 -26
  72. package/esm/mcp/mcp-hooks.js.map +1 -1
  73. package/esm/mcp/tambo-mcp-provider.d.ts +60 -6
  74. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  75. package/esm/mcp/tambo-mcp-provider.js +231 -173
  76. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  77. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  78. package/esm/providers/tambo-interactable-provider.js +11 -4
  79. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  80. package/esm/providers/tambo-provider.d.ts.map +1 -1
  81. package/esm/providers/tambo-provider.js +0 -4
  82. package/esm/providers/tambo-provider.js.map +1 -1
  83. package/package.json +8 -8
@@ -1,15 +1,47 @@
1
1
  import { type OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
2
2
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
- import { CreateMessageRequest, CreateMessageResult, ElicitRequest, ElicitResult } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
+ import { ClientNotification, ClientRequest, CreateMessageRequest, CreateMessageResult, ElicitRequest, ElicitResult } from "@modelcontextprotocol/sdk/types.js";
4
5
  import { JSONSchema7 } from "json-schema";
5
6
  export declare enum MCPTransport {
6
7
  SSE = "sse",
7
8
  HTTP = "http"
8
9
  }
10
+ /**
11
+ * Handler for MCP elicitation requests.
12
+ * Receives the elicit request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
13
+ * @param request - The elicitation request from the server
14
+ * @param extra - Additional context including AbortSignal for cancellation
15
+ * @returns Promise resolving to the elicitation result
16
+ * @example
17
+ * ```typescript
18
+ * const handler: MCPElicitationHandler = async (request, extra) => {
19
+ * // Listen for cancellation
20
+ * extra.signal.addEventListener('abort', () => {
21
+ * console.log('Request cancelled');
22
+ * });
23
+ *
24
+ * // Return user's response
25
+ * return {
26
+ * action: 'accept',
27
+ * content: { name: 'John' }
28
+ * };
29
+ * };
30
+ * ```
31
+ */
32
+ export type MCPElicitationHandler = (e: ElicitRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<ElicitResult>;
33
+ /**
34
+ * Handler for MCP sampling requests (create_message).
35
+ * Receives the sampling request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
36
+ * @param request - The sampling/create_message request from the server
37
+ * @param extra - Additional context including AbortSignal for cancellation
38
+ * @returns Promise resolving to the sampling result
39
+ */
40
+ export type MCPSamplingHandler = (e: CreateMessageRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<CreateMessageResult>;
9
41
  /**
10
42
  * Handlers for MCP requests - these are only used if the server supports the corresponding capabilities
11
- * @param elicitation - Handler for elicitation requests
12
- * @param sampling - Handler for sampling requests
43
+ * @param elicitation - Handler for elicitation requests (receives request and RequestHandlerExtra with AbortSignal)
44
+ * @param sampling - Handler for sampling requests (receives request and RequestHandlerExtra with AbortSignal)
13
45
  * @example
14
46
  * ```typescript
15
47
  * const mcp = await MCPClient.create(
@@ -19,14 +51,14 @@ export declare enum MCPTransport {
19
51
  * undefined,
20
52
  * undefined,
21
53
  * {
22
- * elicitation: (e: ElicitRequest) => Promise.resolve({...}),
54
+ * elicitation: (e, extra) => Promise.resolve({...}),
23
55
  * },
24
- * });
56
+ * );
25
57
  * ```
26
58
  */
27
59
  export interface MCPHandlers {
28
- elicitation: (e: ElicitRequest) => Promise<ElicitResult>;
29
- sampling: (e: CreateMessageRequest) => Promise<CreateMessageResult>;
60
+ elicitation: MCPElicitationHandler;
61
+ sampling: MCPSamplingHandler;
30
62
  }
31
63
  /**
32
64
  * A client for interacting with MCP (Model Context Protocol) servers.
@@ -133,8 +165,8 @@ export declare class MCPClient {
133
165
  * @throws {Error} Will throw an error if the tool call fails or if arguments are invalid
134
166
  */
135
167
  callTool(name: string, args: Record<string, unknown>, _meta?: Record<string, unknown>): Promise<MCPToolCallResult>;
136
- updateElicitationHandler(handler: ((e: ElicitRequest) => Promise<ElicitResult>) | undefined): void;
137
- updateSamplingHandler(handler: ((e: CreateMessageRequest) => Promise<CreateMessageResult>) | undefined): void;
168
+ updateElicitationHandler(handler: MCPElicitationHandler | undefined): void;
169
+ updateSamplingHandler(handler: MCPSamplingHandler | undefined): void;
138
170
  close(): Promise<void>;
139
171
  }
140
172
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,OAAO,EACL,oBAAoB,EAEpB,mBAAmB,EACnB,aAAa,EAEb,YAAY,EACb,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACzD,QAAQ,EAAE,CAAC,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACrE;AAED;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,SAAS,CAAqD;IACtE,OAAO,CAAC,aAAa,CAAe;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAS;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AAG,8BAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YACtD,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;YACzC,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,8BAAmB,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,qBAAqB,CACnB,OAEa;QAEb,iCAAiC;QACjC,IAAI,OAAO,KAAK,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QAED,yFAAyF;QACzF,4DAA4D;QAC5D,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG;YACd,GAAG,IAAI,CAAC,QAAQ;YAChB,QAAQ,EAAE,OAAO;SAClB,CAAC;QACF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,MAAM,GAAG,qCAA0B,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;YACzC,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,qCAA0B,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,KAAK;QACT,yEAAyE;QACzE,yEAAyE;QACzE,UAAU;QACV,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF;AA/PD,8BA+PC","sourcesContent":["import { type OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport {\n CreateMessageRequest,\n CreateMessageRequestSchema,\n CreateMessageResult,\n ElicitRequest,\n ElicitRequestSchema,\n ElicitResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\n}\n\n/**\n * Handlers for MCP requests - these are only used if the server supports the corresponding capabilities\n * @param elicitation - Handler for elicitation requests\n * @param sampling - Handler for sampling requests\n * @example\n * ```typescript\n * const mcp = await MCPClient.create(\n * 'https://api.example.com/mcp',\n * MCPTransport.HTTP,\n * {},\n * undefined,\n * undefined,\n * {\n * elicitation: (e: ElicitRequest) => Promise.resolve({...}),\n * },\n * });\n * ```\n */\nexport interface MCPHandlers {\n elicitation: (e: ElicitRequest) => Promise<ElicitResult>;\n sampling: (e: CreateMessageRequest) => Promise<CreateMessageResult>;\n}\n\n/**\n * A client for interacting with MCP (Model Context Protocol) servers.\n * Provides a simple interface for listing and calling tools exposed by the server.\n * @example\n * ```typescript\n * const mcp = await MCPClient.create('https://api.example.com/mcp');\n * const tools = await mcp.listTools();\n * const result = await mcp.callTool('toolName', { arg1: 'value1' });\n * ```\n */\nexport class MCPClient {\n /**\n * The underlying MCP client\n *\n * Be careful not to mutate the client directly, use the methods provided instead.\n */\n client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\n private transportType: MCPTransport;\n public sessionId?: string;\n private endpoint: string;\n private headers: Record<string, string>;\n private authProvider?: OAuthClientProvider;\n private handlers: Partial<MCPHandlers>;\n\n /**\n * Private constructor to enforce using the static create method.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport to use for the MCP client\n * @param headers - Optional custom headers to include in requests\n */\n private constructor(\n endpoint: string,\n transportType: MCPTransport,\n headers?: Record<string, string>,\n authProvider?: OAuthClientProvider,\n sessionId?: string,\n handlers: Partial<MCPHandlers> = {},\n ) {\n this.endpoint = endpoint;\n this.headers = headers ?? {};\n this.authProvider = authProvider;\n this.transportType = transportType;\n this.handlers = handlers;\n this.transport = this.initializeTransport(sessionId);\n this.client = this.initializeClient();\n }\n\n /**\n * Creates and initializes a new MCPClient instance. This is the recommended\n * way to create an MCPClient as it handles both instantiation and connection\n * setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport type to use for the MCP client. Defaults to HTTP.\n * @param headers - Optional custom headers to include in requests\n * @param authProvider - Optional auth provider to use for authentication\n * @param sessionId - Optional session id to use for the MCP client - if not\n * provided, a new session will be created\n * @returns A connected MCPClient instance ready for use\n * @throws {Error} Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transportType: MCPTransport = MCPTransport.HTTP,\n headers: Record<string, string> | undefined,\n authProvider: OAuthClientProvider | undefined,\n sessionId: string | undefined,\n handlers: Partial<MCPHandlers> = {},\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(\n endpoint,\n transportType,\n headers,\n authProvider,\n sessionId,\n handlers,\n );\n await mcpClient.client.connect(mcpClient.transport);\n if (\"sessionId\" in mcpClient.transport) {\n mcpClient.sessionId = mcpClient.transport.sessionId;\n }\n return mcpClient;\n }\n\n private initializeTransport(sessionId: string | undefined) {\n if (this.transportType === MCPTransport.SSE) {\n return new SSEClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n });\n } else {\n return new StreamableHTTPClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n sessionId,\n });\n }\n }\n\n /**\n * Initializes the MCP client with the appropriate capabilities and handlers\n * @returns The initialized MCP client\n */\n private initializeClient() {\n const elicitationCapability = this.handlers.elicitation\n ? { elicitation: {} }\n : {};\n const samplingCapability = this.handlers.sampling ? { sampling: {} } : {};\n const client = new Client(\n {\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n },\n {\n capabilities: {\n ...elicitationCapability,\n ...samplingCapability,\n },\n },\n );\n\n if (this.handlers.elicitation) {\n client.setRequestHandler(ElicitRequestSchema, this.handlers.elicitation);\n }\n if (this.handlers.sampling) {\n client.setRequestHandler(\n CreateMessageRequestSchema,\n this.handlers.sampling,\n );\n }\n return client;\n }\n\n /**\n * Retrieves a complete list of all available tools from the MCP server.\n * Handles pagination automatically by following cursors until all tools are fetched.\n * @returns A complete list of all available tools and their descriptions\n * @throws {Error} Will throw an error if any server request fails during pagination\n */\n async listTools(): Promise<MCPToolSpec[]> {\n const allTools: MCPToolSpec[] = [];\n let hasMore = true;\n let cursor: string | undefined = undefined;\n\n while (hasMore) {\n const response = await this.client.listTools({ cursor }, {});\n allTools.push(\n ...response.tools.map((tool): MCPToolSpec => {\n // make sure the right type is used\n const inputSchemaType: string = tool.inputSchema.type;\n if (inputSchemaType !== \"object\") {\n throw new Error(\n `Input schema for tool ${tool.name} is not an object`,\n );\n }\n\n return {\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema as JSONSchema7,\n };\n }),\n );\n\n if (response.nextCursor) {\n cursor = response.nextCursor;\n } else {\n hasMore = false;\n }\n }\n\n return allTools;\n }\n\n getServerCapabilities() {\n return this.client.getServerCapabilities();\n }\n\n getServerVersion() {\n return this.client.getServerVersion();\n }\n\n getInstructions() {\n return this.client.getInstructions();\n }\n\n /**\n * Calls a specific tool on the MCP server with the provided arguments.\n * @param name - The name of the tool to call\n * @param args - Arguments to pass to the tool, must match the tool's expected schema\n * @returns The result from the tool execution\n * @throws {Error} Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(\n name: string,\n args: Record<string, unknown>,\n _meta?: Record<string, unknown>,\n ): Promise<MCPToolCallResult> {\n const result = await this.client.callTool({\n name,\n arguments: args,\n _meta,\n });\n return result;\n }\n\n updateElicitationHandler(\n handler: ((e: ElicitRequest) => Promise<ElicitResult>) | undefined,\n ) {\n // Skip if handler hasn't changed\n if (handler === this.handlers.elicitation) {\n return;\n }\n\n // Because we advertise the elicitation capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.elicitation) {\n throw new Error(\"Elicitation handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n elicitation: handler,\n };\n if (!handler) {\n const method = ElicitRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(ElicitRequestSchema, handler);\n }\n\n updateSamplingHandler(\n handler:\n | ((e: CreateMessageRequest) => Promise<CreateMessageResult>)\n | undefined,\n ) {\n // Skip if handler hasn't changed\n if (handler === this.handlers.sampling) {\n return;\n }\n\n // Because we advertise the sampling capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.sampling) {\n throw new Error(\"Sampling handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n sampling: handler,\n };\n if (!handler) {\n const method = CreateMessageRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(CreateMessageRequestSchema, handler);\n }\n\n async close() {\n // Not really sure which one of these to close first, but we'll close the\n // transport first so that no requests can come in and hit closing/closed\n // clients\n await this.transport.close();\n await this.client.close();\n }\n}\n\n/**\n * The result of a tool call.\n * This is the same as the result of a tool call in the OpenAI SDK, but is reified here\n */\nexport type MCPToolCallResult = Awaited<\n ReturnType<typeof Client.prototype.callTool>\n>;\n\n// Example usage:\n/*\nconst mcp = await MCPClient.create('https://api.example.com/mcp', MCPTransport.HTTP);\nconst tools = await mcp.listTools();\nconst result = await mcp.callTool('toolName', { arg1: 'value1' });\n*/\n\nexport interface MCPToolSpec {\n name: string;\n description?: string;\n inputSchema?: JSONSchema7;\n}\n"]}
1
+ {"version":3,"file":"mcp-client.js","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":";;;AACA,wEAAmE;AACnE,oEAA6E;AAC7E,0FAAmG;AAEnG,iEAS4C;AAG5C,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAA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C;YACvC,OAAO;QACT,CAAC;QAED,yFAAyF;QACzF,4DAA4D;QAC5D,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG;YACd,GAAG,IAAI,CAAC,QAAQ;YAChB,QAAQ,EAAE,OAAO;SAClB,CAAC;QACF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,MAAM,GAAG,qCAA0B,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;YACzC,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,qCAA0B,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,KAAK;QACT,yEAAyE;QACzE,yEAAyE;QACzE,UAAU;QACV,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF;AAzPD,8BAyPC","sourcesContent":["import { type OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport {\n ClientNotification,\n ClientRequest,\n CreateMessageRequest,\n CreateMessageRequestSchema,\n CreateMessageResult,\n ElicitRequest,\n ElicitRequestSchema,\n ElicitResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\n}\n\n/**\n * Handler for MCP elicitation requests.\n * Receives the elicit request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.\n * @param request - The elicitation request from the server\n * @param extra - Additional context including AbortSignal for cancellation\n * @returns Promise resolving to the elicitation result\n * @example\n * ```typescript\n * const handler: MCPElicitationHandler = async (request, extra) => {\n * // Listen for cancellation\n * extra.signal.addEventListener('abort', () => {\n * console.log('Request cancelled');\n * });\n *\n * // Return user's response\n * return {\n * action: 'accept',\n * content: { name: 'John' }\n * };\n * };\n * ```\n */\nexport type MCPElicitationHandler = (\n e: ElicitRequest,\n extra: RequestHandlerExtra<ClientRequest, ClientNotification>,\n) => Promise<ElicitResult>;\n\n/**\n * Handler for MCP sampling requests (create_message).\n * Receives the sampling request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.\n * @param request - The sampling/create_message request from the server\n * @param extra - Additional context including AbortSignal for cancellation\n * @returns Promise resolving to the sampling result\n */\nexport type MCPSamplingHandler = (\n e: CreateMessageRequest,\n extra: RequestHandlerExtra<ClientRequest, ClientNotification>,\n) => Promise<CreateMessageResult>;\n\n/**\n * Handlers for MCP requests - these are only used if the server supports the corresponding capabilities\n * @param elicitation - Handler for elicitation requests (receives request and RequestHandlerExtra with AbortSignal)\n * @param sampling - Handler for sampling requests (receives request and RequestHandlerExtra with AbortSignal)\n * @example\n * ```typescript\n * const mcp = await MCPClient.create(\n * 'https://api.example.com/mcp',\n * MCPTransport.HTTP,\n * {},\n * undefined,\n * undefined,\n * {\n * elicitation: (e, extra) => Promise.resolve({...}),\n * },\n * );\n * ```\n */\nexport interface MCPHandlers {\n elicitation: MCPElicitationHandler;\n sampling: MCPSamplingHandler;\n}\n\n/**\n * A client for interacting with MCP (Model Context Protocol) servers.\n * Provides a simple interface for listing and calling tools exposed by the server.\n * @example\n * ```typescript\n * const mcp = await MCPClient.create('https://api.example.com/mcp');\n * const tools = await mcp.listTools();\n * const result = await mcp.callTool('toolName', { arg1: 'value1' });\n * ```\n */\nexport class MCPClient {\n /**\n * The underlying MCP client\n *\n * Be careful not to mutate the client directly, use the methods provided instead.\n */\n client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\n private transportType: MCPTransport;\n public sessionId?: string;\n private endpoint: string;\n private headers: Record<string, string>;\n private authProvider?: OAuthClientProvider;\n private handlers: Partial<MCPHandlers>;\n\n /**\n * Private constructor to enforce using the static create method.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport to use for the MCP client\n * @param headers - Optional custom headers to include in requests\n */\n private constructor(\n endpoint: string,\n transportType: MCPTransport,\n headers?: Record<string, string>,\n authProvider?: OAuthClientProvider,\n sessionId?: string,\n handlers: Partial<MCPHandlers> = {},\n ) {\n this.endpoint = endpoint;\n this.headers = headers ?? {};\n this.authProvider = authProvider;\n this.transportType = transportType;\n this.handlers = handlers;\n this.transport = this.initializeTransport(sessionId);\n this.client = this.initializeClient();\n }\n\n /**\n * Creates and initializes a new MCPClient instance. This is the recommended\n * way to create an MCPClient as it handles both instantiation and connection\n * setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport type to use for the MCP client. Defaults to HTTP.\n * @param headers - Optional custom headers to include in requests\n * @param authProvider - Optional auth provider to use for authentication\n * @param sessionId - Optional session id to use for the MCP client - if not\n * provided, a new session will be created\n * @returns A connected MCPClient instance ready for use\n * @throws {Error} Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transportType: MCPTransport = MCPTransport.HTTP,\n headers: Record<string, string> | undefined,\n authProvider: OAuthClientProvider | undefined,\n sessionId: string | undefined,\n handlers: Partial<MCPHandlers> = {},\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(\n endpoint,\n transportType,\n headers,\n authProvider,\n sessionId,\n handlers,\n );\n await mcpClient.client.connect(mcpClient.transport);\n if (\"sessionId\" in mcpClient.transport) {\n mcpClient.sessionId = mcpClient.transport.sessionId;\n }\n return mcpClient;\n }\n\n private initializeTransport(sessionId: string | undefined) {\n if (this.transportType === MCPTransport.SSE) {\n return new SSEClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n });\n } else {\n return new StreamableHTTPClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n sessionId,\n });\n }\n }\n\n /**\n * Initializes the MCP client with the appropriate capabilities and handlers\n * @returns The initialized MCP client\n */\n private initializeClient() {\n const elicitationCapability = this.handlers.elicitation\n ? { elicitation: {} }\n : {};\n const samplingCapability = this.handlers.sampling ? { sampling: {} } : {};\n const client = new Client(\n {\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n },\n {\n capabilities: {\n ...elicitationCapability,\n ...samplingCapability,\n },\n },\n );\n\n if (this.handlers.elicitation) {\n client.setRequestHandler(ElicitRequestSchema, this.handlers.elicitation);\n }\n if (this.handlers.sampling) {\n client.setRequestHandler(\n CreateMessageRequestSchema,\n this.handlers.sampling,\n );\n }\n return client;\n }\n\n /**\n * Retrieves a complete list of all available tools from the MCP server.\n * Handles pagination automatically by following cursors until all tools are fetched.\n * @returns A complete list of all available tools and their descriptions\n * @throws {Error} Will throw an error if any server request fails during pagination\n */\n async listTools(): Promise<MCPToolSpec[]> {\n const allTools: MCPToolSpec[] = [];\n let hasMore = true;\n let cursor: string | undefined = undefined;\n\n while (hasMore) {\n const response = await this.client.listTools({ cursor }, {});\n allTools.push(\n ...response.tools.map((tool): MCPToolSpec => {\n // make sure the right type is used\n const inputSchemaType: string = tool.inputSchema.type;\n if (inputSchemaType !== \"object\") {\n throw new Error(\n `Input schema for tool ${tool.name} is not an object`,\n );\n }\n\n return {\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema as JSONSchema7,\n };\n }),\n );\n\n if (response.nextCursor) {\n cursor = response.nextCursor;\n } else {\n hasMore = false;\n }\n }\n\n return allTools;\n }\n\n getServerCapabilities() {\n return this.client.getServerCapabilities();\n }\n\n getServerVersion() {\n return this.client.getServerVersion();\n }\n\n getInstructions() {\n return this.client.getInstructions();\n }\n\n /**\n * Calls a specific tool on the MCP server with the provided arguments.\n * @param name - The name of the tool to call\n * @param args - Arguments to pass to the tool, must match the tool's expected schema\n * @returns The result from the tool execution\n * @throws {Error} Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(\n name: string,\n args: Record<string, unknown>,\n _meta?: Record<string, unknown>,\n ): Promise<MCPToolCallResult> {\n const result = await this.client.callTool({\n name,\n arguments: args,\n _meta,\n });\n return result;\n }\n\n updateElicitationHandler(handler: MCPElicitationHandler | undefined) {\n // Skip if handler hasn't changed\n if (handler === this.handlers.elicitation) {\n return;\n }\n\n // Because we advertise the elicitation capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.elicitation) {\n throw new Error(\"Elicitation handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n elicitation: handler,\n };\n if (!handler) {\n const method = ElicitRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(ElicitRequestSchema, handler);\n }\n\n updateSamplingHandler(handler: MCPSamplingHandler | undefined) {\n // Skip if handler hasn't changed\n if (handler === this.handlers.sampling) {\n return;\n }\n\n // Because we advertise the sampling capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.sampling) {\n throw new Error(\"Sampling handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n sampling: handler,\n };\n if (!handler) {\n const method = CreateMessageRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(CreateMessageRequestSchema, handler);\n }\n\n async close() {\n // Not really sure which one of these to close first, but we'll close the\n // transport first so that no requests can come in and hit closing/closed\n // clients\n await this.transport.close();\n await this.client.close();\n }\n}\n\n/**\n * The result of a tool call.\n * This is the same as the result of a tool call in the OpenAI SDK, but is reified here\n */\nexport type MCPToolCallResult = Awaited<\n ReturnType<typeof Client.prototype.callTool>\n>;\n\n// Example usage:\n/*\nconst mcp = await MCPClient.create('https://api.example.com/mcp', MCPTransport.HTTP);\nconst tools = await mcp.listTools();\nconst result = await mcp.callTool('toolName', { arg1: 'value1' });\n*/\n\nexport interface MCPToolSpec {\n name: string;\n description?: string;\n inputSchema?: JSONSchema7;\n}\n"]}
@@ -1,21 +1,35 @@
1
1
  import { type ListPromptsResult } from "@modelcontextprotocol/sdk/types.js";
2
- import { McpServerInfo } from "./tambo-mcp-provider";
2
+ import { UseQueryResult } from "@tanstack/react-query";
3
+ import { type ConnectedMcpServer } from "./tambo-mcp-provider";
3
4
  export type ListPromptItem = ListPromptsResult["prompts"][number];
4
5
  export interface ListPromptEntry {
5
- server: McpServerInfo;
6
+ server: ConnectedMcpServer;
6
7
  prompt: ListPromptItem;
7
8
  }
8
9
  /**
9
10
  * Hook to get the prompts for all the registered MCP servers.
10
11
  * @returns The prompts for the MCP servers, including the server that the prompt was found on.
11
12
  */
12
- export declare function useTamboMcpPromptList(): import("@tanstack/react-query").UseQueryResult<ListPromptEntry[], Error>;
13
+ export declare function useTamboMcpPromptList(): {
14
+ data: ListPromptEntry[];
15
+ error: Error | null;
16
+ errors: Error[];
17
+ isPending: boolean;
18
+ isSuccess: boolean;
19
+ isError: boolean;
20
+ isPaused: boolean;
21
+ isRefetching: boolean;
22
+ isFetching: boolean;
23
+ isLoading: boolean;
24
+ refetch: () => Promise<void>;
25
+ };
13
26
  /**
14
27
  * Hook to get the prompt for the specified name.
15
- * @param promptName - The name of the prompt to get.
28
+ * @param promptName - The name of the prompt to get. If the prompt won't return anything
29
+ * @param args - The arguments to pass to the prompt.
16
30
  * @returns The prompt for the specified name.
17
31
  */
18
- export declare function useTamboMcpPrompt(promptName: string): import("@tanstack/react-query").UseQueryResult<{
32
+ export declare function useTamboMcpPrompt(promptName: string | undefined, args?: Record<string, string>): UseQueryResult<{
19
33
  [x: string]: unknown;
20
34
  messages: {
21
35
  [x: string]: unknown;
@@ -89,5 +103,5 @@ export declare function useTamboMcpPrompt(promptName: string): import("@tanstack
89
103
  _meta?: {
90
104
  [x: string]: unknown;
91
105
  } | undefined;
92
- } | undefined, Error>;
106
+ } | null, Error>;
93
107
  //# sourceMappingURL=mcp-hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-hooks.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAsB,MAAM,sBAAsB,CAAC;AAEzE,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAClE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,6EAyBpC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAsBnD"}
1
+ {"version":3,"file":"mcp-hooks.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAClE,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB;;WA8B5B,KAAK,GAAG,IAAI;YACX,KAAK,EAAE;eACJ,OAAO;eACP,OAAO;aACT,OAAO;cACN,OAAO;kBACH,OAAO;gBACT,OAAO;eACR,OAAO;aACT,MAAM,OAAO,CAAC,IAAI,CAAC;EAb7B;AAwDD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiClC"}
@@ -10,46 +10,93 @@ const tambo_mcp_provider_1 = require("./tambo-mcp-provider");
10
10
  */
11
11
  function useTamboMcpPromptList() {
12
12
  const mcpServers = (0, tambo_mcp_provider_1.useTamboMcpServers)();
13
- return (0, hooks_1.useTamboQuery)({
14
- queryKey: ["mcp-prompts"],
15
- queryFn: async () => {
16
- const promptResults = await Promise.allSettled(mcpServers.map(async (mcpServer) => ({
17
- server: mcpServer,
18
- response: await mcpServer.client?.client.listPrompts(),
19
- })));
20
- const prompts = promptResults
21
- .filter((result) => result.status === "fulfilled")
22
- .flatMap((result) => {
23
- const { server, response } = result.value;
24
- return response?.prompts?.map((prompt) => ({
25
- server,
13
+ const queries = (0, hooks_1.useTamboQueries)({
14
+ queries: mcpServers.map((mcpServer) => ({
15
+ queryKey: ["mcp-prompts", mcpServer.key],
16
+ // Only run for connected servers that have a client
17
+ enabled: isConnectedMcpServer(mcpServer),
18
+ queryFn: async () => {
19
+ // Fast path: if this server doesn't have a client, skip work
20
+ if (!isConnectedMcpServer(mcpServer))
21
+ return [];
22
+ const result = await mcpServer.client.client.listPrompts();
23
+ const prompts = result?.prompts ?? [];
24
+ const promptsEntries = prompts.map((prompt) => ({
25
+ server: mcpServer,
26
26
  prompt,
27
27
  }));
28
- })
29
- .filter((prompt) => prompt !== undefined);
30
- return prompts;
28
+ return promptsEntries;
29
+ },
30
+ })),
31
+ combine: (results) => {
32
+ return combineArrayResults(results);
31
33
  },
32
34
  });
35
+ return queries;
36
+ }
37
+ // TODO: find a more general place for this
38
+ function combineArrayResults(results) {
39
+ const errors = results
40
+ .filter((result) => result.isError)
41
+ .map((result) => result.error);
42
+ // Treat queries that are idle (disabled) as non-blocking for aggregate status
43
+ const enabledish = results.filter((r) => r.fetchStatus !== "idle" || r.isSuccess || r.isError);
44
+ return {
45
+ // Prefer flatMap to avoid extra intermediate arrays
46
+ data: results.flatMap((result) => result.isSuccess && Array.isArray(result.data) ? result.data : []),
47
+ // Preserve a single error for compatibility and expose the full list for diagnostics
48
+ error: errors[0] ?? null,
49
+ errors,
50
+ isPending: enabledish.some((result) => result.isPending),
51
+ isSuccess: enabledish.length > 0 && enabledish.every((result) => result.isSuccess),
52
+ isError: errors.length > 0,
53
+ isPaused: enabledish.some((result) => result.isPaused),
54
+ isRefetching: enabledish.some((result) => result.isRefetching),
55
+ isFetching: enabledish.some((result) => result.isFetching),
56
+ isLoading: enabledish.some((result) => result.isLoading),
57
+ // Aggregate refetch to trigger all underlying queries
58
+ refetch: async () => {
59
+ await Promise.all(results.map(async (r) => {
60
+ await r.refetch();
61
+ }));
62
+ },
63
+ };
64
+ }
65
+ // Type guard for narrowing to connected servers
66
+ function isConnectedMcpServer(server) {
67
+ return "client" in server && server.client != null;
33
68
  }
34
69
  /**
35
70
  * Hook to get the prompt for the specified name.
36
- * @param promptName - The name of the prompt to get.
71
+ * @param promptName - The name of the prompt to get. If the prompt won't return anything
72
+ * @param args - The arguments to pass to the prompt.
37
73
  * @returns The prompt for the specified name.
38
74
  */
39
- function useTamboMcpPrompt(promptName) {
75
+ function useTamboMcpPrompt(promptName, args = {}) {
40
76
  // figure out which server has the prompt
41
77
  const { data: promptEntries } = useTamboMcpPromptList();
42
78
  const promptEntry = promptEntries?.find((prompt) => prompt.prompt.name === promptName);
43
- const mcpServers = (0, tambo_mcp_provider_1.useTamboMcpServers)();
44
- const mcpServer = mcpServers.find((mcpServer) => mcpServer.name === promptEntry?.server.name &&
45
- mcpServer.url === promptEntry?.server.url &&
46
- mcpServer.transport === promptEntry?.server.transport);
79
+ // Use the stable server key (and the server instance itself) instead of brittle
80
+ // name/url/transport matching.
81
+ const mcpServer = promptEntry?.server;
82
+ // Canonicalize args to avoid unstable cache keys from object identity/order
83
+ const sortedArgsEntries = Object.keys(args)
84
+ .sort()
85
+ .map((k) => [k, args[k]]);
47
86
  return (0, hooks_1.useTamboQuery)({
48
- queryKey: ["mcp-prompt", promptName],
87
+ // Include server identity and sorted args to prevent stale cache hits
88
+ queryKey: ["mcp-prompt", promptName, mcpServer?.key, sortedArgsEntries],
89
+ // Only run when we have a prompt name and a connected server
90
+ enabled: Boolean(promptName && mcpServer && isConnectedMcpServer(mcpServer)),
49
91
  queryFn: async () => {
50
- return await mcpServer?.client?.client.getPrompt({
92
+ if (!promptName || !mcpServer || !isConnectedMcpServer(mcpServer)) {
93
+ return null;
94
+ }
95
+ const result = await mcpServer.client.client.getPrompt({
51
96
  name: promptName,
97
+ arguments: args,
52
98
  });
99
+ return result ?? null; // return null because react-query doesn't like undefined results
53
100
  },
54
101
  });
55
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-hooks.js","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":";;AAiBA,sDAyBC;AAOD,8CAsBC;AAnED,oCAAyC;AACzC,6DAAyE;AAQzE;;;GAGG;AACH,SAAgB,qBAAqB;IACnC,MAAM,UAAU,GAAG,IAAA,uCAAkB,GAAE,CAAC;IACxC,OAAO,IAAA,qBAAa,EAAC;QACnB,QAAQ,EAAE,CAAC,aAAa,CAAC;QACzB,OAAO,EAAE,KAAK,IAAgC,EAAE;YAC9C,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,UAAU,CAC5C,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;gBACnC,MAAM,EAAE,SAAS;gBACjB,QAAQ,EAAE,MAAM,SAAS,CAAC,MAAM,EAAE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,EAAE,UAAU,CAAC;QACpC,OAAO,EAAE,KAAK,IAA0C,EAAE;YACxD,OAAO,MAAM,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC;gBAC/C,IAAI,EAAE,UAAU;aACjB,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n GetPromptResult,\n type ListPromptsResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { useTamboQuery } from \"../hooks\";\nimport { McpServerInfo, useTamboMcpServers } from \"./tambo-mcp-provider\";\n\nexport type ListPromptItem = ListPromptsResult[\"prompts\"][number];\nexport interface ListPromptEntry {\n server: McpServerInfo;\n prompt: ListPromptItem;\n}\n\n/**\n * Hook to get the prompts for all the registered MCP servers.\n * @returns The prompts for the MCP servers, including the server that the prompt was found on.\n */\nexport function useTamboMcpPromptList() {\n const mcpServers = useTamboMcpServers();\n return useTamboQuery({\n queryKey: [\"mcp-prompts\"],\n queryFn: async (): Promise<ListPromptEntry[]> => {\n const promptResults = await Promise.allSettled(\n mcpServers.map(async (mcpServer) => ({\n server: mcpServer,\n response: await mcpServer.client?.client.listPrompts(),\n })),\n );\n\n const prompts: ListPromptEntry[] = promptResults\n .filter((result) => result.status === \"fulfilled\")\n .flatMap((result) => {\n const { server, response } = result.value;\n return response?.prompts?.map((prompt: ListPromptItem) => ({\n server,\n prompt,\n }));\n })\n .filter((prompt) => prompt !== undefined);\n return prompts;\n },\n });\n}\n\n/**\n * Hook to get the prompt for the specified name.\n * @param promptName - The name of the prompt to get.\n * @returns The prompt for the specified name.\n */\nexport function useTamboMcpPrompt(promptName: string) {\n // figure out which server has the prompt\n const { data: promptEntries } = useTamboMcpPromptList();\n const promptEntry = promptEntries?.find(\n (prompt) => prompt.prompt.name === promptName,\n );\n const mcpServers = useTamboMcpServers();\n const mcpServer = mcpServers.find(\n (mcpServer) =>\n mcpServer.name === promptEntry?.server.name &&\n mcpServer.url === promptEntry?.server.url &&\n mcpServer.transport === promptEntry?.server.transport,\n );\n\n return useTamboQuery({\n queryKey: [\"mcp-prompt\", promptName],\n queryFn: async (): Promise<GetPromptResult | undefined> => {\n return await mcpServer?.client?.client.getPrompt({\n name: promptName,\n });\n },\n });\n}\n"]}
1
+ {"version":3,"file":"mcp-hooks.js","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":";;AAuBA,sDA0BC;AA8DD,8CAmCC;AA7ID,oCAA0D;AAC1D,6DAI8B;AAS9B;;;GAGG;AACH,SAAgB,qBAAqB;IACnC,MAAM,UAAU,GAAG,IAAA,uCAAkB,GAAE,CAAC;IACxC,MAAM,OAAO,GAAG,IAAA,uBAAe,EAAC;QAC9B,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YACtC,QAAQ,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,CAAC;YACxC,oDAAoD;YACpD,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC;YACxC,OAAO,EAAE,KAAK,IAAgC,EAAE;gBAC9C,6DAA6D;gBAC7D,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC;oBAAE,OAAO,EAAE,CAAC;gBAEhD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;gBAC3D,MAAM,OAAO,GAAqB,MAAM,EAAE,OAAO,IAAI,EAAE,CAAC;gBACxD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;oBAC9C,MAAM,EAAE,SAAS;oBACjB,MAAM;iBACP,CAAC,CAAC,CAAC;gBACJ,OAAO,cAAc,CAAC;YACxB,CAAC;SACF,CAAC,CAAC;QACH,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;YACnB,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;KACF,CAAC,CAAC;IAEH,OA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,EAAE,SAAS,EAAE,GAAG,EAAE,iBAAiB,CAAC;QACvE,6DAA6D;QAC7D,OAAO,EAAE,OAAO,CACd,UAAU,IAAI,SAAS,IAAI,oBAAoB,CAAC,SAAS,CAAC,CAC3D;QACD,OAAO,EAAE,KAAK,IAAqC,EAAE;YACnD,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;gBAClE,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;gBACrD,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;YACH,OAAO,MAAM,IAAI,IAAI,CAAC,CAAC,iEAAiE;QAC1F,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n GetPromptResult,\n type ListPromptsResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { UseQueryResult } from \"@tanstack/react-query\";\nimport { useTamboQueries, useTamboQuery } from \"../hooks\";\nimport {\n type ConnectedMcpServer,\n type McpServer,\n useTamboMcpServers,\n} from \"./tambo-mcp-provider\";\n\nexport type ListPromptItem = ListPromptsResult[\"prompts\"][number];\nexport interface ListPromptEntry {\n // Only connected servers produce prompt entries, so expose the connected type\n server: ConnectedMcpServer;\n prompt: ListPromptItem;\n}\n\n/**\n * Hook to get the prompts for all the registered MCP servers.\n * @returns The prompts for the MCP servers, including the server that the prompt was found on.\n */\nexport function useTamboMcpPromptList() {\n const mcpServers = useTamboMcpServers();\n const queries = useTamboQueries({\n queries: mcpServers.map((mcpServer) => ({\n queryKey: [\"mcp-prompts\", mcpServer.key],\n // Only run for connected servers that have a client\n enabled: isConnectedMcpServer(mcpServer),\n queryFn: async (): Promise<ListPromptEntry[]> => {\n // Fast path: if this server doesn't have a client, skip work\n if (!isConnectedMcpServer(mcpServer)) return [];\n\n const result = await mcpServer.client.client.listPrompts();\n const prompts: ListPromptItem[] = result?.prompts ?? [];\n const promptsEntries = prompts.map((prompt) => ({\n server: mcpServer,\n prompt,\n }));\n return promptsEntries;\n },\n })),\n combine: (results) => {\n return combineArrayResults(results);\n },\n });\n\n return queries;\n}\n// TODO: find a more general place for this\nfunction combineArrayResults<T>(results: UseQueryResult<T[], Error>[]): {\n data: T[];\n error: Error | null;\n errors: Error[];\n isPending: boolean;\n isSuccess: boolean;\n isError: boolean;\n isPaused: boolean;\n isRefetching: boolean;\n isFetching: boolean;\n isLoading: boolean;\n refetch: () => Promise<void>;\n} {\n const errors = results\n .filter((result) => result.isError)\n .map((result) => result.error as Error);\n\n // Treat queries that are idle (disabled) as non-blocking for aggregate status\n const enabledish = results.filter(\n (r) => r.fetchStatus !== \"idle\" || r.isSuccess || r.isError,\n );\n\n return {\n // Prefer flatMap to avoid extra intermediate arrays\n data: results.flatMap((result) =>\n result.isSuccess && Array.isArray(result.data) ? result.data : [],\n ),\n // Preserve a single error for compatibility and expose the full list for diagnostics\n error: errors[0] ?? null,\n errors,\n isPending: enabledish.some((result) => result.isPending),\n isSuccess:\n enabledish.length > 0 && enabledish.every((result) => result.isSuccess),\n isError: errors.length > 0,\n isPaused: enabledish.some((result) => result.isPaused),\n isRefetching: enabledish.some((result) => result.isRefetching),\n isFetching: enabledish.some((result) => result.isFetching),\n isLoading: enabledish.some((result) => result.isLoading),\n // Aggregate refetch to trigger all underlying queries\n refetch: async () => {\n await Promise.all(\n results.map(async (r) => {\n await r.refetch();\n }),\n );\n },\n };\n}\n\n// Type guard for narrowing to connected servers\nfunction isConnectedMcpServer(server: McpServer): server is ConnectedMcpServer {\n return \"client\" in server && server.client != null;\n}\n\n/**\n * Hook to get the prompt for the specified name.\n * @param promptName - The name of the prompt to get. If the prompt won't return anything\n * @param args - The arguments to pass to the prompt.\n * @returns The prompt for the specified name.\n */\nexport function useTamboMcpPrompt(\n promptName: string | undefined,\n args: Record<string, string> = {},\n) {\n // figure out which server has the prompt\n const { data: promptEntries } = useTamboMcpPromptList();\n const promptEntry = promptEntries?.find(\n (prompt) => prompt.prompt.name === promptName,\n );\n // Use the stable server key (and the server instance itself) instead of brittle\n // name/url/transport matching.\n const mcpServer = promptEntry?.server;\n\n // Canonicalize args to avoid unstable cache keys from object identity/order\n const sortedArgsEntries = Object.keys(args)\n .sort()\n .map((k) => [k, args[k]] as const);\n return useTamboQuery({\n // Include server identity and sorted args to prevent stale cache hits\n queryKey: [\"mcp-prompt\", promptName, mcpServer?.key, sortedArgsEntries],\n // Only run when we have a prompt name and a connected server\n enabled: Boolean(\n promptName && mcpServer && isConnectedMcpServer(mcpServer),\n ),\n queryFn: async (): Promise<GetPromptResult | null> => {\n if (!promptName || !mcpServer || !isConnectedMcpServer(mcpServer)) {\n return null;\n }\n const result = await mcpServer.client.client.getPrompt({\n name: promptName,\n arguments: args,\n });\n return result ?? null; // return null because react-query doesn't like undefined results\n },\n });\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import React, { FC } from "react";
2
- import { MCPClient, MCPHandlers, MCPTransport } from "./mcp-client";
2
+ import { MCPClient, MCPElicitationHandler, MCPHandlers, MCPSamplingHandler, MCPTransport } from "./mcp-client";
3
3
  /**
4
4
  * Extracts error message from MCP tool result content.
5
5
  * Handles both array and string content formats.
@@ -8,7 +8,7 @@ import { MCPClient, MCPHandlers, MCPTransport } from "./mcp-client";
8
8
  */
9
9
  export declare function extractErrorMessage(content: unknown): string;
10
10
  /**
11
- * Configuration for connecting to an MCP server.
11
+ * User-provided configuration for an MCP server.
12
12
  */
13
13
  export interface McpServerInfo {
14
14
  /** Optional name for the MCP server */
@@ -28,21 +28,45 @@ export interface McpServerInfo {
28
28
  */
29
29
  handlers?: Partial<MCPHandlers>;
30
30
  }
31
- export interface ConnectedMcpServer extends McpServerInfo {
31
+ /**
32
+ * Normalized server information with a stable derived key.
33
+ */
34
+ interface McpServerConfig extends McpServerInfo {
35
+ /**
36
+ * Stable identity for this server derived from its URL/transport/headers.
37
+ * Present for all server states (connected or failed).
38
+ */
39
+ key: string;
40
+ }
41
+ /**
42
+ * Connected MCP server with an active client.
43
+ */
44
+ export interface ConnectedMcpServer extends McpServerConfig {
32
45
  client: MCPClient;
33
46
  }
34
- export interface FailedMcpServer extends McpServerInfo {
47
+ /**
48
+ * Failed MCP server with a connection error.
49
+ */
50
+ export interface FailedMcpServer extends McpServerConfig {
35
51
  client?: never;
36
52
  connectionError: Error;
37
53
  }
54
+ /**
55
+ * An active or failed MCP server, with access to the MCP client.
56
+ */
38
57
  export type McpServer = ConnectedMcpServer | FailedMcpServer;
39
58
  /**
40
59
  * Provider-level MCP handlers that receive the McpServerInfo as context in addition to the request.
41
60
  * These handlers are applied to all MCP servers unless overridden by per-server handlers.
61
+ *
62
+ * Handlers receive three parameters:
63
+ * 1. request - The MCP request
64
+ * 2. extra - RequestHandlerExtra containing AbortSignal and other metadata
65
+ * 3. serverInfo - Configuration of the MCP server that triggered this request
42
66
  */
43
67
  export interface ProviderMCPHandlers {
44
- elicitation?: (request: Parameters<MCPHandlers["elicitation"]>[0], serverInfo: McpServerInfo) => ReturnType<MCPHandlers["elicitation"]>;
45
- sampling?: (request: Parameters<MCPHandlers["sampling"]>[0], serverInfo: McpServerInfo) => ReturnType<MCPHandlers["sampling"]>;
68
+ elicitation?: (request: Parameters<MCPElicitationHandler>[0], extra: Parameters<MCPElicitationHandler>[1], serverInfo: McpServerConfig) => ReturnType<MCPElicitationHandler>;
69
+ sampling?: (request: Parameters<MCPSamplingHandler>[0], extra: Parameters<MCPSamplingHandler>[1], serverInfo: McpServerConfig) => ReturnType<MCPSamplingHandler>;
46
70
  }
47
71
  /**
48
72
  * This provider is used to register tools from MCP servers.
@@ -82,4 +106,34 @@ export declare const TamboMcpProvider: FC<{
82
106
  * @returns The MCP servers
83
107
  */
84
108
  export declare const useTamboMcpServers: () => McpServer[];
109
+ /**
110
+ * Hook to access elicitation context from TamboMcpProvider.
111
+ * This provides access to the current elicitation request and methods to respond to it.
112
+ *
113
+ * The elicitation state is automatically managed by TamboMcpProvider when MCP servers
114
+ * request user input through the elicitation protocol.
115
+ * @returns The elicitation context with current request and response handlers
116
+ * @example
117
+ * ```tsx
118
+ * function ElicitationUI() {
119
+ * const { elicitation, resolveElicitation } = useTamboElicitationContext();
120
+ *
121
+ * if (!elicitation) return null;
122
+ *
123
+ * return (
124
+ * <div>
125
+ * <p>{elicitation.message}</p>
126
+ * <button onClick={() => resolveElicitation?.({ action: "accept", content: {} })}>
127
+ * Accept
128
+ * </button>
129
+ * </div>
130
+ * );
131
+ * }
132
+ * ```
133
+ */
134
+ export declare const useTamboElicitationContext: () => {
135
+ elicitation: import("./elicitation").TamboElicitationRequest | null;
136
+ resolveElicitation: ((response: import("./elicitation").TamboElicitationResponse) => void) | null;
137
+ };
138
+ export {};
85
139
  //# sourceMappingURL=tambo-mcp-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,EAAE,EAKH,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEpE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAsB5D;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC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