@tambo-ai/react 0.53.2 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js +115 -0
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/dist/mcp/__tests__/use-mcp-servers.test.d.ts +2 -0
- package/dist/mcp/__tests__/use-mcp-servers.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/use-mcp-servers.test.js +118 -0
- package/dist/mcp/__tests__/use-mcp-servers.test.js.map +1 -0
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +2 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tambo-mcp-provider.d.ts +34 -2
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +125 -14
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +15 -0
- package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/dist/providers/__tests__/tambo-registry-provider.test.js +44 -9
- package/dist/providers/__tests__/tambo-registry-provider.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +3 -0
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
- package/dist/providers/tambo-registry-provider.js +12 -1
- package/dist/providers/tambo-registry-provider.js.map +1 -1
- package/dist/util/validate-component-name.d.ts +7 -0
- package/dist/util/validate-component-name.d.ts.map +1 -0
- package/dist/util/validate-component-name.js +14 -0
- package/dist/util/validate-component-name.js.map +1 -0
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js +83 -1
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/esm/mcp/__tests__/use-mcp-servers.test.d.ts +2 -0
- package/esm/mcp/__tests__/use-mcp-servers.test.d.ts.map +1 -0
- package/esm/mcp/__tests__/use-mcp-servers.test.js +83 -0
- package/esm/mcp/__tests__/use-mcp-servers.test.js.map +1 -0
- package/esm/mcp/index.d.ts +1 -1
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +1 -1
- package/esm/mcp/index.js.map +1 -1
- package/esm/mcp/tambo-mcp-provider.d.ts +34 -2
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +90 -13
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +15 -0
- package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/esm/providers/__tests__/tambo-registry-provider.test.js +44 -9
- package/esm/providers/__tests__/tambo-registry-provider.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +3 -0
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
- package/esm/providers/tambo-registry-provider.js +12 -1
- package/esm/providers/tambo-registry-provider.js.map +1 -1
- package/esm/util/validate-component-name.d.ts +7 -0
- package/esm/util/validate-component-name.d.ts.map +1 -0
- package/esm/util/validate-component-name.js +11 -0
- package/esm/util/validate-component-name.js.map +1 -0
- package/package.json +3 -2
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const react_1 = require("@testing-library/react");
|
|
37
|
+
const react_2 = __importStar(require("react"));
|
|
38
|
+
const tambo_registry_provider_1 = require("../../providers/tambo-registry-provider");
|
|
39
|
+
const mcp_client_1 = require("../mcp-client");
|
|
3
40
|
const tambo_mcp_provider_1 = require("../tambo-mcp-provider");
|
|
4
41
|
// Mock the MCP client to avoid ES module issues
|
|
5
42
|
jest.mock("../mcp-client", () => ({
|
|
@@ -112,4 +149,82 @@ describe("extractErrorMessage", () => {
|
|
|
112
149
|
});
|
|
113
150
|
});
|
|
114
151
|
});
|
|
152
|
+
describe("TamboMcpProvider server list changes", () => {
|
|
153
|
+
beforeEach(() => {
|
|
154
|
+
// Mock registry so tool registration is a no-op
|
|
155
|
+
tambo_registry_provider_1.useTamboRegistry.mockReturnValue({
|
|
156
|
+
registerTool: jest.fn(),
|
|
157
|
+
});
|
|
158
|
+
// Ensure MCPClient.create exists and returns a fake client with listTools
|
|
159
|
+
mcp_client_1.MCPClient.create = jest
|
|
160
|
+
.fn()
|
|
161
|
+
.mockResolvedValue({ listTools: jest.fn().mockResolvedValue([]) });
|
|
162
|
+
});
|
|
163
|
+
const Capture = ({ onUpdate, }) => {
|
|
164
|
+
const servers = (0, tambo_mcp_provider_1.useTamboMcpServers)();
|
|
165
|
+
(0, react_2.useEffect)(() => {
|
|
166
|
+
onUpdate(servers);
|
|
167
|
+
}, [servers, onUpdate]);
|
|
168
|
+
return react_2.default.createElement("div", { "data-testid": "urls" }, servers.map((s) => s.url).join(","));
|
|
169
|
+
};
|
|
170
|
+
it("adds a new server when the list grows", async () => {
|
|
171
|
+
let latest = [];
|
|
172
|
+
const { rerender, getByTestId } = (0, react_1.render)(react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: ["https://a.example"] },
|
|
173
|
+
react_2.default.createElement(Capture, { onUpdate: (s) => (latest = s) })));
|
|
174
|
+
// Wait for initial connection
|
|
175
|
+
await (0, react_1.waitFor)(() => {
|
|
176
|
+
expect(latest.length).toBe(1);
|
|
177
|
+
});
|
|
178
|
+
// Add new server
|
|
179
|
+
rerender(react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: ["https://a.example", "https://b.example"] },
|
|
180
|
+
react_2.default.createElement(Capture, { onUpdate: (s) => (latest = s) })));
|
|
181
|
+
await (0, react_1.waitFor)(() => {
|
|
182
|
+
expect(latest.length).toBe(2);
|
|
183
|
+
const urls = getByTestId("urls").textContent || "";
|
|
184
|
+
expect(urls).toContain("https://a.example");
|
|
185
|
+
expect(urls).toContain("https://b.example");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
it("removes a server when the list shrinks", async () => {
|
|
189
|
+
let latest = [];
|
|
190
|
+
const { rerender, getByTestId } = (0, react_1.render)(react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: ["https://a.example", "https://b.example"] },
|
|
191
|
+
react_2.default.createElement(Capture, { onUpdate: (s) => (latest = s) })));
|
|
192
|
+
await (0, react_1.waitFor)(() => {
|
|
193
|
+
expect(latest.length).toBe(2);
|
|
194
|
+
});
|
|
195
|
+
// Remove one server
|
|
196
|
+
rerender(react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: ["https://a.example"] },
|
|
197
|
+
react_2.default.createElement(Capture, { onUpdate: (s) => (latest = s) })));
|
|
198
|
+
await (0, react_1.waitFor)(() => {
|
|
199
|
+
expect(latest.length).toBe(1);
|
|
200
|
+
const urls = getByTestId("urls").textContent || "";
|
|
201
|
+
expect(urls).toContain("https://a.example");
|
|
202
|
+
expect(urls).not.toContain("https://b.example");
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
it("does not duplicate when a new copy of the same list is passed", async () => {
|
|
206
|
+
let latest = [];
|
|
207
|
+
const initial = [
|
|
208
|
+
{ url: "https://a.example", transport: mcp_client_1.MCPTransport.SSE },
|
|
209
|
+
{ url: "https://b.example", transport: mcp_client_1.MCPTransport.SSE },
|
|
210
|
+
];
|
|
211
|
+
const { rerender } = (0, react_1.render)(react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: initial },
|
|
212
|
+
react_2.default.createElement(Capture, { onUpdate: (s) => (latest = s) })));
|
|
213
|
+
await (0, react_1.waitFor)(() => {
|
|
214
|
+
expect(latest.length).toBe(2);
|
|
215
|
+
});
|
|
216
|
+
// Pass a new array instance with the same logical servers
|
|
217
|
+
const same = [
|
|
218
|
+
{ url: "https://a.example", transport: mcp_client_1.MCPTransport.SSE },
|
|
219
|
+
{ url: "https://b.example", transport: mcp_client_1.MCPTransport.SSE },
|
|
220
|
+
];
|
|
221
|
+
rerender(react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: same },
|
|
222
|
+
react_2.default.createElement(Capture, { onUpdate: (s) => (latest = s) })));
|
|
223
|
+
await (0, react_1.waitFor)(() => {
|
|
224
|
+
expect(latest.length).toBe(2);
|
|
225
|
+
const urls = latest.map((s) => s.url).sort();
|
|
226
|
+
expect(urls).toEqual(["https://a.example", "https://b.example"].sort());
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
115
230
|
//# sourceMappingURL=tambo-mcp-provider.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-mcp-provider.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/tambo-mcp-provider.test.tsx"],"names":[],"mappings":";;AAAA,8DAA4D;AAE5D,gDAAgD;AAChD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE;IACpB,YAAY,EAAE;QACZ,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;KACb;CACF,CAAC,CAAC,CAAC;AAEJ,wDAAwD;AACxD,IAAI,CAAC,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,gBAAgB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC5B,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,MAAM,OAAO,GAAG;gBACd,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAChC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,EAAE;gBAC/C,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,8BAA8B,EAAE,EAAE,yB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AG,EAAE;YAC9C,MAAM,OAAO,GAAG;gBACd,KAAK,EAAE,sBAAsB;gBAC7B,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,EAAE,OAAO,EAAE,uBAAuB,EAAE;aAC9C,CAAC;YAEF,MAAM,MAAM,GAAG,IAAA,wCAAmB,EAAC,OAAO,CAAC,CAAC;YAE5C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CACjB,2FAA2F,CAC5F,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,MAAM,OAAO,GAAG,EAAE,CAAC;YAEnB,MAAM,MAAM,GAAG,IAAA,wCAAmB,EAAC,OAAO,CAAC,CAAC;YAE5C,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { extractErrorMessage } from \"../tambo-mcp-provider\";\n\n// Mock the MCP client to avoid ES module issues\njest.mock(\"../mcp-client\", () => ({\n MCPClient: jest.fn(),\n MCPTransport: {\n SSE: \"sse\",\n HTTP: \"http\",\n },\n}));\n\n// Mock the registry provider to avoid dependency issues\njest.mock(\"../../providers/tambo-registry-provider\", () => ({\n useTamboRegistry: jest.fn(),\n}));\n\ndescribe(\"extractErrorMessage\", () => {\n describe(\"Array content handling\", () => {\n it(\"should extract text from array content with multiple text items\", () => {\n const content = [\n { type: \"text\", text: \"Error:\" },\n { type: \"text\", text: \"Tool execution failed\" },\n { type: \"image\", url: \"http://example.com/error.png\" }, // Should be filtered out\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error: Tool execution failed\");\n });\n\n it(\"should extract text from array content with single text item\", () => {\n const content = [{ type: \"text\", text: \"Simple error message\" }];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Simple error message\");\n });\n\n it(\"should return fallback message for array content with no text items\", () => {\n const content = [\n { type: \"image\", url: \"http://example.com/error.png\" },\n { type: \"resource\", uri: \"file://error.log\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error occurred but no details provided\");\n });\n\n it(\"should return fallback message for empty array content\", () => {\n const content: any[] = [];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error occurred but no details provided\");\n });\n\n it(\"should handle array content with mixed types correctly\", () => {\n const content = [\n { type: \"resource\", uri: \"file://log.txt\" },\n { type: \"text\", text: \"First error\" },\n { type: \"image\", url: \"http://example.com/img.png\" },\n { type: \"text\", text: \"Second error\" },\n { type: \"unknown\", data: \"something\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"First error Second error\");\n });\n\n it(\"should handle array content with malformed items\", () => {\n const content = [\n null,\n { type: \"text\", text: \"Valid error\" },\n { type: \"text\" }, // Missing text property\n { type: \"text\", text: null }, // Invalid text type\n { type: \"text\", text: \"Another valid error\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Valid error Another valid error\");\n });\n });\n\n describe(\"Non-array content handling\", () => {\n it(\"should return string content as-is\", () => {\n const content = \"Direct error message\";\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Direct error message\");\n });\n\n it(\"should handle null content\", () => {\n const content = null;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Unknown error occurred\");\n });\n\n it(\"should handle undefined content\", () => {\n const content = undefined;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Unknown error occurred\");\n });\n\n it(\"should handle number content\", () => {\n const content = 42;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"42\");\n });\n\n it(\"should handle boolean content\", () => {\n const content = false;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"false\");\n });\n\n it(\"should handle object content\", () => {\n const content = { error: \"Something went wrong\" };\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe('{\"error\":\"Something went wrong\"}');\n });\n\n it(\"should handle complex object content\", () => {\n const content = {\n error: \"Something went wrong\",\n code: 500,\n details: { message: \"Internal server error\" },\n };\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\n '{\"error\":\"Something went wrong\",\"code\":500,\"details\":{\"message\":\"Internal server error\"}}',\n );\n });\n\n it(\"should handle empty object content\", () => {\n const content = {};\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"{}\");\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"tambo-mcp-provider.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/tambo-mcp-provider.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAyD;AACzD,+CAAyC;AACzC,qFAA2E;AAC3E,8CAAwD;AACxD,8DAK+B;AAE/B,gDAAgD;AAChD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE;IACpB,YAAY,EAAE;QACZ,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;KACb;CACF,CAAC,CAAC,CAAC;AAEJ,wDAAwD;AACxD,IAAI,CAAC,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,gBAAgB,EAAE,IAAI,CAAC,EAAE,EAAE;CAC5B,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,MAAM,OAAO,GAAG;gBACd,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAChC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,EAAE;gBAC/C,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,8BAA8B,EAAE,EAAE,yBAAyB;aAClF,C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E,mBAAmB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { render, waitFor } from \"@testing-library/react\";\nimport React, { useEffect } from \"react\";\nimport { useTamboRegistry } from \"../../providers/tambo-registry-provider\";\nimport { MCPClient, MCPTransport } from \"../mcp-client\";\nimport {\n extractErrorMessage,\n TamboMcpProvider,\n useTamboMcpServers,\n type McpServer,\n} from \"../tambo-mcp-provider\";\n\n// Mock the MCP client to avoid ES module issues\njest.mock(\"../mcp-client\", () => ({\n MCPClient: jest.fn(),\n MCPTransport: {\n SSE: \"sse\",\n HTTP: \"http\",\n },\n}));\n\n// Mock the registry provider to avoid dependency issues\njest.mock(\"../../providers/tambo-registry-provider\", () => ({\n useTamboRegistry: jest.fn(),\n}));\n\ndescribe(\"extractErrorMessage\", () => {\n describe(\"Array content handling\", () => {\n it(\"should extract text from array content with multiple text items\", () => {\n const content = [\n { type: \"text\", text: \"Error:\" },\n { type: \"text\", text: \"Tool execution failed\" },\n { type: \"image\", url: \"http://example.com/error.png\" }, // Should be filtered out\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error: Tool execution failed\");\n });\n\n it(\"should extract text from array content with single text item\", () => {\n const content = [{ type: \"text\", text: \"Simple error message\" }];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Simple error message\");\n });\n\n it(\"should return fallback message for array content with no text items\", () => {\n const content = [\n { type: \"image\", url: \"http://example.com/error.png\" },\n { type: \"resource\", uri: \"file://error.log\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error occurred but no details provided\");\n });\n\n it(\"should return fallback message for empty array content\", () => {\n const content: any[] = [];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Error occurred but no details provided\");\n });\n\n it(\"should handle array content with mixed types correctly\", () => {\n const content = [\n { type: \"resource\", uri: \"file://log.txt\" },\n { type: \"text\", text: \"First error\" },\n { type: \"image\", url: \"http://example.com/img.png\" },\n { type: \"text\", text: \"Second error\" },\n { type: \"unknown\", data: \"something\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"First error Second error\");\n });\n\n it(\"should handle array content with malformed items\", () => {\n const content = [\n null,\n { type: \"text\", text: \"Valid error\" },\n { type: \"text\" }, // Missing text property\n { type: \"text\", text: null }, // Invalid text type\n { type: \"text\", text: \"Another valid error\" },\n ];\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Valid error Another valid error\");\n });\n });\n\n describe(\"Non-array content handling\", () => {\n it(\"should return string content as-is\", () => {\n const content = \"Direct error message\";\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Direct error message\");\n });\n\n it(\"should handle null content\", () => {\n const content = null;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Unknown error occurred\");\n });\n\n it(\"should handle undefined content\", () => {\n const content = undefined;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"Unknown error occurred\");\n });\n\n it(\"should handle number content\", () => {\n const content = 42;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"42\");\n });\n\n it(\"should handle boolean content\", () => {\n const content = false;\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"false\");\n });\n\n it(\"should handle object content\", () => {\n const content = { error: \"Something went wrong\" };\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe('{\"error\":\"Something went wrong\"}');\n });\n\n it(\"should handle complex object content\", () => {\n const content = {\n error: \"Something went wrong\",\n code: 500,\n details: { message: \"Internal server error\" },\n };\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\n '{\"error\":\"Something went wrong\",\"code\":500,\"details\":{\"message\":\"Internal server error\"}}',\n );\n });\n\n it(\"should handle empty object content\", () => {\n const content = {};\n\n const result = extractErrorMessage(content);\n\n expect(result).toBe(\"{}\");\n });\n });\n});\n\ndescribe(\"TamboMcpProvider server list changes\", () => {\n beforeEach(() => {\n // Mock registry so tool registration is a no-op\n (useTamboRegistry as unknown as jest.Mock).mockReturnValue({\n registerTool: jest.fn(),\n });\n\n // Ensure MCPClient.create exists and returns a fake client with listTools\n (MCPClient as unknown as any).create = jest\n .fn()\n .mockResolvedValue({ listTools: jest.fn().mockResolvedValue([]) });\n });\n\n const Capture: React.FC<{ onUpdate: (servers: McpServer[]) => void }> = ({\n onUpdate,\n }) => {\n const servers = useTamboMcpServers();\n useEffect(() => {\n onUpdate(servers);\n }, [servers, onUpdate]);\n return <div data-testid=\"urls\">{servers.map((s) => s.url).join(\",\")}</div>;\n };\n\n it(\"adds a new server when the list grows\", async () => {\n let latest: McpServer[] = [];\n const { rerender, getByTestId } = render(\n <TamboMcpProvider mcpServers={[\"https://a.example\"]}>\n <Capture onUpdate={(s) => (latest = s)} />\n </TamboMcpProvider>,\n );\n\n // Wait for initial connection\n await waitFor(() => {\n expect(latest.length).toBe(1);\n });\n\n // Add new server\n rerender(\n <TamboMcpProvider mcpServers={[\"https://a.example\", \"https://b.example\"]}>\n <Capture onUpdate={(s) => (latest = s)} />\n </TamboMcpProvider>,\n );\n\n await waitFor(() => {\n expect(latest.length).toBe(2);\n const urls = getByTestId(\"urls\").textContent || \"\";\n expect(urls).toContain(\"https://a.example\");\n expect(urls).toContain(\"https://b.example\");\n });\n });\n\n it(\"removes a server when the list shrinks\", async () => {\n let latest: McpServer[] = [];\n const { rerender, getByTestId } = render(\n <TamboMcpProvider mcpServers={[\"https://a.example\", \"https://b.example\"]}>\n <Capture onUpdate={(s) => (latest = s)} />\n </TamboMcpProvider>,\n );\n\n await waitFor(() => {\n expect(latest.length).toBe(2);\n });\n\n // Remove one server\n rerender(\n <TamboMcpProvider mcpServers={[\"https://a.example\"]}>\n <Capture onUpdate={(s) => (latest = s)} />\n </TamboMcpProvider>,\n );\n\n await waitFor(() => {\n expect(latest.length).toBe(1);\n const urls = getByTestId(\"urls\").textContent || \"\";\n expect(urls).toContain(\"https://a.example\");\n expect(urls).not.toContain(\"https://b.example\");\n });\n });\n\n it(\"does not duplicate when a new copy of the same list is passed\", async () => {\n let latest: McpServer[] = [];\n const initial = [\n { url: \"https://a.example\", transport: MCPTransport.SSE },\n { url: \"https://b.example\", transport: MCPTransport.SSE },\n ];\n\n const { rerender } = render(\n <TamboMcpProvider mcpServers={initial}>\n <Capture onUpdate={(s) => (latest = s)} />\n </TamboMcpProvider>,\n );\n\n await waitFor(() => {\n expect(latest.length).toBe(2);\n });\n\n // Pass a new array instance with the same logical servers\n const same = [\n { url: \"https://a.example\", transport: MCPTransport.SSE },\n { url: \"https://b.example\", transport: MCPTransport.SSE },\n ];\n rerender(\n <TamboMcpProvider mcpServers={same}>\n <Capture onUpdate={(s) => (latest = s)} />\n </TamboMcpProvider>,\n );\n\n await waitFor(() => {\n expect(latest.length).toBe(2);\n const urls = latest.map((s) => s.url).sort();\n expect(urls).toEqual([\"https://a.example\", \"https://b.example\"].sort());\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mcp-servers.test.d.ts","sourceRoot":"","sources":["../../../src/mcp/__tests__/use-mcp-servers.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const react_1 = require("@testing-library/react");
|
|
37
|
+
const react_2 = __importStar(require("react"));
|
|
38
|
+
const tambo_registry_provider_1 = require("../../providers/tambo-registry-provider");
|
|
39
|
+
const tambo_mcp_provider_1 = require("../tambo-mcp-provider");
|
|
40
|
+
// Mock the registry to provide a no-op registerTool
|
|
41
|
+
// Do not mock the registry; use the real provider in render
|
|
42
|
+
// Mock the MCP client; use a mutable implementation to avoid TDZ issues
|
|
43
|
+
let createImpl = jest.fn();
|
|
44
|
+
jest.mock("../mcp-client", () => ({
|
|
45
|
+
MCPClient: { create: (...args) => createImpl(...args) },
|
|
46
|
+
MCPTransport: { SSE: "sse", HTTP: "http" },
|
|
47
|
+
}));
|
|
48
|
+
// Import after mocks note: jest.mock calls are hoisted, so standard imports are fine
|
|
49
|
+
describe("useTamboMcpServers + TamboMcpProvider", () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
createImpl = jest.fn();
|
|
52
|
+
});
|
|
53
|
+
it("provides normalized MCP server entries to inner components", async () => {
|
|
54
|
+
const fakeClient = { listTools: jest.fn().mockResolvedValue([]) };
|
|
55
|
+
createImpl.mockResolvedValue(fakeClient);
|
|
56
|
+
const Inner = () => {
|
|
57
|
+
const servers = (0, tambo_mcp_provider_1.useTamboMcpServers)();
|
|
58
|
+
return (react_2.default.createElement("div", null,
|
|
59
|
+
react_2.default.createElement("div", { "data-testid": "count" }, servers.length),
|
|
60
|
+
react_2.default.createElement("div", { "data-testid": "urls" }, servers.map((s) => s.url).join(","))));
|
|
61
|
+
};
|
|
62
|
+
const { getByTestId } = (0, react_1.render)(react_2.default.createElement(tambo_registry_provider_1.TamboRegistryProvider, null,
|
|
63
|
+
react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: [{ url: "https://one.example" }, "https://two.example"] },
|
|
64
|
+
react_2.default.createElement(Inner, null))));
|
|
65
|
+
await (0, react_1.waitFor)(() => {
|
|
66
|
+
expect(getByTestId("count").textContent).toBe("2");
|
|
67
|
+
const urls = getByTestId("urls").textContent || "";
|
|
68
|
+
expect(urls).toContain("https://one.example");
|
|
69
|
+
expect(urls).toContain("https://two.example");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it("marks a successfully connected server with a client instance", async () => {
|
|
73
|
+
const fakeClient = { listTools: jest.fn().mockResolvedValue([]) };
|
|
74
|
+
createImpl.mockResolvedValue(fakeClient);
|
|
75
|
+
let latest = [];
|
|
76
|
+
const Capture = () => {
|
|
77
|
+
const servers = (0, tambo_mcp_provider_1.useTamboMcpServers)();
|
|
78
|
+
(0, react_2.useEffect)(() => {
|
|
79
|
+
latest = servers;
|
|
80
|
+
}, [servers]);
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
(0, react_1.render)(react_2.default.createElement(tambo_registry_provider_1.TamboRegistryProvider, null,
|
|
84
|
+
react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: [{ url: "https://ok.example" }] },
|
|
85
|
+
react_2.default.createElement(Capture, null))));
|
|
86
|
+
await (0, react_1.waitFor)(() => {
|
|
87
|
+
expect(latest.length).toBe(1);
|
|
88
|
+
expect("client" in latest[0]).toBe(true);
|
|
89
|
+
expect(latest[0].client).toBe(fakeClient);
|
|
90
|
+
// no connectionError on connected server
|
|
91
|
+
expect(latest[0].connectionError).toBeUndefined();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
it("marks a failed server with a connectionError and no client", async () => {
|
|
95
|
+
const boom = new Error("boom");
|
|
96
|
+
createImpl.mockRejectedValue(boom);
|
|
97
|
+
let latest = [];
|
|
98
|
+
const Capture = () => {
|
|
99
|
+
const servers = (0, tambo_mcp_provider_1.useTamboMcpServers)();
|
|
100
|
+
(0, react_2.useEffect)(() => {
|
|
101
|
+
latest = servers;
|
|
102
|
+
}, [servers]);
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
(0, react_1.render)(react_2.default.createElement(tambo_registry_provider_1.TamboRegistryProvider, null,
|
|
106
|
+
react_2.default.createElement(tambo_mcp_provider_1.TamboMcpProvider, { mcpServers: [{ url: "https://fail.example" }] },
|
|
107
|
+
react_2.default.createElement(Capture, null))));
|
|
108
|
+
await (0, react_1.waitFor)(() => {
|
|
109
|
+
expect(latest.length).toBe(1);
|
|
110
|
+
expect("client" in latest[0]).toBe(false);
|
|
111
|
+
// @ts-expect-error narrowing at runtime
|
|
112
|
+
expect(latest[0].connectionError).toBeInstanceOf(Error);
|
|
113
|
+
// @ts-expect-error narrowing at runtime
|
|
114
|
+
expect(latest[0].connectionError?.message).toBe("boom");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=use-mcp-servers.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mcp-servers.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/use-mcp-servers.test.tsx"],"names":[],"mappings":";;;;;;;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AAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1C,wCAAwC;YACxC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YACxD,wCAAwC;YACxC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { render, waitFor } from \"@testing-library/react\";\nimport React, { useEffect } from \"react\";\nimport { TamboRegistryProvider } from \"../../providers/tambo-registry-provider\";\nimport {\n TamboMcpProvider,\n useTamboMcpServers,\n type McpServer,\n} from \"../tambo-mcp-provider\";\n\n// Mock the registry to provide a no-op registerTool\n// Do not mock the registry; use the real provider in render\n\n// Mock the MCP client; use a mutable implementation to avoid TDZ issues\nlet createImpl: jest.Mock<any, any> = jest.fn();\njest.mock(\"../mcp-client\", () => ({\n MCPClient: { create: (...args: any[]) => createImpl(...args) },\n MCPTransport: { SSE: \"sse\", HTTP: \"http\" },\n}));\n\n// Import after mocks note: jest.mock calls are hoisted, so standard imports are fine\n\ndescribe(\"useTamboMcpServers + TamboMcpProvider\", () => {\n beforeEach(() => {\n createImpl = jest.fn();\n });\n\n it(\"provides normalized MCP server entries to inner components\", async () => {\n const fakeClient = { listTools: jest.fn().mockResolvedValue([]) } as any;\n createImpl.mockResolvedValue(fakeClient);\n\n const Inner: React.FC = () => {\n const servers = useTamboMcpServers();\n return (\n <div>\n <div data-testid=\"count\">{servers.length}</div>\n <div data-testid=\"urls\">{servers.map((s) => s.url).join(\",\")}</div>\n </div>\n );\n };\n\n const { getByTestId } = render(\n <TamboRegistryProvider>\n <TamboMcpProvider\n mcpServers={[{ url: \"https://one.example\" }, \"https://two.example\"]}\n >\n <Inner />\n </TamboMcpProvider>\n </TamboRegistryProvider>,\n );\n\n await waitFor(() => {\n expect(getByTestId(\"count\").textContent).toBe(\"2\");\n const urls = getByTestId(\"urls\").textContent || \"\";\n expect(urls).toContain(\"https://one.example\");\n expect(urls).toContain(\"https://two.example\");\n });\n });\n\n it(\"marks a successfully connected server with a client instance\", async () => {\n const fakeClient = { listTools: jest.fn().mockResolvedValue([]) } as any;\n createImpl.mockResolvedValue(fakeClient);\n\n let latest: McpServer[] = [];\n const Capture: React.FC = () => {\n const servers = useTamboMcpServers();\n useEffect(() => {\n latest = servers;\n }, [servers]);\n return null;\n };\n\n render(\n <TamboRegistryProvider>\n <TamboMcpProvider mcpServers={[{ url: \"https://ok.example\" }]}>\n <Capture />\n </TamboMcpProvider>\n </TamboRegistryProvider>,\n );\n\n await waitFor(() => {\n expect(latest.length).toBe(1);\n expect(\"client\" in latest[0]).toBe(true);\n expect((latest[0] as any).client).toBe(fakeClient);\n // no connectionError on connected server\n expect((latest[0] as any).connectionError).toBeUndefined();\n });\n });\n\n it(\"marks a failed server with a connectionError and no client\", async () => {\n const boom = new Error(\"boom\");\n createImpl.mockRejectedValue(boom);\n\n let latest: McpServer[] = [];\n const Capture: React.FC = () => {\n const servers = useTamboMcpServers();\n useEffect(() => {\n latest = servers;\n }, [servers]);\n return null;\n };\n\n render(\n <TamboRegistryProvider>\n <TamboMcpProvider mcpServers={[{ url: \"https://fail.example\" }]}>\n <Capture />\n </TamboMcpProvider>\n </TamboRegistryProvider>,\n );\n\n await waitFor(() => {\n expect(latest.length).toBe(1);\n expect(\"client\" in latest[0]).toBe(false);\n // @ts-expect-error narrowing at runtime\n expect(latest[0].connectionError).toBeInstanceOf(Error);\n // @ts-expect-error narrowing at runtime\n expect(latest[0].connectionError?.message).toBe(\"boom\");\n });\n });\n});\n"]}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { MCPTransport } from "./mcp-client";
|
|
2
|
-
export { TamboMcpProvider, type McpServerInfo } from "./tambo-mcp-provider";
|
|
2
|
+
export { TamboMcpProvider, useTamboMcpServers, type ConnectedMcpServer, type FailedMcpServer, type McpServer, type McpServerInfo, } from "./tambo-mcp-provider";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/mcp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC"}
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TamboMcpProvider = exports.MCPTransport = void 0;
|
|
3
|
+
exports.useTamboMcpServers = exports.TamboMcpProvider = exports.MCPTransport = void 0;
|
|
4
4
|
var mcp_client_1 = require("./mcp-client");
|
|
5
5
|
Object.defineProperty(exports, "MCPTransport", { enumerable: true, get: function () { return mcp_client_1.MCPTransport; } });
|
|
6
6
|
var tambo_mcp_provider_1 = require("./tambo-mcp-provider");
|
|
7
7
|
Object.defineProperty(exports, "TamboMcpProvider", { enumerable: true, get: function () { return tambo_mcp_provider_1.TamboMcpProvider; } });
|
|
8
|
+
Object.defineProperty(exports, "useTamboMcpServers", { enumerable: true, get: function () { return tambo_mcp_provider_1.useTamboMcpServers; } });
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAAnC,0GAAA,YAAY,OAAA;AACrB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAAnC,0GAAA,YAAY,OAAA;AACrB,2DAO8B;AAN5B,sHAAA,gBAAgB,OAAA;AAChB,wHAAA,kBAAkB,OAAA","sourcesContent":["export { MCPTransport } from \"./mcp-client\";\nexport {\n TamboMcpProvider,\n useTamboMcpServers,\n type ConnectedMcpServer,\n type FailedMcpServer,\n type McpServer,\n type McpServerInfo,\n} from \"./tambo-mcp-provider\";\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC } from "react";
|
|
2
|
-
import { MCPTransport } from "./mcp-client";
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { MCPClient, MCPTransport } from "./mcp-client";
|
|
3
3
|
/**
|
|
4
4
|
* Extracts error message from MCP tool result content.
|
|
5
5
|
* Handles both array and string content formats.
|
|
@@ -14,6 +14,14 @@ export interface McpServerInfo {
|
|
|
14
14
|
transport?: MCPTransport;
|
|
15
15
|
customHeaders?: Record<string, string>;
|
|
16
16
|
}
|
|
17
|
+
export interface ConnectedMcpServer extends McpServerInfo {
|
|
18
|
+
client: MCPClient;
|
|
19
|
+
}
|
|
20
|
+
export interface FailedMcpServer extends McpServerInfo {
|
|
21
|
+
client?: never;
|
|
22
|
+
connectionError: Error;
|
|
23
|
+
}
|
|
24
|
+
export type McpServer = ConnectedMcpServer | FailedMcpServer;
|
|
17
25
|
/**
|
|
18
26
|
* This provider is used to register tools from MCP servers.
|
|
19
27
|
* @returns the wrapped children
|
|
@@ -22,4 +30,28 @@ export declare const TamboMcpProvider: FC<{
|
|
|
22
30
|
mcpServers: (McpServerInfo | string)[];
|
|
23
31
|
children: React.ReactNode;
|
|
24
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Hook to access the actual MCP servers, as they are connected (or fail to
|
|
35
|
+
* connect).
|
|
36
|
+
*
|
|
37
|
+
* You can call methods on the MCP client that is included in the MCP server
|
|
38
|
+
* object.
|
|
39
|
+
*
|
|
40
|
+
* If the server fails to connect, the `client` property will be `undefined` and
|
|
41
|
+
* the `connectionError` property will be set.
|
|
42
|
+
*
|
|
43
|
+
* For example, to forcibly disconnect and reconnect all MCP servers:
|
|
44
|
+
*
|
|
45
|
+
* ```tsx
|
|
46
|
+
* const mcpServers = useTamboMcpServers();
|
|
47
|
+
* mcpServers.forEach((mcpServer) => {
|
|
48
|
+
* mcpServer.client?.reconnect();
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* Note that the MCP servers are not guaranteed to be in the same order as the
|
|
53
|
+
* input array, because they are added as they are connected.
|
|
54
|
+
* @returns The MCP servers
|
|
55
|
+
*/
|
|
56
|
+
export declare const useTamboMcpServers: () => McpServer[];
|
|
25
57
|
//# sourceMappingURL=tambo-mcp-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tambo-mcp-provider.d.ts","sourceRoot":"","sources":["../../src/mcp/tambo-mcp-provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,EAAE,EAIH,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAsB5D;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACvD,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,eAAe,EAAE,KAAK,CAAC;CACxB;AAED,MAAM,MAAM,SAAS,GAAG,kBAAkB,GAAG,eAAe,CAAC;AAG7D;;;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,CAsIA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,kBAAkB,mBAE9B,CAAC"}
|
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TamboMcpProvider = void 0;
|
|
36
|
+
exports.useTamboMcpServers = exports.TamboMcpProvider = void 0;
|
|
4
37
|
exports.extractErrorMessage = extractErrorMessage;
|
|
5
|
-
const
|
|
38
|
+
const fast_equals_1 = require("fast-equals");
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
6
40
|
const tambo_registry_provider_1 = require("../providers/tambo-registry-provider");
|
|
7
41
|
const mcp_client_1 = require("./mcp-client");
|
|
8
42
|
/**
|
|
@@ -28,28 +62,65 @@ function extractErrorMessage(content) {
|
|
|
28
62
|
}
|
|
29
63
|
return `${content}`;
|
|
30
64
|
}
|
|
65
|
+
const McpProviderContext = (0, react_1.createContext)([]);
|
|
31
66
|
/**
|
|
32
67
|
* This provider is used to register tools from MCP servers.
|
|
33
68
|
* @returns the wrapped children
|
|
34
69
|
*/
|
|
35
70
|
const TamboMcpProvider = ({ mcpServers, children }) => {
|
|
36
71
|
const { registerTool } = (0, tambo_registry_provider_1.useTamboRegistry)();
|
|
72
|
+
const [connectedMcpServers, setConnectedMcpServers] = (0, react_1.useState)([]);
|
|
37
73
|
(0, react_1.useEffect)(() => {
|
|
38
74
|
if (!mcpServers) {
|
|
39
75
|
return;
|
|
40
76
|
}
|
|
41
|
-
async function registerMcpServers(
|
|
77
|
+
async function registerMcpServers(mcpServerInfos) {
|
|
42
78
|
// Maps tool names to the MCP client that registered them
|
|
43
79
|
const mcpServerMap = new Map();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
setConnectedMcpServers((prev) =>
|
|
81
|
+
// remove any servers that are not in the new list
|
|
82
|
+
prev.filter((s) => mcpServerInfos.some((mcpServerInfo) => equalsMcpServer(s, mcpServerInfo))));
|
|
83
|
+
// initialize the MCP clients, converting McpServerInfo -> McpServer
|
|
84
|
+
const mcpServers = await Promise.allSettled(mcpServerInfos.map(async (mcpServerInfo) => {
|
|
85
|
+
try {
|
|
86
|
+
const client = await mcp_client_1.MCPClient.create(mcpServerInfo.url, mcpServerInfo.transport, mcpServerInfo.customHeaders);
|
|
87
|
+
const connectedMcpServer = {
|
|
88
|
+
...mcpServerInfo,
|
|
89
|
+
client: client,
|
|
90
|
+
};
|
|
91
|
+
// note because the promises may resolve in any order, the resulting
|
|
92
|
+
// array may not be in the same order as the input array
|
|
93
|
+
setConnectedMcpServers((prev) => [
|
|
94
|
+
// replace the server if it already exists
|
|
95
|
+
...prev.filter((s) => !equalsMcpServer(s, mcpServerInfo)),
|
|
96
|
+
connectedMcpServer,
|
|
97
|
+
]);
|
|
98
|
+
return connectedMcpServer;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const failedMcpServer = {
|
|
102
|
+
...mcpServerInfo,
|
|
103
|
+
connectionError: error,
|
|
104
|
+
};
|
|
105
|
+
// note because the promises may resolve in any order, the resulting
|
|
106
|
+
// array may not be in the same order as the input array
|
|
107
|
+
setConnectedMcpServers((prev) => [
|
|
108
|
+
// replace the server if it already exists
|
|
109
|
+
...prev.filter((s) => !equalsMcpServer(s, mcpServerInfo)),
|
|
110
|
+
failedMcpServer,
|
|
111
|
+
]);
|
|
112
|
+
return failedMcpServer;
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
// note do not rely on the state
|
|
116
|
+
const connectedMcpServers = mcpServers
|
|
117
|
+
.filter((result) => result.status === "fulfilled")
|
|
118
|
+
.map((result) => result.value);
|
|
119
|
+
// Now create a map of tool name to MCP client
|
|
120
|
+
const serverToolLists = connectedMcpServers.map(async (mcpServer) => {
|
|
121
|
+
const tools = (await mcpServer.client?.listTools()) ?? [];
|
|
51
122
|
tools.forEach((tool) => {
|
|
52
|
-
mcpServerMap.set(tool.name,
|
|
123
|
+
mcpServerMap.set(tool.name, mcpServer);
|
|
53
124
|
});
|
|
54
125
|
return tools;
|
|
55
126
|
});
|
|
@@ -74,7 +145,11 @@ const TamboMcpProvider = ({ mcpServers, children }) => {
|
|
|
74
145
|
// should never happen
|
|
75
146
|
throw new Error(`MCP server for tool ${tool.name} not found`);
|
|
76
147
|
}
|
|
77
|
-
|
|
148
|
+
if (!mcpServer.client) {
|
|
149
|
+
// this can't actually happen because the tool can't be registered if the server is not connected
|
|
150
|
+
throw new Error(`MCP server for tool ${tool.name} is not connected`);
|
|
151
|
+
}
|
|
152
|
+
const result = await mcpServer.client.callTool(tool.name, args);
|
|
78
153
|
if (result.isError) {
|
|
79
154
|
const errorMessage = extractErrorMessage(result.content);
|
|
80
155
|
throw new Error(errorMessage);
|
|
@@ -85,9 +160,45 @@ const TamboMcpProvider = ({ mcpServers, children }) => {
|
|
|
85
160
|
});
|
|
86
161
|
});
|
|
87
162
|
}
|
|
88
|
-
|
|
163
|
+
// normalize the server infos
|
|
164
|
+
const mcpServerInfos = mcpServers.map((mcpServer) => typeof mcpServer === "string"
|
|
165
|
+
? { url: mcpServer, transport: mcp_client_1.MCPTransport.SSE }
|
|
166
|
+
: mcpServer);
|
|
167
|
+
registerMcpServers(mcpServerInfos);
|
|
89
168
|
}, [mcpServers, registerTool]);
|
|
90
|
-
return children;
|
|
169
|
+
return (react_1.default.createElement(McpProviderContext.Provider, { value: connectedMcpServers }, children));
|
|
91
170
|
};
|
|
92
171
|
exports.TamboMcpProvider = TamboMcpProvider;
|
|
172
|
+
/**
|
|
173
|
+
* Hook to access the actual MCP servers, as they are connected (or fail to
|
|
174
|
+
* connect).
|
|
175
|
+
*
|
|
176
|
+
* You can call methods on the MCP client that is included in the MCP server
|
|
177
|
+
* object.
|
|
178
|
+
*
|
|
179
|
+
* If the server fails to connect, the `client` property will be `undefined` and
|
|
180
|
+
* the `connectionError` property will be set.
|
|
181
|
+
*
|
|
182
|
+
* For example, to forcibly disconnect and reconnect all MCP servers:
|
|
183
|
+
*
|
|
184
|
+
* ```tsx
|
|
185
|
+
* const mcpServers = useTamboMcpServers();
|
|
186
|
+
* mcpServers.forEach((mcpServer) => {
|
|
187
|
+
* mcpServer.client?.reconnect();
|
|
188
|
+
* });
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* Note that the MCP servers are not guaranteed to be in the same order as the
|
|
192
|
+
* input array, because they are added as they are connected.
|
|
193
|
+
* @returns The MCP servers
|
|
194
|
+
*/
|
|
195
|
+
const useTamboMcpServers = () => {
|
|
196
|
+
return (0, react_1.useContext)(McpProviderContext);
|
|
197
|
+
};
|
|
198
|
+
exports.useTamboMcpServers = useTamboMcpServers;
|
|
199
|
+
function equalsMcpServer(s, mcpServerInfo) {
|
|
200
|
+
return (s.url === mcpServerInfo.url &&
|
|
201
|
+
s.transport === mcpServerInfo.transport &&
|
|
202
|
+
(0, fast_equals_1.deepEqual)(s.customHeaders, mcpServerInfo.customHeaders));
|
|
203
|
+
}
|
|
93
204
|
//# sourceMappingURL=tambo-mcp-provider.js.map
|