@tambo-ai/react 0.58.1 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/react-query-hooks.d.ts +14 -1
- package/dist/hooks/react-query-hooks.d.ts.map +1 -1
- package/dist/hooks/react-query-hooks.js +13 -0
- package/dist/hooks/react-query-hooks.js.map +1 -1
- package/dist/hooks/use-tambo-stream-status.js +1 -1
- package/dist/hooks/use-tambo-stream-status.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/__tests__/elicitation.test.d.ts +2 -0
- package/dist/mcp/__tests__/elicitation.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/elicitation.test.js +261 -0
- package/dist/mcp/__tests__/elicitation.test.js.map +1 -0
- package/dist/mcp/__tests__/mcp-client.test.js +0 -266
- package/dist/mcp/__tests__/mcp-client.test.js.map +1 -1
- package/dist/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
- package/dist/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
- package/dist/mcp/__tests__/mcp-hooks.test.js +504 -0
- package/dist/mcp/__tests__/mcp-hooks.test.js.map +1 -0
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js +361 -16
- package/dist/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/dist/mcp/__tests__/use-mcp-servers.test.js +34 -9
- package/dist/mcp/__tests__/use-mcp-servers.test.js.map +1 -1
- package/dist/mcp/elicitation.d.ts +80 -0
- package/dist/mcp/elicitation.d.ts.map +1 -0
- package/dist/mcp/elicitation.js +55 -0
- package/dist/mcp/elicitation.js.map +1 -0
- package/dist/mcp/index.d.ts +4 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +5 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-client.d.ts +51 -86
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +22 -159
- package/dist/mcp/mcp-client.js.map +1 -1
- package/dist/mcp/mcp-hooks.d.ts +107 -0
- package/dist/mcp/mcp-hooks.d.ts.map +1 -0
- package/dist/mcp/mcp-hooks.js +103 -0
- package/dist/mcp/mcp-hooks.js.map +1 -0
- package/dist/mcp/tambo-mcp-provider.d.ts +86 -4
- package/dist/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/dist/mcp/tambo-mcp-provider.js +275 -106
- package/dist/mcp/tambo-mcp-provider.js.map +1 -1
- package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js +3 -1
- package/dist/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/dist/providers/__tests__/tambo-thread-provider.test.js +25 -12
- package/dist/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +11 -4
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-mcp-token-provider.d.ts +34 -0
- package/dist/providers/tambo-mcp-token-provider.d.ts.map +1 -0
- package/dist/providers/tambo-mcp-token-provider.js +69 -0
- package/dist/providers/tambo-mcp-token-provider.js.map +1 -0
- package/dist/providers/tambo-provider.d.ts.map +1 -1
- package/dist/providers/tambo-provider.js +7 -9
- package/dist/providers/tambo-provider.js.map +1 -1
- package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
- package/dist/providers/tambo-thread-provider.js +14 -0
- package/dist/providers/tambo-thread-provider.js.map +1 -1
- package/esm/hooks/react-query-hooks.d.ts +14 -1
- package/esm/hooks/react-query-hooks.d.ts.map +1 -1
- package/esm/hooks/react-query-hooks.js +13 -1
- package/esm/hooks/react-query-hooks.js.map +1 -1
- package/esm/hooks/use-tambo-stream-status.js +1 -1
- package/esm/hooks/use-tambo-stream-status.js.map +1 -1
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/esm/mcp/__tests__/elicitation.test.d.ts +2 -0
- package/esm/mcp/__tests__/elicitation.test.d.ts.map +1 -0
- package/esm/mcp/__tests__/elicitation.test.js +259 -0
- package/esm/mcp/__tests__/elicitation.test.js.map +1 -0
- package/esm/mcp/__tests__/mcp-client.test.js +0 -266
- package/esm/mcp/__tests__/mcp-client.test.js.map +1 -1
- package/esm/mcp/__tests__/mcp-hooks.test.d.ts +2 -0
- package/esm/mcp/__tests__/mcp-hooks.test.d.ts.map +1 -0
- package/esm/mcp/__tests__/mcp-hooks.test.js +469 -0
- package/esm/mcp/__tests__/mcp-hooks.test.js.map +1 -0
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js +361 -16
- package/esm/mcp/__tests__/tambo-mcp-provider.test.js.map +1 -1
- package/esm/mcp/__tests__/use-mcp-servers.test.js +34 -9
- package/esm/mcp/__tests__/use-mcp-servers.test.js.map +1 -1
- package/esm/mcp/elicitation.d.ts +80 -0
- package/esm/mcp/elicitation.d.ts.map +1 -0
- package/esm/mcp/elicitation.js +52 -0
- package/esm/mcp/elicitation.js.map +1 -0
- package/esm/mcp/index.d.ts +4 -1
- package/esm/mcp/index.d.ts.map +1 -1
- package/esm/mcp/index.js +2 -1
- package/esm/mcp/index.js.map +1 -1
- package/esm/mcp/mcp-client.d.ts +51 -86
- package/esm/mcp/mcp-client.d.ts.map +1 -1
- package/esm/mcp/mcp-client.js +22 -159
- package/esm/mcp/mcp-client.js.map +1 -1
- package/esm/mcp/mcp-hooks.d.ts +107 -0
- package/esm/mcp/mcp-hooks.d.ts.map +1 -0
- package/esm/mcp/mcp-hooks.js +99 -0
- package/esm/mcp/mcp-hooks.js.map +1 -0
- package/esm/mcp/tambo-mcp-provider.d.ts +86 -4
- package/esm/mcp/tambo-mcp-provider.d.ts.map +1 -1
- package/esm/mcp/tambo-mcp-provider.js +275 -107
- package/esm/mcp/tambo-mcp-provider.js.map +1 -1
- package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js +3 -1
- package/esm/providers/__tests__/tambo-thread-provider-initial-messages.test.js.map +1 -1
- package/esm/providers/__tests__/tambo-thread-provider.test.js +25 -12
- package/esm/providers/__tests__/tambo-thread-provider.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +11 -4
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-mcp-token-provider.d.ts +34 -0
- package/esm/providers/tambo-mcp-token-provider.d.ts.map +1 -0
- package/esm/providers/tambo-mcp-token-provider.js +31 -0
- package/esm/providers/tambo-mcp-token-provider.js.map +1 -0
- package/esm/providers/tambo-provider.d.ts.map +1 -1
- package/esm/providers/tambo-provider.js +7 -9
- package/esm/providers/tambo-provider.js.map +1 -1
- package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
- package/esm/providers/tambo-thread-provider.js +14 -0
- package/esm/providers/tambo-thread-provider.js.map +1 -1
- package/package.json +8 -8
package/esm/mcp/mcp-client.d.ts
CHANGED
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
import { type OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
2
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
|
+
import { ClientNotification, ClientRequest, CreateMessageRequest, CreateMessageResult, ElicitRequest, ElicitResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
5
|
import { JSONSchema7 } from "json-schema";
|
|
5
6
|
export declare enum MCPTransport {
|
|
6
7
|
SSE = "sse",
|
|
7
8
|
HTTP = "http"
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Handler for MCP elicitation requests.
|
|
12
|
+
* Receives the elicit request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
|
|
13
|
+
* @param request - The elicitation request from the server
|
|
14
|
+
* @param extra - Additional context including AbortSignal for cancellation
|
|
15
|
+
* @returns Promise resolving to the elicitation result
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const handler: MCPElicitationHandler = async (request, extra) => {
|
|
19
|
+
* // Listen for cancellation
|
|
20
|
+
* extra.signal.addEventListener('abort', () => {
|
|
21
|
+
* console.log('Request cancelled');
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Return user's response
|
|
25
|
+
* return {
|
|
26
|
+
* action: 'accept',
|
|
27
|
+
* content: { name: 'John' }
|
|
28
|
+
* };
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type MCPElicitationHandler = (e: ElicitRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<ElicitResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Handler for MCP sampling requests (create_message).
|
|
35
|
+
* Receives the sampling request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.
|
|
36
|
+
* @param request - The sampling/create_message request from the server
|
|
37
|
+
* @param extra - Additional context including AbortSignal for cancellation
|
|
38
|
+
* @returns Promise resolving to the sampling result
|
|
39
|
+
*/
|
|
40
|
+
export type MCPSamplingHandler = (e: CreateMessageRequest, extra: RequestHandlerExtra<ClientRequest, ClientNotification>) => Promise<CreateMessageResult>;
|
|
9
41
|
/**
|
|
10
42
|
* Handlers for MCP requests - these are only used if the server supports the corresponding capabilities
|
|
11
|
-
* @param elicitation - Handler for elicitation requests
|
|
12
|
-
* @param sampling - Handler for sampling requests
|
|
43
|
+
* @param elicitation - Handler for elicitation requests (receives request and RequestHandlerExtra with AbortSignal)
|
|
44
|
+
* @param sampling - Handler for sampling requests (receives request and RequestHandlerExtra with AbortSignal)
|
|
13
45
|
* @example
|
|
14
46
|
* ```typescript
|
|
15
47
|
* const mcp = await MCPClient.create(
|
|
@@ -19,14 +51,14 @@ export declare enum MCPTransport {
|
|
|
19
51
|
* undefined,
|
|
20
52
|
* undefined,
|
|
21
53
|
* {
|
|
22
|
-
* elicitation: (e
|
|
54
|
+
* elicitation: (e, extra) => Promise.resolve({...}),
|
|
23
55
|
* },
|
|
24
|
-
*
|
|
56
|
+
* );
|
|
25
57
|
* ```
|
|
26
58
|
*/
|
|
27
|
-
interface MCPHandlers {
|
|
28
|
-
elicitation
|
|
29
|
-
sampling
|
|
59
|
+
export interface MCPHandlers {
|
|
60
|
+
elicitation: MCPElicitationHandler;
|
|
61
|
+
sampling: MCPSamplingHandler;
|
|
30
62
|
}
|
|
31
63
|
/**
|
|
32
64
|
* A client for interacting with MCP (Model Context Protocol) servers.
|
|
@@ -39,7 +71,12 @@ interface MCPHandlers {
|
|
|
39
71
|
* ```
|
|
40
72
|
*/
|
|
41
73
|
export declare class MCPClient {
|
|
42
|
-
|
|
74
|
+
/**
|
|
75
|
+
* The underlying MCP client
|
|
76
|
+
*
|
|
77
|
+
* Be careful not to mutate the client directly, use the methods provided instead.
|
|
78
|
+
*/
|
|
79
|
+
client: Client;
|
|
43
80
|
private transport;
|
|
44
81
|
private transportType;
|
|
45
82
|
sessionId?: string;
|
|
@@ -47,42 +84,6 @@ export declare class MCPClient {
|
|
|
47
84
|
private headers;
|
|
48
85
|
private authProvider?;
|
|
49
86
|
private handlers;
|
|
50
|
-
/**
|
|
51
|
-
* Tracks an in-flight reconnect so concurrent triggers coalesce
|
|
52
|
-
* (single-flight). When set, additional calls to `reconnect()` or
|
|
53
|
-
* the automatic `onclose` handler will await the same Promise instead of
|
|
54
|
-
* starting another reconnect sequence.
|
|
55
|
-
*/
|
|
56
|
-
private reconnecting?;
|
|
57
|
-
/**
|
|
58
|
-
* Timer id for a scheduled automatic reconnect (used by `onclose`).
|
|
59
|
-
* Present only while waiting for the backoff delay to elapse.
|
|
60
|
-
*/
|
|
61
|
-
private reconnectTimer?;
|
|
62
|
-
/**
|
|
63
|
-
* Count of consecutive automatic reconnect failures used to compute
|
|
64
|
-
* exponential backoff. Reset to 0 after a successful connection.
|
|
65
|
-
*/
|
|
66
|
-
private backoffAttempts;
|
|
67
|
-
/**
|
|
68
|
-
* Backoff policy (discoverable constants)
|
|
69
|
-
* - BACKOFF_INITIAL_MS: initial delay for the first automatic retry
|
|
70
|
-
* - BACKOFF_MULTIPLIER: exponential growth factor for each failed attempt
|
|
71
|
-
* - BACKOFF_MAX_MS: upper bound for the delay
|
|
72
|
-
* - BACKOFF_JITTER_RATIO: jitter range as a fraction of the base delay
|
|
73
|
-
*
|
|
74
|
-
* Jitter is applied symmetrically in [-ratio, +ratio]. For example, with a
|
|
75
|
-
* 500ms base delay and 0.2 ratio, the actual delay is in [400ms, 600ms].
|
|
76
|
-
*
|
|
77
|
-
* The backoff applies only to automatic reconnects started from the
|
|
78
|
-
* `onclose` handler. Explicit/manual calls to `reconnect()` run immediately
|
|
79
|
-
* (no backoff), and will preempt any scheduled automatic attempt.
|
|
80
|
-
*/
|
|
81
|
-
static readonly BACKOFF_INITIAL_MS = 500;
|
|
82
|
-
static readonly BACKOFF_MULTIPLIER = 2;
|
|
83
|
-
static readonly BACKOFF_MAX_MS = 30000;
|
|
84
|
-
static readonly BACKOFF_JITTER_RATIO = 0.2;
|
|
85
|
-
elicitation: EventTarget;
|
|
86
87
|
/**
|
|
87
88
|
* Private constructor to enforce using the static create method.
|
|
88
89
|
* @param endpoint - The URL of the MCP server to connect to
|
|
@@ -103,43 +104,7 @@ export declare class MCPClient {
|
|
|
103
104
|
* @returns A connected MCPClient instance ready for use
|
|
104
105
|
* @throws {Error} Will throw an error if connection fails
|
|
105
106
|
*/
|
|
106
|
-
static create(endpoint: string, transportType: MCPTransport | undefined, headers: Record<string, string> | undefined, authProvider: OAuthClientProvider | undefined, sessionId: string | undefined, handlers?: MCPHandlers): Promise<MCPClient>;
|
|
107
|
-
/**
|
|
108
|
-
* Reconnects to the MCP server, optionally retaining the same session ID.
|
|
109
|
-
*
|
|
110
|
-
* Single‑flight semantics:
|
|
111
|
-
* - If a reconnect is already in progress (triggered either manually or by
|
|
112
|
-
* the automatic `onclose` handler), additional calls will await the
|
|
113
|
-
* in-flight reconnect rather than start another one.
|
|
114
|
-
* - If an automatic reconnect has been scheduled but not yet started (i.e.,
|
|
115
|
-
* we are waiting in a backoff delay), calling `reconnect()` manually will
|
|
116
|
-
* cancel the scheduled attempt and perform an immediate reconnect.
|
|
117
|
-
*
|
|
118
|
-
* Backoff policy:
|
|
119
|
-
* - Backoff delays with jitter are applied only for automatic reconnects
|
|
120
|
-
* (via `onclose`). Manual calls to `reconnect()` do not use backoff.
|
|
121
|
-
* @param newSession - Whether to create a new session (true) or reuse existing session ID (false)
|
|
122
|
-
* @param reportErrorOnClose - Whether to report errors when closing the client
|
|
123
|
-
* Note that only StreamableHTTPClientTransport supports session IDs.
|
|
124
|
-
* @returns A promise that resolves when the reconnect is complete
|
|
125
|
-
*/
|
|
126
|
-
reconnect(newSession?: boolean, reportErrorOnClose?: boolean): Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* Called by the underlying MCP SDK when the connection closes.
|
|
129
|
-
* Schedules an automatic reconnect with bounded exponential backoff and
|
|
130
|
-
* jitter. If a reconnect is already scheduled or running, this is a no-op.
|
|
131
|
-
*/
|
|
132
|
-
private onclose;
|
|
133
|
-
/**
|
|
134
|
-
* Compute the next backoff delay with symmetric jitter.
|
|
135
|
-
* @returns The next backoff delay in milliseconds
|
|
136
|
-
*/
|
|
137
|
-
private computeBackoffDelayMs;
|
|
138
|
-
/**
|
|
139
|
-
* Schedule an automatic reconnect attempt if one is not already scheduled
|
|
140
|
-
* or running. Uses the backoff policy and self-reschedules on failure.
|
|
141
|
-
*/
|
|
142
|
-
private scheduleAutoReconnect;
|
|
107
|
+
static create(endpoint: string, transportType: MCPTransport | undefined, headers: Record<string, string> | undefined, authProvider: OAuthClientProvider | undefined, sessionId: string | undefined, handlers?: Partial<MCPHandlers>): Promise<MCPClient>;
|
|
143
108
|
private initializeTransport;
|
|
144
109
|
/**
|
|
145
110
|
* Initializes the MCP client with the appropriate capabilities and handlers
|
|
@@ -199,9 +164,10 @@ export declare class MCPClient {
|
|
|
199
164
|
* @returns The result from the tool execution
|
|
200
165
|
* @throws {Error} Will throw an error if the tool call fails or if arguments are invalid
|
|
201
166
|
*/
|
|
202
|
-
callTool(name: string, args: Record<string, unknown>): Promise<MCPToolCallResult>;
|
|
203
|
-
updateElicitationHandler(handler:
|
|
204
|
-
updateSamplingHandler(handler:
|
|
167
|
+
callTool(name: string, args: Record<string, unknown>, _meta?: Record<string, unknown>): Promise<MCPToolCallResult>;
|
|
168
|
+
updateElicitationHandler(handler: MCPElicitationHandler | undefined): void;
|
|
169
|
+
updateSamplingHandler(handler: MCPSamplingHandler | undefined): void;
|
|
170
|
+
close(): Promise<void>;
|
|
205
171
|
}
|
|
206
172
|
/**
|
|
207
173
|
* The result of a tool call.
|
|
@@ -213,5 +179,4 @@ export interface MCPToolSpec {
|
|
|
213
179
|
description?: string;
|
|
214
180
|
inputSchema?: JSONSchema7;
|
|
215
181
|
}
|
|
216
|
-
export {};
|
|
217
182
|
//# sourceMappingURL=mcp-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,OAAO,EACL,oBAAoB,EAEpB,mBAAmB,EACnB,aAAa,EAEb,YAAY,EACb,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAED
|
|
1
|
+
{"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,OAAO,KAAK,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AM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,YAAY,EAAE,mBAAmB,GAAG,SAAS,EAC7C,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,QAAQ,GAAE,OAAO,CAAC,WAAW,CAAM,GAClC,OAAO,CAAC,SAAS,CAAC;IAgBrB,OAAO,CAAC,mBAAmB;IAe3B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA8BxB;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAmCzC,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;IAIrB,gBAAgB;;;;;;;;;;;;;IAIhB,eAAe;IAIf;;;;;;OAMG;IACG,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,iBAAiB,CAAC;IAS7B,wBAAwB,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS;IAuBnE,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,GAAG,SAAS;IAuBvD,KAAK;CAOZ;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CACrC,UAAU,CAAC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAC7C,CAAC;AASF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B"}
|
package/esm/mcp/mcp-client.js
CHANGED
|
@@ -18,6 +18,11 @@ export var MCPTransport;
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export class MCPClient {
|
|
21
|
+
/**
|
|
22
|
+
* The underlying MCP client
|
|
23
|
+
*
|
|
24
|
+
* Be careful not to mutate the client directly, use the methods provided instead.
|
|
25
|
+
*/
|
|
21
26
|
client;
|
|
22
27
|
transport;
|
|
23
28
|
transportType;
|
|
@@ -26,42 +31,6 @@ export class MCPClient {
|
|
|
26
31
|
headers;
|
|
27
32
|
authProvider;
|
|
28
33
|
handlers;
|
|
29
|
-
/**
|
|
30
|
-
* Tracks an in-flight reconnect so concurrent triggers coalesce
|
|
31
|
-
* (single-flight). When set, additional calls to `reconnect()` or
|
|
32
|
-
* the automatic `onclose` handler will await the same Promise instead of
|
|
33
|
-
* starting another reconnect sequence.
|
|
34
|
-
*/
|
|
35
|
-
reconnecting;
|
|
36
|
-
/**
|
|
37
|
-
* Timer id for a scheduled automatic reconnect (used by `onclose`).
|
|
38
|
-
* Present only while waiting for the backoff delay to elapse.
|
|
39
|
-
*/
|
|
40
|
-
reconnectTimer;
|
|
41
|
-
/**
|
|
42
|
-
* Count of consecutive automatic reconnect failures used to compute
|
|
43
|
-
* exponential backoff. Reset to 0 after a successful connection.
|
|
44
|
-
*/
|
|
45
|
-
backoffAttempts = 0;
|
|
46
|
-
/**
|
|
47
|
-
* Backoff policy (discoverable constants)
|
|
48
|
-
* - BACKOFF_INITIAL_MS: initial delay for the first automatic retry
|
|
49
|
-
* - BACKOFF_MULTIPLIER: exponential growth factor for each failed attempt
|
|
50
|
-
* - BACKOFF_MAX_MS: upper bound for the delay
|
|
51
|
-
* - BACKOFF_JITTER_RATIO: jitter range as a fraction of the base delay
|
|
52
|
-
*
|
|
53
|
-
* Jitter is applied symmetrically in [-ratio, +ratio]. For example, with a
|
|
54
|
-
* 500ms base delay and 0.2 ratio, the actual delay is in [400ms, 600ms].
|
|
55
|
-
*
|
|
56
|
-
* The backoff applies only to automatic reconnects started from the
|
|
57
|
-
* `onclose` handler. Explicit/manual calls to `reconnect()` run immediately
|
|
58
|
-
* (no backoff), and will preempt any scheduled automatic attempt.
|
|
59
|
-
*/
|
|
60
|
-
static BACKOFF_INITIAL_MS = 500;
|
|
61
|
-
static BACKOFF_MULTIPLIER = 2;
|
|
62
|
-
static BACKOFF_MAX_MS = 30_000;
|
|
63
|
-
static BACKOFF_JITTER_RATIO = 0.2;
|
|
64
|
-
elicitation = new EventTarget();
|
|
65
34
|
/**
|
|
66
35
|
* Private constructor to enforce using the static create method.
|
|
67
36
|
* @param endpoint - The URL of the MCP server to connect to
|
|
@@ -98,127 +67,6 @@ export class MCPClient {
|
|
|
98
67
|
}
|
|
99
68
|
return mcpClient;
|
|
100
69
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Reconnects to the MCP server, optionally retaining the same session ID.
|
|
103
|
-
*
|
|
104
|
-
* Single‑flight semantics:
|
|
105
|
-
* - If a reconnect is already in progress (triggered either manually or by
|
|
106
|
-
* the automatic `onclose` handler), additional calls will await the
|
|
107
|
-
* in-flight reconnect rather than start another one.
|
|
108
|
-
* - If an automatic reconnect has been scheduled but not yet started (i.e.,
|
|
109
|
-
* we are waiting in a backoff delay), calling `reconnect()` manually will
|
|
110
|
-
* cancel the scheduled attempt and perform an immediate reconnect.
|
|
111
|
-
*
|
|
112
|
-
* Backoff policy:
|
|
113
|
-
* - Backoff delays with jitter are applied only for automatic reconnects
|
|
114
|
-
* (via `onclose`). Manual calls to `reconnect()` do not use backoff.
|
|
115
|
-
* @param newSession - Whether to create a new session (true) or reuse existing session ID (false)
|
|
116
|
-
* @param reportErrorOnClose - Whether to report errors when closing the client
|
|
117
|
-
* Note that only StreamableHTTPClientTransport supports session IDs.
|
|
118
|
-
* @returns A promise that resolves when the reconnect is complete
|
|
119
|
-
*/
|
|
120
|
-
async reconnect(newSession = false, reportErrorOnClose = true) {
|
|
121
|
-
// If a reconnect is already running, coalesce into it.
|
|
122
|
-
if (this.reconnecting) {
|
|
123
|
-
return await this.reconnecting;
|
|
124
|
-
}
|
|
125
|
-
// Manual reconnect preempts any scheduled automatic attempt.
|
|
126
|
-
if (this.reconnectTimer) {
|
|
127
|
-
clearTimeout(this.reconnectTimer);
|
|
128
|
-
this.reconnectTimer = undefined;
|
|
129
|
-
}
|
|
130
|
-
const doReconnect = async () => {
|
|
131
|
-
const sessionId = newSession ? undefined : this.sessionId;
|
|
132
|
-
// Prevent re-entrant onclose during deliberate close by detaching
|
|
133
|
-
// the handler from the previous client instance.
|
|
134
|
-
const prevClient = this.client;
|
|
135
|
-
// Prevent re-entrant onclose callbacks from the previous client
|
|
136
|
-
prevClient.onclose = undefined;
|
|
137
|
-
try {
|
|
138
|
-
await prevClient.close();
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
if (reportErrorOnClose) {
|
|
142
|
-
console.error("Error closing Tambo MCP Client:", error);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
this.transport = this.initializeTransport(sessionId);
|
|
146
|
-
this.client = this.initializeClient();
|
|
147
|
-
await this.client.connect(this.transport);
|
|
148
|
-
// We may have gotten a session id from the server, so we need to set it
|
|
149
|
-
if ("sessionId" in this.transport) {
|
|
150
|
-
this.sessionId = this.transport.sessionId;
|
|
151
|
-
if (sessionId !== this.sessionId) {
|
|
152
|
-
// This is a pretty unusual thing to happen, but it might be possible?
|
|
153
|
-
console.warn("Session id mismatch", sessionId, this.sessionId);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
this.reconnecting = (async () => {
|
|
158
|
-
try {
|
|
159
|
-
await doReconnect();
|
|
160
|
-
// Successful manual reconnect: reset backoff.
|
|
161
|
-
this.backoffAttempts = 0;
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
this.reconnecting = undefined;
|
|
165
|
-
}
|
|
166
|
-
})();
|
|
167
|
-
return await this.reconnecting;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Called by the underlying MCP SDK when the connection closes.
|
|
171
|
-
* Schedules an automatic reconnect with bounded exponential backoff and
|
|
172
|
-
* jitter. If a reconnect is already scheduled or running, this is a no-op.
|
|
173
|
-
*/
|
|
174
|
-
onclose() {
|
|
175
|
-
this.scheduleAutoReconnect();
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Compute the next backoff delay with symmetric jitter.
|
|
179
|
-
* @returns The next backoff delay in milliseconds
|
|
180
|
-
*/
|
|
181
|
-
computeBackoffDelayMs() {
|
|
182
|
-
const base = Math.min(MCPClient.BACKOFF_MAX_MS, MCPClient.BACKOFF_INITIAL_MS *
|
|
183
|
-
Math.pow(MCPClient.BACKOFF_MULTIPLIER, this.backoffAttempts));
|
|
184
|
-
const jitterRange = MCPClient.BACKOFF_JITTER_RATIO * base;
|
|
185
|
-
const jitter = (Math.random() * 2 - 1) * jitterRange; // [-range, +range]
|
|
186
|
-
const ms = Math.max(0, Math.round(base + jitter));
|
|
187
|
-
return ms;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Schedule an automatic reconnect attempt if one is not already scheduled
|
|
191
|
-
* or running. Uses the backoff policy and self-reschedules on failure.
|
|
192
|
-
*/
|
|
193
|
-
scheduleAutoReconnect() {
|
|
194
|
-
if (this.reconnecting || this.reconnectTimer) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
const delayMs = this.computeBackoffDelayMs();
|
|
198
|
-
console.warn("Tambo MCP Client closed; attempting automatic reconnect in", `${delayMs}ms`);
|
|
199
|
-
this.reconnectTimer = setTimeout(async () => {
|
|
200
|
-
this.reconnectTimer = undefined;
|
|
201
|
-
// Start the actual reconnect (single-flight)
|
|
202
|
-
const inFlight = (this.reconnecting = this.reconnect(false, false));
|
|
203
|
-
try {
|
|
204
|
-
await inFlight;
|
|
205
|
-
// Success: reset attempts
|
|
206
|
-
this.backoffAttempts = 0;
|
|
207
|
-
}
|
|
208
|
-
catch (err) {
|
|
209
|
-
// Failure: increase attempts; scheduling occurs in finally below so the
|
|
210
|
-
// new timer isn't blocked by `this.reconnecting` being truthy.
|
|
211
|
-
this.backoffAttempts += 1;
|
|
212
|
-
console.warn("Automatic reconnect failed; will retry with backoff.", err);
|
|
213
|
-
}
|
|
214
|
-
finally {
|
|
215
|
-
this.reconnecting = undefined;
|
|
216
|
-
if (this.backoffAttempts > 0) {
|
|
217
|
-
this.scheduleAutoReconnect();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}, delayMs);
|
|
221
|
-
}
|
|
222
70
|
initializeTransport(sessionId) {
|
|
223
71
|
if (this.transportType === MCPTransport.SSE) {
|
|
224
72
|
return new SSEClientTransport(new URL(this.endpoint), {
|
|
@@ -252,7 +100,6 @@ export class MCPClient {
|
|
|
252
100
|
...samplingCapability,
|
|
253
101
|
},
|
|
254
102
|
});
|
|
255
|
-
client.onclose = this.onclose.bind(this);
|
|
256
103
|
if (this.handlers.elicitation) {
|
|
257
104
|
client.setRequestHandler(ElicitRequestSchema, this.handlers.elicitation);
|
|
258
105
|
}
|
|
@@ -310,14 +157,19 @@ export class MCPClient {
|
|
|
310
157
|
* @returns The result from the tool execution
|
|
311
158
|
* @throws {Error} Will throw an error if the tool call fails or if arguments are invalid
|
|
312
159
|
*/
|
|
313
|
-
async callTool(name, args) {
|
|
160
|
+
async callTool(name, args, _meta) {
|
|
314
161
|
const result = await this.client.callTool({
|
|
315
162
|
name,
|
|
316
163
|
arguments: args,
|
|
164
|
+
_meta,
|
|
317
165
|
});
|
|
318
166
|
return result;
|
|
319
167
|
}
|
|
320
168
|
updateElicitationHandler(handler) {
|
|
169
|
+
// Skip if handler hasn't changed
|
|
170
|
+
if (handler === this.handlers.elicitation) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
321
173
|
// Because we advertise the elicitation capability on initial connection, we can only update
|
|
322
174
|
// an existing handler, not add it if we haven't set it yet.
|
|
323
175
|
if (handler && !this.handlers.elicitation) {
|
|
@@ -335,6 +187,10 @@ export class MCPClient {
|
|
|
335
187
|
this.client.setRequestHandler(ElicitRequestSchema, handler);
|
|
336
188
|
}
|
|
337
189
|
updateSamplingHandler(handler) {
|
|
190
|
+
// Skip if handler hasn't changed
|
|
191
|
+
if (handler === this.handlers.sampling) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
338
194
|
// Because we advertise the sampling capability on initial connection, we can only update
|
|
339
195
|
// an existing handler, not add it if we haven't set it yet.
|
|
340
196
|
if (handler && !this.handlers.sampling) {
|
|
@@ -351,5 +207,12 @@ export class MCPClient {
|
|
|
351
207
|
}
|
|
352
208
|
this.client.setRequestHandler(CreateMessageRequestSchema, handler);
|
|
353
209
|
}
|
|
210
|
+
async close() {
|
|
211
|
+
// Not really sure which one of these to close first, but we'll close the
|
|
212
|
+
// transport first so that no requests can come in and hit closing/closed
|
|
213
|
+
// clients
|
|
214
|
+
await this.transport.close();
|
|
215
|
+
await this.client.close();
|
|
216
|
+
}
|
|
354
217
|
}
|
|
355
218
|
//# sourceMappingURL=mcp-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-client.js","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAEL,0BAA0B,EAG1B,mBAAmB,GAEpB,MAAM,oCAAoC,CAAC;AAG5C,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,6BAAa,CAAA;AACf,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAyBD;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IACZ,MAAM,CAAS;IACf,SAAS,CAAqD;IAC9D,aAAa,CAAe;IAC7B,SAAS,CAAU;IAClB,QAAQ,CAAS;IACjB,OAAO,CAAyB;IAChC,YAAY,CAAuB;IACnC,QAAQ,CAAc;IAC9B;;;;;OAKG;IACK,YAAY,CAAiB;IACrC;;;OAGG;IACK,cAAc,CAAiC;IACvD;;;OAGG;IACK,eAAe,GAAG,CAAC,CAAC;IAE5B;;;;;;;;;;;;;OAaG;I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AiB,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC","sourcesContent":["import { type OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport {\n CreateMessageRequest,\n CreateMessageRequestSchema,\n CreateMessageResult,\n ElicitRequest,\n ElicitRequestSchema,\n ElicitResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\n}\n\n/**\n * Handlers for MCP requests - these are only used if the server supports the corresponding capabilities\n * @param elicitation - Handler for elicitation requests\n * @param sampling - Handler for sampling requests\n * @example\n * ```typescript\n * const mcp = await MCPClient.create(\n * 'https://api.example.com/mcp',\n * MCPTransport.HTTP,\n * {},\n * undefined,\n * undefined,\n * {\n * elicitation: (e: ElicitRequest) => Promise.resolve({...}),\n * },\n * });\n * ```\n */\ninterface MCPHandlers {\n elicitation?: (e: ElicitRequest) => Promise<ElicitResult>;\n sampling?: (e: CreateMessageRequest) => Promise<CreateMessageResult>;\n}\n\n/**\n * A client for interacting with MCP (Model Context Protocol) servers.\n * Provides a simple interface for listing and calling tools exposed by the server.\n * @example\n * ```typescript\n * const mcp = await MCPClient.create('https://api.example.com/mcp');\n * const tools = await mcp.listTools();\n * const result = await mcp.callTool('toolName', { arg1: 'value1' });\n * ```\n */\nexport class MCPClient {\n private client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\n private transportType: MCPTransport;\n public sessionId?: string;\n private endpoint: string;\n private headers: Record<string, string>;\n private authProvider?: OAuthClientProvider;\n private handlers: MCPHandlers;\n /**\n * Tracks an in-flight reconnect so concurrent triggers coalesce\n * (single-flight). When set, additional calls to `reconnect()` or\n * the automatic `onclose` handler will await the same Promise instead of\n * starting another reconnect sequence.\n */\n private reconnecting?: Promise<void>;\n /**\n * Timer id for a scheduled automatic reconnect (used by `onclose`).\n * Present only while waiting for the backoff delay to elapse.\n */\n private reconnectTimer?: ReturnType<typeof setTimeout>;\n /**\n * Count of consecutive automatic reconnect failures used to compute\n * exponential backoff. Reset to 0 after a successful connection.\n */\n private backoffAttempts = 0;\n\n /**\n * Backoff policy (discoverable constants)\n * - BACKOFF_INITIAL_MS: initial delay for the first automatic retry\n * - BACKOFF_MULTIPLIER: exponential growth factor for each failed attempt\n * - BACKOFF_MAX_MS: upper bound for the delay\n * - BACKOFF_JITTER_RATIO: jitter range as a fraction of the base delay\n *\n * Jitter is applied symmetrically in [-ratio, +ratio]. For example, with a\n * 500ms base delay and 0.2 ratio, the actual delay is in [400ms, 600ms].\n *\n * The backoff applies only to automatic reconnects started from the\n * `onclose` handler. Explicit/manual calls to `reconnect()` run immediately\n * (no backoff), and will preempt any scheduled automatic attempt.\n */\n static readonly BACKOFF_INITIAL_MS = 500;\n static readonly BACKOFF_MULTIPLIER = 2;\n static readonly BACKOFF_MAX_MS = 30_000;\n static readonly BACKOFF_JITTER_RATIO = 0.2;\n\n public elicitation: EventTarget = new EventTarget();\n /**\n * Private constructor to enforce using the static create method.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport to use for the MCP client\n * @param headers - Optional custom headers to include in requests\n */\n private constructor(\n endpoint: string,\n transportType: MCPTransport,\n headers?: Record<string, string>,\n authProvider?: OAuthClientProvider,\n sessionId?: string,\n handlers: MCPHandlers = {},\n ) {\n this.endpoint = endpoint;\n this.headers = headers ?? {};\n this.authProvider = authProvider;\n this.transportType = transportType;\n this.handlers = handlers;\n this.transport = this.initializeTransport(sessionId);\n this.client = this.initializeClient();\n }\n\n /**\n * Creates and initializes a new MCPClient instance. This is the recommended\n * way to create an MCPClient as it handles both instantiation and connection\n * setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport type to use for the MCP client. Defaults to HTTP.\n * @param headers - Optional custom headers to include in requests\n * @param authProvider - Optional auth provider to use for authentication\n * @param sessionId - Optional session id to use for the MCP client - if not\n * provided, a new session will be created\n * @returns A connected MCPClient instance ready for use\n * @throws {Error} Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transportType: MCPTransport = MCPTransport.HTTP,\n headers: Record<string, string> | undefined,\n authProvider: OAuthClientProvider | undefined,\n sessionId: string | undefined,\n handlers: MCPHandlers = {},\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(\n endpoint,\n transportType,\n headers,\n authProvider,\n sessionId,\n handlers,\n );\n await mcpClient.client.connect(mcpClient.transport);\n if (\"sessionId\" in mcpClient.transport) {\n mcpClient.sessionId = mcpClient.transport.sessionId;\n }\n return mcpClient;\n }\n /**\n * Reconnects to the MCP server, optionally retaining the same session ID.\n *\n * Single‑flight semantics:\n * - If a reconnect is already in progress (triggered either manually or by\n * the automatic `onclose` handler), additional calls will await the\n * in-flight reconnect rather than start another one.\n * - If an automatic reconnect has been scheduled but not yet started (i.e.,\n * we are waiting in a backoff delay), calling `reconnect()` manually will\n * cancel the scheduled attempt and perform an immediate reconnect.\n *\n * Backoff policy:\n * - Backoff delays with jitter are applied only for automatic reconnects\n * (via `onclose`). Manual calls to `reconnect()` do not use backoff.\n * @param newSession - Whether to create a new session (true) or reuse existing session ID (false)\n * @param reportErrorOnClose - Whether to report errors when closing the client\n * Note that only StreamableHTTPClientTransport supports session IDs.\n * @returns A promise that resolves when the reconnect is complete\n */\n async reconnect(newSession = false, reportErrorOnClose = true) {\n // If a reconnect is already running, coalesce into it.\n if (this.reconnecting) {\n return await this.reconnecting;\n }\n\n // Manual reconnect preempts any scheduled automatic attempt.\n if (this.reconnectTimer) {\n clearTimeout(this.reconnectTimer);\n this.reconnectTimer = undefined;\n }\n\n const doReconnect = async () => {\n const sessionId = newSession ? undefined : this.sessionId;\n\n // Prevent re-entrant onclose during deliberate close by detaching\n // the handler from the previous client instance.\n const prevClient = this.client;\n // Prevent re-entrant onclose callbacks from the previous client\n prevClient.onclose = undefined;\n\n try {\n await prevClient.close();\n } catch (error) {\n if (reportErrorOnClose) {\n console.error(\"Error closing Tambo MCP Client:\", error);\n }\n }\n\n this.transport = this.initializeTransport(sessionId);\n this.client = this.initializeClient();\n await this.client.connect(this.transport);\n // We may have gotten a session id from the server, so we need to set it\n if (\"sessionId\" in this.transport) {\n this.sessionId = this.transport.sessionId;\n if (sessionId !== this.sessionId) {\n // This is a pretty unusual thing to happen, but it might be possible?\n console.warn(\"Session id mismatch\", sessionId, this.sessionId);\n }\n }\n };\n\n this.reconnecting = (async () => {\n try {\n await doReconnect();\n // Successful manual reconnect: reset backoff.\n this.backoffAttempts = 0;\n } finally {\n this.reconnecting = undefined;\n }\n })();\n\n return await this.reconnecting;\n }\n\n /**\n * Called by the underlying MCP SDK when the connection closes.\n * Schedules an automatic reconnect with bounded exponential backoff and\n * jitter. If a reconnect is already scheduled or running, this is a no-op.\n */\n private onclose() {\n this.scheduleAutoReconnect();\n }\n\n /**\n * Compute the next backoff delay with symmetric jitter.\n * @returns The next backoff delay in milliseconds\n */\n private computeBackoffDelayMs(): number {\n const base = Math.min(\n MCPClient.BACKOFF_MAX_MS,\n MCPClient.BACKOFF_INITIAL_MS *\n Math.pow(MCPClient.BACKOFF_MULTIPLIER, this.backoffAttempts),\n );\n const jitterRange = MCPClient.BACKOFF_JITTER_RATIO * base;\n const jitter = (Math.random() * 2 - 1) * jitterRange; // [-range, +range]\n const ms = Math.max(0, Math.round(base + jitter));\n return ms;\n }\n\n /**\n * Schedule an automatic reconnect attempt if one is not already scheduled\n * or running. Uses the backoff policy and self-reschedules on failure.\n */\n private scheduleAutoReconnect() {\n if (this.reconnecting || this.reconnectTimer) {\n return;\n }\n\n const delayMs = this.computeBackoffDelayMs();\n console.warn(\n \"Tambo MCP Client closed; attempting automatic reconnect in\",\n `${delayMs}ms`,\n );\n\n this.reconnectTimer = setTimeout(async () => {\n this.reconnectTimer = undefined;\n // Start the actual reconnect (single-flight)\n const inFlight = (this.reconnecting = this.reconnect(false, false));\n try {\n await inFlight;\n // Success: reset attempts\n this.backoffAttempts = 0;\n } catch (err) {\n // Failure: increase attempts; scheduling occurs in finally below so the\n // new timer isn't blocked by `this.reconnecting` being truthy.\n this.backoffAttempts += 1;\n console.warn(\n \"Automatic reconnect failed; will retry with backoff.\",\n err,\n );\n } finally {\n this.reconnecting = undefined;\n if (this.backoffAttempts > 0) {\n this.scheduleAutoReconnect();\n }\n }\n }, delayMs);\n }\n\n private initializeTransport(sessionId: string | undefined) {\n if (this.transportType === MCPTransport.SSE) {\n return new SSEClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n });\n } else {\n return new StreamableHTTPClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n sessionId,\n });\n }\n }\n\n /**\n * Initializes the MCP client with the appropriate capabilities and handlers\n * @returns The initialized MCP client\n */\n private initializeClient() {\n const elicitationCapability = this.handlers.elicitation\n ? { elicitation: {} }\n : {};\n const samplingCapability = this.handlers.sampling ? { sampling: {} } : {};\n const client = new Client(\n {\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n },\n {\n capabilities: {\n ...elicitationCapability,\n ...samplingCapability,\n },\n },\n );\n client.onclose = this.onclose.bind(this);\n if (this.handlers.elicitation) {\n client.setRequestHandler(ElicitRequestSchema, this.handlers.elicitation);\n }\n if (this.handlers.sampling) {\n client.setRequestHandler(\n CreateMessageRequestSchema,\n this.handlers.sampling,\n );\n }\n return client;\n }\n\n /**\n * Retrieves a complete list of all available tools from the MCP server.\n * Handles pagination automatically by following cursors until all tools are fetched.\n * @returns A complete list of all available tools and their descriptions\n * @throws {Error} Will throw an error if any server request fails during pagination\n */\n async listTools(): Promise<MCPToolSpec[]> {\n const allTools: MCPToolSpec[] = [];\n let hasMore = true;\n let cursor: string | undefined = undefined;\n\n while (hasMore) {\n const response = await this.client.listTools({ cursor }, {});\n allTools.push(\n ...response.tools.map((tool): MCPToolSpec => {\n // make sure the right type is used\n const inputSchemaType: string = tool.inputSchema.type;\n if (inputSchemaType !== \"object\") {\n throw new Error(\n `Input schema for tool ${tool.name} is not an object`,\n );\n }\n\n return {\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema as JSONSchema7,\n };\n }),\n );\n\n if (response.nextCursor) {\n cursor = response.nextCursor;\n } else {\n hasMore = false;\n }\n }\n\n return allTools;\n }\n\n getServerCapabilities() {\n return this.client.getServerCapabilities();\n }\n\n getServerVersion() {\n return this.client.getServerVersion();\n }\n\n getInstructions() {\n return this.client.getInstructions();\n }\n\n /**\n * Calls a specific tool on the MCP server with the provided arguments.\n * @param name - The name of the tool to call\n * @param args - Arguments to pass to the tool, must match the tool's expected schema\n * @returns The result from the tool execution\n * @throws {Error} Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(\n name: string,\n args: Record<string, unknown>,\n ): Promise<MCPToolCallResult> {\n const result = await this.client.callTool({\n name,\n arguments: args,\n });\n return result;\n }\n\n updateElicitationHandler(\n handler: ((e: ElicitRequest) => Promise<ElicitResult>) | undefined,\n ) {\n // Because we advertise the elicitation capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.elicitation) {\n throw new Error(\"Elicitation handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n elicitation: handler,\n };\n if (!handler) {\n const method = ElicitRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(ElicitRequestSchema, handler);\n }\n\n updateSamplingHandler(\n handler:\n | ((e: CreateMessageRequest) => Promise<CreateMessageResult>)\n | undefined,\n ) {\n // Because we advertise the sampling capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.sampling) {\n throw new Error(\"Sampling handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n sampling: handler,\n };\n if (!handler) {\n const method = CreateMessageRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(CreateMessageRequestSchema, handler);\n }\n}\n\n/**\n * The result of a tool call.\n * This is the same as the result of a tool call in the OpenAI SDK, but is reified here\n */\nexport type MCPToolCallResult = Awaited<\n ReturnType<typeof Client.prototype.callTool>\n>;\n\n// Example usage:\n/*\nconst mcp = await MCPClient.create('https://api.example.com/mcp', MCPTransport.HTTP);\nconst tools = await mcp.listTools();\nconst result = await mcp.callTool('toolName', { arg1: 'value1' });\n*/\n\nexport interface MCPToolSpec {\n name: string;\n description?: string;\n inputSchema?: JSONSchema7;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp-client.js","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,EAIL,0BAA0B,EAG1B,mBAAmB,GAEpB,MAAM,oCAAoC,CAAC;AAG5C,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,6BAAa,CAAA;AACf,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAgED;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IACpB;;;;OAIG;IACH,MAAM,CAAS;IACP,SAAS,CAAqD;IAC9D,aAAa,CAAe;IAC7B,SAAS,CAAU;IAClB,QAAQ,CAAS;IACjB,OAAO,CAAyB;IAChC,YAAY,CAAuB;IACnC,QAAQ,CAAuB;IAEvC;;;;;OAKG;IACH,YACE,QAAgB,EAChB,aAA2B,EAC3B,OAAgC,EAChC,YAAkC,EAClC,SAAkB,EAClB,WAAiC,EAAE;QAEnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,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;YACzC,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,KAAK;QACT,yEAAyE;QACzE,yEAAyE;QACzE,UAAU;QACV,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { type OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { SSEClientTransport } from \"@modelcontextprotocol/sdk/client/sse.js\";\nimport { StreamableHTTPClientTransport } from \"@modelcontextprotocol/sdk/client/streamableHttp.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport {\n ClientNotification,\n ClientRequest,\n CreateMessageRequest,\n CreateMessageRequestSchema,\n CreateMessageResult,\n ElicitRequest,\n ElicitRequestSchema,\n ElicitResult,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { JSONSchema7 } from \"json-schema\";\n\nexport enum MCPTransport {\n SSE = \"sse\",\n HTTP = \"http\",\n}\n\n/**\n * Handler for MCP elicitation requests.\n * Receives the elicit request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.\n * @param request - The elicitation request from the server\n * @param extra - Additional context including AbortSignal for cancellation\n * @returns Promise resolving to the elicitation result\n * @example\n * ```typescript\n * const handler: MCPElicitationHandler = async (request, extra) => {\n * // Listen for cancellation\n * extra.signal.addEventListener('abort', () => {\n * console.log('Request cancelled');\n * });\n *\n * // Return user's response\n * return {\n * action: 'accept',\n * content: { name: 'John' }\n * };\n * };\n * ```\n */\nexport type MCPElicitationHandler = (\n e: ElicitRequest,\n extra: RequestHandlerExtra<ClientRequest, ClientNotification>,\n) => Promise<ElicitResult>;\n\n/**\n * Handler for MCP sampling requests (create_message).\n * Receives the sampling request and a RequestHandlerExtra containing an AbortSignal that fires when the request is cancelled.\n * @param request - The sampling/create_message request from the server\n * @param extra - Additional context including AbortSignal for cancellation\n * @returns Promise resolving to the sampling result\n */\nexport type MCPSamplingHandler = (\n e: CreateMessageRequest,\n extra: RequestHandlerExtra<ClientRequest, ClientNotification>,\n) => Promise<CreateMessageResult>;\n\n/**\n * Handlers for MCP requests - these are only used if the server supports the corresponding capabilities\n * @param elicitation - Handler for elicitation requests (receives request and RequestHandlerExtra with AbortSignal)\n * @param sampling - Handler for sampling requests (receives request and RequestHandlerExtra with AbortSignal)\n * @example\n * ```typescript\n * const mcp = await MCPClient.create(\n * 'https://api.example.com/mcp',\n * MCPTransport.HTTP,\n * {},\n * undefined,\n * undefined,\n * {\n * elicitation: (e, extra) => Promise.resolve({...}),\n * },\n * );\n * ```\n */\nexport interface MCPHandlers {\n elicitation: MCPElicitationHandler;\n sampling: MCPSamplingHandler;\n}\n\n/**\n * A client for interacting with MCP (Model Context Protocol) servers.\n * Provides a simple interface for listing and calling tools exposed by the server.\n * @example\n * ```typescript\n * const mcp = await MCPClient.create('https://api.example.com/mcp');\n * const tools = await mcp.listTools();\n * const result = await mcp.callTool('toolName', { arg1: 'value1' });\n * ```\n */\nexport class MCPClient {\n /**\n * The underlying MCP client\n *\n * Be careful not to mutate the client directly, use the methods provided instead.\n */\n client: Client;\n private transport: SSEClientTransport | StreamableHTTPClientTransport;\n private transportType: MCPTransport;\n public sessionId?: string;\n private endpoint: string;\n private headers: Record<string, string>;\n private authProvider?: OAuthClientProvider;\n private handlers: Partial<MCPHandlers>;\n\n /**\n * Private constructor to enforce using the static create method.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport to use for the MCP client\n * @param headers - Optional custom headers to include in requests\n */\n private constructor(\n endpoint: string,\n transportType: MCPTransport,\n headers?: Record<string, string>,\n authProvider?: OAuthClientProvider,\n sessionId?: string,\n handlers: Partial<MCPHandlers> = {},\n ) {\n this.endpoint = endpoint;\n this.headers = headers ?? {};\n this.authProvider = authProvider;\n this.transportType = transportType;\n this.handlers = handlers;\n this.transport = this.initializeTransport(sessionId);\n this.client = this.initializeClient();\n }\n\n /**\n * Creates and initializes a new MCPClient instance. This is the recommended\n * way to create an MCPClient as it handles both instantiation and connection\n * setup.\n * @param endpoint - The URL of the MCP server to connect to\n * @param transportType - The transport type to use for the MCP client. Defaults to HTTP.\n * @param headers - Optional custom headers to include in requests\n * @param authProvider - Optional auth provider to use for authentication\n * @param sessionId - Optional session id to use for the MCP client - if not\n * provided, a new session will be created\n * @returns A connected MCPClient instance ready for use\n * @throws {Error} Will throw an error if connection fails\n */\n static async create(\n endpoint: string,\n transportType: MCPTransport = MCPTransport.HTTP,\n headers: Record<string, string> | undefined,\n authProvider: OAuthClientProvider | undefined,\n sessionId: string | undefined,\n handlers: Partial<MCPHandlers> = {},\n ): Promise<MCPClient> {\n const mcpClient = new MCPClient(\n endpoint,\n transportType,\n headers,\n authProvider,\n sessionId,\n handlers,\n );\n await mcpClient.client.connect(mcpClient.transport);\n if (\"sessionId\" in mcpClient.transport) {\n mcpClient.sessionId = mcpClient.transport.sessionId;\n }\n return mcpClient;\n }\n\n private initializeTransport(sessionId: string | undefined) {\n if (this.transportType === MCPTransport.SSE) {\n return new SSEClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n });\n } else {\n return new StreamableHTTPClientTransport(new URL(this.endpoint), {\n authProvider: this.authProvider,\n requestInit: { headers: this.headers },\n sessionId,\n });\n }\n }\n\n /**\n * Initializes the MCP client with the appropriate capabilities and handlers\n * @returns The initialized MCP client\n */\n private initializeClient() {\n const elicitationCapability = this.handlers.elicitation\n ? { elicitation: {} }\n : {};\n const samplingCapability = this.handlers.sampling ? { sampling: {} } : {};\n const client = new Client(\n {\n name: \"tambo-mcp-client\",\n version: \"1.0.0\",\n },\n {\n capabilities: {\n ...elicitationCapability,\n ...samplingCapability,\n },\n },\n );\n\n if (this.handlers.elicitation) {\n client.setRequestHandler(ElicitRequestSchema, this.handlers.elicitation);\n }\n if (this.handlers.sampling) {\n client.setRequestHandler(\n CreateMessageRequestSchema,\n this.handlers.sampling,\n );\n }\n return client;\n }\n\n /**\n * Retrieves a complete list of all available tools from the MCP server.\n * Handles pagination automatically by following cursors until all tools are fetched.\n * @returns A complete list of all available tools and their descriptions\n * @throws {Error} Will throw an error if any server request fails during pagination\n */\n async listTools(): Promise<MCPToolSpec[]> {\n const allTools: MCPToolSpec[] = [];\n let hasMore = true;\n let cursor: string | undefined = undefined;\n\n while (hasMore) {\n const response = await this.client.listTools({ cursor }, {});\n allTools.push(\n ...response.tools.map((tool): MCPToolSpec => {\n // make sure the right type is used\n const inputSchemaType: string = tool.inputSchema.type;\n if (inputSchemaType !== \"object\") {\n throw new Error(\n `Input schema for tool ${tool.name} is not an object`,\n );\n }\n\n return {\n name: tool.name,\n description: tool.description,\n inputSchema: tool.inputSchema as JSONSchema7,\n };\n }),\n );\n\n if (response.nextCursor) {\n cursor = response.nextCursor;\n } else {\n hasMore = false;\n }\n }\n\n return allTools;\n }\n\n getServerCapabilities() {\n return this.client.getServerCapabilities();\n }\n\n getServerVersion() {\n return this.client.getServerVersion();\n }\n\n getInstructions() {\n return this.client.getInstructions();\n }\n\n /**\n * Calls a specific tool on the MCP server with the provided arguments.\n * @param name - The name of the tool to call\n * @param args - Arguments to pass to the tool, must match the tool's expected schema\n * @returns The result from the tool execution\n * @throws {Error} Will throw an error if the tool call fails or if arguments are invalid\n */\n async callTool(\n name: string,\n args: Record<string, unknown>,\n _meta?: Record<string, unknown>,\n ): Promise<MCPToolCallResult> {\n const result = await this.client.callTool({\n name,\n arguments: args,\n _meta,\n });\n return result;\n }\n\n updateElicitationHandler(handler: MCPElicitationHandler | undefined) {\n // Skip if handler hasn't changed\n if (handler === this.handlers.elicitation) {\n return;\n }\n\n // Because we advertise the elicitation capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.elicitation) {\n throw new Error(\"Elicitation handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n elicitation: handler,\n };\n if (!handler) {\n const method = ElicitRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(ElicitRequestSchema, handler);\n }\n\n updateSamplingHandler(handler: MCPSamplingHandler | undefined) {\n // Skip if handler hasn't changed\n if (handler === this.handlers.sampling) {\n return;\n }\n\n // Because we advertise the sampling capability on initial connection, we can only update\n // an existing handler, not add it if we haven't set it yet.\n if (handler && !this.handlers.sampling) {\n throw new Error(\"Sampling handler must be set on create\");\n }\n this.handlers = {\n ...this.handlers,\n sampling: handler,\n };\n if (!handler) {\n const method = CreateMessageRequestSchema.shape.method.value;\n this.client.removeRequestHandler(method);\n return;\n }\n this.client.setRequestHandler(CreateMessageRequestSchema, handler);\n }\n\n async close() {\n // Not really sure which one of these to close first, but we'll close the\n // transport first so that no requests can come in and hit closing/closed\n // clients\n await this.transport.close();\n await this.client.close();\n }\n}\n\n/**\n * The result of a tool call.\n * This is the same as the result of a tool call in the OpenAI SDK, but is reified here\n */\nexport type MCPToolCallResult = Awaited<\n ReturnType<typeof Client.prototype.callTool>\n>;\n\n// Example usage:\n/*\nconst mcp = await MCPClient.create('https://api.example.com/mcp', MCPTransport.HTTP);\nconst tools = await mcp.listTools();\nconst result = await mcp.callTool('toolName', { arg1: 'value1' });\n*/\n\nexport interface MCPToolSpec {\n name: string;\n description?: string;\n inputSchema?: JSONSchema7;\n}\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type ListPromptsResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { UseQueryResult } from "@tanstack/react-query";
|
|
3
|
+
import { type ConnectedMcpServer } from "./tambo-mcp-provider";
|
|
4
|
+
export type ListPromptItem = ListPromptsResult["prompts"][number];
|
|
5
|
+
export interface ListPromptEntry {
|
|
6
|
+
server: ConnectedMcpServer;
|
|
7
|
+
prompt: ListPromptItem;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hook to get the prompts for all the registered MCP servers.
|
|
11
|
+
* @returns The prompts for the MCP servers, including the server that the prompt was found on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useTamboMcpPromptList(): {
|
|
14
|
+
data: ListPromptEntry[];
|
|
15
|
+
error: Error | null;
|
|
16
|
+
errors: Error[];
|
|
17
|
+
isPending: boolean;
|
|
18
|
+
isSuccess: boolean;
|
|
19
|
+
isError: boolean;
|
|
20
|
+
isPaused: boolean;
|
|
21
|
+
isRefetching: boolean;
|
|
22
|
+
isFetching: boolean;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
refetch: () => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Hook to get the prompt for the specified name.
|
|
28
|
+
* @param promptName - The name of the prompt to get. If the prompt won't return anything
|
|
29
|
+
* @param args - The arguments to pass to the prompt.
|
|
30
|
+
* @returns The prompt for the specified name.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useTamboMcpPrompt(promptName: string | undefined, args?: Record<string, string>): UseQueryResult<{
|
|
33
|
+
[x: string]: unknown;
|
|
34
|
+
messages: {
|
|
35
|
+
[x: string]: unknown;
|
|
36
|
+
content: {
|
|
37
|
+
[x: string]: unknown;
|
|
38
|
+
text: string;
|
|
39
|
+
type: "text";
|
|
40
|
+
_meta?: {
|
|
41
|
+
[x: string]: unknown;
|
|
42
|
+
} | undefined;
|
|
43
|
+
} | {
|
|
44
|
+
[x: string]: unknown;
|
|
45
|
+
data: string;
|
|
46
|
+
type: "image";
|
|
47
|
+
mimeType: string;
|
|
48
|
+
_meta?: {
|
|
49
|
+
[x: string]: unknown;
|
|
50
|
+
} | undefined;
|
|
51
|
+
} | {
|
|
52
|
+
[x: string]: unknown;
|
|
53
|
+
data: string;
|
|
54
|
+
type: "audio";
|
|
55
|
+
mimeType: string;
|
|
56
|
+
_meta?: {
|
|
57
|
+
[x: string]: unknown;
|
|
58
|
+
} | undefined;
|
|
59
|
+
} | {
|
|
60
|
+
[x: string]: unknown;
|
|
61
|
+
name: string;
|
|
62
|
+
type: "resource_link";
|
|
63
|
+
uri: string;
|
|
64
|
+
title?: string | undefined;
|
|
65
|
+
description?: string | undefined;
|
|
66
|
+
_meta?: {
|
|
67
|
+
[x: string]: unknown;
|
|
68
|
+
} | undefined;
|
|
69
|
+
mimeType?: string | undefined;
|
|
70
|
+
icons?: {
|
|
71
|
+
[x: string]: unknown;
|
|
72
|
+
src: string;
|
|
73
|
+
mimeType?: string | undefined;
|
|
74
|
+
sizes?: string[] | undefined;
|
|
75
|
+
}[] | undefined;
|
|
76
|
+
} | {
|
|
77
|
+
[x: string]: unknown;
|
|
78
|
+
type: "resource";
|
|
79
|
+
resource: {
|
|
80
|
+
[x: string]: unknown;
|
|
81
|
+
text: string;
|
|
82
|
+
uri: string;
|
|
83
|
+
_meta?: {
|
|
84
|
+
[x: string]: unknown;
|
|
85
|
+
} | undefined;
|
|
86
|
+
mimeType?: string | undefined;
|
|
87
|
+
} | {
|
|
88
|
+
[x: string]: unknown;
|
|
89
|
+
uri: string;
|
|
90
|
+
blob: string;
|
|
91
|
+
_meta?: {
|
|
92
|
+
[x: string]: unknown;
|
|
93
|
+
} | undefined;
|
|
94
|
+
mimeType?: string | undefined;
|
|
95
|
+
};
|
|
96
|
+
_meta?: {
|
|
97
|
+
[x: string]: unknown;
|
|
98
|
+
} | undefined;
|
|
99
|
+
};
|
|
100
|
+
role: "user" | "assistant";
|
|
101
|
+
}[];
|
|
102
|
+
description?: string | undefined;
|
|
103
|
+
_meta?: {
|
|
104
|
+
[x: string]: unknown;
|
|
105
|
+
} | undefined;
|
|
106
|
+
} | null, Error>;
|
|
107
|
+
//# sourceMappingURL=mcp-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-hooks.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAClE,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB;;WA8B5B,KAAK,GAAG,IAAI;YACX,KAAK,EAAE;eACJ,OAAO;eACP,OAAO;aACT,OAAO;cACN,OAAO;kBACH,OAAO;gBACT,OAAO;eACR,OAAO;aACT,MAAM,OAAO,CAAC,IAAI,CAAC;EAb7B;AAwDD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiClC"}
|