@tambo-ai/react 0.49.0 → 0.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/hooks/__tests__/use-component-state.test.js +4 -1
  2. package/dist/hooks/__tests__/use-component-state.test.js.map +1 -1
  3. package/dist/hooks/__tests__/use-message-images.test.d.ts +2 -0
  4. package/dist/hooks/__tests__/use-message-images.test.d.ts.map +1 -0
  5. package/dist/hooks/__tests__/use-message-images.test.js +66 -0
  6. package/dist/hooks/__tests__/use-message-images.test.js.map +1 -0
  7. package/dist/hooks/__tests__/use-tambo-threads.test.js +1 -1
  8. package/dist/hooks/__tests__/use-tambo-threads.test.js.map +1 -1
  9. package/dist/hooks/use-component-state.js +3 -3
  10. package/dist/hooks/use-component-state.js.map +1 -1
  11. package/dist/hooks/use-message-images.d.ts +25 -0
  12. package/dist/hooks/use-message-images.d.ts.map +1 -0
  13. package/dist/hooks/use-message-images.js +66 -0
  14. package/dist/hooks/use-message-images.js.map +1 -0
  15. package/dist/hooks/use-suggestions.js +4 -2
  16. package/dist/hooks/use-suggestions.js.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/mcp/__tests__/mcp-client.test.d.ts +2 -0
  22. package/dist/mcp/__tests__/mcp-client.test.d.ts.map +1 -0
  23. package/dist/mcp/__tests__/mcp-client.test.js +502 -0
  24. package/dist/mcp/__tests__/mcp-client.test.js.map +1 -0
  25. package/dist/mcp/mcp-client.d.ts +77 -3
  26. package/dist/mcp/mcp-client.d.ts.map +1 -1
  27. package/dist/mcp/mcp-client.js +184 -19
  28. package/dist/mcp/mcp-client.js.map +1 -1
  29. package/dist/mcp/tambo-mcp-provider.d.ts +1 -0
  30. package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
  31. package/dist/mcp/tambo-mcp-provider.js +1 -0
  32. package/dist/mcp/tambo-mcp-provider.js.map +1 -1
  33. package/dist/model/tambo-interactable.d.ts +1 -1
  34. package/dist/model/tambo-interactable.d.ts.map +1 -1
  35. package/dist/model/tambo-interactable.js.map +1 -1
  36. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts +2 -0
  37. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts.map +1 -0
  38. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +677 -0
  39. package/dist/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -0
  40. package/dist/providers/__tests__/tambo-stubs.test.js +6 -2
  41. package/dist/providers/__tests__/tambo-stubs.test.js.map +1 -1
  42. package/dist/providers/__tests__/tambo-thread-provider.test.js +14 -14
  43. package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  44. package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
  45. package/dist/providers/tambo-interactable-provider.js +26 -24
  46. package/dist/providers/tambo-interactable-provider.js.map +1 -1
  47. package/dist/providers/tambo-provider.d.ts +1 -0
  48. package/dist/providers/tambo-provider.d.ts.map +1 -1
  49. package/dist/providers/tambo-provider.js +1 -0
  50. package/dist/providers/tambo-provider.js.map +1 -1
  51. package/dist/providers/tambo-thread-input-provider.d.ts +11 -0
  52. package/dist/providers/tambo-thread-input-provider.d.ts.map +1 -1
  53. package/dist/providers/tambo-thread-input-provider.js +63 -12
  54. package/dist/providers/tambo-thread-input-provider.js.map +1 -1
  55. package/dist/providers/tambo-thread-provider.d.ts +1 -0
  56. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  57. package/dist/providers/tambo-thread-provider.js +9 -5
  58. package/dist/providers/tambo-thread-provider.js.map +1 -1
  59. package/dist/setupTests.d.ts +0 -1
  60. package/dist/setupTests.d.ts.map +1 -1
  61. package/dist/setupTests.js +0 -1
  62. package/dist/setupTests.js.map +1 -1
  63. package/dist/util/__tests__/message-builder.test.d.ts +2 -0
  64. package/dist/util/__tests__/message-builder.test.d.ts.map +1 -0
  65. package/dist/util/__tests__/message-builder.test.js +191 -0
  66. package/dist/util/__tests__/message-builder.test.js.map +1 -0
  67. package/dist/util/message-builder.d.ts +10 -0
  68. package/dist/util/message-builder.d.ts.map +1 -0
  69. package/dist/util/message-builder.js +31 -0
  70. package/dist/util/message-builder.js.map +1 -0
  71. package/esm/hooks/__tests__/use-component-state.test.js +4 -1
  72. package/esm/hooks/__tests__/use-component-state.test.js.map +1 -1
  73. package/esm/hooks/__tests__/use-message-images.test.d.ts +2 -0
  74. package/esm/hooks/__tests__/use-message-images.test.d.ts.map +1 -0
  75. package/esm/hooks/__tests__/use-message-images.test.js +64 -0
  76. package/esm/hooks/__tests__/use-message-images.test.js.map +1 -0
  77. package/esm/hooks/__tests__/use-tambo-threads.test.js +1 -1
  78. package/esm/hooks/__tests__/use-tambo-threads.test.js.map +1 -1
  79. package/esm/hooks/use-component-state.js +3 -3
  80. package/esm/hooks/use-component-state.js.map +1 -1
  81. package/esm/hooks/use-message-images.d.ts +25 -0
  82. package/esm/hooks/use-message-images.d.ts.map +1 -0
  83. package/esm/hooks/use-message-images.js +63 -0
  84. package/esm/hooks/use-message-images.js.map +1 -0
  85. package/esm/hooks/use-suggestions.js +4 -2
  86. package/esm/hooks/use-suggestions.js.map +1 -1
  87. package/esm/index.d.ts +1 -0
  88. package/esm/index.d.ts.map +1 -1
  89. package/esm/index.js +1 -0
  90. package/esm/index.js.map +1 -1
  91. package/esm/mcp/__tests__/mcp-client.test.d.ts +2 -0
  92. package/esm/mcp/__tests__/mcp-client.test.d.ts.map +1 -0
  93. package/esm/mcp/__tests__/mcp-client.test.js +500 -0
  94. package/esm/mcp/__tests__/mcp-client.test.js.map +1 -0
  95. package/esm/mcp/mcp-client.d.ts +77 -3
  96. package/esm/mcp/mcp-client.d.ts.map +1 -1
  97. package/esm/mcp/mcp-client.js +184 -19
  98. package/esm/mcp/mcp-client.js.map +1 -1
  99. package/esm/mcp/tambo-mcp-provider.d.ts +1 -0
  100. package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
  101. package/esm/mcp/tambo-mcp-provider.js +1 -0
  102. package/esm/mcp/tambo-mcp-provider.js.map +1 -1
  103. package/esm/model/tambo-interactable.d.ts +1 -1
  104. package/esm/model/tambo-interactable.d.ts.map +1 -1
  105. package/esm/model/tambo-interactable.js.map +1 -1
  106. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts +2 -0
  107. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.d.ts.map +1 -0
  108. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js +672 -0
  109. package/esm/providers/__tests__/tambo-interactable-provider-partial-updates.test.js.map +1 -0
  110. package/esm/providers/__tests__/tambo-stubs.test.js +6 -2
  111. package/esm/providers/__tests__/tambo-stubs.test.js.map +1 -1
  112. package/esm/providers/__tests__/tambo-thread-provider.test.js +14 -14
  113. package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
  114. package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
  115. package/esm/providers/tambo-interactable-provider.js +26 -24
  116. package/esm/providers/tambo-interactable-provider.js.map +1 -1
  117. package/esm/providers/tambo-provider.d.ts +1 -0
  118. package/esm/providers/tambo-provider.d.ts.map +1 -1
  119. package/esm/providers/tambo-provider.js +1 -0
  120. package/esm/providers/tambo-provider.js.map +1 -1
  121. package/esm/providers/tambo-thread-input-provider.d.ts +11 -0
  122. package/esm/providers/tambo-thread-input-provider.d.ts.map +1 -1
  123. package/esm/providers/tambo-thread-input-provider.js +63 -12
  124. package/esm/providers/tambo-thread-input-provider.js.map +1 -1
  125. package/esm/providers/tambo-thread-provider.d.ts +1 -0
  126. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  127. package/esm/providers/tambo-thread-provider.js +9 -5
  128. package/esm/providers/tambo-thread-provider.js.map +1 -1
  129. package/esm/setupTests.d.ts +0 -1
  130. package/esm/setupTests.d.ts.map +1 -1
  131. package/esm/setupTests.js +0 -1
  132. package/esm/setupTests.js.map +1 -1
  133. package/esm/util/__tests__/message-builder.test.d.ts +2 -0
  134. package/esm/util/__tests__/message-builder.test.d.ts.map +1 -0
  135. package/esm/util/__tests__/message-builder.test.js +189 -0
  136. package/esm/util/__tests__/message-builder.test.js.map +1 -0
  137. package/esm/util/message-builder.d.ts +10 -0
  138. package/esm/util/message-builder.d.ts.map +1 -0
  139. package/esm/util/message-builder.js +28 -0
  140. package/esm/util/message-builder.js.map +1 -0
  141. package/package.json +7 -7
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,wKAAwK;;;;;;;;;;;;;;;;;AAExK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAGqC;AAFnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AAExB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,2EAIyC;AAHvC,+HAAA,oBAAoB,OAAA;AAKtB,gCAAgC;AAChC,yCAuBqB;AAtBnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,wHAAA,2BAA2B,OAAA;AAC3B,oHAAA,uBAAuB,OAAA;AACvB,0GAAA,aAAa,OAAA;AACb,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AACvB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,mHAAA,sBAAsB,OAAA;AACtB,oHAAA,uBAAuB,OAAA;AACvB,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,gHAAA,mBAAmB,OAAA;AAqBrB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA;AASjB,mFAIiD;AAH/C,2HAAA,qBAAqB,OAAoB;AAI3C,uFAGiD;AAF/C,mIAAA,oBAAoB,OAAA;AACpB,8IAAA,+BAA+B,OAAA;AAGjC,0BAA0B;AAC1B,qDAG2B;AAFzB,2HAAA,wBAAwB,OAAA;AACxB,2HAAA,wBAAwB,OAAA","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n} from \"./hooks/use-current-message\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboStubProvider,\n TamboThreadInputProvider,\n TamboThreadProvider,\n useIsTamboTokenUpdating,\n useTambo,\n useTamboClient,\n useTamboContextHelpers,\n useTamboGenerationStage,\n useTamboStream,\n useTamboThread,\n useTamboThreadInput,\n type TamboComponent,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n type TamboThreadInputContextProps,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport {\n useTamboInteractable,\n useCurrentInteractablesSnapshot,\n} from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"./context-helpers\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,wKAAwK;;;;;;;;;;;;;;;;;AAExK,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,mEAGqC;AAFnC,2HAAA,oBAAoB,OAAA;AACpB,6HAAA,sBAAsB,OAAA;AAExB,iEAAgF;AAAvE,sHAAA,gBAAgB,OAAA;AACzB,mEAAqE;AAA5D,6HAAA,sBAAsB,OAAA;AAC/B,0DAAwC;AACxC,2EAIyC;AAHvC,+HAAA,oBAAoB,OAAA;AAKtB,gCAAgC;AAChC,yCAuBqB;AAtBnB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,wHAAA,2BAA2B,OAAA;AAC3B,oHAAA,uBAAuB,OAAA;AACvB,0GAAA,aAAa,OAAA;AACb,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AACvB,qGAAA,QAAQ,OAAA;AACR,2GAAA,cAAc,OAAA;AACd,mHAAA,sBAAsB,OAAA;AACtB,oHAAA,uBAAuB,OAAA;AACvB,2GAAA,cAAc,OAAA;AACd,2GAAA,cAAc,OAAA;AACd,gHAAA,mBAAmB,OAAA;AAqBrB,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAQ3B,mFAG6C;AAF3C,8HAAA,eAAe,OAAA;AASjB,mFAIiD;AAH/C,2HAAA,qBAAqB,OAAoB;AAI3C,uFAGiD;AAF/C,mIAAA,oBAAoB,OAAA;AACpB,8IAAA,+BAA+B,OAAA;AAGjC,0BAA0B;AAC1B,qDAG2B;AAFzB,2HAAA,wBAAwB,OAAA;AACxB,2HAAA,wBAAwB,OAAA","sourcesContent":["/** Exports for the library. Only publically available exports are re-exported here. Anything not exported here is not supported and may change or break at any time. */\n\nexport { useTamboComponentState } from \"./hooks/use-component-state\";\nexport {\n TamboMessageProvider,\n useTamboCurrentMessage,\n} from \"./hooks/use-current-message\";\nexport { useMessageImages, type StagedImage } from \"./hooks/use-message-images\";\nexport { useTamboStreamingProps } from \"./hooks/use-streaming-props\";\nexport * from \"./hooks/use-suggestions\";\nexport {\n useTamboStreamStatus,\n type PropStatus,\n type StreamStatus,\n} from \"./hooks/use-tambo-stream-status\";\n\n// Re-export provider components\nexport {\n TamboClientProvider,\n TamboComponentProvider,\n TamboContextHelpersProvider,\n TamboPropStreamProvider,\n TamboProvider,\n TamboStubProvider,\n TamboThreadInputProvider,\n TamboThreadProvider,\n useIsTamboTokenUpdating,\n useTambo,\n useTamboClient,\n useTamboContextHelpers,\n useTamboGenerationStage,\n useTamboStream,\n useTamboThread,\n useTamboThreadInput,\n type TamboComponent,\n type TamboContextHelpersContextProps,\n type TamboContextHelpersProviderProps,\n type TamboRegistryContext,\n type TamboStubProviderProps,\n type TamboThreadInputContextProps,\n} from \"./providers\";\n\n// Re-export types from Tambo Node SDK\nexport type {\n APIError,\n RateLimitError,\n TamboAIError,\n} from \"@tambo-ai/typescript-sdk\";\nexport type {\n Suggestion,\n SuggestionGenerateParams,\n SuggestionGenerateResponse,\n SuggestionListResponse,\n} from \"@tambo-ai/typescript-sdk/resources/beta/threads/suggestions\";\nexport { useTamboThreadList } from \"./hooks/use-tambo-threads\";\nexport {\n type ComponentContextToolMetadata,\n type ComponentRegistry,\n type ParameterSpec,\n type RegisteredComponent,\n type TamboTool,\n} from \"./model/component-metadata\";\nexport {\n GenerationStage,\n type TamboThreadMessage,\n} from \"./model/generate-component-response\";\nexport { type TamboThread } from \"./model/tambo-thread\";\n\nexport type {\n TamboInteractableComponent as InteractableComponent,\n TamboInteractableContext,\n} from \"./model/tambo-interactable\";\nexport {\n withTamboInteractable as withInteractable,\n type InteractableConfig,\n type WithTamboInteractableProps,\n} from \"./providers/hoc/with-tambo-interactable\";\nexport {\n useTamboInteractable,\n useCurrentInteractablesSnapshot,\n} from \"./providers/tambo-interactable-provider\";\n\n// Context helpers exports\nexport {\n currentPageContextHelper,\n currentTimeContextHelper,\n} from \"./context-helpers\";\nexport type {\n AdditionalContext,\n ContextHelperFn,\n ContextHelpers,\n} from \"./context-helpers\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mcp-client.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.test.d.ts","sourceRoot":"","sources":["../../../src/mcp/__tests__/mcp-client.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,502 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mcp_client_1 = require("../mcp-client");
4
+ // Mock the MCP SDK modules
5
+ jest.mock("@modelcontextprotocol/sdk/client/index.js", () => ({
6
+ Client: jest.fn().mockImplementation(() => ({
7
+ connect: jest.fn(),
8
+ close: jest.fn(),
9
+ listTools: jest.fn(),
10
+ callTool: jest.fn(),
11
+ onclose: null,
12
+ })),
13
+ }));
14
+ jest.mock("@modelcontextprotocol/sdk/client/sse.js", () => ({
15
+ SSEClientTransport: jest.fn().mockImplementation(() => ({
16
+ // SSE transport doesn't have sessionId
17
+ })),
18
+ }));
19
+ jest.mock("@modelcontextprotocol/sdk/client/streamableHttp.js", () => ({
20
+ StreamableHTTPClientTransport: jest
21
+ .fn()
22
+ .mockImplementation((url, options) => ({
23
+ sessionId: options?.sessionId,
24
+ })),
25
+ }));
26
+ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
27
+ const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
28
+ const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
29
+ // Type the mocked modules
30
+ const MockedClient = index_js_1.Client;
31
+ const MockedSSEClientTransport = sse_js_1.SSEClientTransport;
32
+ const MockedStreamableHTTPClientTransport = streamableHttp_js_1.StreamableHTTPClientTransport;
33
+ describe("MCPClient", () => {
34
+ let mockClientInstance;
35
+ let mockTransportInstance;
36
+ beforeEach(() => {
37
+ jest.clearAllMocks();
38
+ // Create mock instances
39
+ mockClientInstance = {
40
+ connect: jest.fn().mockResolvedValue(undefined),
41
+ close: jest.fn().mockResolvedValue(undefined),
42
+ listTools: jest.fn(),
43
+ callTool: jest.fn(),
44
+ onclose: null,
45
+ };
46
+ mockTransportInstance = {
47
+ sessionId: "test-session-id",
48
+ };
49
+ // Setup mocks
50
+ MockedClient.mockImplementation(() => mockClientInstance);
51
+ MockedStreamableHTTPClientTransport.mockImplementation(() => mockTransportInstance);
52
+ MockedSSEClientTransport.mockImplementation(() => ({}));
53
+ });
54
+ describe("create", () => {
55
+ it("should create and connect an MCPClient with HTTP transport by default", async () => {
56
+ const endpoint = "https://api.example.com/mcp";
57
+ const headers = { Authorization: "Bearer token" };
58
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP, headers);
59
+ expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(new URL(endpoint), { sessionId: undefined, requestInit: { headers } });
60
+ expect(MockedClient).toHaveBeenCalledWith({
61
+ name: "tambo-mcp-client",
62
+ version: "1.0.0",
63
+ });
64
+ expect(mockClientInstance.connect).toHaveBeenCalledWith(mockTransportInstance);
65
+ expect(client).toBeInstanceOf(mcp_client_1.MCPClient);
66
+ });
67
+ it("should create and connect an MCPClient with SSE transport", async () => {
68
+ const endpoint = "https://api.example.com/mcp";
69
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.SSE);
70
+ expect(MockedSSEClientTransport).toHaveBeenCalledWith(new URL(endpoint), {
71
+ requestInit: { headers: {} },
72
+ });
73
+ expect(mockClientInstance.connect).toHaveBeenCalledWith({});
74
+ expect(client).toBeInstanceOf(mcp_client_1.MCPClient);
75
+ });
76
+ it("should create client with default headers when none provided", async () => {
77
+ const endpoint = "https://api.example.com/mcp";
78
+ await mcp_client_1.MCPClient.create(endpoint);
79
+ expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(new URL(endpoint), { sessionId: undefined, requestInit: { headers: {} } });
80
+ });
81
+ });
82
+ describe("reconnect", () => {
83
+ it("should create new transport and client instances and call connect when reconnect() is called (default behavior)", async () => {
84
+ const endpoint = "https://api.example.com/mcp";
85
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
86
+ // Clear previous calls to focus on reconnect behavior
87
+ jest.clearAllMocks();
88
+ // Create new mock instances to verify new instances are created
89
+ const newMockClientInstance = {
90
+ connect: jest.fn().mockResolvedValue(undefined),
91
+ close: jest.fn().mockResolvedValue(undefined),
92
+ listTools: jest.fn(),
93
+ callTool: jest.fn(),
94
+ onclose: null,
95
+ };
96
+ const newMockTransportInstance = {
97
+ sessionId: "new-session-id",
98
+ };
99
+ // Mock the constructors to return new instances
100
+ MockedClient.mockImplementation(() => newMockClientInstance);
101
+ MockedStreamableHTTPClientTransport.mockImplementation(() => newMockTransportInstance);
102
+ await client.reconnect(); // Uses default parameters
103
+ // Verify old client was closed
104
+ expect(mockClientInstance.close).toHaveBeenCalled();
105
+ // Verify new transport was created with preserved session ID (default behavior)
106
+ expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(new URL(endpoint), { sessionId: "test-session-id", requestInit: { headers: {} } });
107
+ // Verify new client was created
108
+ expect(MockedClient).toHaveBeenCalledWith({
109
+ name: "tambo-mcp-client",
110
+ version: "1.0.0",
111
+ });
112
+ // Verify new client's connect was called with new transport
113
+ expect(newMockClientInstance.connect).toHaveBeenCalledWith(newMockTransportInstance);
114
+ });
115
+ it("should reconnect without session ID for SSE transport", async () => {
116
+ const endpoint = "https://api.example.com/mcp";
117
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.SSE);
118
+ // Clear previous calls
119
+ jest.clearAllMocks();
120
+ await client.reconnect();
121
+ expect(mockClientInstance.close).toHaveBeenCalled();
122
+ expect(MockedSSEClientTransport).toHaveBeenCalledWith(new URL(endpoint), {
123
+ requestInit: { headers: {} },
124
+ });
125
+ expect(mockClientInstance.connect).toHaveBeenCalledWith({});
126
+ });
127
+ it("should handle close errors when reportErrorOnClose is true", async () => {
128
+ const endpoint = "https://api.example.com/mcp";
129
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
130
+ const consoleSpy = jest.spyOn(console, "error").mockImplementation();
131
+ // Make close throw an error
132
+ mockClientInstance.close.mockRejectedValue(new Error("Close failed"));
133
+ await client.reconnect(false, true);
134
+ expect(consoleSpy).toHaveBeenCalledWith("Error closing Tambo MCP Client:", expect.any(Error));
135
+ consoleSpy.mockRestore();
136
+ });
137
+ it("should not log close errors when reportErrorOnClose is false", async () => {
138
+ const endpoint = "https://api.example.com/mcp";
139
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
140
+ const consoleSpy = jest.spyOn(console, "error").mockImplementation();
141
+ // Make close throw an error
142
+ mockClientInstance.close.mockRejectedValue(new Error("Close failed"));
143
+ await client.reconnect(false, false);
144
+ expect(consoleSpy).not.toHaveBeenCalled();
145
+ consoleSpy.mockRestore();
146
+ });
147
+ it("should create new session when newSession is true", async () => {
148
+ const endpoint = "https://api.example.com/mcp";
149
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
150
+ // Clear previous calls to focus on reconnect behavior
151
+ jest.clearAllMocks();
152
+ // Create new mock instances to verify new instances are created
153
+ const newMockClientInstance = {
154
+ connect: jest.fn().mockResolvedValue(undefined),
155
+ close: jest.fn().mockResolvedValue(undefined),
156
+ listTools: jest.fn(),
157
+ callTool: jest.fn(),
158
+ onclose: null,
159
+ };
160
+ const newMockTransportInstance = {
161
+ sessionId: "new-session-id",
162
+ };
163
+ // Mock the constructors to return new instances
164
+ MockedClient.mockImplementation(() => newMockClientInstance);
165
+ MockedStreamableHTTPClientTransport.mockImplementation(() => newMockTransportInstance);
166
+ await client.reconnect(true, true); // newSession = true, reportErrorOnClose = true
167
+ // Verify old client was closed
168
+ expect(mockClientInstance.close).toHaveBeenCalled();
169
+ // Verify new transport was created with undefined session ID (new session)
170
+ expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(new URL(endpoint), { sessionId: undefined, requestInit: { headers: {} } });
171
+ // Verify new client was created
172
+ expect(MockedClient).toHaveBeenCalledWith({
173
+ name: "tambo-mcp-client",
174
+ version: "1.0.0",
175
+ });
176
+ // Verify new client's connect was called with new transport
177
+ expect(newMockClientInstance.connect).toHaveBeenCalledWith(newMockTransportInstance);
178
+ });
179
+ it("should reuse existing session when newSession is false (default)", async () => {
180
+ const endpoint = "https://api.example.com/mcp";
181
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
182
+ // Clear previous calls to focus on reconnect behavior
183
+ jest.clearAllMocks();
184
+ // Create new mock instances to verify new instances are created
185
+ const newMockClientInstance = {
186
+ connect: jest.fn().mockResolvedValue(undefined),
187
+ close: jest.fn().mockResolvedValue(undefined),
188
+ listTools: jest.fn(),
189
+ callTool: jest.fn(),
190
+ onclose: null,
191
+ };
192
+ const newMockTransportInstance = {
193
+ sessionId: "reused-session-id",
194
+ };
195
+ // Mock the constructors to return new instances
196
+ MockedClient.mockImplementation(() => newMockClientInstance);
197
+ MockedStreamableHTTPClientTransport.mockImplementation(() => newMockTransportInstance);
198
+ await client.reconnect(false, true); // newSession = false, reportErrorOnClose = true
199
+ // Verify old client was closed
200
+ expect(mockClientInstance.close).toHaveBeenCalled();
201
+ // Verify new transport was created with preserved session ID
202
+ expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(new URL(endpoint), { sessionId: "test-session-id", requestInit: { headers: {} } });
203
+ // Verify new client was created
204
+ expect(MockedClient).toHaveBeenCalledWith({
205
+ name: "tambo-mcp-client",
206
+ version: "1.0.0",
207
+ });
208
+ // Verify new client's connect was called with new transport
209
+ expect(newMockClientInstance.connect).toHaveBeenCalledWith(newMockTransportInstance);
210
+ });
211
+ });
212
+ describe("onclose", () => {
213
+ it("should reconnect MCPClient when client is closed by external means (no backoff on manual preemption)", async () => {
214
+ const endpoint = "https://api.example.com/mcp";
215
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
216
+ jest.useFakeTimers();
217
+ const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
218
+ // Create new mock instances to verify reconnection creates new instances
219
+ const newMockClientInstance = {
220
+ connect: jest.fn().mockResolvedValue(undefined),
221
+ close: jest.fn().mockResolvedValue(undefined),
222
+ listTools: jest.fn(),
223
+ callTool: jest.fn(),
224
+ onclose: null,
225
+ };
226
+ const newMockTransportInstance = {
227
+ sessionId: "reconnected-session-id",
228
+ };
229
+ // Mock the constructors to return new instances for reconnection
230
+ MockedClient.mockImplementation(() => newMockClientInstance);
231
+ MockedStreamableHTTPClientTransport.mockImplementation(() => newMockTransportInstance);
232
+ // Reset counts after initial creation
233
+ jest.clearAllMocks();
234
+ // Trigger automatic onclose (schedules a delayed reconnect)
235
+ client.onclose();
236
+ // Manual reconnect should preempt the scheduled automatic attempt
237
+ const reconnectPromise = client.reconnect();
238
+ // No timers should be pending after manual preemption
239
+ await reconnectPromise;
240
+ // Verify warning message is logged
241
+ expect(consoleSpy).toHaveBeenCalled();
242
+ // Verify old client was closed
243
+ expect(mockClientInstance.close).toHaveBeenCalled();
244
+ // Verify new transport was created with preserved session ID
245
+ expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(new URL(endpoint), { sessionId: "test-session-id", requestInit: { headers: {} } });
246
+ // Verify new client was created
247
+ expect(MockedClient).toHaveBeenCalledWith({
248
+ name: "tambo-mcp-client",
249
+ version: "1.0.0",
250
+ });
251
+ // Verify new client's connect was called with new transport
252
+ expect(newMockClientInstance.connect).toHaveBeenCalledWith(newMockTransportInstance);
253
+ // Ensure only a single reconnect attempt occurred
254
+ expect(MockedClient).toHaveBeenCalledTimes(1);
255
+ expect(newMockClientInstance.connect).toHaveBeenCalledTimes(1);
256
+ consoleSpy.mockRestore();
257
+ jest.useRealTimers();
258
+ });
259
+ });
260
+ describe("reconnect re-entrancy and single-flight", () => {
261
+ it("prevents re-entrant onclose during deliberate close and coalesces concurrent calls", async () => {
262
+ const endpoint = "https://api.example.com/mcp";
263
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
264
+ // Simulate an implementation where closing the client would call its own onclose handler
265
+ const closeImpl = jest.fn(async () => {
266
+ if (typeof mockClientInstance.onclose === "function") {
267
+ // would cause recursion if not detached
268
+ mockClientInstance.onclose();
269
+ }
270
+ return;
271
+ });
272
+ mockClientInstance.close = closeImpl;
273
+ // Prepare new instances for the reconnect
274
+ const newMockClientInstance = {
275
+ connect: jest.fn().mockResolvedValue(undefined),
276
+ close: jest.fn().mockResolvedValue(undefined),
277
+ listTools: jest.fn(),
278
+ callTool: jest.fn(),
279
+ onclose: null,
280
+ };
281
+ MockedClient.mockImplementation(() => newMockClientInstance);
282
+ // Reset counts after initial creation
283
+ jest.clearAllMocks();
284
+ // Trigger auto onclose and manual reconnect nearly simultaneously
285
+ client.onclose();
286
+ await client.reconnect();
287
+ // Should have detached onclose before calling close, avoiding recursion
288
+ expect(closeImpl).toHaveBeenCalledTimes(1);
289
+ expect(mockClientInstance.onclose).toBeUndefined();
290
+ // Single-flight: only one new client/connect
291
+ expect(MockedClient).toHaveBeenCalledTimes(1);
292
+ expect(newMockClientInstance.connect).toHaveBeenCalledTimes(1);
293
+ });
294
+ });
295
+ describe("backoff + jitter (automatic reconnect)", () => {
296
+ it("applies jitter and resets to initial delay after a successful reconnect (manual preempt)", async () => {
297
+ jest.useFakeTimers();
298
+ const base = mcp_client_1.MCPClient.BACKOFF_INITIAL_MS;
299
+ const ratio = mcp_client_1.MCPClient.BACKOFF_JITTER_RATIO;
300
+ const min = Math.round(base * (1 - ratio));
301
+ const max = Math.round(base * (1 + ratio));
302
+ const setTimeoutSpy = jest.spyOn(global, "setTimeout");
303
+ const randSpy = jest.spyOn(Math, "random").mockReturnValue(0.0); // extreme low jitter
304
+ const endpoint = "https://api.example.com/mcp";
305
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
306
+ // Prepare one attempt that will succeed to avoid rescheduling
307
+ MockedClient.mockImplementation(() => ({
308
+ connect: jest.fn().mockResolvedValue(undefined),
309
+ close: jest.fn().mockResolvedValue(undefined),
310
+ listTools: jest.fn(),
311
+ callTool: jest.fn(),
312
+ onclose: null,
313
+ }));
314
+ // Trigger once to capture the delay
315
+ client.onclose();
316
+ expect(setTimeoutSpy).toHaveBeenCalled();
317
+ const numericDelays = setTimeoutSpy.mock.calls
318
+ .map((c) => c[1])
319
+ .filter((v) => typeof v === "number");
320
+ expect(numericDelays.length).toBeGreaterThan(0);
321
+ const d = numericDelays[0];
322
+ expect(d).toBeGreaterThanOrEqual(min);
323
+ expect(d).toBeLessThanOrEqual(max);
324
+ // Manual reconnect succeeds and should reset backoff attempts
325
+ await client.reconnect();
326
+ // Trigger onclose again and ensure we start from initial range again
327
+ client.onclose();
328
+ const numericDelays2 = setTimeoutSpy.mock.calls
329
+ .map((c) => c[1])
330
+ .filter((v) => typeof v === "number");
331
+ expect(numericDelays2.length).toBeGreaterThanOrEqual(2);
332
+ const dAgain = numericDelays2[1];
333
+ expect(dAgain).toBeGreaterThanOrEqual(min);
334
+ expect(dAgain).toBeLessThanOrEqual(max);
335
+ jest.useRealTimers();
336
+ setTimeoutSpy.mockRestore();
337
+ randSpy.mockRestore();
338
+ });
339
+ });
340
+ describe("listTools", () => {
341
+ it("should list all tools with pagination", async () => {
342
+ const endpoint = "https://api.example.com/mcp";
343
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
344
+ const mockTools = [
345
+ {
346
+ name: "tool1",
347
+ description: "First tool",
348
+ inputSchema: {
349
+ type: "object",
350
+ properties: { arg1: { type: "string" } },
351
+ },
352
+ },
353
+ {
354
+ name: "tool2",
355
+ description: "Second tool",
356
+ inputSchema: {
357
+ type: "object",
358
+ properties: { arg2: { type: "number" } },
359
+ },
360
+ },
361
+ ];
362
+ const mockResponse1 = {
363
+ tools: [mockTools[0]],
364
+ nextCursor: "cursor1",
365
+ };
366
+ const mockResponse2 = {
367
+ tools: [mockTools[1]],
368
+ nextCursor: undefined,
369
+ };
370
+ mockClientInstance.listTools
371
+ .mockResolvedValueOnce(mockResponse1)
372
+ .mockResolvedValueOnce(mockResponse2);
373
+ const result = await client.listTools();
374
+ expect(mockClientInstance.listTools).toHaveBeenCalledTimes(2);
375
+ expect(mockClientInstance.listTools).toHaveBeenNthCalledWith(1, { cursor: undefined }, {});
376
+ expect(mockClientInstance.listTools).toHaveBeenNthCalledWith(2, { cursor: "cursor1" }, {});
377
+ expect(result).toEqual([
378
+ {
379
+ name: "tool1",
380
+ description: "First tool",
381
+ inputSchema: {
382
+ type: "object",
383
+ properties: { arg1: { type: "string" } },
384
+ },
385
+ },
386
+ {
387
+ name: "tool2",
388
+ description: "Second tool",
389
+ inputSchema: {
390
+ type: "object",
391
+ properties: { arg2: { type: "number" } },
392
+ },
393
+ },
394
+ ]);
395
+ });
396
+ it("should handle single page of tools", async () => {
397
+ const endpoint = "https://api.example.com/mcp";
398
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
399
+ const mockTools = [
400
+ {
401
+ name: "tool1",
402
+ description: "Only tool",
403
+ inputSchema: {
404
+ type: "object",
405
+ properties: { arg1: { type: "string" } },
406
+ },
407
+ },
408
+ ];
409
+ const mockResponse = {
410
+ tools: mockTools,
411
+ nextCursor: undefined,
412
+ };
413
+ mockClientInstance.listTools.mockResolvedValue(mockResponse);
414
+ const result = await client.listTools();
415
+ expect(mockClientInstance.listTools).toHaveBeenCalledTimes(1);
416
+ expect(result).toEqual([
417
+ {
418
+ name: "tool1",
419
+ description: "Only tool",
420
+ inputSchema: {
421
+ type: "object",
422
+ properties: { arg1: { type: "string" } },
423
+ },
424
+ },
425
+ ]);
426
+ });
427
+ it("should throw error for invalid input schema", async () => {
428
+ const endpoint = "https://api.example.com/mcp";
429
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
430
+ const mockTools = [
431
+ {
432
+ name: "invalid-tool",
433
+ description: "Tool with invalid schema",
434
+ inputSchema: { type: "string" }, // Invalid - should be object
435
+ },
436
+ ];
437
+ const mockResponse = {
438
+ tools: mockTools,
439
+ nextCursor: undefined,
440
+ };
441
+ mockClientInstance.listTools.mockResolvedValue(mockResponse);
442
+ await expect(client.listTools()).rejects.toThrow("Input schema for tool invalid-tool is not an object");
443
+ });
444
+ });
445
+ describe("callTool", () => {
446
+ it("should call a tool with arguments", async () => {
447
+ const endpoint = "https://api.example.com/mcp";
448
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
449
+ const mockResult = { success: true, data: "test result" };
450
+ mockClientInstance.callTool.mockResolvedValue(mockResult);
451
+ const result = await client.callTool("testTool", {
452
+ arg1: "value1",
453
+ arg2: 42,
454
+ });
455
+ expect(mockClientInstance.callTool).toHaveBeenCalledWith({
456
+ name: "testTool",
457
+ arguments: { arg1: "value1", arg2: 42 },
458
+ });
459
+ expect(result).toBe(mockResult);
460
+ });
461
+ it("should handle tool call errors", async () => {
462
+ const endpoint = "https://api.example.com/mcp";
463
+ const client = await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP);
464
+ const error = new Error("Tool call failed");
465
+ mockClientInstance.callTool.mockRejectedValue(error);
466
+ await expect(client.callTool("testTool", {})).rejects.toThrow("Tool call failed");
467
+ });
468
+ });
469
+ describe("transport initialization", () => {
470
+ it("should initialize HTTP transport with session ID", async () => {
471
+ const endpoint = "https://api.example.com/mcp";
472
+ const headers = { Authorization: "Bearer token" };
473
+ await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.HTTP, headers);
474
+ expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(new URL(endpoint), { sessionId: undefined, requestInit: { headers } });
475
+ });
476
+ it("should initialize SSE transport without session ID", async () => {
477
+ const endpoint = "https://api.example.com/mcp";
478
+ const headers = { Authorization: "Bearer token" };
479
+ await mcp_client_1.MCPClient.create(endpoint, mcp_client_1.MCPTransport.SSE, headers);
480
+ expect(MockedSSEClientTransport).toHaveBeenCalledWith(new URL(endpoint), {
481
+ requestInit: { headers },
482
+ });
483
+ });
484
+ });
485
+ describe("client initialization", () => {
486
+ it("should initialize client with correct name and version", async () => {
487
+ const endpoint = "https://api.example.com/mcp";
488
+ await mcp_client_1.MCPClient.create(endpoint);
489
+ expect(MockedClient).toHaveBeenCalledWith({
490
+ name: "tambo-mcp-client",
491
+ version: "1.0.0",
492
+ });
493
+ });
494
+ it("should set onclose handler", async () => {
495
+ const endpoint = "https://api.example.com/mcp";
496
+ const _client = await mcp_client_1.MCPClient.create(endpoint);
497
+ expect(mockClientInstance.onclose).toBeDefined();
498
+ expect(typeof mockClientInstance.onclose).toBe("function");
499
+ });
500
+ });
501
+ });
502
+ //# sourceMappingURL=mcp-client.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.test.js","sourceRoot":"","sources":["../../../src/mcp/__tests__/mcp-client.test.ts"],"names":[],"mappings":";;AAAA,8CAAwD;AAExD,2BAA2B;AAC3B,IAAI,CAAC,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE,CAAC,CAAC;IAC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,CAAC;YAC/C,MAAM,OAAO,GAAG,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;YAElD,MAAM,sBAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,yBAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAE5D,MAAM,CAAC,wBAAwB,CAAC,CAAC,oBAAoB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE;gBACvE,WAAW,EAAE,EAAE,OAAO,EAAE;aACzB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACrC,EAAE,CAAC,wDAAwD,EAAE,KAAK,IAAI,EAAE;YACtE,MAAM,QAAQ,GAAG,6BAA6B,CAAC;YAE/C,MAAM,sBAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAEjC,MAAM,CAAC,YAAY,CAAC,CAAC,oBAAoB,CAAC;gBACxC,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC1C,MAAM,QAAQ,GAAG,6BAA6B,CAAC;YAC/C,MAAM,OAAO,GAAG,MAAM,sBAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAEjD,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,CAAC,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { MCPClient, MCPTransport } from \"../mcp-client\";\n\n// Mock the MCP SDK modules\njest.mock(\"@modelcontextprotocol/sdk/client/index.js\", () => ({\n Client: jest.fn().mockImplementation(() => ({\n connect: jest.fn(),\n close: jest.fn(),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n })),\n}));\n\njest.mock(\"@modelcontextprotocol/sdk/client/sse.js\", () => ({\n SSEClientTransport: jest.fn().mockImplementation(() => ({\n // SSE transport doesn't have sessionId\n })),\n}));\n\njest.mock(\"@modelcontextprotocol/sdk/client/streamableHttp.js\", () => ({\n StreamableHTTPClientTransport: jest\n .fn()\n .mockImplementation((url, options) => ({\n sessionId: options?.sessionId,\n })),\n}));\n\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\n\n// Type the mocked modules\nconst MockedClient = Client as jest.MockedClass<typeof Client>;\nconst MockedSSEClientTransport = SSEClientTransport as jest.MockedClass<\n typeof SSEClientTransport\n>;\nconst MockedStreamableHTTPClientTransport =\n StreamableHTTPClientTransport as jest.MockedClass<\n typeof StreamableHTTPClientTransport\n >;\n\ndescribe(\"MCPClient\", () => {\n let mockClientInstance: any;\n let mockTransportInstance: any;\n\n beforeEach(() => {\n jest.clearAllMocks();\n\n // Create mock instances\n mockClientInstance = {\n connect: jest.fn().mockResolvedValue(undefined),\n close: jest.fn().mockResolvedValue(undefined),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n };\n\n mockTransportInstance = {\n sessionId: \"test-session-id\",\n };\n\n // Setup mocks\n MockedClient.mockImplementation(() => mockClientInstance);\n MockedStreamableHTTPClientTransport.mockImplementation(\n () => mockTransportInstance,\n );\n MockedSSEClientTransport.mockImplementation(\n () => ({}) as SSEClientTransport,\n );\n });\n\n describe(\"create\", () => {\n it(\"should create and connect an MCPClient with HTTP transport by default\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const headers = { Authorization: \"Bearer token\" };\n\n const client = await MCPClient.create(\n endpoint,\n MCPTransport.HTTP,\n headers,\n );\n\n expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(\n new URL(endpoint),\n { sessionId: undefined, requestInit: { headers } },\n );\n expect(MockedClient).toHaveBeenCalledWith({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n expect(mockClientInstance.connect).toHaveBeenCalledWith(\n mockTransportInstance,\n );\n expect(client).toBeInstanceOf(MCPClient);\n });\n\n it(\"should create and connect an MCPClient with SSE transport\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n\n const client = await MCPClient.create(endpoint, MCPTransport.SSE);\n\n expect(MockedSSEClientTransport).toHaveBeenCalledWith(new URL(endpoint), {\n requestInit: { headers: {} },\n });\n expect(mockClientInstance.connect).toHaveBeenCalledWith({});\n expect(client).toBeInstanceOf(MCPClient);\n });\n\n it(\"should create client with default headers when none provided\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n\n await MCPClient.create(endpoint);\n\n expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(\n new URL(endpoint),\n { sessionId: undefined, requestInit: { headers: {} } },\n );\n });\n });\n\n describe(\"reconnect\", () => {\n it(\"should create new transport and client instances and call connect when reconnect() is called (default behavior)\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n // Clear previous calls to focus on reconnect behavior\n jest.clearAllMocks();\n\n // Create new mock instances to verify new instances are created\n const newMockClientInstance = {\n connect: jest.fn().mockResolvedValue(undefined),\n close: jest.fn().mockResolvedValue(undefined),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n };\n\n const newMockTransportInstance = {\n sessionId: \"new-session-id\",\n };\n\n // Mock the constructors to return new instances\n MockedClient.mockImplementation(() => newMockClientInstance as any);\n MockedStreamableHTTPClientTransport.mockImplementation(\n () => newMockTransportInstance as any,\n );\n\n await client.reconnect(); // Uses default parameters\n\n // Verify old client was closed\n expect(mockClientInstance.close).toHaveBeenCalled();\n\n // Verify new transport was created with preserved session ID (default behavior)\n expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(\n new URL(endpoint),\n { sessionId: \"test-session-id\", requestInit: { headers: {} } },\n );\n\n // Verify new client was created\n expect(MockedClient).toHaveBeenCalledWith({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n\n // Verify new client's connect was called with new transport\n expect(newMockClientInstance.connect).toHaveBeenCalledWith(\n newMockTransportInstance,\n );\n });\n\n it(\"should reconnect without session ID for SSE transport\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.SSE);\n\n // Clear previous calls\n jest.clearAllMocks();\n\n await client.reconnect();\n\n expect(mockClientInstance.close).toHaveBeenCalled();\n expect(MockedSSEClientTransport).toHaveBeenCalledWith(new URL(endpoint), {\n requestInit: { headers: {} },\n });\n expect(mockClientInstance.connect).toHaveBeenCalledWith({});\n });\n\n it(\"should handle close errors when reportErrorOnClose is true\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation();\n\n // Make close throw an error\n mockClientInstance.close.mockRejectedValue(new Error(\"Close failed\"));\n\n await client.reconnect(false, true);\n\n expect(consoleSpy).toHaveBeenCalledWith(\n \"Error closing Tambo MCP Client:\",\n expect.any(Error),\n );\n consoleSpy.mockRestore();\n });\n\n it(\"should not log close errors when reportErrorOnClose is false\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n const consoleSpy = jest.spyOn(console, \"error\").mockImplementation();\n\n // Make close throw an error\n mockClientInstance.close.mockRejectedValue(new Error(\"Close failed\"));\n\n await client.reconnect(false, false);\n\n expect(consoleSpy).not.toHaveBeenCalled();\n consoleSpy.mockRestore();\n });\n\n it(\"should create new session when newSession is true\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n // Clear previous calls to focus on reconnect behavior\n jest.clearAllMocks();\n\n // Create new mock instances to verify new instances are created\n const newMockClientInstance = {\n connect: jest.fn().mockResolvedValue(undefined),\n close: jest.fn().mockResolvedValue(undefined),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n };\n\n const newMockTransportInstance = {\n sessionId: \"new-session-id\",\n };\n\n // Mock the constructors to return new instances\n MockedClient.mockImplementation(() => newMockClientInstance as any);\n MockedStreamableHTTPClientTransport.mockImplementation(\n () => newMockTransportInstance as any,\n );\n\n await client.reconnect(true, true); // newSession = true, reportErrorOnClose = true\n\n // Verify old client was closed\n expect(mockClientInstance.close).toHaveBeenCalled();\n\n // Verify new transport was created with undefined session ID (new session)\n expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(\n new URL(endpoint),\n { sessionId: undefined, requestInit: { headers: {} } },\n );\n\n // Verify new client was created\n expect(MockedClient).toHaveBeenCalledWith({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n\n // Verify new client's connect was called with new transport\n expect(newMockClientInstance.connect).toHaveBeenCalledWith(\n newMockTransportInstance,\n );\n });\n\n it(\"should reuse existing session when newSession is false (default)\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n // Clear previous calls to focus on reconnect behavior\n jest.clearAllMocks();\n\n // Create new mock instances to verify new instances are created\n const newMockClientInstance = {\n connect: jest.fn().mockResolvedValue(undefined),\n close: jest.fn().mockResolvedValue(undefined),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n };\n\n const newMockTransportInstance = {\n sessionId: \"reused-session-id\",\n };\n\n // Mock the constructors to return new instances\n MockedClient.mockImplementation(() => newMockClientInstance as any);\n MockedStreamableHTTPClientTransport.mockImplementation(\n () => newMockTransportInstance as any,\n );\n\n await client.reconnect(false, true); // newSession = false, reportErrorOnClose = true\n\n // Verify old client was closed\n expect(mockClientInstance.close).toHaveBeenCalled();\n\n // Verify new transport was created with preserved session ID\n expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(\n new URL(endpoint),\n { sessionId: \"test-session-id\", requestInit: { headers: {} } },\n );\n\n // Verify new client was created\n expect(MockedClient).toHaveBeenCalledWith({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n\n // Verify new client's connect was called with new transport\n expect(newMockClientInstance.connect).toHaveBeenCalledWith(\n newMockTransportInstance,\n );\n });\n });\n\n describe(\"onclose\", () => {\n it(\"should reconnect MCPClient when client is closed by external means (no backoff on manual preemption)\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n jest.useFakeTimers();\n const consoleSpy = jest.spyOn(console, \"warn\").mockImplementation();\n\n // Create new mock instances to verify reconnection creates new instances\n const newMockClientInstance = {\n connect: jest.fn().mockResolvedValue(undefined),\n close: jest.fn().mockResolvedValue(undefined),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n };\n\n const newMockTransportInstance = {\n sessionId: \"reconnected-session-id\",\n };\n\n // Mock the constructors to return new instances for reconnection\n MockedClient.mockImplementation(() => newMockClientInstance as any);\n MockedStreamableHTTPClientTransport.mockImplementation(\n () => newMockTransportInstance as any,\n );\n\n // Reset counts after initial creation\n jest.clearAllMocks();\n\n // Trigger automatic onclose (schedules a delayed reconnect)\n (client as any).onclose();\n // Manual reconnect should preempt the scheduled automatic attempt\n const reconnectPromise = client.reconnect();\n // No timers should be pending after manual preemption\n await reconnectPromise;\n\n // Verify warning message is logged\n expect(consoleSpy).toHaveBeenCalled();\n\n // Verify old client was closed\n expect(mockClientInstance.close).toHaveBeenCalled();\n\n // Verify new transport was created with preserved session ID\n expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(\n new URL(endpoint),\n { sessionId: \"test-session-id\", requestInit: { headers: {} } },\n );\n\n // Verify new client was created\n expect(MockedClient).toHaveBeenCalledWith({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n\n // Verify new client's connect was called with new transport\n expect(newMockClientInstance.connect).toHaveBeenCalledWith(\n newMockTransportInstance,\n );\n\n // Ensure only a single reconnect attempt occurred\n expect(MockedClient).toHaveBeenCalledTimes(1);\n expect(newMockClientInstance.connect).toHaveBeenCalledTimes(1);\n\n consoleSpy.mockRestore();\n jest.useRealTimers();\n });\n });\n\n describe(\"reconnect re-entrancy and single-flight\", () => {\n it(\"prevents re-entrant onclose during deliberate close and coalesces concurrent calls\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n // Simulate an implementation where closing the client would call its own onclose handler\n const closeImpl = jest.fn(async () => {\n if (typeof mockClientInstance.onclose === \"function\") {\n // would cause recursion if not detached\n (mockClientInstance.onclose as unknown as () => void)();\n }\n return;\n });\n mockClientInstance.close = closeImpl;\n\n // Prepare new instances for the reconnect\n const newMockClientInstance = {\n connect: jest.fn().mockResolvedValue(undefined),\n close: jest.fn().mockResolvedValue(undefined),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n };\n MockedClient.mockImplementation(() => newMockClientInstance as any);\n\n // Reset counts after initial creation\n jest.clearAllMocks();\n\n // Trigger auto onclose and manual reconnect nearly simultaneously\n (client as any).onclose();\n await client.reconnect();\n\n // Should have detached onclose before calling close, avoiding recursion\n expect(closeImpl).toHaveBeenCalledTimes(1);\n expect(mockClientInstance.onclose).toBeUndefined();\n\n // Single-flight: only one new client/connect\n expect(MockedClient).toHaveBeenCalledTimes(1);\n expect(newMockClientInstance.connect).toHaveBeenCalledTimes(1);\n });\n });\n\n describe(\"backoff + jitter (automatic reconnect)\", () => {\n it(\"applies jitter and resets to initial delay after a successful reconnect (manual preempt)\", async () => {\n jest.useFakeTimers();\n const base = MCPClient.BACKOFF_INITIAL_MS;\n const ratio = MCPClient.BACKOFF_JITTER_RATIO;\n const min = Math.round(base * (1 - ratio));\n const max = Math.round(base * (1 + ratio));\n const setTimeoutSpy = jest.spyOn(global, \"setTimeout\");\n const randSpy = jest.spyOn(Math, \"random\").mockReturnValue(0.0); // extreme low jitter\n\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n // Prepare one attempt that will succeed to avoid rescheduling\n MockedClient.mockImplementation(\n () =>\n ({\n connect: jest.fn().mockResolvedValue(undefined),\n close: jest.fn().mockResolvedValue(undefined),\n listTools: jest.fn(),\n callTool: jest.fn(),\n onclose: null,\n }) as any,\n );\n\n // Trigger once to capture the delay\n (client as any).onclose();\n expect(setTimeoutSpy).toHaveBeenCalled();\n const numericDelays = setTimeoutSpy.mock.calls\n .map((c) => c[1])\n .filter((v) => typeof v === \"number\") as number[];\n expect(numericDelays.length).toBeGreaterThan(0);\n const d = numericDelays[0]!;\n expect(d).toBeGreaterThanOrEqual(min);\n expect(d).toBeLessThanOrEqual(max);\n\n // Manual reconnect succeeds and should reset backoff attempts\n await client.reconnect();\n\n // Trigger onclose again and ensure we start from initial range again\n (client as any).onclose();\n const numericDelays2 = setTimeoutSpy.mock.calls\n .map((c) => c[1])\n .filter((v) => typeof v === \"number\") as number[];\n expect(numericDelays2.length).toBeGreaterThanOrEqual(2);\n const dAgain = numericDelays2[1]!;\n expect(dAgain).toBeGreaterThanOrEqual(min);\n expect(dAgain).toBeLessThanOrEqual(max);\n\n jest.useRealTimers();\n setTimeoutSpy.mockRestore();\n randSpy.mockRestore();\n });\n });\n\n describe(\"listTools\", () => {\n it(\"should list all tools with pagination\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n const mockTools = [\n {\n name: \"tool1\",\n description: \"First tool\",\n inputSchema: {\n type: \"object\",\n properties: { arg1: { type: \"string\" } },\n },\n },\n {\n name: \"tool2\",\n description: \"Second tool\",\n inputSchema: {\n type: \"object\",\n properties: { arg2: { type: \"number\" } },\n },\n },\n ];\n\n const mockResponse1 = {\n tools: [mockTools[0]],\n nextCursor: \"cursor1\",\n };\n\n const mockResponse2 = {\n tools: [mockTools[1]],\n nextCursor: undefined,\n };\n\n mockClientInstance.listTools\n .mockResolvedValueOnce(mockResponse1)\n .mockResolvedValueOnce(mockResponse2);\n\n const result = await client.listTools();\n\n expect(mockClientInstance.listTools).toHaveBeenCalledTimes(2);\n expect(mockClientInstance.listTools).toHaveBeenNthCalledWith(\n 1,\n { cursor: undefined },\n {},\n );\n expect(mockClientInstance.listTools).toHaveBeenNthCalledWith(\n 2,\n { cursor: \"cursor1\" },\n {},\n );\n expect(result).toEqual([\n {\n name: \"tool1\",\n description: \"First tool\",\n inputSchema: {\n type: \"object\",\n properties: { arg1: { type: \"string\" } },\n },\n },\n {\n name: \"tool2\",\n description: \"Second tool\",\n inputSchema: {\n type: \"object\",\n properties: { arg2: { type: \"number\" } },\n },\n },\n ]);\n });\n\n it(\"should handle single page of tools\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n const mockTools = [\n {\n name: \"tool1\",\n description: \"Only tool\",\n inputSchema: {\n type: \"object\",\n properties: { arg1: { type: \"string\" } },\n },\n },\n ];\n\n const mockResponse = {\n tools: mockTools,\n nextCursor: undefined,\n };\n\n mockClientInstance.listTools.mockResolvedValue(mockResponse);\n\n const result = await client.listTools();\n\n expect(mockClientInstance.listTools).toHaveBeenCalledTimes(1);\n expect(result).toEqual([\n {\n name: \"tool1\",\n description: \"Only tool\",\n inputSchema: {\n type: \"object\",\n properties: { arg1: { type: \"string\" } },\n },\n },\n ]);\n });\n\n it(\"should throw error for invalid input schema\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n const mockTools = [\n {\n name: \"invalid-tool\",\n description: \"Tool with invalid schema\",\n inputSchema: { type: \"string\" }, // Invalid - should be object\n },\n ];\n\n const mockResponse = {\n tools: mockTools,\n nextCursor: undefined,\n };\n\n mockClientInstance.listTools.mockResolvedValue(mockResponse);\n\n await expect(client.listTools()).rejects.toThrow(\n \"Input schema for tool invalid-tool is not an object\",\n );\n });\n });\n\n describe(\"callTool\", () => {\n it(\"should call a tool with arguments\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n const mockResult = { success: true, data: \"test result\" };\n mockClientInstance.callTool.mockResolvedValue(mockResult);\n\n const result = await client.callTool(\"testTool\", {\n arg1: \"value1\",\n arg2: 42,\n });\n\n expect(mockClientInstance.callTool).toHaveBeenCalledWith({\n name: \"testTool\",\n arguments: { arg1: \"value1\", arg2: 42 },\n });\n expect(result).toBe(mockResult);\n });\n\n it(\"should handle tool call errors\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const client = await MCPClient.create(endpoint, MCPTransport.HTTP);\n\n const error = new Error(\"Tool call failed\");\n mockClientInstance.callTool.mockRejectedValue(error);\n\n await expect(client.callTool(\"testTool\", {})).rejects.toThrow(\n \"Tool call failed\",\n );\n });\n });\n\n describe(\"transport initialization\", () => {\n it(\"should initialize HTTP transport with session ID\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const headers = { Authorization: \"Bearer token\" };\n\n await MCPClient.create(endpoint, MCPTransport.HTTP, headers);\n\n expect(MockedStreamableHTTPClientTransport).toHaveBeenCalledWith(\n new URL(endpoint),\n { sessionId: undefined, requestInit: { headers } },\n );\n });\n\n it(\"should initialize SSE transport without session ID\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const headers = { Authorization: \"Bearer token\" };\n\n await MCPClient.create(endpoint, MCPTransport.SSE, headers);\n\n expect(MockedSSEClientTransport).toHaveBeenCalledWith(new URL(endpoint), {\n requestInit: { headers },\n });\n });\n });\n\n describe(\"client initialization\", () => {\n it(\"should initialize client with correct name and version\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n\n await MCPClient.create(endpoint);\n\n expect(MockedClient).toHaveBeenCalledWith({\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n });\n });\n\n it(\"should set onclose handler\", async () => {\n const endpoint = \"https://api.example.com/mcp\";\n const _client = await MCPClient.create(endpoint);\n\n expect(mockClientInstance.onclose).toBeDefined();\n expect(typeof mockClientInstance.onclose).toBe(\"function\");\n });\n });\n});\n"]}