@mcp-ts/sdk 2.4.1 → 2.4.3
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 +3 -4
- package/dist/adapters/agui-adapter.d.ts +3 -4
- package/dist/adapters/agui-middleware.d.mts +3 -4
- package/dist/adapters/agui-middleware.d.ts +3 -4
- package/dist/adapters/ai-adapter.d.mts +3 -4
- package/dist/adapters/ai-adapter.d.ts +3 -4
- package/dist/adapters/langchain-adapter.d.mts +3 -4
- package/dist/adapters/langchain-adapter.d.ts +3 -4
- package/dist/adapters/mastra-adapter.d.mts +2 -2
- package/dist/adapters/mastra-adapter.d.ts +2 -2
- package/dist/bin/mcp-ts.js +5 -5
- package/dist/bin/mcp-ts.js.map +1 -1
- package/dist/bin/mcp-ts.mjs +5 -5
- package/dist/bin/mcp-ts.mjs.map +1 -1
- package/dist/client/index.d.mts +2 -3
- package/dist/client/index.d.ts +2 -3
- package/dist/client/react.d.mts +4 -6
- package/dist/client/react.d.ts +4 -6
- package/dist/client/vue.d.mts +4 -6
- package/dist/client/vue.d.ts +4 -6
- package/dist/{index-Ch7ouNSa.d.ts → index-B8kJSrBJ.d.ts} +1 -2
- package/dist/{index-L5XoXgsb.d.mts → index-DiJsm_lK.d.mts} +1 -2
- package/dist/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +174 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +174 -110
- package/dist/index.mjs.map +1 -1
- package/dist/{multi-session-client-k-9RvWvi.d.mts → multi-session-client-B6hsYO8V.d.mts} +218 -71
- package/dist/{multi-session-client-Bwm-efqg.d.ts → multi-session-client-DOBvtaQV.d.ts} +218 -71
- package/dist/server/index.d.mts +5 -128
- package/dist/server/index.d.ts +5 -128
- package/dist/server/index.js +174 -110
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +174 -110
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.d.mts +4 -5
- package/dist/shared/index.d.ts +4 -5
- package/dist/{tool-router-CuApsDiV.d.mts → tool-router-CbG4Tum6.d.mts} +1 -1
- package/dist/{tool-router-CZMrOG8J.d.ts → tool-router-ChIhPwgP.d.ts} +1 -1
- package/dist/{types-DCk_IF4L.d.mts → types-CjczQwNX.d.mts} +122 -1
- package/dist/{types-DCk_IF4L.d.ts → types-CjczQwNX.d.ts} +122 -1
- package/package.json +1 -1
- package/src/bin/mcp-ts.ts +5 -5
- package/src/server/mcp/multi-session-client.ts +190 -132
- package/src/server/mcp/oauth-client.ts +49 -7
- package/src/server/storage/index.ts +8 -8
- package/dist/events-C4m7tK1U.d.mts +0 -122
- package/dist/events-C4m7tK1U.d.ts +0 -122
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as Event, M as McpConnectionEvent, t as McpObservabilityEvent, s as McpConnectionState, A as ToolClientProvider } from './types-CjczQwNX.js';
|
|
2
2
|
import { ListToolsResult, CallToolResult, ListPromptsResult, GetPromptResult, ListResourcesResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
4
4
|
import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
@@ -264,6 +264,17 @@ declare class MCPClient {
|
|
|
264
264
|
* @throws {Error} When client is not connected
|
|
265
265
|
*/
|
|
266
266
|
readResource(uri: string): Promise<ReadResourceResult>;
|
|
267
|
+
/**
|
|
268
|
+
* Wraps an MCP request with automatic transport-session recovery.
|
|
269
|
+
*
|
|
270
|
+
* When the downstream MCP server rejects the request with a 404 indicating
|
|
271
|
+
* the transport session has expired, this method tears down the stale SDK
|
|
272
|
+
* client and transport, calls {@link reconnect} to negotiate a fresh session,
|
|
273
|
+
* and retries the request once.
|
|
274
|
+
*
|
|
275
|
+
* Non-transient errors (network failures, auth errors, etc.) propagate as-is.
|
|
276
|
+
*/
|
|
277
|
+
private withRetry;
|
|
267
278
|
/**
|
|
268
279
|
* Reconnects to MCP server using existing OAuth provider from Redis
|
|
269
280
|
* Used for session restoration in serverless environments
|
|
@@ -328,102 +339,192 @@ declare class MCPClient {
|
|
|
328
339
|
getSessionId(): string;
|
|
329
340
|
}
|
|
330
341
|
|
|
342
|
+
interface OAuthState {
|
|
343
|
+
nonce: string;
|
|
344
|
+
sessionId: string;
|
|
345
|
+
serverId: string;
|
|
346
|
+
createdAt: number;
|
|
347
|
+
}
|
|
348
|
+
type SessionStatus = 'pending' | 'active';
|
|
349
|
+
interface Session {
|
|
350
|
+
sessionId: string;
|
|
351
|
+
serverId?: string;
|
|
352
|
+
serverName?: string;
|
|
353
|
+
serverUrl: string;
|
|
354
|
+
transportType: 'sse' | 'streamable-http';
|
|
355
|
+
callbackUrl: string;
|
|
356
|
+
createdAt: number;
|
|
357
|
+
updatedAt?: number;
|
|
358
|
+
/**
|
|
359
|
+
* Storage-owned expiration timestamp for pending/inactive sessions.
|
|
360
|
+
* Active sessions use updatedAt-based dormancy cleanup instead.
|
|
361
|
+
*/
|
|
362
|
+
expiresAt?: number | null;
|
|
363
|
+
userId: string;
|
|
364
|
+
headers?: Record<string, string>;
|
|
365
|
+
authUrl?: string | null;
|
|
366
|
+
/**
|
|
367
|
+
* Session status marker used for lifecycle cleanup:
|
|
368
|
+
* - pending: short-lived intermediate/auth-pending session state
|
|
369
|
+
* - active: restorable session after successful connection/auth completion
|
|
370
|
+
*/
|
|
371
|
+
status?: SessionStatus;
|
|
372
|
+
}
|
|
373
|
+
interface SessionCredentials {
|
|
374
|
+
sessionId: string;
|
|
375
|
+
userId: string;
|
|
376
|
+
clientInformation?: OAuthClientInformationMixed | null;
|
|
377
|
+
tokens?: OAuthTokens | null;
|
|
378
|
+
codeVerifier?: string | null;
|
|
379
|
+
clientId?: string | null;
|
|
380
|
+
oauthState?: OAuthState | null;
|
|
381
|
+
}
|
|
382
|
+
type SessionMutationType = 'create' | 'update' | 'delete';
|
|
383
|
+
interface SessionMutationEvent {
|
|
384
|
+
type: SessionMutationType;
|
|
385
|
+
userId: string;
|
|
386
|
+
sessionId: string;
|
|
387
|
+
timestamp: number;
|
|
388
|
+
session?: Session;
|
|
389
|
+
patch?: Partial<Session>;
|
|
390
|
+
}
|
|
391
|
+
type SessionMutationListener = (event: SessionMutationEvent) => void | Promise<void>;
|
|
331
392
|
/**
|
|
332
|
-
*
|
|
333
|
-
* Allows aggregating tools from all connected servers.
|
|
393
|
+
* Interface for MCP session stores.
|
|
334
394
|
*/
|
|
395
|
+
interface SessionStore {
|
|
396
|
+
/**
|
|
397
|
+
* Optional initialization (e.g., database connection)
|
|
398
|
+
*/
|
|
399
|
+
init?(): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* Generates a unique session ID
|
|
402
|
+
*/
|
|
403
|
+
generateSessionId(): string;
|
|
404
|
+
/**
|
|
405
|
+
* Creates a new session. Throws if session already exists.
|
|
406
|
+
* @param session - Session data to create
|
|
407
|
+
*/
|
|
408
|
+
create(session: Session): Promise<void>;
|
|
409
|
+
/**
|
|
410
|
+
* Updates an existing session with partial data. Throws if session does not exist.
|
|
411
|
+
* @param userId - User identifier
|
|
412
|
+
* @param sessionId - Session identifier
|
|
413
|
+
* @param data - Partial session data to update
|
|
414
|
+
*/
|
|
415
|
+
update(userId: string, sessionId: string, data: Partial<Session>): Promise<void>;
|
|
416
|
+
/**
|
|
417
|
+
* Patches runtime credentials for an existing session.
|
|
418
|
+
* These values are separated from connection metadata in durable SQL stores.
|
|
419
|
+
*/
|
|
420
|
+
patchCredentials(userId: string, sessionId: string, data: Partial<SessionCredentials>): Promise<void>;
|
|
421
|
+
/**
|
|
422
|
+
* Retrieves a session
|
|
423
|
+
*/
|
|
424
|
+
get(userId: string, sessionId: string): Promise<Session | null>;
|
|
425
|
+
/**
|
|
426
|
+
* Retrieves runtime credentials for a session.
|
|
427
|
+
*/
|
|
428
|
+
getCredentials(userId: string, sessionId: string): Promise<SessionCredentials | null>;
|
|
429
|
+
/**
|
|
430
|
+
* Clears runtime credentials without removing connection metadata.
|
|
431
|
+
*/
|
|
432
|
+
clearCredentials(userId: string, sessionId: string): Promise<void>;
|
|
433
|
+
/**
|
|
434
|
+
* Gets full session data for all sessions owned by a user
|
|
435
|
+
*/
|
|
436
|
+
list(userId: string): Promise<Session[]>;
|
|
437
|
+
/**
|
|
438
|
+
* Removes a session
|
|
439
|
+
*/
|
|
440
|
+
delete(userId: string, sessionId: string): Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* Gets all session IDs owned by a user
|
|
443
|
+
*/
|
|
444
|
+
listIds(userId: string): Promise<string[]>;
|
|
445
|
+
/**
|
|
446
|
+
* Gets all session IDs across all users (Admin)
|
|
447
|
+
*/
|
|
448
|
+
listAllIds(): Promise<string[]>;
|
|
449
|
+
/**
|
|
450
|
+
* Clears all sessions (Admin)
|
|
451
|
+
*/
|
|
452
|
+
clearAll(): Promise<void>;
|
|
453
|
+
/**
|
|
454
|
+
* Clean up expired sessions
|
|
455
|
+
*/
|
|
456
|
+
cleanupExpired(): Promise<void>;
|
|
457
|
+
/**
|
|
458
|
+
* Disconnect from storage backend
|
|
459
|
+
*/
|
|
460
|
+
disconnect(): Promise<void>;
|
|
461
|
+
}
|
|
462
|
+
|
|
335
463
|
interface MultiSessionOptions {
|
|
336
464
|
/**
|
|
337
|
-
* Connection timeout in milliseconds
|
|
465
|
+
* Connection timeout in milliseconds.
|
|
338
466
|
* @default 15000
|
|
339
467
|
*/
|
|
340
468
|
timeout?: number;
|
|
341
469
|
/**
|
|
342
|
-
* Maximum number of retry attempts
|
|
470
|
+
* Maximum number of retry attempts per session.
|
|
343
471
|
* @default 2
|
|
344
472
|
*/
|
|
345
473
|
maxRetries?: number;
|
|
346
474
|
/**
|
|
347
|
-
* Delay between
|
|
475
|
+
* Delay between retry attempts in milliseconds.
|
|
348
476
|
* @default 1000
|
|
349
477
|
*/
|
|
350
478
|
retryDelay?: number;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Manages multiple MCP client connections for a single user.
|
|
354
|
-
*
|
|
355
|
-
* On a traditional long-running server, you can cache this instance per user
|
|
356
|
-
* so the connections stay alive between requests. On serverless, a new instance
|
|
357
|
-
* will be created per invocation, but the underlying session data is always
|
|
358
|
-
* read from the storage backend so nothing is lost between calls.
|
|
359
|
-
*/
|
|
360
|
-
declare class MultiSessionClient {
|
|
361
|
-
private clients;
|
|
362
|
-
private userId;
|
|
363
|
-
private options;
|
|
364
479
|
/**
|
|
365
|
-
*
|
|
480
|
+
* Custom session provider. When provided, `connect()` calls this
|
|
481
|
+
* instead of querying the storage backend. Useful when sessions are
|
|
482
|
+
* synced externally (e.g. via Supabase Realtime, WebSocket, or an
|
|
483
|
+
* in-memory cache).
|
|
366
484
|
*
|
|
367
|
-
*
|
|
368
|
-
* @param options - Optional tuning for connection timeout, retry count, and retry delay.
|
|
369
|
-
* Falls back to sensible defaults if not provided.
|
|
485
|
+
* Default: reads from the storage backend via `sessions.list(userId)`.
|
|
370
486
|
*/
|
|
371
|
-
|
|
487
|
+
sessionProvider?: () => Promise<Session[]>;
|
|
372
488
|
/**
|
|
373
|
-
*
|
|
374
|
-
* ones that are ready to connect.
|
|
375
|
-
*
|
|
376
|
-
* A session is considered connectable when:
|
|
377
|
-
* - It has a `serverId`, `serverUrl`, and `callbackUrl` (i.e. it was fully initialized)
|
|
378
|
-
* - Its status is `active`. Pending sessions are skipped here
|
|
379
|
-
* and let the OAuth flow complete separately before we try to reconnect them.
|
|
489
|
+
* Called after a session is successfully connected.
|
|
380
490
|
*/
|
|
381
|
-
|
|
491
|
+
onSessionConnected?: (sessionId: string, client: MCPClient) => void;
|
|
382
492
|
/**
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
* Batching prevents overwhelming the event loop or external servers when a user
|
|
386
|
-
* has many active MCP sessions (e.g. 20+ servers). Within each batch, sessions
|
|
387
|
-
* are connected concurrently using `Promise.all` for speed.
|
|
493
|
+
* Called when a session is evicted from the in-memory client list
|
|
494
|
+
* because it no longer exists in the active sessions list.
|
|
388
495
|
*/
|
|
389
|
-
|
|
390
|
-
private connectionPromises;
|
|
496
|
+
onSessionEvicted?: (sessionId: string) => void;
|
|
391
497
|
/**
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
* - If a client for this session already exists and is connected, returns immediately.
|
|
395
|
-
* - If the existing client entry is no longer connected (e.g. it was explicitly
|
|
396
|
-
* disconnected), it is evicted so that `establishConnectionWithRetries` creates a
|
|
397
|
-
* fresh transport — preventing "Client already connected" errors from the SDK.
|
|
398
|
-
* - If a connection attempt for this session is already in-flight (e.g. from a
|
|
399
|
-
* concurrent call), it joins the existing promise instead of starting a new one.
|
|
400
|
-
* This is the key concurrency lock — the `connectionPromises` map acts as a
|
|
401
|
-
* per-session mutex so we never spin up two physical connections for the same session.
|
|
402
|
-
* - On completion (success or failure), the promise is cleaned up from the map.
|
|
498
|
+
* Called when all retry attempts for a session have been exhausted.
|
|
403
499
|
*/
|
|
404
|
-
|
|
500
|
+
onSessionFailed?: (sessionId: string, error: unknown) => void;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Manages multiple MCP client connections for a single user.
|
|
504
|
+
*
|
|
505
|
+
* Cached instances stay alive between requests on long-running servers.
|
|
506
|
+
* On serverless, the underlying session data persists in storage — the
|
|
507
|
+
* client rehydrates from `sessionProvider` (or the default storage backend)
|
|
508
|
+
* each time `connect()` is called.
|
|
509
|
+
*
|
|
510
|
+
* @implements {ToolClientProvider}
|
|
511
|
+
*/
|
|
512
|
+
declare class MultiSessionClient implements ToolClientProvider {
|
|
513
|
+
private clients;
|
|
514
|
+
private connectionPromises;
|
|
515
|
+
private userId;
|
|
516
|
+
private options;
|
|
405
517
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* Attempts to establish a physical MCP connection, retrying up to `maxRetries` times
|
|
409
|
-
* if the connection fails. Each attempt:
|
|
410
|
-
* 1. Creates a fresh `MCPClient` instance from the session data.
|
|
411
|
-
* 2. Races the connect call against a timeout promise — if the server doesn't respond
|
|
412
|
-
* within `timeoutMs`, the attempt is aborted and counted as a failure.
|
|
413
|
-
* 3. On success, replaces any stale client entry for this session in the `clients` array.
|
|
414
|
-
* 4. On failure, waits `retryDelay` ms before the next attempt.
|
|
415
|
-
*
|
|
416
|
-
* If all attempts are exhausted, logs an error and returns silently (does not throw),
|
|
417
|
-
* so a single bad server doesn't block the rest of the batch from connecting.
|
|
518
|
+
* @param userId - Unique identifier for the user (e.g. user ID or email).
|
|
519
|
+
* @param options - Optional tuning and lifecycle hooks.
|
|
418
520
|
*/
|
|
419
|
-
|
|
521
|
+
constructor(userId: string, options?: MultiSessionOptions);
|
|
420
522
|
/**
|
|
421
|
-
*
|
|
422
|
-
* storage and establishes connections to all of them in batches.
|
|
523
|
+
* Fetches active sessions and establishes connections to all of them.
|
|
423
524
|
*
|
|
424
|
-
* Call this once after creating the client. On
|
|
425
|
-
* cache the `MultiSessionClient` instance
|
|
426
|
-
*
|
|
525
|
+
* Call this once after creating the client. On long-running servers you
|
|
526
|
+
* can cache the `MultiSessionClient` instance and call `connect()` on
|
|
527
|
+
* each request — already-connected sessions are skipped internally.
|
|
427
528
|
*/
|
|
428
529
|
connect(): Promise<void>;
|
|
429
530
|
/**
|
|
@@ -445,7 +546,13 @@ declare class MultiSessionClient {
|
|
|
445
546
|
*/
|
|
446
547
|
getClients(): MCPClient[];
|
|
447
548
|
/**
|
|
448
|
-
*
|
|
549
|
+
* Removes and disconnects a single session by ID.
|
|
550
|
+
*
|
|
551
|
+
* @returns `true` if the session was found and removed, `false` if not found.
|
|
552
|
+
*/
|
|
553
|
+
removeSession(sessionId: string): Promise<boolean>;
|
|
554
|
+
/**
|
|
555
|
+
* Gracefully disconnects all active MCP clients and clears the internal list.
|
|
449
556
|
*
|
|
450
557
|
* For Streamable HTTP sessions, each client sends an HTTP DELETE to its MCP
|
|
451
558
|
* endpoint per the spec before closing locally. All disconnects run in
|
|
@@ -455,6 +562,46 @@ declare class MultiSessionClient {
|
|
|
455
562
|
* underlying transport resources (SSE streams, HTTP connections, etc.).
|
|
456
563
|
*/
|
|
457
564
|
disconnect(): Promise<void>;
|
|
565
|
+
/**
|
|
566
|
+
* Resolves the list of sessions to connect.
|
|
567
|
+
*
|
|
568
|
+
* Uses the custom `sessionProvider` when provided, otherwise falls back
|
|
569
|
+
* to querying the storage backend via `sessions.list(userId)`.
|
|
570
|
+
*/
|
|
571
|
+
private fetchActiveSessions;
|
|
572
|
+
/**
|
|
573
|
+
* Connects a list of sessions in controlled batches.
|
|
574
|
+
*
|
|
575
|
+
* Batching prevents overwhelming the event loop or external servers when
|
|
576
|
+
* a user has many active MCP sessions. Within each batch, sessions are
|
|
577
|
+
* connected concurrently using `Promise.all`.
|
|
578
|
+
*/
|
|
579
|
+
private connectInBatches;
|
|
580
|
+
/**
|
|
581
|
+
* Connects a single session, with deduplication to prevent race conditions.
|
|
582
|
+
*
|
|
583
|
+
* - If a client for this session already exists and is connected, returns
|
|
584
|
+
* immediately.
|
|
585
|
+
* - If the existing client entry is no longer connected (e.g. explicit
|
|
586
|
+
* disconnect), it is evicted so a fresh transport is created.
|
|
587
|
+
* - If a connection attempt for this session is already in-flight, the
|
|
588
|
+
* existing promise is reused as a per-session mutex.
|
|
589
|
+
* - On completion (success or failure), the promise is cleaned up from
|
|
590
|
+
* the connectionPromises map.
|
|
591
|
+
*/
|
|
592
|
+
private connectSession;
|
|
593
|
+
/**
|
|
594
|
+
* Core connection loop for a single session with retry logic.
|
|
595
|
+
*
|
|
596
|
+
* 1. Creates a fresh `MCPClient` from the session data.
|
|
597
|
+
* 2. Races `client.connect()` against a timeout.
|
|
598
|
+
* 3. On success, replaces any stale entry and fires `onSessionConnected`.
|
|
599
|
+
* 4. On failure, waits `retryDelay` ms before the next attempt.
|
|
600
|
+
*
|
|
601
|
+
* If all attempts are exhausted, logs an error and returns silently so
|
|
602
|
+
* a single bad server doesn't block the rest of the batch.
|
|
603
|
+
*/
|
|
604
|
+
private establishConnectionWithRetries;
|
|
458
605
|
}
|
|
459
606
|
|
|
460
|
-
export { MCPClient as M,
|
|
607
|
+
export { MCPClient as M, type Session as S, MultiSessionClient as a, type SessionMutationEvent as b, type SessionMutationListener as c, type SessionMutationType as d, type SessionStore as e, StorageOAuthClientProvider as f };
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,135 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { c as SessionMutationListener, e as SessionStore } from '../multi-session-client-B6hsYO8V.mjs';
|
|
2
|
+
export { M as MCPClient, a as MultiSessionClient, S as Session, b as SessionMutationEvent, d as SessionMutationType, f as StorageOAuthClientProvider } from '../multi-session-client-B6hsYO8V.mjs';
|
|
2
3
|
export { U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-DELRKQPU.mjs';
|
|
3
|
-
import {
|
|
4
|
+
import { M as McpConnectionEvent, t as McpObservabilityEvent, x as McpRpcResponse, w as McpRpcRequest } from '../types-CjczQwNX.mjs';
|
|
5
|
+
export { a as CallToolRequest, b as CallToolResponse, f as ConnectRequest, g as ConnectResponse, k as Disposable, E as Emitter, m as Event, q as ListToolsResponse, s as McpConnectionState, T as ToolClient, A as ToolClientProvider, B as ToolInfo } from '../types-CjczQwNX.mjs';
|
|
4
6
|
export { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
|
-
import { M as McpConnectionEvent, d as McpObservabilityEvent } from '../events-C4m7tK1U.mjs';
|
|
6
|
-
export { D as Disposable, E as Emitter, b as Event, c as McpConnectionState } from '../events-C4m7tK1U.mjs';
|
|
7
|
-
import { r as McpRpcResponse, q as McpRpcRequest } from '../types-DCk_IF4L.mjs';
|
|
8
|
-
export { a as CallToolRequest, b as CallToolResponse, f as ConnectRequest, g as ConnectResponse, n as ListToolsResponse, T as ToolClient, u as ToolClientProvider, v as ToolInfo } from '../types-DCk_IF4L.mjs';
|
|
9
7
|
export { CallToolResult, ListToolsResult, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
10
8
|
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
11
9
|
|
|
12
|
-
interface OAuthState {
|
|
13
|
-
nonce: string;
|
|
14
|
-
sessionId: string;
|
|
15
|
-
serverId: string;
|
|
16
|
-
createdAt: number;
|
|
17
|
-
}
|
|
18
|
-
type SessionStatus = 'pending' | 'active';
|
|
19
|
-
interface Session {
|
|
20
|
-
sessionId: string;
|
|
21
|
-
serverId?: string;
|
|
22
|
-
serverName?: string;
|
|
23
|
-
serverUrl: string;
|
|
24
|
-
transportType: 'sse' | 'streamable-http';
|
|
25
|
-
callbackUrl: string;
|
|
26
|
-
createdAt: number;
|
|
27
|
-
updatedAt?: number;
|
|
28
|
-
/**
|
|
29
|
-
* Storage-owned expiration timestamp for pending/inactive sessions.
|
|
30
|
-
* Active sessions use updatedAt-based dormancy cleanup instead.
|
|
31
|
-
*/
|
|
32
|
-
expiresAt?: number | null;
|
|
33
|
-
userId: string;
|
|
34
|
-
headers?: Record<string, string>;
|
|
35
|
-
authUrl?: string | null;
|
|
36
|
-
/**
|
|
37
|
-
* Session status marker used for lifecycle cleanup:
|
|
38
|
-
* - pending: short-lived intermediate/auth-pending session state
|
|
39
|
-
* - active: restorable session after successful connection/auth completion
|
|
40
|
-
*/
|
|
41
|
-
status?: SessionStatus;
|
|
42
|
-
}
|
|
43
|
-
interface SessionCredentials {
|
|
44
|
-
sessionId: string;
|
|
45
|
-
userId: string;
|
|
46
|
-
clientInformation?: OAuthClientInformationMixed | null;
|
|
47
|
-
tokens?: OAuthTokens | null;
|
|
48
|
-
codeVerifier?: string | null;
|
|
49
|
-
clientId?: string | null;
|
|
50
|
-
oauthState?: OAuthState | null;
|
|
51
|
-
}
|
|
52
|
-
type SessionMutationType = 'create' | 'update' | 'delete';
|
|
53
|
-
interface SessionMutationEvent {
|
|
54
|
-
type: SessionMutationType;
|
|
55
|
-
userId: string;
|
|
56
|
-
sessionId: string;
|
|
57
|
-
timestamp: number;
|
|
58
|
-
session?: Session;
|
|
59
|
-
patch?: Partial<Session>;
|
|
60
|
-
}
|
|
61
|
-
type SessionMutationListener = (event: SessionMutationEvent) => void | Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Interface for MCP session stores.
|
|
64
|
-
*/
|
|
65
|
-
interface SessionStore {
|
|
66
|
-
/**
|
|
67
|
-
* Optional initialization (e.g., database connection)
|
|
68
|
-
*/
|
|
69
|
-
init?(): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Generates a unique session ID
|
|
72
|
-
*/
|
|
73
|
-
generateSessionId(): string;
|
|
74
|
-
/**
|
|
75
|
-
* Creates a new session. Throws if session already exists.
|
|
76
|
-
* @param session - Session data to create
|
|
77
|
-
*/
|
|
78
|
-
create(session: Session): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Updates an existing session with partial data. Throws if session does not exist.
|
|
81
|
-
* @param userId - User identifier
|
|
82
|
-
* @param sessionId - Session identifier
|
|
83
|
-
* @param data - Partial session data to update
|
|
84
|
-
*/
|
|
85
|
-
update(userId: string, sessionId: string, data: Partial<Session>): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Patches runtime credentials for an existing session.
|
|
88
|
-
* These values are separated from connection metadata in durable SQL stores.
|
|
89
|
-
*/
|
|
90
|
-
patchCredentials(userId: string, sessionId: string, data: Partial<SessionCredentials>): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Retrieves a session
|
|
93
|
-
*/
|
|
94
|
-
get(userId: string, sessionId: string): Promise<Session | null>;
|
|
95
|
-
/**
|
|
96
|
-
* Retrieves runtime credentials for a session.
|
|
97
|
-
*/
|
|
98
|
-
getCredentials(userId: string, sessionId: string): Promise<SessionCredentials | null>;
|
|
99
|
-
/**
|
|
100
|
-
* Clears runtime credentials without removing connection metadata.
|
|
101
|
-
*/
|
|
102
|
-
clearCredentials(userId: string, sessionId: string): Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* Gets full session data for all sessions owned by a user
|
|
105
|
-
*/
|
|
106
|
-
list(userId: string): Promise<Session[]>;
|
|
107
|
-
/**
|
|
108
|
-
* Removes a session
|
|
109
|
-
*/
|
|
110
|
-
delete(userId: string, sessionId: string): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Gets all session IDs owned by a user
|
|
113
|
-
*/
|
|
114
|
-
listIds(userId: string): Promise<string[]>;
|
|
115
|
-
/**
|
|
116
|
-
* Gets all session IDs across all users (Admin)
|
|
117
|
-
*/
|
|
118
|
-
listAllIds(): Promise<string[]>;
|
|
119
|
-
/**
|
|
120
|
-
* Clears all sessions (Admin)
|
|
121
|
-
*/
|
|
122
|
-
clearAll(): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Clean up expired sessions
|
|
125
|
-
*/
|
|
126
|
-
cleanupExpired(): Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* Disconnect from storage backend
|
|
129
|
-
*/
|
|
130
|
-
disconnect(): Promise<void>;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
10
|
declare function onSessionMutation(listener: SessionMutationListener): () => void;
|
|
134
11
|
/**
|
|
135
12
|
* Global session store instance
|
|
@@ -302,4 +179,4 @@ declare function createNextMcpHandler(options?: NextMcpHandlerOptions): {
|
|
|
302
179
|
POST: (request: Request) => Promise<Response>;
|
|
303
180
|
};
|
|
304
181
|
|
|
305
|
-
export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions,
|
|
182
|
+
export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions, SessionMutationListener, SessionStore, createNextMcpHandler, createSSEHandler, onSessionMutation, sessions };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,135 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { c as SessionMutationListener, e as SessionStore } from '../multi-session-client-DOBvtaQV.js';
|
|
2
|
+
export { M as MCPClient, a as MultiSessionClient, S as Session, b as SessionMutationEvent, d as SessionMutationType, f as StorageOAuthClientProvider } from '../multi-session-client-DOBvtaQV.js';
|
|
2
3
|
export { U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-DELRKQPU.js';
|
|
3
|
-
import {
|
|
4
|
+
import { M as McpConnectionEvent, t as McpObservabilityEvent, x as McpRpcResponse, w as McpRpcRequest } from '../types-CjczQwNX.js';
|
|
5
|
+
export { a as CallToolRequest, b as CallToolResponse, f as ConnectRequest, g as ConnectResponse, k as Disposable, E as Emitter, m as Event, q as ListToolsResponse, s as McpConnectionState, T as ToolClient, A as ToolClientProvider, B as ToolInfo } from '../types-CjczQwNX.js';
|
|
4
6
|
export { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
|
-
import { M as McpConnectionEvent, d as McpObservabilityEvent } from '../events-C4m7tK1U.js';
|
|
6
|
-
export { D as Disposable, E as Emitter, b as Event, c as McpConnectionState } from '../events-C4m7tK1U.js';
|
|
7
|
-
import { r as McpRpcResponse, q as McpRpcRequest } from '../types-DCk_IF4L.js';
|
|
8
|
-
export { a as CallToolRequest, b as CallToolResponse, f as ConnectRequest, g as ConnectResponse, n as ListToolsResponse, T as ToolClient, u as ToolClientProvider, v as ToolInfo } from '../types-DCk_IF4L.js';
|
|
9
7
|
export { CallToolResult, ListToolsResult, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
10
8
|
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
11
9
|
|
|
12
|
-
interface OAuthState {
|
|
13
|
-
nonce: string;
|
|
14
|
-
sessionId: string;
|
|
15
|
-
serverId: string;
|
|
16
|
-
createdAt: number;
|
|
17
|
-
}
|
|
18
|
-
type SessionStatus = 'pending' | 'active';
|
|
19
|
-
interface Session {
|
|
20
|
-
sessionId: string;
|
|
21
|
-
serverId?: string;
|
|
22
|
-
serverName?: string;
|
|
23
|
-
serverUrl: string;
|
|
24
|
-
transportType: 'sse' | 'streamable-http';
|
|
25
|
-
callbackUrl: string;
|
|
26
|
-
createdAt: number;
|
|
27
|
-
updatedAt?: number;
|
|
28
|
-
/**
|
|
29
|
-
* Storage-owned expiration timestamp for pending/inactive sessions.
|
|
30
|
-
* Active sessions use updatedAt-based dormancy cleanup instead.
|
|
31
|
-
*/
|
|
32
|
-
expiresAt?: number | null;
|
|
33
|
-
userId: string;
|
|
34
|
-
headers?: Record<string, string>;
|
|
35
|
-
authUrl?: string | null;
|
|
36
|
-
/**
|
|
37
|
-
* Session status marker used for lifecycle cleanup:
|
|
38
|
-
* - pending: short-lived intermediate/auth-pending session state
|
|
39
|
-
* - active: restorable session after successful connection/auth completion
|
|
40
|
-
*/
|
|
41
|
-
status?: SessionStatus;
|
|
42
|
-
}
|
|
43
|
-
interface SessionCredentials {
|
|
44
|
-
sessionId: string;
|
|
45
|
-
userId: string;
|
|
46
|
-
clientInformation?: OAuthClientInformationMixed | null;
|
|
47
|
-
tokens?: OAuthTokens | null;
|
|
48
|
-
codeVerifier?: string | null;
|
|
49
|
-
clientId?: string | null;
|
|
50
|
-
oauthState?: OAuthState | null;
|
|
51
|
-
}
|
|
52
|
-
type SessionMutationType = 'create' | 'update' | 'delete';
|
|
53
|
-
interface SessionMutationEvent {
|
|
54
|
-
type: SessionMutationType;
|
|
55
|
-
userId: string;
|
|
56
|
-
sessionId: string;
|
|
57
|
-
timestamp: number;
|
|
58
|
-
session?: Session;
|
|
59
|
-
patch?: Partial<Session>;
|
|
60
|
-
}
|
|
61
|
-
type SessionMutationListener = (event: SessionMutationEvent) => void | Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Interface for MCP session stores.
|
|
64
|
-
*/
|
|
65
|
-
interface SessionStore {
|
|
66
|
-
/**
|
|
67
|
-
* Optional initialization (e.g., database connection)
|
|
68
|
-
*/
|
|
69
|
-
init?(): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Generates a unique session ID
|
|
72
|
-
*/
|
|
73
|
-
generateSessionId(): string;
|
|
74
|
-
/**
|
|
75
|
-
* Creates a new session. Throws if session already exists.
|
|
76
|
-
* @param session - Session data to create
|
|
77
|
-
*/
|
|
78
|
-
create(session: Session): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Updates an existing session with partial data. Throws if session does not exist.
|
|
81
|
-
* @param userId - User identifier
|
|
82
|
-
* @param sessionId - Session identifier
|
|
83
|
-
* @param data - Partial session data to update
|
|
84
|
-
*/
|
|
85
|
-
update(userId: string, sessionId: string, data: Partial<Session>): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Patches runtime credentials for an existing session.
|
|
88
|
-
* These values are separated from connection metadata in durable SQL stores.
|
|
89
|
-
*/
|
|
90
|
-
patchCredentials(userId: string, sessionId: string, data: Partial<SessionCredentials>): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Retrieves a session
|
|
93
|
-
*/
|
|
94
|
-
get(userId: string, sessionId: string): Promise<Session | null>;
|
|
95
|
-
/**
|
|
96
|
-
* Retrieves runtime credentials for a session.
|
|
97
|
-
*/
|
|
98
|
-
getCredentials(userId: string, sessionId: string): Promise<SessionCredentials | null>;
|
|
99
|
-
/**
|
|
100
|
-
* Clears runtime credentials without removing connection metadata.
|
|
101
|
-
*/
|
|
102
|
-
clearCredentials(userId: string, sessionId: string): Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* Gets full session data for all sessions owned by a user
|
|
105
|
-
*/
|
|
106
|
-
list(userId: string): Promise<Session[]>;
|
|
107
|
-
/**
|
|
108
|
-
* Removes a session
|
|
109
|
-
*/
|
|
110
|
-
delete(userId: string, sessionId: string): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Gets all session IDs owned by a user
|
|
113
|
-
*/
|
|
114
|
-
listIds(userId: string): Promise<string[]>;
|
|
115
|
-
/**
|
|
116
|
-
* Gets all session IDs across all users (Admin)
|
|
117
|
-
*/
|
|
118
|
-
listAllIds(): Promise<string[]>;
|
|
119
|
-
/**
|
|
120
|
-
* Clears all sessions (Admin)
|
|
121
|
-
*/
|
|
122
|
-
clearAll(): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Clean up expired sessions
|
|
125
|
-
*/
|
|
126
|
-
cleanupExpired(): Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* Disconnect from storage backend
|
|
129
|
-
*/
|
|
130
|
-
disconnect(): Promise<void>;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
10
|
declare function onSessionMutation(listener: SessionMutationListener): () => void;
|
|
134
11
|
/**
|
|
135
12
|
* Global session store instance
|
|
@@ -302,4 +179,4 @@ declare function createNextMcpHandler(options?: NextMcpHandlerOptions): {
|
|
|
302
179
|
POST: (request: Request) => Promise<Response>;
|
|
303
180
|
};
|
|
304
181
|
|
|
305
|
-
export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions,
|
|
182
|
+
export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions, SessionMutationListener, SessionStore, createNextMcpHandler, createSSEHandler, onSessionMutation, sessions };
|