@mcp-ts/sdk 1.3.5 → 1.3.7
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/adapters/agui-adapter.d.mts +1 -1
- package/dist/adapters/agui-adapter.d.ts +1 -1
- package/dist/adapters/agui-adapter.js +2 -2
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs +2 -2
- package/dist/adapters/agui-adapter.mjs.map +1 -1
- package/dist/adapters/agui-middleware.d.mts +1 -1
- package/dist/adapters/agui-middleware.d.ts +1 -1
- package/dist/adapters/agui-middleware.js.map +1 -1
- package/dist/adapters/agui-middleware.mjs.map +1 -1
- package/dist/adapters/ai-adapter.d.mts +1 -1
- package/dist/adapters/ai-adapter.d.ts +1 -1
- package/dist/adapters/ai-adapter.js +1 -1
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs +1 -1
- package/dist/adapters/ai-adapter.mjs.map +1 -1
- package/dist/adapters/langchain-adapter.d.mts +1 -1
- package/dist/adapters/langchain-adapter.d.ts +1 -1
- package/dist/adapters/langchain-adapter.js +1 -1
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +1 -1
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/adapters/mastra-adapter.d.mts +1 -1
- package/dist/adapters/mastra-adapter.d.ts +1 -1
- package/dist/adapters/mastra-adapter.js +1 -1
- package/dist/adapters/mastra-adapter.js.map +1 -1
- package/dist/adapters/mastra-adapter.mjs +1 -1
- package/dist/adapters/mastra-adapter.mjs.map +1 -1
- package/dist/bin/mcp-ts.d.mts +1 -0
- package/dist/bin/mcp-ts.d.ts +1 -0
- package/dist/bin/mcp-ts.js +105 -0
- package/dist/bin/mcp-ts.js.map +1 -0
- package/dist/bin/mcp-ts.mjs +82 -0
- package/dist/bin/mcp-ts.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +411 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -91
- package/dist/index.mjs.map +1 -1
- package/dist/{multi-session-client-BYLarghq.d.ts → multi-session-client-CHE8QpVE.d.ts} +75 -5
- package/dist/{multi-session-client-CzhMkE0k.d.mts → multi-session-client-CQsRbxYI.d.mts} +75 -5
- package/dist/server/index.d.mts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +394 -90
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +350 -91
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.js +10 -2
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +10 -2
- package/dist/shared/index.mjs.map +1 -1
- package/package.json +19 -6
- package/src/adapters/agui-adapter.ts +222 -222
- package/src/adapters/ai-adapter.ts +115 -115
- package/src/adapters/langchain-adapter.ts +127 -127
- package/src/adapters/mastra-adapter.ts +126 -126
- package/src/bin/mcp-ts.ts +102 -0
- package/src/server/handlers/nextjs-handler.ts +12 -12
- package/src/server/handlers/sse-handler.ts +61 -61
- package/src/server/mcp/multi-session-client.ts +135 -39
- package/src/server/storage/file-backend.ts +4 -16
- package/src/server/storage/index.ts +68 -25
- package/src/server/storage/memory-backend.ts +7 -16
- package/src/server/storage/redis-backend.ts +12 -16
- package/src/server/storage/sqlite-backend.ts +3 -6
- package/src/server/storage/supabase-backend.ts +228 -0
- package/src/shared/event-routing.ts +28 -28
- package/src/shared/utils.ts +22 -0
- package/supabase/migrations/20260330195700_install_mcp_sessions.sql +84 -0
|
@@ -367,25 +367,95 @@ interface MultiSessionOptions {
|
|
|
367
367
|
retryDelay?: number;
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
|
-
* Manages multiple MCP connections for a single user identity.
|
|
371
|
-
*
|
|
370
|
+
* Manages multiple MCP client connections for a single user identity.
|
|
371
|
+
*
|
|
372
|
+
* On a traditional long-running server, you can cache this instance per user
|
|
373
|
+
* so the connections stay alive between requests. On serverless, a new instance
|
|
374
|
+
* will be created per invocation, but the underlying session data is always
|
|
375
|
+
* read from the storage backend so nothing is lost between calls.
|
|
372
376
|
*/
|
|
373
377
|
declare class MultiSessionClient {
|
|
374
378
|
private clients;
|
|
375
379
|
private identity;
|
|
376
380
|
private options;
|
|
381
|
+
/**
|
|
382
|
+
* Creates a new MultiSessionClient for the given user identity.
|
|
383
|
+
*
|
|
384
|
+
* @param identity - A unique string identifying the user (e.g. user ID or email).
|
|
385
|
+
* @param options - Optional tuning for connection timeout, retry count, and retry delay.
|
|
386
|
+
* Falls back to sensible defaults if not provided.
|
|
387
|
+
*/
|
|
377
388
|
constructor(identity: string, options?: MultiSessionOptions);
|
|
389
|
+
/**
|
|
390
|
+
* Fetches all sessions for this identity from storage and returns only the
|
|
391
|
+
* ones that are ready to connect.
|
|
392
|
+
*
|
|
393
|
+
* A session is considered connectable when:
|
|
394
|
+
* - It has a `serverId`, `serverUrl`, and `callbackUrl` (i.e. it was fully initialized)
|
|
395
|
+
* - Its `active` flag is not explicitly `false` — sessions with `active: false` are
|
|
396
|
+
* either mid-OAuth flow, auth-pending, or previously failed. We skip those here
|
|
397
|
+
* and let the OAuth flow complete separately before we try to reconnect them.
|
|
398
|
+
*
|
|
399
|
+
* Note: Sessions where `active` is `undefined` (legacy records) are included
|
|
400
|
+
* for backwards compatibility.
|
|
401
|
+
*/
|
|
378
402
|
private getActiveSessions;
|
|
403
|
+
/**
|
|
404
|
+
* Connects to a list of sessions in controlled batches of `CONNECTION_BATCH_SIZE`.
|
|
405
|
+
*
|
|
406
|
+
* Batching prevents overwhelming the event loop or external servers when a user
|
|
407
|
+
* has many active MCP sessions (e.g. 20+ servers). Within each batch, sessions
|
|
408
|
+
* are connected concurrently using `Promise.all` for speed.
|
|
409
|
+
*/
|
|
379
410
|
private connectInBatches;
|
|
411
|
+
private connectionPromises;
|
|
412
|
+
/**
|
|
413
|
+
* Connects a single session, with built-in deduplication to prevent race conditions.
|
|
414
|
+
*
|
|
415
|
+
* - If a client for this session already exists and is connected, returns immediately.
|
|
416
|
+
* - If a connection attempt for this session is already in-flight (e.g. from a
|
|
417
|
+
* concurrent call), it joins the existing promise instead of starting a new one.
|
|
418
|
+
* This is the key concurrency lock — the `connectionPromises` map acts as a
|
|
419
|
+
* per-session mutex so we never spin up two physical connections for the same session.
|
|
420
|
+
* - On completion (success or failure), the promise is cleaned up from the map.
|
|
421
|
+
*/
|
|
380
422
|
private connectSession;
|
|
381
|
-
|
|
423
|
+
/**
|
|
424
|
+
* The core connection loop for a single session.
|
|
425
|
+
*
|
|
426
|
+
* Attempts to establish a physical MCP connection, retrying up to `maxRetries` times
|
|
427
|
+
* if the connection fails. Each attempt:
|
|
428
|
+
* 1. Creates a fresh `MCPClient` instance from the session data.
|
|
429
|
+
* 2. Races the connect call against a timeout promise — if the server doesn't respond
|
|
430
|
+
* within `timeoutMs`, the attempt is aborted and counted as a failure.
|
|
431
|
+
* 3. On success, replaces any stale client entry for this session in the `clients` array.
|
|
432
|
+
* 4. On failure, waits `retryDelay` ms before the next attempt.
|
|
433
|
+
*
|
|
434
|
+
* If all attempts are exhausted, logs an error and returns silently (does not throw),
|
|
435
|
+
* so a single bad server doesn't block the rest of the batch from connecting.
|
|
436
|
+
*/
|
|
437
|
+
private establishConnectionWithRetries;
|
|
438
|
+
/**
|
|
439
|
+
* The main entry point. Fetches all active sessions for this identity from
|
|
440
|
+
* storage and establishes connections to all of them in batches.
|
|
441
|
+
*
|
|
442
|
+
* Call this once after creating the client. On traditional servers, you can
|
|
443
|
+
* cache the `MultiSessionClient` instance after calling `connect()` to avoid
|
|
444
|
+
* re-fetching and re-connecting on every request.
|
|
445
|
+
*/
|
|
382
446
|
connect(): Promise<void>;
|
|
383
447
|
/**
|
|
384
|
-
* Returns
|
|
448
|
+
* Returns all currently connected `MCPClient` instances.
|
|
449
|
+
*
|
|
450
|
+
* Use this to enumerate available tools across all connected servers,
|
|
451
|
+
* or to route a tool call to the right client by `serverId`.
|
|
385
452
|
*/
|
|
386
453
|
getClients(): MCPClient[];
|
|
387
454
|
/**
|
|
388
|
-
*
|
|
455
|
+
* Gracefully disconnects all active MCP clients and clears the internal client list.
|
|
456
|
+
*
|
|
457
|
+
* Call this during server shutdown or when a user logs out to free up
|
|
458
|
+
* underlying transport resources (SSE streams, HTTP connections, etc.).
|
|
389
459
|
*/
|
|
390
460
|
disconnect(): void;
|
|
391
461
|
}
|
|
@@ -367,25 +367,95 @@ interface MultiSessionOptions {
|
|
|
367
367
|
retryDelay?: number;
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
|
-
* Manages multiple MCP connections for a single user identity.
|
|
371
|
-
*
|
|
370
|
+
* Manages multiple MCP client connections for a single user identity.
|
|
371
|
+
*
|
|
372
|
+
* On a traditional long-running server, you can cache this instance per user
|
|
373
|
+
* so the connections stay alive between requests. On serverless, a new instance
|
|
374
|
+
* will be created per invocation, but the underlying session data is always
|
|
375
|
+
* read from the storage backend so nothing is lost between calls.
|
|
372
376
|
*/
|
|
373
377
|
declare class MultiSessionClient {
|
|
374
378
|
private clients;
|
|
375
379
|
private identity;
|
|
376
380
|
private options;
|
|
381
|
+
/**
|
|
382
|
+
* Creates a new MultiSessionClient for the given user identity.
|
|
383
|
+
*
|
|
384
|
+
* @param identity - A unique string identifying the user (e.g. user ID or email).
|
|
385
|
+
* @param options - Optional tuning for connection timeout, retry count, and retry delay.
|
|
386
|
+
* Falls back to sensible defaults if not provided.
|
|
387
|
+
*/
|
|
377
388
|
constructor(identity: string, options?: MultiSessionOptions);
|
|
389
|
+
/**
|
|
390
|
+
* Fetches all sessions for this identity from storage and returns only the
|
|
391
|
+
* ones that are ready to connect.
|
|
392
|
+
*
|
|
393
|
+
* A session is considered connectable when:
|
|
394
|
+
* - It has a `serverId`, `serverUrl`, and `callbackUrl` (i.e. it was fully initialized)
|
|
395
|
+
* - Its `active` flag is not explicitly `false` — sessions with `active: false` are
|
|
396
|
+
* either mid-OAuth flow, auth-pending, or previously failed. We skip those here
|
|
397
|
+
* and let the OAuth flow complete separately before we try to reconnect them.
|
|
398
|
+
*
|
|
399
|
+
* Note: Sessions where `active` is `undefined` (legacy records) are included
|
|
400
|
+
* for backwards compatibility.
|
|
401
|
+
*/
|
|
378
402
|
private getActiveSessions;
|
|
403
|
+
/**
|
|
404
|
+
* Connects to a list of sessions in controlled batches of `CONNECTION_BATCH_SIZE`.
|
|
405
|
+
*
|
|
406
|
+
* Batching prevents overwhelming the event loop or external servers when a user
|
|
407
|
+
* has many active MCP sessions (e.g. 20+ servers). Within each batch, sessions
|
|
408
|
+
* are connected concurrently using `Promise.all` for speed.
|
|
409
|
+
*/
|
|
379
410
|
private connectInBatches;
|
|
411
|
+
private connectionPromises;
|
|
412
|
+
/**
|
|
413
|
+
* Connects a single session, with built-in deduplication to prevent race conditions.
|
|
414
|
+
*
|
|
415
|
+
* - If a client for this session already exists and is connected, returns immediately.
|
|
416
|
+
* - If a connection attempt for this session is already in-flight (e.g. from a
|
|
417
|
+
* concurrent call), it joins the existing promise instead of starting a new one.
|
|
418
|
+
* This is the key concurrency lock — the `connectionPromises` map acts as a
|
|
419
|
+
* per-session mutex so we never spin up two physical connections for the same session.
|
|
420
|
+
* - On completion (success or failure), the promise is cleaned up from the map.
|
|
421
|
+
*/
|
|
380
422
|
private connectSession;
|
|
381
|
-
|
|
423
|
+
/**
|
|
424
|
+
* The core connection loop for a single session.
|
|
425
|
+
*
|
|
426
|
+
* Attempts to establish a physical MCP connection, retrying up to `maxRetries` times
|
|
427
|
+
* if the connection fails. Each attempt:
|
|
428
|
+
* 1. Creates a fresh `MCPClient` instance from the session data.
|
|
429
|
+
* 2. Races the connect call against a timeout promise — if the server doesn't respond
|
|
430
|
+
* within `timeoutMs`, the attempt is aborted and counted as a failure.
|
|
431
|
+
* 3. On success, replaces any stale client entry for this session in the `clients` array.
|
|
432
|
+
* 4. On failure, waits `retryDelay` ms before the next attempt.
|
|
433
|
+
*
|
|
434
|
+
* If all attempts are exhausted, logs an error and returns silently (does not throw),
|
|
435
|
+
* so a single bad server doesn't block the rest of the batch from connecting.
|
|
436
|
+
*/
|
|
437
|
+
private establishConnectionWithRetries;
|
|
438
|
+
/**
|
|
439
|
+
* The main entry point. Fetches all active sessions for this identity from
|
|
440
|
+
* storage and establishes connections to all of them in batches.
|
|
441
|
+
*
|
|
442
|
+
* Call this once after creating the client. On traditional servers, you can
|
|
443
|
+
* cache the `MultiSessionClient` instance after calling `connect()` to avoid
|
|
444
|
+
* re-fetching and re-connecting on every request.
|
|
445
|
+
*/
|
|
382
446
|
connect(): Promise<void>;
|
|
383
447
|
/**
|
|
384
|
-
* Returns
|
|
448
|
+
* Returns all currently connected `MCPClient` instances.
|
|
449
|
+
*
|
|
450
|
+
* Use this to enumerate available tools across all connected servers,
|
|
451
|
+
* or to route a tool call to the right client by `serverId`.
|
|
385
452
|
*/
|
|
386
453
|
getClients(): MCPClient[];
|
|
387
454
|
/**
|
|
388
|
-
*
|
|
455
|
+
* Gracefully disconnects all active MCP clients and clears the internal client list.
|
|
456
|
+
*
|
|
457
|
+
* Call this during server shutdown or when a user logs out to free up
|
|
458
|
+
* underlying transport resources (SSE streams, HTTP connections, etc.).
|
|
389
459
|
*/
|
|
390
460
|
disconnect(): void;
|
|
391
461
|
}
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { M as MCPClient, a as MultiSessionClient, S as StorageOAuthClientProvider } from '../multi-session-client-
|
|
1
|
+
export { M as MCPClient, a as MultiSessionClient, S as StorageOAuthClientProvider } from '../multi-session-client-CQsRbxYI.mjs';
|
|
2
2
|
export { U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-0qmYrqoa.mjs';
|
|
3
3
|
import { OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
4
4
|
export { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { M as MCPClient, a as MultiSessionClient, S as StorageOAuthClientProvider } from '../multi-session-client-
|
|
1
|
+
export { M as MCPClient, a as MultiSessionClient, S as StorageOAuthClientProvider } from '../multi-session-client-CHE8QpVE.js';
|
|
2
2
|
export { U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-0qmYrqoa.js';
|
|
3
3
|
import { OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
4
4
|
export { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|