@tambo-ai/react 0.23.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -3
  4. package/dist/index.js.map +1 -1
  5. package/dist/mcp/index.d.ts +2 -0
  6. package/dist/mcp/index.d.ts.map +1 -0
  7. package/dist/mcp/index.js +6 -0
  8. package/dist/mcp/index.js.map +1 -0
  9. package/dist/mcp/mcp-client.d.ts.map +1 -0
  10. package/dist/mcp/mcp-client.js.map +1 -0
  11. package/dist/mcp/mcp-tools-client.d.ts.map +1 -0
  12. package/dist/mcp/mcp-tools-client.js.map +1 -0
  13. package/dist/mcp/tambo-mcp-provider.d.ts +18 -0
  14. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -0
  15. package/dist/{providers → mcp}/tambo-mcp-provider.js +7 -3
  16. package/dist/mcp/tambo-mcp-provider.js.map +1 -0
  17. package/esm/index.d.ts +0 -1
  18. package/esm/index.d.ts.map +1 -1
  19. package/esm/index.js +0 -1
  20. package/esm/index.js.map +1 -1
  21. package/esm/mcp/index.d.ts +2 -0
  22. package/esm/mcp/index.d.ts.map +1 -0
  23. package/esm/mcp/index.js +2 -0
  24. package/esm/mcp/index.js.map +1 -0
  25. package/esm/mcp/mcp-client.d.ts.map +1 -0
  26. package/esm/mcp/mcp-client.js.map +1 -0
  27. package/esm/mcp/mcp-tools-client.d.ts.map +1 -0
  28. package/esm/mcp/mcp-tools-client.js.map +1 -0
  29. package/esm/mcp/tambo-mcp-provider.d.ts +18 -0
  30. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -0
  31. package/esm/{providers → mcp}/tambo-mcp-provider.js +7 -3
  32. package/esm/mcp/tambo-mcp-provider.js.map +1 -0
  33. package/package.json +6 -1
  34. package/dist/providers/tambo-mcp-provider.d.ts +0 -10
  35. package/dist/providers/tambo-mcp-provider.d.ts.map +0 -1
  36. package/dist/providers/tambo-mcp-provider.js.map +0 -1
  37. package/dist/util/mcp-client.d.ts.map +0 -1
  38. package/dist/util/mcp-client.js.map +0 -1
  39. package/dist/util/mcp-tools-client.d.ts.map +0 -1
  40. package/dist/util/mcp-tools-client.js.map +0 -1
  41. package/esm/providers/tambo-mcp-provider.d.ts +0 -10
  42. package/esm/providers/tambo-mcp-provider.d.ts.map +0 -1
  43. package/esm/providers/tambo-mcp-provider.js.map +0 -1
  44. package/esm/util/mcp-client.d.ts.map +0 -1
  45. package/esm/util/mcp-client.js.map +0 -1
  46. package/esm/util/mcp-tools-client.d.ts.map +0 -1
  47. package/esm/util/mcp-tools-client.js.map +0 -1
  48. /package/dist/{util → mcp}/mcp-client.d.ts +0 -0
  49. /package/dist/{util → mcp}/mcp-client.js +0 -0
  50. /package/dist/{util → mcp}/mcp-tools-client.d.ts +0 -0
  51. /package/dist/{util → mcp}/mcp-tools-client.js +0 -0
  52. /package/esm/{util → mcp}/mcp-client.d.ts +0 -0
  53. /package/esm/{util → mcp}/mcp-client.js +0 -0
  54. /package/esm/{util → mcp}/mcp-tools-client.d.ts +0 -0
  55. /package/esm/{util → mcp}/mcp-tools-client.js +0 -0
package/dist/index.d.ts CHANGED
@@ -11,5 +11,4 @@ export { useTamboThreadList } from "./hooks/use-tambo-threads";
11
11
  export { type ComponentContextToolMetadata, type ComponentRegistry, type ParameterSpec, type RegisteredComponent, type TamboTool, } from "./model/component-metadata";
12
12
  export { GenerationStage, type TamboThreadMessage, } from "./model/generate-component-response";
13
13
  export { type TamboThread } from "./model/tambo-thread";
14
- export { TamboMcpProvider } from "./providers/tambo-mcp-provider";
15
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAA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C;AAG/D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,UAAU,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.TamboMcpProvider = exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThread = exports.useTamboClient = exports.useTambo = exports.TamboThreadProvider = exports.TamboProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboThreadInput = exports.useTamboStreamingProps = exports.useTamboMessageContext = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
17
+ exports.GenerationStage = exports.useTamboThreadList = exports.useTamboThread = exports.useTamboClient = exports.useTambo = exports.TamboThreadProvider = exports.TamboProvider = exports.TamboComponentProvider = exports.TamboClientProvider = exports.useTamboThreadInput = exports.useTamboStreamingProps = exports.useTamboMessageContext = exports.useTamboCurrentMessage = exports.TamboMessageProvider = exports.useTamboComponentState = void 0;
18
18
  /** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */
19
19
  var use_component_state_1 = require("./hooks/use-component-state");
20
20
  Object.defineProperty(exports, "useTamboComponentState", { enumerable: true, get: function () { return use_component_state_1.useTamboComponentState; } });
@@ -40,6 +40,4 @@ var use_tambo_threads_1 = require("./hooks/use-tambo-threads");
40
40
  Object.defineProperty(exports, "useTamboThreadList", { enumerable: true, get: function () { return use_tambo_threads_1.useTamboThreadList; } });
41
41
  var generate_component_response_1 = require("./model/generate-component-response");
42
42
  Object.defineProperty(exports, "GenerationStage", { enumerable: true, get: function () { return generate_component_response_1.GenerationStage; } });
