@tambo-ai/react 0.22.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 (47) hide show
  1. package/dist/mcp/index.d.ts +2 -0
  2. package/dist/mcp/index.d.ts.map +1 -0
  3. package/dist/mcp/index.js +6 -0
  4. package/dist/mcp/index.js.map +1 -0
  5. package/dist/mcp/mcp-client.d.ts +198 -0
  6. package/dist/mcp/mcp-client.d.ts.map +1 -0
  7. package/dist/mcp/mcp-client.js +108 -0
  8. package/dist/mcp/mcp-client.js.map +1 -0
  9. package/dist/mcp/mcp-tools-client.d.ts +96 -0
  10. package/dist/mcp/mcp-tools-client.d.ts.map +1 -0
  11. package/dist/mcp/mcp-tools-client.js +178 -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/mcp/tambo-mcp-provider.js +69 -0
  16. package/dist/mcp/tambo-mcp-provider.js.map +1 -0
  17. package/dist/model/component-metadata.d.ts +10 -1
  18. package/dist/model/component-metadata.d.ts.map +1 -1
  19. package/dist/model/component-metadata.js.map +1 -1
  20. package/dist/testing/tools.js.map +1 -1
  21. package/dist/util/registry.d.ts.map +1 -1
  22. package/dist/util/registry.js +18 -0
  23. package/dist/util/registry.js.map +1 -1
  24. package/esm/mcp/index.d.ts +2 -0
  25. package/esm/mcp/index.d.ts.map +1 -0
  26. package/esm/mcp/index.js +2 -0
  27. package/esm/mcp/index.js.map +1 -0
  28. package/esm/mcp/mcp-client.d.ts +198 -0
  29. package/esm/mcp/mcp-client.d.ts.map +1 -0
  30. package/esm/mcp/mcp-client.js +104 -0
  31. package/esm/mcp/mcp-client.js.map +1 -0
  32. package/esm/mcp/mcp-tools-client.d.ts +96 -0
  33. package/esm/mcp/mcp-tools-client.d.ts.map +1 -0
  34. package/esm/mcp/mcp-tools-client.js +174 -0
  35. package/esm/mcp/mcp-tools-client.js.map +1 -0
  36. package/esm/mcp/tambo-mcp-provider.d.ts +18 -0
  37. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -0
  38. package/esm/mcp/tambo-mcp-provider.js +65 -0
  39. package/esm/mcp/tambo-mcp-provider.js.map +1 -0
  40. package/esm/model/component-metadata.d.ts +10 -1
  41. package/esm/model/component-metadata.d.ts.map +1 -1
  42. package/esm/model/component-metadata.js.map +1 -1
  43. package/esm/testing/tools.js.map +1 -1
  44. package/esm/util/registry.d.ts.map +1 -1
  45. package/esm/util/registry.js +18 -0
  46. package/esm/util/registry.js.map +1 -1
  47. package/package.json +7 -1
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Minimal Model Context Protocol (MCP) client using JSON-RPC 2.0
3
+ * Supports only listTools() and callTool() operations
4
+ */
5
+ /**
6
+ * Interface representing a Tool in the MCP
7
+ */
8
+ export interface Tool {
9
+ name: string;
10
+ description?: string;
11
+ inputSchema: {
12
+ type: "object";
13
+ properties: Record<string, any>;
14
+ required?: string[];
15
+ };
16
+ annotations?: Record<string, any>;
17
+ }
18
+ /**
19
+ * Response from tools/list endpoint
20
+ */
21
+ export interface ListToolsResult {
22
+ tools: Tool[];
23
+ }
24
+ /**
25
+ * Content type for tool responses
26
+ */
27
+ export interface ToolContent {
28
+ type: string;
29
+ text?: string;
30
+ annotations?: Record<string, any>;
31
+ }
32
+ /**
33
+ * Response from tools/call endpoint
34
+ */
35
+ export interface CallToolResult {
36
+ content: ToolContent[];
37
+ isError?: boolean;
38
+ }
39
+ /**
40
+ * A minimal TypeScript client for the Model Context Protocol (MCP)
41
+ *
42
+ * This client provides a streamlined interface to communicate with MCP servers
43
+ * using JSON-RPC 2.0 over HTTP. It supports listing available tools and calling tools
44
+ * with arguments, including support for Server-Sent Events (SSE) streaming responses.
45
+ * @example
46
+ * ```typescript
47
+ * // Basic usage
48
+ * const mcpClient = new MCPClient('https://example.com/mcp');
49
+ * const tools = await mcpClient.listTools();
50
+ * const toolResponse = await mcpClient.callTool('my-tool', { arg1: 'value1' });
51
+ *
52
+ * // For streaming responses:
53
+ * const stream = await mcpClient.callToolStream('streaming-tool', { arg1: 'value1' });
54
+ * for await (const chunk of mcpClient.parseStreamingResponses(stream)) {
55
+ * console.log('Received chunk:', chunk);
56
+ * }
57
+ * ```
58
+ */
59
+ export declare class MCPClient {
60
+ private baseUrl;
61
+ private headers;
62
+ private requestId;
63
+ /**
64
+ * Creates a new MCP client
65
+ * @param url - The base URL of the MCP server
66
+ * @param extraHeaders - Optional additional headers to include in requests
67
+ */
68
+ constructor(url: string, extraHeaders?: Record<string, string>);
69
+ /**
70
+ * Lists available tools on the MCP server
71
+ * @returns Promise resolving to the list of available tools
72
+ */
73
+ listTools(): Promise<ListToolsResult>;
74
+ /**
75
+ * Calls a tool with the provided arguments
76
+ * @param toolName - The name of the tool to call
77
+ * @param args - The arguments to pass to the tool
78
+ * @returns Promise resolving to the tool's response
79
+ */
80
+ callTool(toolName: string, args: any): Promise<CallToolResult>;
81
+ /**
82
+ * Calls a tool with the provided arguments and returns a stream of results
83
+ * @param toolName - The name of the tool to call
84
+ * @param args - The arguments to pass to the tool
85
+ * @returns ReadableStream of the tool's response
86
+ */
87
+ callToolStream(toolName: string, args: any): Promise<ReadableStream<Uint8Array>>;
88
+ /**
89
+ * Parse SSE messages from a stream into JSON-RPC responses
90
+ * @param stream - ReadableStream to parse
91
+ * @returns AsyncGenerator yielding parsed JSON-RPC responses
92
+ * @yields {CallToolResult} The parsed JSON-RPC response
93
+ */
94
+ parseStreamingResponses(stream: ReadableStream<Uint8Array>): AsyncGenerator<CallToolResult, void, unknown>;
95
+ }
96
+ //# sourceMappingURL=mcp-tools-client.d.ts.map
@@ -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,IAA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AM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,cAAc,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC;CAwCjD"}
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Minimal Model Context Protocol (MCP) client using JSON-RPC 2.0
3
+ * Supports only listTools() and callTool() operations
4
+ */
5
+ /**
6
+ * A minimal TypeScript client for the Model Context Protocol (MCP)
7
+ *
8
+ * This client provides a streamlined interface to communicate with MCP servers
9
+ * using JSON-RPC 2.0 over HTTP. It supports listing available tools and calling tools
10
+ * with arguments, including support for Server-Sent Events (SSE) streaming responses.
11
+ * @example
12
+ * ```typescript
13
+ * // Basic usage
14
+ * const mcpClient = new MCPClient('https://example.com/mcp');
15
+ * const tools = await mcpClient.listTools();
16
+ * const toolResponse = await mcpClient.callTool('my-tool', { arg1: 'value1' });
17
+ *
18
+ * // For streaming responses:
19
+ * const stream = await mcpClient.callToolStream('streaming-tool', { arg1: 'value1' });
20
+ * for await (const chunk of mcpClient.parseStreamingResponses(stream)) {
21
+ * console.log('Received chunk:', chunk);
22
+ * }
23
+ * ```
24
+ */
25
+ export class MCPClient {
26
+ baseUrl;
27
+ headers;
28
+ requestId = 1;
29
+ /**
30
+ * Creates a new MCP client
31
+ * @param url - The base URL of the MCP server
32
+ * @param extraHeaders - Optional additional headers to include in requests
33
+ */
34
+ constructor(url, extraHeaders) {
35
+ this.baseUrl = url.endsWith("/") ? url : `${url}/`;
36
+ this.headers = {
37
+ "Content-Type": "application/json",
38
+ Accept: "application/json",
39
+ ...(extraHeaders ?? {}),
40
+ };
41
+ }
42
+ /**
43
+ * Lists available tools on the MCP server
44
+ * @returns Promise resolving to the list of available tools
45
+ */
46
+ async listTools() {
47
+ const jsonRpcRequest = {
48
+ jsonrpc: "2.0",
49
+ method: "tools/list",
50
+ params: {},
51
+ id: this.requestId++,
52
+ };
53
+ const response = await fetch(this.baseUrl, {
54
+ method: "POST",
55
+ headers: this.headers,
56
+ body: JSON.stringify(jsonRpcRequest),
57
+ });
58
+ if (!response.ok) {
59
+ throw new Error(`Failed to list tools: ${response.status} ${response.statusText}`);
60
+ }
61
+ const jsonRpcResponse = await response.json();
62
+ // Handle JSON-RPC error
63
+ if (jsonRpcResponse.error) {
64
+ throw new Error(`JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`);
65
+ }
66
+ return jsonRpcResponse.result;
67
+ }
68
+ /**
69
+ * Calls a tool with the provided arguments
70
+ * @param toolName - The name of the tool to call
71
+ * @param args - The arguments to pass to the tool
72
+ * @returns Promise resolving to the tool's response
73
+ */
74
+ async callTool(toolName, args) {
75
+ const jsonRpcRequest = {
76
+ jsonrpc: "2.0",
77
+ method: "tools/call",
78
+ params: {
79
+ name: toolName,
80
+ arguments: args,
81
+ },
82
+ id: this.requestId++,
83
+ };
84
+ const response = await fetch(this.baseUrl, {
85
+ method: "POST",
86
+ headers: this.headers,
87
+ body: JSON.stringify(jsonRpcRequest),
88
+ });
89
+ if (!response.ok) {
90
+ throw new Error(`Failed to call tool ${toolName}: ${response.status} ${response.statusText}`);
91
+ }
92
+ const jsonRpcResponse = await response.json();
93
+ // Handle JSON-RPC error
94
+ if (jsonRpcResponse.error) {
95
+ throw new Error(`JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`);
96
+ }
97
+ return jsonRpcResponse.result;
98
+ }
99
+ /**
100
+ * Calls a tool with the provided arguments and returns a stream of results
101
+ * @param toolName - The name of the tool to call
102
+ * @param args - The arguments to pass to the tool
103
+ * @returns ReadableStream of the tool's response
104
+ */
105
+ async callToolStream(toolName, args) {
106
+ const jsonRpcRequest = {
107
+ jsonrpc: "2.0",
108
+ method: "tools/call",
109
+ params: {
110
+ name: toolName,
111
+ arguments: args,
112
+ },
113
+ id: this.requestId++,
114
+ };
115
+ const response = await fetch(this.baseUrl, {
116
+ method: "POST",
117
+ headers: {
118
+ ...this.headers,
119
+ Accept: "text/event-stream",
120
+ },
121
+ body: JSON.stringify(jsonRpcRequest),
122
+ });
123
+ if (!response.ok) {
124
+ throw new Error(`Failed to call tool ${toolName}: ${response.status} ${response.statusText}`);
125
+ }
126
+ if (!response.body) {
127
+ throw new Error("Response body is null");
128
+ }
129
+ // Return the response body as a stream
130
+ return response.body;
131
+ }
132
+ /**
133
+ * Parse SSE messages from a stream into JSON-RPC responses
134
+ * @param stream - ReadableStream to parse
135
+ * @returns AsyncGenerator yielding parsed JSON-RPC responses
136
+ * @yields {CallToolResult} The parsed JSON-RPC response
137
+ */
138
+ async *parseStreamingResponses(stream) {
139
+ const reader = stream.getReader();
140
+ const decoder = new TextDecoder();
141
+ let buffer = "";
142
+ try {
143
+ while (true) {
144
+ const { done, value } = await reader.read();
145
+ if (done)
146
+ break;
147
+ buffer += decoder.decode(value, { stream: true });
148
+ // Process complete SSE messages
149
+ const lines = buffer.split("\n\n");
150
+ buffer = lines.pop() ?? "";
151
+ for (const line of lines) {
152
+ if (line.startsWith("data: ")) {
153
+ const jsonData = line.slice(6).trim();
154
+ try {
155
+ const jsonRpcResponse = JSON.parse(jsonData);
156
+ // Handle JSON-RPC error
157
+ if (jsonRpcResponse.error) {
158
+ throw new Error(`JSON-RPC error: ${jsonRpcResponse.error.code} - ${jsonRpcResponse.error.message}`);
159
+ }
160
+ yield jsonRpcResponse.result;
161
+ }
162
+ catch (e) {
163
+ console.error("Failed to parse JSON:", e);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }
169
+ finally {
170
+ reader.releaseLock();
171
+ }
172
+ }
173
+ }
174
+ //# sourceMappingURL=mcp-tools-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tools-client.js","sourceRoot":"","sources":["../../src/mcp/mcp-tools-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAwCH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,SAAS;IACZ,OAAO,CAAS;IAChB,OAAO,CAAyB;IAChC,SAAS,GAAG,CAAC,CAAC;IAEtB;;;;OAIG;IACH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I,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"}
@@ -0,0 +1,65 @@
1
+ import { useEffect } from "react";
2
+ import { useTamboRegistry } from "../providers/tambo-registry-provider";
3
+ import { MCPClient, MCPTransport } from "./mcp-client";
4
+ /**
5
+ * This provider is used to register tools from MCP servers.
6
+ * @returns the wrapped children
7
+ */
8
+ export const TamboMcpProvider = ({ mcpServers, children }) => {
9
+ const { registerTool } = useTamboRegistry();
10
+ useEffect(() => {
11
+ if (!mcpServers) {
12
+ return;
13
+ }
14
+ async function registerMcpServers(mcpServers) {
15
+ // Maps tool names to the MCP client that registered them
16
+ const mcpServerMap = new Map();
17
+ const serverToolLists = mcpServers.map(async (mcpServer) => {
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);
23
+ const tools = await mcpClient.listTools();
24
+ tools.forEach((tool) => {
25
+ mcpServerMap.set(tool.name, mcpClient);
26
+ });
27
+ return tools;
28
+ });
29
+ const toolResults = await Promise.allSettled(serverToolLists);
30
+ // Just log the failed tools, we can't do anything about them
31
+ const failedTools = toolResults.filter((result) => result.status === "rejected");
32
+ if (failedTools.length > 0) {
33
+ console.error("Failed to register tools from MCP servers:", failedTools.map((result) => result.reason));
34
+ }
35
+ // Register the successful tools
36
+ const allTools = toolResults
37
+ .filter((result) => result.status === "fulfilled")
38
+ .map((result) => result.value)
39
+ .flat();
40
+ allTools.forEach((tool) => {
41
+ registerTool({
42
+ description: tool.description ?? "",
43
+ name: tool.name,
44
+ tool: async (args) => {
45
+ const mcpServer = mcpServerMap.get(tool.name);
46
+ if (!mcpServer) {
47
+ // should never happen
48
+ throw new Error(`MCP server for tool ${tool.name} not found`);
49
+ }
50
+ const result = await mcpServer.callTool(tool.name, args);
51
+ if (result.isError) {
52
+ // TODO: is there a better way to handle this?
53
+ throw new Error(`${result.content}`);
54
+ }
55
+ return result.content;
56
+ },
57
+ toolSchema: tool.inputSchema,
58
+ });
59
+ });
60
+ }
61
+ registerMcpServers(mcpServers);
62
+ }, [mcpServers, registerTool]);
63
+ return children;
64
+ };
65
+ //# sourceMappingURL=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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 { 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"]}
@@ -24,11 +24,20 @@ export interface RegisteredComponent extends TamboAI.AvailableComponent {
24
24
  }
25
25
  export type ComponentRegistry = Record<string, RegisteredComponent>;
26
26
  export type TamboToolRegistry = Record<string, TamboTool>;
27
+ /**
28
+ * A JSON Schema that is compatible with the MCP.
29
+ * This is a simplified JSON Schema that is compatible with the MCPClient and the toolSchema.
30
+ *
31
+ * Do not export this type from the SDK.
32
+ */
33
+ export type JSONSchemaLite = ReturnType<typeof zodToJsonSchema> & {
34
+ description?: string;
35
+ };
27
36
  export interface TamboTool<Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>, Returns extends z.ZodTypeAny = z.ZodTypeAny> {
28
37
  name: string;
29
38
  description: string;
30
39
  tool: (...args: z.infer<Args>) => z.infer<Returns>;
31
- toolSchema: z.ZodFunction<Args, Returns>;
40
+ toolSchema: z.ZodFunction<Args, Returns> | JSONSchemaLite;
32
41
  }
33
42
  export type TamboToolAssociations = Record<string, string[]>;
34
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"component-metadata.d.ts","sourceRoot":"","sources":["../../src/model/component-met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CAAC,CAAC;AAC7D;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAE9B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,UAAU,GAAG,WAAW,CAAC;IACzC;;;;OAIG;IACH,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,uDAAuD;IACvD,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;CAC/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { JSONSchema7 } from \"json-schema\";\nimport { ComponentType } from \"react\";\nimport z from \"zod\";\nimport type zodToJsonSchema from \"zod-to-json-schema\";\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: ReturnType<typeof zodToJsonSchema>;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation using zod-to-json-schema.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<string, TamboTool>;\n\nexport interface TamboTool<\n Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>,\n Returns extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n name: string;\n description: string;\n tool: (...args: z.infer<Args>) => z.infer<Returns>;\n toolSchema: z.ZodFunction<Args, Returns>;\n}\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /**\n * The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /**\n * A zod schema for the component props. (Recommended)\n * Either this or propsDefinition must be provided, but not both.\n */\n propsSchema?: z.ZodTypeAny | JSONSchema7;\n /**\n * The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n * @deprecated Use propsSchema instead.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: TamboTool[];\n}\n"]}
1
+ {"version":3,"file":"component-metadata.js","sourceRoot":"","sources":["../../src/model/component-metadata.ts"],"names":[],"mappings":"","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { JSONSchema7 } from \"json-schema\";\nimport { ComponentType } from \"react\";\nimport z from \"zod\";\nimport type zodToJsonSchema from \"zod-to-json-schema\";\n/** Extension of the ToolParameters interface from Tambo AI to include JSONSchema definition */\nexport type ParameterSpec = TamboAI.ToolParameters & {\n schema?: ReturnType<typeof zodToJsonSchema>;\n};\n\n/**\n * Extends the base ContextTool interface from Tambo AI to include schema information\n * for parameter validation using zod-to-json-schema.\n */\nexport interface ComponentContextToolMetadata\n extends TamboAI.ComponentContextToolMetadata {\n parameters: ParameterSpec[];\n}\n\nexport interface ComponentContextTool {\n getComponentContext: (...args: any[]) => Promise<any>;\n definition: ComponentContextToolMetadata;\n}\n\nexport interface RegisteredComponent extends TamboAI.AvailableComponent {\n component: ComponentType<any>;\n loadingComponent?: ComponentType<any>;\n}\n\nexport type ComponentRegistry = Record<string, RegisteredComponent>;\n\nexport type TamboToolRegistry = Record<string, TamboTool>;\n\n/**\n * A JSON Schema that is compatible with the MCP.\n * This is a simplified JSON Schema that is compatible with the MCPClient and the toolSchema.\n *\n * Do not export this type from the SDK.\n */\nexport type JSONSchemaLite = ReturnType<typeof zodToJsonSchema> & {\n description?: string;\n};\n\nexport interface TamboTool<\n Args extends z.ZodTuple<any, any> = z.ZodTuple<any, any>,\n Returns extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n name: string;\n description: string;\n tool: (...args: z.infer<Args>) => z.infer<Returns>;\n toolSchema: z.ZodFunction<Args, Returns> | JSONSchemaLite;\n}\n\nexport type TamboToolAssociations = Record<string, string[]>;\n/**\n * A component that can be registered with the TamboRegistryProvider.\n */\n\nexport interface TamboComponent {\n /** The name of the component */\n name: string;\n /** The description of the component */\n description: string;\n /**\n * The React component to render.\n *\n * Make sure to pass the Component itself, not an instance of the component. For example,\n * if you have a component like this:\n *\n * ```tsx\n * const MyComponent = () => {\n * return <div>My Component</div>;\n * };\n * ```\n *\n * You should pass the `Component`:\n *\n * ```tsx\n * const components = [MyComponent];\n * <TamboRegistryProvider components={components} />\n * ```\n */\n component: ComponentType<any>;\n\n /**\n * A zod schema for the component props. (Recommended)\n * Either this or propsDefinition must be provided, but not both.\n */\n propsSchema?: z.ZodTypeAny | JSONSchema7;\n /**\n * The props definition of the component as a JSON object.\n * Either this or propsSchema must be provided, but not both.\n * @deprecated Use propsSchema instead.\n */\n propsDefinition?: any;\n /** The loading component to render while the component is loading */\n loadingComponent?: ComponentType<any>;\n /** The tools that are associated with the component */\n associatedTools?: TamboTool[];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/testing/tools.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAGjD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAA8B;IAC9D,OAAO,YAAY,CAAC,GAAG,CACrB,CAAC,EACC,SAAS,EAAE,UAAU,EACrB,WAAW,EACX,eAAe,EACf,GAAG,cAAc,EAClB,EAAE,EAAE,CAAC,CAAC;QACL,GAAG,cAAc;QACjB,KAAK,EAAE,eAAe,CAAC,WAA2B,CAAC;QACnD,YAAY,EAAE,eAAe,EAAE,GAAG,CAChC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;YAC9C,GAAG,SAAS;YACZ,UAAU,EAAE,UAAU;iBACnB,UAAU,EAAE;iBACZ,KAAK,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,KAAa,EAAE,EAAE,CAAC,CAAC;gBAC9C,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,EAAE;gBACzB,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;gBAC1B,UAAU,EAAE,IAAI;gBAChB,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,IAAI,EAAG,eAAe,CAAC,CAAC,CAAS,CAAC,IAAI;aACvC,CAAC,CAAC;SACN,CAAC,CACH;KACF,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport { TamboComponent } from \"../providers\";\n\n/**\n * Serializes the registry for testing purposes\n * @param mockRegistry - The registry to serialize\n * @returns The serialized registry\n */\nexport function serializeRegistry(mockRegistry: TamboComponent[]) {\n return mockRegistry.map(\n ({\n component: _component,\n propsSchema,\n associatedTools,\n ...componentEntry\n }) => ({\n ...componentEntry,\n props: zodToJsonSchema(propsSchema as z.ZodTypeAny),\n contextTools: associatedTools?.map(\n ({ toolSchema, tool: _tool, ...toolEntry }) => ({\n ...toolEntry,\n parameters: toolSchema\n .parameters()\n .items.map((p: z.ZodTypeAny, index: number) => ({\n name: `param${index + 1}`,\n schema: zodToJsonSchema(p),\n isRequired: true,\n description: p.description,\n type: (zodToJsonSchema(p) as any).type,\n })),\n }),\n ),\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/testing/tools.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAGjD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAA8B;IAC9D,OAAO,YAAY,CAAC,GAAG,CACrB,CAAC,EACC,SAAS,EAAE,UAAU,EACrB,WAAW,EACX,eAAe,EACf,GAAG,cAAc,EAClB,EAAE,EAAE,CAAC,CAAC;QACL,GAAG,cAAc;QACjB,KAAK,EAAE,eAAe,CAAC,WAA2B,CAAC;QACnD,YAAY,EAAE,eAAe,EAAE,GAAG,CAChC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;YAC9C,GAAG,SAAS;YACZ,UAAU,EAAG,UAAsC;iBAChD,UAAU,EAAE;iBACZ,KAAK,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,KAAa,EAAE,EAAE,CAAC,CAAC;gBAC9C,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,EAAE;gBACzB,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;gBAC1B,UAAU,EAAE,IAAI;gBAChB,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,IAAI,EAAG,eAAe,CAAC,CAAC,CAAS,CAAC,IAAI;aACvC,CAAC,CAAC;SACN,CAAC,CACH;KACF,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport { TamboComponent } from \"../providers\";\n\n/**\n * Serializes the registry for testing purposes\n * @param mockRegistry - The registry to serialize\n * @returns The serialized registry\n */\nexport function serializeRegistry(mockRegistry: TamboComponent[]) {\n return mockRegistry.map(\n ({\n component: _component,\n propsSchema,\n associatedTools,\n ...componentEntry\n }) => ({\n ...componentEntry,\n props: zodToJsonSchema(propsSchema as z.ZodTypeAny),\n contextTools: associatedTools?.map(\n ({ toolSchema, tool: _tool, ...toolEntry }) => ({\n ...toolEntry,\n parameters: (toolSchema as z.ZodFunction<any, any>)\n .parameters()\n .items.map((p: z.ZodTypeAny, index: number) => ({\n name: `param${index + 1}`,\n schema: zodToJsonSchema(p),\n isRequired: true,\n description: p.description,\n type: (zodToJsonSchema(p) as any).type,\n })),\n }),\n ),\n }),\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EAEjB,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,EAuB5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,SAAS,EAKX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,WAAW,mBAAmB,KAC7B,GAYF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,MAAM,EACrB,mBAAmB,iBAAiB,KACnC,mBAUF,CAAC;AAUF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,QAAO,MAGnC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,MAAM,SAAS,KACd,4BAQF,CAAC"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EAGjB,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,mBAAmB,iBAAiB,EACpC,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,OAAO,CAAC,kBAAkB,EAuB5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,iBAAiB,EAC/B,kBAAkB,qBAAqB,KACtC,SAAS,EAKX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,WAAW,mBAAmB,KAC7B,GAYF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACnC,eAAe,MAAM,EACrB,mBAAmB,iBAAiB,KACnC,mBAUF,CAAC;AAUF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,QAAO,MAGnC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,MAAM,SAAS,KACd,4BAQF,CAAC"}
@@ -96,7 +96,25 @@ export const mapTamboToolToContextTool = (tool) => {
96
96
  parameters,
97
97
  };
98
98
  };
99
+ function isJsonSchema(schema) {
100
+ return (typeof schema === "object" &&
101
+ schema !== null &&
102
+ "type" in schema &&
103
+ typeof schema.type === "string" &&
104
+ schema.type === "object");
105
+ }
99
106
  const getParametersFromZodFunction = (schema) => {
107
+ if (isJsonSchema(schema)) {
108
+ return [
109
+ {
110
+ name: "args",
111
+ type: "object",
112
+ description: schema.description ?? "",
113
+ isRequired: true,
114
+ schema: schema,
115
+ },
116
+ ];
117
+ }
100
118
  const parameters = schema.parameters();
101
119
  return parameters.items.map((param, index) => {
102
120
  const name = `param${index + 1}`;
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAWjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,YAA+B,EAC/B,gBAAuC,EACT,EAAE;IAChC,MAAM,mBAAmB,GAAiC,EAAE,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACvE,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAEzD,MAAM,YAAY,GAAG;YACnB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtC,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;gBACpC,IAAI,CAAC,IAAI;oBAAE,OAAO,IAAI,CAAC;gBACvB,OAAO,yBAAyB,CAAC,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC;SACH,CAAC,MAAM,CAAC,CAAC,IAAI,EAAwC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAExE,mBAAmB,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,cAAc,CAAC,IAAI;YACzB,WAAW,EAAE,cAAc,CAAC,WAAW;YACvC,KAAK,EAAE,cAAc,CAAC,KAAK;YAC3B,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,YAA+B,EAC/B,gBAAuC,EAC1B,EAAE;IACf,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;Q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C;QACjB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC;QAClB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,SAAS,CAAC;QACnB,KAAK,UAAU;YACb,OAAO,OAAO,CAAC;QACjB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentContextToolMetadata,\n ComponentRegistry,\n ParameterSpec,\n RegisteredComponent,\n TamboTool,\n TamboToolAssociations,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\n\n/**\n * Get all the available components from the component registry\n * @param componentRegistry - The component registry\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The available components\n */\nexport const getAvailableComponents = (\n componentRegistry: ComponentRegistry,\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboAI.AvailableComponent[] => {\n const availableComponents: TamboAI.AvailableComponent[] = [];\n\n for (const [name, componentEntry] of Object.entries(componentRegistry)) {\n const associatedToolNames = toolAssociations[name] || [];\n\n const contextTools = [\n ...associatedToolNames.map((toolName) => {\n const tool = toolRegistry[toolName];\n if (!tool) return null;\n return mapTamboToolToContextTool(tool);\n }),\n ].filter((tool): tool is ComponentContextToolMetadata => tool !== null);\n\n availableComponents.push({\n name: componentEntry.name,\n description: componentEntry.description,\n props: componentEntry.props,\n contextTools,\n });\n }\n\n return availableComponents;\n};\n\n/**\n * Get tools from tool registry that are not associated with any component\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The tools that are not associated with any component\n */\nexport const getUnassociatedTools = (\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboTool[] => {\n return Object.values(toolRegistry).filter((tool) => {\n // Check if the tool's name appears in any of the tool association arrays\n return !Object.values(toolAssociations).flat().includes(tool.name);\n });\n};\n\n/**\n * Helper function to convert component props from Zod schema to JSON Schema\n * @param component - The component to convert\n * @returns The converted props\n */\nexport const convertPropsToJsonSchema = (\n component: RegisteredComponent,\n): any => {\n if (!component.props) {\n return component.props;\n }\n\n // Check if props is a Zod schema (we can't directly check the type, so we check for _def)\n if (component.props._def && typeof component.props.parse === \"function\") {\n // Use two-step type assertion for safety\n return zodToJsonSchema(component.props as unknown as z.ZodTypeAny);\n }\n\n return component.props;\n};\n\n/**\n * Get a component by name from the component registry\n * @param componentName - The name of the component to get\n * @param componentRegistry - The component registry\n * @returns The component registration information\n */\nexport const getComponentFromRegistry = (\n componentName: string,\n componentRegistry: ComponentRegistry,\n): RegisteredComponent => {\n const componentEntry = componentRegistry[componentName];\n\n if (!componentEntry) {\n throw new Error(\n `Tambo tried to use Component ${componentName}, but it was not found.`,\n );\n }\n\n return componentEntry;\n};\n\nconst getDefaultContextAdditions = (): string[] => {\n const utcOffsetHours = new Date().getTimezoneOffset() / 60;\n const utcOffset = `(UTC${utcOffsetHours > 0 ? \"+\" : \"\"}${utcOffsetHours})`;\n return [\n `The current time in user's timezone (${utcOffset}) is: ${new Date().toLocaleString()}`,\n ];\n};\n\n/**\n * Get the client context for the current thread, such as the current time in the user's timezone\n * @returns a string of context additions that will be added to the prompt when the thread is advanced.\n */\nexport const getClientContext = (): string => {\n const contextAdditions = getDefaultContextAdditions();\n return contextAdditions.join(\"\\n\");\n};\n\n/**\n * Map a Tambo tool to a context tool\n * @param tool - The tool to map\n * @returns The context tool\n */\nexport const mapTamboToolToContextTool = (\n tool: TamboTool,\n): ComponentContextToolMetadata => {\n const parameters = getParametersFromZodFunction(tool.toolSchema);\n\n return {\n name: tool.name,\n description: tool.description,\n parameters,\n };\n};\n\nconst getParametersFromZodFunction = (\n schema: z.ZodFunction<any, any>,\n): ParameterSpec[] => {\n const parameters: z.ZodTuple = schema.parameters();\n return parameters.items.map((param, index): ParameterSpec => {\n const name = `param${index + 1}`;\n const type = getZodBaseType(param);\n const description = param.description ?? \"\";\n const isRequired = !param.isOptional();\n const schema = zodToJsonSchema(param);\n\n return {\n name,\n type,\n description,\n isRequired,\n schema,\n };\n });\n};\n\nconst getZodBaseType = (schema: z.ZodTypeAny): string => {\n const typeName = schema._def.typeName;\n switch (typeName) {\n case \"ZodString\":\n return \"string\";\n case \"ZodNumber\":\n return \"number\";\n case \"ZodBoolean\":\n return \"boolean\";\n case \"ZodArray\":\n return \"array\";\n case \"ZodEnum\":\n return \"enum\";\n case \"ZodDate\":\n return \"date\";\n case \"ZodObject\":\n return \"object\";\n default:\n console.warn(\"falling back to string for\", typeName);\n return \"string\";\n }\n};\n"]}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/util/registry.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAYjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,YAA+B,EAC/B,gBAAuC,EACT,EAAE;IAChC,MAAM,mBAAmB,GAAiC,EAAE,CAAC;IAE7D,KAAK,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACvE,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAEzD,MAAM,YAAY,GAAG;YACnB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtC,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;gBACpC,IAAI,CAAC,IAAI;oBAAE,OAAO,IAAI,CAAC;gBAC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,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,CAAC,IAAI,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAC;YACrD,OAAO,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import TamboAI from \"@tambo-ai/typescript-sdk\";\nimport { z } from \"zod\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport {\n ComponentContextToolMetadata,\n ComponentRegistry,\n JSONSchemaLite,\n ParameterSpec,\n RegisteredComponent,\n TamboTool,\n TamboToolAssociations,\n TamboToolRegistry,\n} from \"../model/component-metadata\";\n\n/**\n * Get all the available components from the component registry\n * @param componentRegistry - The component registry\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The available components\n */\nexport const getAvailableComponents = (\n componentRegistry: ComponentRegistry,\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboAI.AvailableComponent[] => {\n const availableComponents: TamboAI.AvailableComponent[] = [];\n\n for (const [name, componentEntry] of Object.entries(componentRegistry)) {\n const associatedToolNames = toolAssociations[name] || [];\n\n const contextTools = [\n ...associatedToolNames.map((toolName) => {\n const tool = toolRegistry[toolName];\n if (!tool) return null;\n return mapTamboToolToContextTool(tool);\n }),\n ].filter((tool): tool is ComponentContextToolMetadata => tool !== null);\n\n availableComponents.push({\n name: componentEntry.name,\n description: componentEntry.description,\n props: componentEntry.props,\n contextTools,\n });\n }\n\n return availableComponents;\n};\n\n/**\n * Get tools from tool registry that are not associated with any component\n * @param toolRegistry - The tool registry\n * @param toolAssociations - The tool associations\n * @returns The tools that are not associated with any component\n */\nexport const getUnassociatedTools = (\n toolRegistry: TamboToolRegistry,\n toolAssociations: TamboToolAssociations,\n): TamboTool[] => {\n return Object.values(toolRegistry).filter((tool) => {\n // Check if the tool's name appears in any of the tool association arrays\n return !Object.values(toolAssociations).flat().includes(tool.name);\n });\n};\n\n/**\n * Helper function to convert component props from Zod schema to JSON Schema\n * @param component - The component to convert\n * @returns The converted props\n */\nexport const convertPropsToJsonSchema = (\n component: RegisteredComponent,\n): any => {\n if (!component.props) {\n return component.props;\n }\n\n // Check if props is a Zod schema (we can't directly check the type, so we check for _def)\n if (component.props._def && typeof component.props.parse === \"function\") {\n // Use two-step type assertion for safety\n return zodToJsonSchema(component.props as unknown as z.ZodTypeAny);\n }\n\n return component.props;\n};\n\n/**\n * Get a component by name from the component registry\n * @param componentName - The name of the component to get\n * @param componentRegistry - The component registry\n * @returns The component registration information\n */\nexport const getComponentFromRegistry = (\n componentName: string,\n componentRegistry: ComponentRegistry,\n): RegisteredComponent => {\n const componentEntry = componentRegistry[componentName];\n\n if (!componentEntry) {\n throw new Error(\n `Tambo tried to use Component ${componentName}, but it was not found.`,\n );\n }\n\n return componentEntry;\n};\n\nconst getDefaultContextAdditions = (): string[] => {\n const utcOffsetHours = new Date().getTimezoneOffset() / 60;\n const utcOffset = `(UTC${utcOffsetHours > 0 ? \"+\" : \"\"}${utcOffsetHours})`;\n return [\n `The current time in user's timezone (${utcOffset}) is: ${new Date().toLocaleString()}`,\n ];\n};\n\n/**\n * Get the client context for the current thread, such as the current time in the user's timezone\n * @returns a string of context additions that will be added to the prompt when the thread is advanced.\n */\nexport const getClientContext = (): string => {\n const contextAdditions = getDefaultContextAdditions();\n return contextAdditions.join(\"\\n\");\n};\n\n/**\n * Map a Tambo tool to a context tool\n * @param tool - The tool to map\n * @returns The context tool\n */\nexport const mapTamboToolToContextTool = (\n tool: TamboTool,\n): ComponentContextToolMetadata => {\n const parameters = getParametersFromZodFunction(tool.toolSchema);\n\n return {\n name: tool.name,\n description: tool.description,\n parameters,\n };\n};\n\nfunction isJsonSchema(\n schema: unknown,\n): schema is ReturnType<typeof zodToJsonSchema> {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n \"type\" in schema &&\n typeof (schema as { type: unknown }).type === \"string\" &&\n (schema as { type: string }).type === \"object\"\n );\n}\n\nconst getParametersFromZodFunction = (\n schema: z.ZodFunction<any, any> | JSONSchemaLite,\n): ParameterSpec[] => {\n if (isJsonSchema(schema)) {\n return [\n {\n name: \"args\",\n type: \"object\",\n description: schema.description ?? \"\",\n isRequired: true,\n schema: schema,\n },\n ];\n }\n\n const parameters: z.ZodTuple = schema.parameters();\n return parameters.items.map((param, index): ParameterSpec => {\n const name = `param${index + 1}`;\n const type = getZodBaseType(param);\n const description = param.description ?? \"\";\n const isRequired = !param.isOptional();\n const schema = zodToJsonSchema(param);\n\n return {\n name,\n type,\n description,\n isRequired,\n schema,\n };\n });\n};\n\nconst getZodBaseType = (schema: z.ZodTypeAny): string => {\n const typeName = schema._def.typeName;\n switch (typeName) {\n case \"ZodString\":\n return \"string\";\n case \"ZodNumber\":\n return \"number\";\n case \"ZodBoolean\":\n return \"boolean\";\n case \"ZodArray\":\n return \"array\";\n case \"ZodEnum\":\n return \"enum\";\n case \"ZodDate\":\n return \"date\";\n case \"ZodObject\":\n return \"object\";\n default:\n console.warn(\"falling back to string for\", typeName);\n return \"string\";\n }\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tambo-ai/react",
3
- "version": "0.22.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": [
@@ -62,6 +67,7 @@
62
67
  "react-dom": "^18.0.0 || ^19.0.0"
63
68
  },
64
69
  "dependencies": {
70
+ "@modelcontextprotocol/sdk": "^1.11.0",
65
71
  "@tambo-ai/typescript-sdk": "^0.47.0",
66
72
  "@tanstack/react-query": "^5.75.2",
67
73
  "partial-json": "^0.1.7",