43
- var tambo_mcp_provider_1 = require("./providers/tambo-mcp-provider");
44
- Object.defineProperty(exports, "TamboMcpProvider", { enumerable: true, get: function () { return tambo_mcp_provider_1.TamboMcpProvider; } });
45
43
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wKAAwK;AACxK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAIqC;AAHnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AACtB,6HAAA,sBAAsB,OAAA;AAExB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,6DAA+D;AAAtD,uHAAA,mBAAmB,OAAA;AAE5B,gCAAgC;AAChC,yCAUqB;AATnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,0GAAA,aAAa,OAAA;AACb,gHAAA,mBAAmB,OAAA;AACnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AAiBhB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA;AAIjB,qEAAkE;AAAzD,sHAAA,gBAAgB,OAAA","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboThread,\n type TamboComponent,\n type TamboRegistryContext,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\nexport { TamboMcpProvider } from \"./providers/tambo-mcp-provider\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wKAAwK;AACxK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAIqC;AAHnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AACtB,6HAAA,sBAAsB,OAAA;AAExB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,6DAA+D;AAAtD,uHAAA,mBAAmB,OAAA;AAE5B,gCAAgC;AAChC,yCAUqB;AATnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,0GAAA,aAAa,OAAA;AACb,gHAAA,mBAAmB,OAAA;AACnB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AAiBhB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboThread,\n type TamboComponent,\n type TamboRegistryContext,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n"]}
@@ -0,0 +1,2 @@
1
+ export { TamboMcpProvider } from "./tambo-mcp-provider";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TamboMcpProvider = void 0;
4
+ var tambo_mcp_provider_1 = require("./tambo-mcp-provider");
5
+ Object.defineProperty(exports, "TamboMcpProvider", { enumerable: true, get: function () { return tambo_mcp_provider_1.TamboMcpProvider; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";;;AAAA,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA","sourcesContent":["export { TamboMcpProvider } from \"./tambo-mcp-provider\";\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AACD;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAqD;IAEtE;;;;;OAKG;IACH,OAAO;IAoBP;;;;;;;;OAQG;WACU,MAAM,CACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,YAAgC,EAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC;IAMrB;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC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BACN,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,IAA6B;QACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxC,IAAI;YACJ,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAtGD,8BAsGC","sourcesContent":["import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\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 private client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\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 transport - 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 transport: MCPTransport,\n headers?: Record<string, string>,\n ) {\n if (transport === MCPTransport.SSE) {\n this.transport = new SSEClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n } else {\n this.transport = new StreamableHTTPClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n }\n this.client = new Client({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n }\n\n /**\n * Creates and initializes a new MCPClient instance.\n * This is the recommended way to create an MCPClient as it handles both\n * instantiation and connection setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param headers - Optional custom headers to include in requests\n * @returns A connected MCPClient instance ready for use\n * @throws Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transport: MCPTransport = MCPTransport.HTTP,\n headers?: Record<string, string>,\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(endpoint, transport, headers);\n await mcpClient.client.connect(mcpClient.transport);\n return mcpClient;\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 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 if (tool.inputSchema.type !== \"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 /**\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 Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(name: string, args: Record<string, unknown>) {\n const result = await this.client.callTool({\n name,\n arguments: args,\n });\n return result;\n }\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"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tools-client.d.ts","sourceRo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E,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC5C,IAAI,IAAI;oBAAE,MAAM;gBAEhB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBAElD,gCAAgC;gBAChC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACnC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;gBAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACzB,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;wBACtC,IAAI,CAAC;4BACH,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;4BAE7C,wBAAwB;4BACxB,IAAI,eAAe,CAAC,KAAK,EAAE,CAAC;gCAC1B,MAAM,IAAI,KAAK,CACb,mBAAmB,eAAe,CAAC,KAAK,CAAC,IAAI,MAAM,eAAe,CAAC,KAAK,CAAC,OAAO,EAAE,CACnF,CAAC;4BACJ,CAAC;4BAED,MAAM,eAAe,CAAC,MAAM,CAAC;wBAC/B,CAAC;wBAAC,OAAO,CAAC,EAAE,CAAC;4BACX,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;wBAC5C,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AA3LD,8BA2LC","sourcesContent":["/**\n * Minimal Model Context Protocol (MCP) client using JSON-RPC 2.0\n * Supports only listTools() and callTool() operations\n */\n\n/**\n * Interface representing a Tool in the MCP\n */\nexport interface Tool {\n name: string;\n description?: string;\n inputSchema: {\n type: \"object\";\n properties: Record<string, any>;\n required?: string[];\n };\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/list endpoint\n */\nexport interface ListToolsResult {\n tools: Tool[];\n}\n\n/**\n * Content type for tool responses\n */\nexport interface ToolContent {\n type: string;\n text?: string;\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/call endpoint\n */\nexport interface CallToolResult {\n content: ToolContent[];\n isError?: boolean;\n}\n\n/**\n * A minimal TypeScript client for the Model Context Protocol (MCP)\n *\n * This client provides a streamlined interface to communicate with MCP servers\n * using JSON-RPC 2.0 over HTTP. It supports listing available tools and calling tools\n * with arguments, including support for Server-Sent Events (SSE) streaming responses.\n * @example\n * ```typescript\n * // Basic usage\n * const mcpClient = new MCPClient('https://example.com/mcp');\n * const tools = await mcpClient.listTools();\n * const toolResponse = await mcpClient.callTool('my-tool', { arg1: 'value1' });\n *\n * // For streaming responses:\n * const stream = await mcpClient.callToolStream('streaming-tool', { arg1: 'value1' });\n * for await (const chunk of mcpClient.parseStreamingResponses(stream)) {\n * console.log('Received chunk:', chunk);\n * }\n * ```\n */\nexport class MCPClient {\n private baseUrl: string;\n private headers: Record<string, string>;\n private requestId = 1;\n\n /**\n * Creates a new MCP client\n * @param url - The base URL of the MCP server\n * @param extraHeaders - Optional additional headers to include in requests\n */\n constructor(url: string, extraHeaders?: Record<string, string>) {\n this.baseUrl = url.endsWith(\"/\") ? url : `${url}/`;\n this.headers = {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...(extraHeaders ?? {}),\n };\n }\n\n /**\n * Lists available tools on the MCP server\n * @returns Promise resolving to the list of available tools\n */\n async listTools(): Promise<ListToolsResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/list\",\n params: {},\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to list tools: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns Promise resolving to the tool's response\n */\n async callTool(toolName: string, args: any): Promise<CallToolResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments and returns a stream of results\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns ReadableStream of the tool's response\n */\n async callToolStream(\n toolName: string,\n args: any,\n ): Promise<ReadableStream<Uint8Array>> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: {\n ...this.headers,\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n // Return the response body as a stream\n return response.body;\n }\n\n /**\n * Parse SSE messages from a stream into JSON-RPC responses\n * @param stream - ReadableStream to parse\n * @returns AsyncGenerator yielding parsed JSON-RPC responses\n * @yields {CallToolResult} The parsed JSON-RPC response\n */\n async *parseStreamingResponses(\n stream: ReadableStream<Uint8Array>,\n ): AsyncGenerator<CallToolResult, void, unknown> {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Process complete SSE messages\n const lines = buffer.split(\"\\n\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const jsonData = line.slice(6).trim();\n try {\n const jsonRpcResponse = JSON.parse(jsonData);\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n yield jsonRpcResponse.result;\n } catch (e) {\n console.error(\"Failed to parse JSON:\", e);\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { FC } from "react";
2
+ import { MCPTransport } from "./mcp-client";
3
+ interface McpServerInfo {
4
+ name?: string;
5
+ url: string;
6
+ description?: string;
7
+ transport?: MCPTransport;
8
+ }
9
+ /**
10
+ * This provider is used to register tools from MCP servers.
11
+ * @returns the wrapped children
12
+ */
13
+ export declare const TamboMcpProvider: FC<{
14
+ mcpServers: (McpServerInfo | string)[];
15
+ children: React.ReactNode;
16
+ }>;
17
+ export {};
18
+ //# sourceMappingURL=tambo-mcp-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAa,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvD,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AACD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC;IAChC,UAAU,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAkEA,CAAC"}
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TamboMcpProvider = void 0;
4
4
  const react_1 = require("react");
5
- const mcp_client_1 = require("../util/mcp-client");
6
- const tambo_registry_provider_1 = require("./tambo-registry-provider");
5
+ const tambo_registry_provider_1 = require("../providers/tambo-registry-provider");
6
+ const mcp_client_1 = require("./mcp-client");
7
7
  /**
8
8
  * This provider is used to register tools from MCP servers.
9
9
  * @returns the wrapped children
@@ -18,7 +18,11 @@ const TamboMcpProvider = ({ mcpServers, children }) => {
18
18
  // Maps tool names to the MCP client that registered them
19
19
  const mcpServerMap = new Map();
20
20
  const serverToolLists = mcpServers.map(async (mcpServer) => {
21
- const mcpClient = await mcp_client_1.MCPClient.create(mcpServer, mcp_client_1.MCPTransport.SSE);
21
+ const server = typeof mcpServer === "string"
22
+ ? { url: mcpServer, transport: mcp_client_1.MCPTransport.SSE }
23
+ : mcpServer;
24
+ const { url, transport = mcp_client_1.MCPTransport.SSE } = server;
25
+ const mcpClient = await mcp_client_1.MCPClient.create(url, transport);
22
26
  const tools = await mcpClient.listTools();
23
27
  tools.forEach((tool) => {
24
28
  mcpServerMap.set(tool.name, mcpClient);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":";;;A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AAI,CAAC,WAAsC;iBACxD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE/B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AArEW,QAAA,gBAAgB,oBAqE3B","sourcesContent":["import { FC, useEffect } from \"react\";\nimport { TamboTool } from \"../model/component-metadata\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { MCPClient, MCPTransport } from \"./mcp-client\";\n\ninterface McpServerInfo {\n name?: string;\n url: string;\n description?: string;\n transport?: MCPTransport;\n}\n/**\n * This provider is used to register tools from MCP servers.\n * @returns the wrapped children\n */\nexport const TamboMcpProvider: FC<{\n mcpServers: (McpServerInfo | string)[];\n children: React.ReactNode;\n}> = ({ mcpServers, children }) => {\n const { registerTool } = useTamboRegistry();\n\n useEffect(() => {\n if (!mcpServers) {\n return;\n }\n async function registerMcpServers(mcpServers: (McpServerInfo | string)[]) {\n // Maps tool names to the MCP client that registered them\n const mcpServerMap = new Map<string, MCPClient>();\n const serverToolLists = mcpServers.map(async (mcpServer) => {\n const server =\n typeof mcpServer === \"string\"\n ? { url: mcpServer, transport: MCPTransport.SSE }\n : mcpServer;\n const { url, transport = MCPTransport.SSE } = server;\n const mcpClient = await MCPClient.create(url, transport);\n const tools = await mcpClient.listTools();\n tools.forEach((tool) => {\n mcpServerMap.set(tool.name, mcpClient);\n });\n return tools;\n });\n const toolResults = await Promise.allSettled(serverToolLists);\n\n // Just log the failed tools, we can't do anything about them\n const failedTools = toolResults.filter(\n (result) => result.status === \"rejected\",\n );\n if (failedTools.length > 0) {\n console.error(\n \"Failed to register tools from MCP servers:\",\n failedTools.map((result) => result.reason),\n );\n }\n\n // Register the successful tools\n const allTools = toolResults\n .filter((result) => result.status === \"fulfilled\")\n .map((result) => result.value)\n .flat();\n allTools.forEach((tool) => {\n registerTool({\n description: tool.description ?? \"\",\n name: tool.name,\n tool: async (args: Record<string, unknown>) => {\n const mcpServer = mcpServerMap.get(tool.name);\n if (!mcpServer) {\n // should never happen\n throw new Error(`MCP server for tool ${tool.name} not found`);\n }\n const result = await mcpServer.callTool(tool.name, args);\n if (result.isError) {\n // TODO: is there a better way to handle this?\n throw new Error(`${result.content}`);\n }\n return result.content;\n },\n toolSchema: tool.inputSchema as TamboTool[\"toolSchema\"],\n });\n });\n }\n registerMcpServers(mcpServers);\n }, [mcpServers, registerTool]);\n\n return children;\n};\n"]}
package/esm/index.d.ts CHANGED
@@ -11,5 +11,4 @@ export { useTamboThreadList } from "./hooks/use-tambo-threads";
11
11
  export { type ComponentContextToolMetadata, type ComponentRegistry, type ParameterSpec, type RegisteredComponent, type TamboTool, } from "./model/component-metadata";
12
12
  export { GenerationStage, type TamboThreadMessage, } from "./model/generate-component-response";
13
13
  export { type TamboThread } from "./model/tambo-thread";
14
- export { TamboMcpProvider } from "./providers/tambo-mcp-provider";
15
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,YAAY,GACb,MA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BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC"}
package/esm/index.js CHANGED
@@ -8,5 +8,4 @@ export { useTamboThreadInput } from "./hooks/use-thread-input";
8
8
  export { TamboClientProvider, TamboComponentProvider, TamboProvider, TamboThreadProvider, useTambo, useTamboClient, useTamboThread, } from "./providers";
9
9
  export { useTamboThreadList } from "./hooks/use-tambo-threads";
10
10
  export { GenerationStage, } from "./model/generate-component-response";
11
- export { TamboMcpProvider } from "./providers/tambo-mcp-provider";
12
11
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,GAGf,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboThread,\n type TamboComponent,\n type TamboRegistryContext,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\nexport { TamboMcpProvider } from \"./providers/tambo-mcp-provider\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wKAAwK;AACxK,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,gCAAgC;AAChC,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,cAAc,EACd,cAAc,GAGf,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D,OAAO,EACL,eAAe,GAEhB,MAAM,qCAAqC,CAAC","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n useTamboMessageContext,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport { useTamboThreadInput } from \"./hooks/use-thread-input\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboProvider,\n TamboThreadProvider,\n useTambo,\n useTamboClient,\n useTamboThread,\n type TamboComponent,\n type TamboRegistryContext,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n"]}
@@ -0,0 +1,2 @@
1
+ export { TamboMcpProvider } from "./tambo-mcp-provider";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { TamboMcpProvider } from "./tambo-mcp-provider";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { TamboMcpProvider } from \"./tambo-mcp-provider\";\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AACD;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAqD;IAEtE;;;;;OAKG;IACH,OAAO;IAoBP;;;;;;;;OAQG;WACU,MAAM,CACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,YAAgC,EAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC;IAMrB;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAiCzC;;;;;;OAMG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAO3D;AASD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAA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QAAQ,CAAC;YACxC,IAAI;YACJ,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\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 private client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\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 transport - 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 transport: MCPTransport,\n headers?: Record<string, string>,\n ) {\n if (transport === MCPTransport.SSE) {\n this.transport = new SSEClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n } else {\n this.transport = new StreamableHTTPClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n }\n this.client = new Client({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n }\n\n /**\n * Creates and initializes a new MCPClient instance.\n * This is the recommended way to create an MCPClient as it handles both\n * instantiation and connection setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param headers - Optional custom headers to include in requests\n * @returns A connected MCPClient instance ready for use\n * @throws Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transport: MCPTransport = MCPTransport.HTTP,\n headers?: Record<string, string>,\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(endpoint, transport, headers);\n await mcpClient.client.connect(mcpClient.transport);\n return mcpClient;\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 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 if (tool.inputSchema.type !== \"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 /**\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 Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(name: string, args: Record<string, unknown>) {\n const result = await this.client.callTool({\n name,\n arguments: args,\n });\n return result;\n }\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"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tools-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-tools-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,E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AM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACnC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;gBAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACzB,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;wBACtC,IAAI,CAAC;4BACH,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;4BAE7C,wBAAwB;4BACxB,IAAI,eAAe,CAAC,KAAK,EAAE,CAAC;gCAC1B,MAAM,IAAI,KAAK,CACb,mBAAmB,eAAe,CAAC,KAAK,CAAC,IAAI,MAAM,eAAe,CAAC,KAAK,CAAC,OAAO,EAAE,CACnF,CAAC;4BACJ,CAAC;4BAED,MAAM,eAAe,CAAC,MAAM,CAAC;wBAC/B,CAAC;wBAAC,OAAO,CAAC,EAAE,CAAC;4BACX,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;wBAC5C,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * Minimal Model Context Protocol (MCP) client using JSON-RPC 2.0\n * Supports only listTools() and callTool() operations\n */\n\n/**\n * Interface representing a Tool in the MCP\n */\nexport interface Tool {\n name: string;\n description?: string;\n inputSchema: {\n type: \"object\";\n properties: Record<string, any>;\n required?: string[];\n };\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/list endpoint\n */\nexport interface ListToolsResult {\n tools: Tool[];\n}\n\n/**\n * Content type for tool responses\n */\nexport interface ToolContent {\n type: string;\n text?: string;\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/call endpoint\n */\nexport interface CallToolResult {\n content: ToolContent[];\n isError?: boolean;\n}\n\n/**\n * A minimal TypeScript client for the Model Context Protocol (MCP)\n *\n * This client provides a streamlined interface to communicate with MCP servers\n * using JSON-RPC 2.0 over HTTP. It supports listing available tools and calling tools\n * with arguments, including support for Server-Sent Events (SSE) streaming responses.\n * @example\n * ```typescript\n * // Basic usage\n * const mcpClient = new MCPClient('https://example.com/mcp');\n * const tools = await mcpClient.listTools();\n * const toolResponse = await mcpClient.callTool('my-tool', { arg1: 'value1' });\n *\n * // For streaming responses:\n * const stream = await mcpClient.callToolStream('streaming-tool', { arg1: 'value1' });\n * for await (const chunk of mcpClient.parseStreamingResponses(stream)) {\n * console.log('Received chunk:', chunk);\n * }\n * ```\n */\nexport class MCPClient {\n private baseUrl: string;\n private headers: Record<string, string>;\n private requestId = 1;\n\n /**\n * Creates a new MCP client\n * @param url - The base URL of the MCP server\n * @param extraHeaders - Optional additional headers to include in requests\n */\n constructor(url: string, extraHeaders?: Record<string, string>) {\n this.baseUrl = url.endsWith(\"/\") ? url : `${url}/`;\n this.headers = {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...(extraHeaders ?? {}),\n };\n }\n\n /**\n * Lists available tools on the MCP server\n * @returns Promise resolving to the list of available tools\n */\n async listTools(): Promise<ListToolsResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/list\",\n params: {},\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to list tools: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns Promise resolving to the tool's response\n */\n async callTool(toolName: string, args: any): Promise<CallToolResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments and returns a stream of results\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns ReadableStream of the tool's response\n */\n async callToolStream(\n toolName: string,\n args: any,\n ): Promise<ReadableStream<Uint8Array>> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: {\n ...this.headers,\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n // Return the response body as a stream\n return response.body;\n }\n\n /**\n * Parse SSE messages from a stream into JSON-RPC responses\n * @param stream - ReadableStream to parse\n * @returns AsyncGenerator yielding parsed JSON-RPC responses\n * @yields {CallToolResult} The parsed JSON-RPC response\n */\n async *parseStreamingResponses(\n stream: ReadableStream<Uint8Array>,\n ): AsyncGenerator<CallToolResult, void, unknown> {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Process complete SSE messages\n const lines = buffer.split(\"\\n\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const jsonData = line.slice(6).trim();\n try {\n const jsonRpcResponse = JSON.parse(jsonData);\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n yield jsonRpcResponse.result;\n } catch (e) {\n console.error(\"Failed to parse JSON:\", e);\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { FC } from "react";
2
+ import { MCPTransport } from "./mcp-client";
3
+ interface McpServerInfo {
4
+ name?: string;
5
+ url: string;
6
+ description?: string;
7
+ transport?: MCPTransport;
8
+ }
9
+ /**
10
+ * This provider is used to register tools from MCP servers.
11
+ * @returns the wrapped children
12
+ */
13
+ export declare const TamboMcpProvider: FC<{
14
+ mcpServers: (McpServerInfo | string)[];
15
+ children: React.ReactNode;
16
+ }>;
17
+ export {};
18
+ //# sourceMappingURL=tambo-mcp-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAa,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvD,UAAU,aAAa;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AACD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC;IAChC,UAAU,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAkEA,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from "react";
2
- import { MCPClient, MCPTransport } from "../util/mcp-client";
3
- import { useTamboRegistry } from "./tambo-registry-provider";
2
+ import { useTamboRegistry } from "../providers/tambo-registry-provider";
3
+ import { MCPClient, MCPTransport } from "./mcp-client";
4
4
  /**
5
5
  * This provider is used to register tools from MCP servers.
6
6
  * @returns the wrapped children
@@ -15,7 +15,11 @@ export const TamboMcpProvider = ({ mcpServers, children }) => {
15
15
  // Maps tool names to the MCP client that registered them
16
16
  const mcpServerMap = new Map();
17
17
  const serverToolLists = mcpServers.map(async (mcpServer) => {
18
- const mcpClient = await MCPClient.create(mcpServer, MCPTransport.SSE);
18
+ const server = typeof mcpServer === "string"
19
+ ? { url: mcpServer, transport: MCPTransport.SSE }
20
+ : mcpServer;
21
+ const { url, transport = MCPTransport.SSE } = server;
22
+ const mcpClient = await MCPClient.create(url, transport);
19
23
  const tools = await mcpClient.listTools();
20
24
  tools.forEach((tool) => {
21
25
  mcpServerMap.set(tool.name, mcpClient);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQvD;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAGxB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAChC,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAE5C,SAAS,CAAC,G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useEffect } from \"react\";\nimport { TamboTool } from \"../model/component-metadata\";\nimport { useTamboRegistry } from \"../providers/tambo-registry-provider\";\nimport { MCPClient, MCPTransport } from \"./mcp-client\";\n\ninterface McpServerInfo {\n name?: string;\n url: string;\n description?: string;\n transport?: MCPTransport;\n}\n/**\n * This provider is used to register tools from MCP servers.\n * @returns the wrapped children\n */\nexport const TamboMcpProvider: FC<{\n mcpServers: (McpServerInfo | string)[];\n children: React.ReactNode;\n}> = ({ mcpServers, children }) => {\n const { registerTool } = useTamboRegistry();\n\n useEffect(() => {\n if (!mcpServers) {\n return;\n }\n async function registerMcpServers(mcpServers: (McpServerInfo | string)[]) {\n // Maps tool names to the MCP client that registered them\n const mcpServerMap = new Map<string, MCPClient>();\n const serverToolLists = mcpServers.map(async (mcpServer) => {\n const server =\n typeof mcpServer === \"string\"\n ? { url: mcpServer, transport: MCPTransport.SSE }\n : mcpServer;\n const { url, transport = MCPTransport.SSE } = server;\n const mcpClient = await MCPClient.create(url, transport);\n const tools = await mcpClient.listTools();\n tools.forEach((tool) => {\n mcpServerMap.set(tool.name, mcpClient);\n });\n return tools;\n });\n const toolResults = await Promise.allSettled(serverToolLists);\n\n // Just log the failed tools, we can't do anything about them\n const failedTools = toolResults.filter(\n (result) => result.status === \"rejected\",\n );\n if (failedTools.length > 0) {\n console.error(\n \"Failed to register tools from MCP servers:\",\n failedTools.map((result) => result.reason),\n );\n }\n\n // Register the successful tools\n const allTools = toolResults\n .filter((result) => result.status === \"fulfilled\")\n .map((result) => result.value)\n .flat();\n allTools.forEach((tool) => {\n registerTool({\n description: tool.description ?? \"\",\n name: tool.name,\n tool: async (args: Record<string, unknown>) => {\n const mcpServer = mcpServerMap.get(tool.name);\n if (!mcpServer) {\n // should never happen\n throw new Error(`MCP server for tool ${tool.name} not found`);\n }\n const result = await mcpServer.callTool(tool.name, args);\n if (result.isError) {\n // TODO: is there a better way to handle this?\n throw new Error(`${result.content}`);\n }\n return result.content;\n },\n toolSchema: tool.inputSchema as TamboTool[\"toolSchema\"],\n });\n });\n }\n registerMcpServers(mcpServers);\n }, [mcpServers, registerTool]);\n\n return children;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tambo-ai/react",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "React client package for Tambo AI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,6 +16,11 @@
16
16
  "import": "./esm/index.js",
17
17
  "require": "./dist/index.js",
18
18
  "types": "./dist/index.d.ts"
19
+ },
20
+ "./mcp": {
21
+ "import": "./esm/mcp/index.js",
22
+ "require": "./dist/mcp/index.js",
23
+ "types": "./dist/mcp/index.d.ts"
19
24
  }
20
25
  },
21
26
  "files": [
@@ -1,10 +0,0 @@
1
- import { FC } from "react";
2
- /**
3
- * This provider is used to register tools from MCP servers.
4
- * @returns the wrapped children
5
- */
6
- export declare const TamboMcpProvider: FC<{
7
- mcpServers: string[];
8
- children: React.ReactNode;
9
- }>;
10
- //# sourceMappingURL=tambo-mcp-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAKtC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CA6DA,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-mcp-provider.tsx"],"names":[],"mappings":";;;AAAA,iCAAsC;AAEtC,mDAA6D;AAC7D,uEAA6D;AAE7D;;;GAGG;AACI,MAAM,gBAAgB,GAGxB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAChC,MAAM,E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BACjD,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;iBAC7B,IAAI,EAAE,CAAC;YACV,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACxB,YAAY,CAAC;oBACX,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;oBACnC,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,IAAI,EAAE,KAAK,EAAE,IAA6B,EAAE,EAAE;wBAC5C,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;4BACf,sBAAsB;4BACtB,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC;wBAChE,CAAC;wBACD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;wBACzD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;4BACnB,8CAA8C;4BAC9C,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;wBACvC,CAAC;wBACD,OAAO,MAAM,CAAC,OAAO,CAAC;oBACxB,CAAC;oBACD,UAAU,EAAE,IAAI,CAAC,WAAsC;iBACxD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE/B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAhEW,QAAA,gBAAgB,oBAgE3B","sourcesContent":["import { FC, useEffect } from \"react\";\nimport { TamboTool } from \"../model/component-metadata\";\nimport { MCPClient, MCPTransport } from \"../util/mcp-client\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\n/**\n * This provider is used to register tools from MCP servers.\n * @returns the wrapped children\n */\nexport const TamboMcpProvider: FC<{\n mcpServers: string[];\n children: React.ReactNode;\n}> = ({ mcpServers, children }) => {\n const { registerTool } = useTamboRegistry();\n\n useEffect(() => {\n if (!mcpServers) {\n return;\n }\n async function registerMcpServers(mcpServers: string[]) {\n // Maps tool names to the MCP client that registered them\n const mcpServerMap = new Map<string, MCPClient>();\n const serverToolLists = mcpServers.map(async (mcpServer) => {\n const mcpClient = await MCPClient.create(mcpServer, MCPTransport.SSE);\n const tools = await mcpClient.listTools();\n tools.forEach((tool) => {\n mcpServerMap.set(tool.name, mcpClient);\n });\n return tools;\n });\n const toolResults = await Promise.allSettled(serverToolLists);\n\n // Just log the failed tools, we can't do anything about them\n const failedTools = toolResults.filter(\n (result) => result.status === \"rejected\",\n );\n if (failedTools.length > 0) {\n console.error(\n \"Failed to register tools from MCP servers:\",\n failedTools.map((result) => result.reason),\n );\n }\n\n // Register the successful tools\n const allTools = toolResults\n .filter((result) => result.status === \"fulfilled\")\n .map((result) => result.value)\n .flat();\n allTools.forEach((tool) => {\n registerTool({\n description: tool.description ?? \"\",\n name: tool.name,\n tool: async (args: Record<string, unknown>) => {\n const mcpServer = mcpServerMap.get(tool.name);\n if (!mcpServer) {\n // should never happen\n throw new Error(`MCP server for tool ${tool.name} not found`);\n }\n const result = await mcpServer.callTool(tool.name, args);\n if (result.isError) {\n // TODO: is there a better way to handle this?\n throw new Error(`${result.content}`);\n }\n return result.content;\n },\n toolSchema: tool.inputSchema as TamboTool[\"toolSchema\"],\n });\n });\n }\n registerMcpServers(mcpServers);\n }, [mcpServers, registerTool]);\n\n return children;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/util/mcp-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAC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,IAAI,KAAK,CACb,yBAAyB,IAAI,CAAC,IAAI,mBAAmB,CACtD,CAAC;gBACJ,CAAC;gBAED,OAAO;oBACL,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,WAAW,EAAE,IAAI,CAAC,WAA0B;iBAC7C,CAAC;YACJ,CAAC,CAAC,CACH,CAAC;YAEF,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;gBACxB,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC;YAC/B,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,IAA6B;QACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxC,IAAI;YACJ,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAtGD,8BAsGC","sourcesContent":["import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\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 private client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\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 transport - 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 transport: MCPTransport,\n headers?: Record<string, string>,\n ) {\n if (transport === MCPTransport.SSE) {\n this.transport = new SSEClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n } else {\n this.transport = new StreamableHTTPClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n }\n this.client = new Client({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n }\n\n /**\n * Creates and initializes a new MCPClient instance.\n * This is the recommended way to create an MCPClient as it handles both\n * instantiation and connection setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param headers - Optional custom headers to include in requests\n * @returns A connected MCPClient instance ready for use\n * @throws Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transport: MCPTransport = MCPTransport.HTTP,\n headers?: Record<string, string>,\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(endpoint, transport, headers);\n await mcpClient.client.connect(mcpClient.transport);\n return mcpClient;\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 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 if (tool.inputSchema.type !== \"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 /**\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 Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(name: string, args: Record<string, unknown>) {\n const result = await this.client.callTool({\n name,\n arguments: args,\n });\n return result;\n }\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 +0,0 @@
1
- {"version":3,"file":"mcp-tools-client.d.ts","sourceRoot":"","sources":["../../src/util/mcp-tools-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAyB;I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AE,CAAC;4BACX,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;wBAC5C,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AA3LD,8BA2LC","sourcesContent":["/**\n * Minimal Model Context Protocol (MCP) client using JSON-RPC 2.0\n * Supports only listTools() and callTool() operations\n */\n\n/**\n * Interface representing a Tool in the MCP\n */\nexport interface Tool {\n name: string;\n description?: string;\n inputSchema: {\n type: \"object\";\n properties: Record<string, any>;\n required?: string[];\n };\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/list endpoint\n */\nexport interface ListToolsResult {\n tools: Tool[];\n}\n\n/**\n * Content type for tool responses\n */\nexport interface ToolContent {\n type: string;\n text?: string;\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/call endpoint\n */\nexport interface CallToolResult {\n content: ToolContent[];\n isError?: boolean;\n}\n\n/**\n * A minimal TypeScript client for the Model Context Protocol (MCP)\n *\n * This client provides a streamlined interface to communicate with MCP servers\n * using JSON-RPC 2.0 over HTTP. It supports listing available tools and calling tools\n * with arguments, including support for Server-Sent Events (SSE) streaming responses.\n * @example\n * ```typescript\n * // Basic usage\n * const mcpClient = new MCPClient('https://example.com/mcp');\n * const tools = await mcpClient.listTools();\n * const toolResponse = await mcpClient.callTool('my-tool', { arg1: 'value1' });\n *\n * // For streaming responses:\n * const stream = await mcpClient.callToolStream('streaming-tool', { arg1: 'value1' });\n * for await (const chunk of mcpClient.parseStreamingResponses(stream)) {\n * console.log('Received chunk:', chunk);\n * }\n * ```\n */\nexport class MCPClient {\n private baseUrl: string;\n private headers: Record<string, string>;\n private requestId = 1;\n\n /**\n * Creates a new MCP client\n * @param url - The base URL of the MCP server\n * @param extraHeaders - Optional additional headers to include in requests\n */\n constructor(url: string, extraHeaders?: Record<string, string>) {\n this.baseUrl = url.endsWith(\"/\") ? url : `${url}/`;\n this.headers = {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...(extraHeaders ?? {}),\n };\n }\n\n /**\n * Lists available tools on the MCP server\n * @returns Promise resolving to the list of available tools\n */\n async listTools(): Promise<ListToolsResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/list\",\n params: {},\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to list tools: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns Promise resolving to the tool's response\n */\n async callTool(toolName: string, args: any): Promise<CallToolResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments and returns a stream of results\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns ReadableStream of the tool's response\n */\n async callToolStream(\n toolName: string,\n args: any,\n ): Promise<ReadableStream<Uint8Array>> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: {\n ...this.headers,\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n // Return the response body as a stream\n return response.body;\n }\n\n /**\n * Parse SSE messages from a stream into JSON-RPC responses\n * @param stream - ReadableStream to parse\n * @returns AsyncGenerator yielding parsed JSON-RPC responses\n * @yields {CallToolResult} The parsed JSON-RPC response\n */\n async *parseStreamingResponses(\n stream: ReadableStream<Uint8Array>,\n ): AsyncGenerator<CallToolResult, void, unknown> {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Process complete SSE messages\n const lines = buffer.split(\"\\n\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const jsonData = line.slice(6).trim();\n try {\n const jsonRpcResponse = JSON.parse(jsonData);\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n yield jsonRpcResponse.result;\n } catch (e) {\n console.error(\"Failed to parse JSON:\", e);\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n"]}
@@ -1,10 +0,0 @@
1
- import { FC } from "react";
2
- /**
3
- * This provider is used to register tools from MCP servers.
4
- * @returns the wrapped children
5
- */
6
- export declare const TamboMcpProvider: FC<{
7
- mcpServers: string[];
8
- children: React.ReactNode;
9
- }>;
10
- //# sourceMappingURL=tambo-mcp-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/providers/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAKtC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CA6DA,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tambo-mcp-provider.js","sourceRoot":"","sources":["../../src/providers/tambo-mcp-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAGxB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAChC,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAE5C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO;QACT,CAAC;QACD,KAAK,UAAU,kBAAkB,CAAC,UAAoB;YACpD,yDAAyD;YACzD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAqB,CAAC;YAClD,MAAM,eAAe,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;gBACzD,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;gBACtE,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,SAAS,EAAE,CAAC;gBAC1C,KAAK,CAAC,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C,CAAC;wBAChE,CAAC;wBACD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;wBACzD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;4BACnB,8CAA8C;4BAC9C,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;wBACvC,CAAC;wBACD,OAAO,MAAM,CAAC,OAAO,CAAC;oBACxB,CAAC;oBACD,UAAU,EAAE,IAAI,CAAC,WAAsC;iBACxD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE/B,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import { FC, useEffect } from \"react\";\nimport { TamboTool } from \"../model/component-metadata\";\nimport { MCPClient, MCPTransport } from \"../util/mcp-client\";\nimport { useTamboRegistry } from \"./tambo-registry-provider\";\n\n/**\n * This provider is used to register tools from MCP servers.\n * @returns the wrapped children\n */\nexport const TamboMcpProvider: FC<{\n mcpServers: string[];\n children: React.ReactNode;\n}> = ({ mcpServers, children }) => {\n const { registerTool } = useTamboRegistry();\n\n useEffect(() => {\n if (!mcpServers) {\n return;\n }\n async function registerMcpServers(mcpServers: string[]) {\n // Maps tool names to the MCP client that registered them\n const mcpServerMap = new Map<string, MCPClient>();\n const serverToolLists = mcpServers.map(async (mcpServer) => {\n const mcpClient = await MCPClient.create(mcpServer, MCPTransport.SSE);\n const tools = await mcpClient.listTools();\n tools.forEach((tool) => {\n mcpServerMap.set(tool.name, mcpClient);\n });\n return tools;\n });\n const toolResults = await Promise.allSettled(serverToolLists);\n\n // Just log the failed tools, we can't do anything about them\n const failedTools = toolResults.filter(\n (result) => result.status === \"rejected\",\n );\n if (failedTools.length > 0) {\n console.error(\n \"Failed to register tools from MCP servers:\",\n failedTools.map((result) => result.reason),\n );\n }\n\n // Register the successful tools\n const allTools = toolResults\n .filter((result) => result.status === \"fulfilled\")\n .map((result) => result.value)\n .flat();\n allTools.forEach((tool) => {\n registerTool({\n description: tool.description ?? \"\",\n name: tool.name,\n tool: async (args: Record<string, unknown>) => {\n const mcpServer = mcpServerMap.get(tool.name);\n if (!mcpServer) {\n // should never happen\n throw new Error(`MCP server for tool ${tool.name} not found`);\n }\n const result = await mcpServer.callTool(tool.name, args);\n if (result.isError) {\n // TODO: is there a better way to handle this?\n throw new Error(`${result.content}`);\n }\n return result.content;\n },\n toolSchema: tool.inputSchema as TamboTool[\"toolSchema\"],\n });\n });\n }\n registerMcpServers(mcpServers);\n }, [mcpServers, registerTool]);\n\n return children;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/util/mcp-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AACD;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAqD;IAEtE;;;;;OAKG;IACH,OAAO;IAoBP;;;;;;;;OAQG;WACU,MAAM,CACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,YAAgC,EAC3C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,SAAS,CAAC;IAMrB;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAiCzC;;;;;;OAMG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,IAA6B;QACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxC,IAAI;YACJ,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\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 private client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\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 transport - 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 transport: MCPTransport,\n headers?: Record<string, string>,\n ) {\n if (transport === MCPTransport.SSE) {\n this.transport = new SSEClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n } else {\n this.transport = new StreamableHTTPClientTransport(new URL(endpoint), {\n requestInit: { headers },\n });\n }\n this.client = new Client({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n }\n\n /**\n * Creates and initializes a new MCPClient instance.\n * This is the recommended way to create an MCPClient as it handles both\n * instantiation and connection setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param headers - Optional custom headers to include in requests\n * @returns A connected MCPClient instance ready for use\n * @throws Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transport: MCPTransport = MCPTransport.HTTP,\n headers?: Record<string, string>,\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(endpoint, transport, headers);\n await mcpClient.client.connect(mcpClient.transport);\n return mcpClient;\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 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 if (tool.inputSchema.type !== \"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 /**\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 Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(name: string, args: Record<string, unknown>) {\n const result = await this.client.callTool({\n name,\n arguments: args,\n });\n return result;\n }\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 +0,0 @@
1
- {"version":3,"file":"mcp-tools-client.d.ts","sourceRoot":"","sources":["../../src/util/mcp-tools-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;G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,MAAM;gBAEhB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBAElD,gCAAgC;gBAChC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACnC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;gBAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACzB,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;wBACtC,IAAI,CAAC;4BACH,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;4BAE7C,wBAAwB;4BACxB,IAAI,eAAe,CAAC,KAAK,EAAE,CAAC;gCAC1B,MAAM,IAAI,KAAK,CACb,mBAAmB,eAAe,CAAC,KAAK,CAAC,IAAI,MAAM,eAAe,CAAC,KAAK,CAAC,OAAO,EAAE,CACnF,CAAC;4BACJ,CAAC;4BAED,MAAM,eAAe,CAAC,MAAM,CAAC;wBAC/B,CAAC;wBAAC,OAAO,CAAC,EAAE,CAAC;4BACX,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;wBAC5C,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * Minimal Model Context Protocol (MCP) client using JSON-RPC 2.0\n * Supports only listTools() and callTool() operations\n */\n\n/**\n * Interface representing a Tool in the MCP\n */\nexport interface Tool {\n name: string;\n description?: string;\n inputSchema: {\n type: \"object\";\n properties: Record<string, any>;\n required?: string[];\n };\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/list endpoint\n */\nexport interface ListToolsResult {\n tools: Tool[];\n}\n\n/**\n * Content type for tool responses\n */\nexport interface ToolContent {\n type: string;\n text?: string;\n annotations?: Record<string, any>;\n}\n\n/**\n * Response from tools/call endpoint\n */\nexport interface CallToolResult {\n content: ToolContent[];\n isError?: boolean;\n}\n\n/**\n * A minimal TypeScript client for the Model Context Protocol (MCP)\n *\n * This client provides a streamlined interface to communicate with MCP servers\n * using JSON-RPC 2.0 over HTTP. It supports listing available tools and calling tools\n * with arguments, including support for Server-Sent Events (SSE) streaming responses.\n * @example\n * ```typescript\n * // Basic usage\n * const mcpClient = new MCPClient('https://example.com/mcp');\n * const tools = await mcpClient.listTools();\n * const toolResponse = await mcpClient.callTool('my-tool', { arg1: 'value1' });\n *\n * // For streaming responses:\n * const stream = await mcpClient.callToolStream('streaming-tool', { arg1: 'value1' });\n * for await (const chunk of mcpClient.parseStreamingResponses(stream)) {\n * console.log('Received chunk:', chunk);\n * }\n * ```\n */\nexport class MCPClient {\n private baseUrl: string;\n private headers: Record<string, string>;\n private requestId = 1;\n\n /**\n * Creates a new MCP client\n * @param url - The base URL of the MCP server\n * @param extraHeaders - Optional additional headers to include in requests\n */\n constructor(url: string, extraHeaders?: Record<string, string>) {\n this.baseUrl = url.endsWith(\"/\") ? url : `${url}/`;\n this.headers = {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...(extraHeaders ?? {}),\n };\n }\n\n /**\n * Lists available tools on the MCP server\n * @returns Promise resolving to the list of available tools\n */\n async listTools(): Promise<ListToolsResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/list\",\n params: {},\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to list tools: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns Promise resolving to the tool's response\n */\n async callTool(toolName: string, args: any): Promise<CallToolResult> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n const jsonRpcResponse = await response.json();\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n return jsonRpcResponse.result;\n }\n\n /**\n * Calls a tool with the provided arguments and returns a stream of results\n * @param toolName - The name of the tool to call\n * @param args - The arguments to pass to the tool\n * @returns ReadableStream of the tool's response\n */\n async callToolStream(\n toolName: string,\n args: any,\n ): Promise<ReadableStream<Uint8Array>> {\n const jsonRpcRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: toolName,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.baseUrl, {\n method: \"POST\",\n headers: {\n ...this.headers,\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify(jsonRpcRequest),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to call tool ${toolName}: ${response.status} ${response.statusText}`,\n );\n }\n\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n // Return the response body as a stream\n return response.body;\n }\n\n /**\n * Parse SSE messages from a stream into JSON-RPC responses\n * @param stream - ReadableStream to parse\n * @returns AsyncGenerator yielding parsed JSON-RPC responses\n * @yields {CallToolResult} The parsed JSON-RPC response\n */\n async *parseStreamingResponses(\n stream: ReadableStream<Uint8Array>,\n ): AsyncGenerator<CallToolResult, void, unknown> {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n // Process complete SSE messages\n const lines = buffer.split(\"\\n\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const jsonData = line.slice(6).trim();\n try {\n const jsonRpcResponse = JSON.parse(jsonData);\n\n // Handle JSON-RPC error\n if (jsonRpcResponse.error) {\n throw new Error(\n `JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`,\n );\n }\n\n yield jsonRpcResponse.result;\n } catch (e) {\n console.error(\"Failed to parse JSON:\", e);\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n"]}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes