@mcp-ts/sdk 2.5.3 → 2.6.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/README.md +3 -574
- package/dist/adapters/agui-adapter.d.mts +4 -4
- package/dist/adapters/agui-adapter.d.ts +4 -4
- package/dist/adapters/agui-middleware.d.mts +4 -4
- package/dist/adapters/agui-middleware.d.ts +4 -4
- package/dist/adapters/ai-adapter.d.mts +4 -4
- package/dist/adapters/ai-adapter.d.ts +4 -4
- package/dist/adapters/langchain-adapter.d.mts +4 -4
- package/dist/adapters/langchain-adapter.d.ts +4 -4
- package/dist/adapters/mastra-adapter.d.mts +3 -3
- package/dist/adapters/mastra-adapter.d.ts +3 -3
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +3 -0
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/react.d.mts +10 -18
- package/dist/client/react.d.ts +10 -18
- package/dist/client/react.js +17 -0
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +17 -0
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +4 -4
- package/dist/client/vue.d.ts +4 -4
- package/dist/client/vue.js +3 -0
- package/dist/client/vue.js.map +1 -1
- package/dist/client/vue.mjs +3 -0
- package/dist/client/vue.mjs.map +1 -1
- package/dist/{index-BRZO_JyI.d.mts → index-BrDkbut5.d.ts} +2 -1
- package/dist/{index-C3YGagi2.d.ts → index-DHQvlx4K.d.mts} +2 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1056 -876
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1048 -871
- package/dist/index.mjs.map +1 -1
- package/dist/{multi-session-client-CuacvZaQ.d.ts → multi-session-client-CQzymvHl.d.ts} +183 -227
- package/dist/{multi-session-client-DqzT8Oo7.d.mts → multi-session-client-C_Ja2TuV.d.mts} +183 -227
- package/dist/server/index.d.mts +338 -88
- package/dist/server/index.d.ts +338 -88
- package/dist/server/index.js +1053 -876
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +1045 -871
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.d.mts +4 -4
- package/dist/shared/index.d.ts +4 -4
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-B0qpui-V.d.mts → tool-router-C1n7OXbl.d.mts} +1 -1
- package/dist/{tool-router-2qUyZ-cP.d.ts → tool-router-CBIawFnt.d.ts} +1 -1
- package/dist/{types-BkJ_rgzo.d.mts → types-DX71u9gR.d.mts} +11 -5
- package/dist/{types-BkJ_rgzo.d.ts → types-DX71u9gR.d.ts} +11 -5
- package/migrations/neon/20260513010000_install_mcp_sessions.sql +4 -34
- package/migrations/supabase/20260330195700_install_mcp_sessions.sql +5 -62
- package/package.json +2 -1
- package/src/client/core/sse-client.ts +5 -0
- package/src/client/react/use-mcp.ts +27 -28
- package/src/server/handlers/sse-handler.ts +671 -633
- package/src/server/index.ts +2 -1
- package/src/server/mcp/multi-session-client.ts +34 -10
- package/src/server/mcp/oauth-client.ts +197 -205
- package/src/server/mcp/storage-oauth-provider.ts +148 -41
- package/src/server/mcp/tool-policy-gateway.ts +11 -1
- package/src/server/storage/file-backend.ts +25 -21
- package/src/server/storage/index.ts +71 -0
- package/src/server/storage/memory-backend.ts +24 -12
- package/src/server/storage/neon-backend.ts +70 -72
- package/src/server/storage/redis-backend.ts +26 -36
- package/src/server/storage/sqlite-backend.ts +25 -39
- package/src/server/storage/supabase-backend.ts +45 -54
- package/src/server/storage/types.ts +22 -2
- package/src/shared/types.ts +13 -3
|
@@ -1,100 +1,152 @@
|
|
|
1
|
-
import { m as Event, M as McpConnectionEvent, t as McpObservabilityEvent, s as McpConnectionState, A as ToolClientProvider, T as ToolClient } from './types-
|
|
2
|
-
import { ListToolsResult, CallToolResult, ListPromptsResult, GetPromptResult, ListResourcesResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
1
|
+
import { m as Event, M as McpConnectionEvent, t as McpObservabilityEvent, s as McpConnectionState, A as ToolClientProvider, T as ToolClient } from './types-DX71u9gR.mjs';
|
|
2
|
+
import { ListToolsResult, CallToolResult, ListPromptsResult, GetPromptResult, ListResourcesResult, ReadResourceResult, Implementation } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
3
4
|
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
4
|
-
import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
authUrl: string | undefined;
|
|
12
|
-
clientId: string | undefined;
|
|
13
|
-
serverId: string | undefined;
|
|
14
|
-
checkState(state: string): Promise<{
|
|
15
|
-
valid: boolean;
|
|
16
|
-
serverId?: string;
|
|
17
|
-
error?: string;
|
|
18
|
-
}>;
|
|
19
|
-
consumeState(state: string): Promise<void>;
|
|
20
|
-
deleteCodeVerifier(): Promise<void>;
|
|
6
|
+
interface OAuthState {
|
|
7
|
+
nonce: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
serverId: string;
|
|
10
|
+
createdAt: number;
|
|
21
11
|
}
|
|
22
|
-
|
|
12
|
+
type SessionStatus = 'pending' | 'active';
|
|
13
|
+
type ToolPolicyMode = 'all' | 'allowlist' | 'denylist';
|
|
14
|
+
interface ToolPolicy {
|
|
15
|
+
mode: ToolPolicyMode;
|
|
16
|
+
toolIds: string[];
|
|
17
|
+
updatedAt: number;
|
|
18
|
+
}
|
|
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;
|
|
23
33
|
userId: string;
|
|
24
|
-
|
|
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
|
+
toolPolicy?: ToolPolicy;
|
|
43
|
+
/** When false, the session is excluded from agent tool discovery and RPC access. Defaults to true. */
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
clientInformation?: OAuthClientInformationMixed | null;
|
|
46
|
+
tokens?: OAuthTokens | null;
|
|
47
|
+
codeVerifier?: string | null;
|
|
48
|
+
codeVerifierChallenge?: string | null;
|
|
49
|
+
codeVerifierNonce?: string | null;
|
|
50
|
+
clientId?: string | null;
|
|
51
|
+
oauthState?: OAuthState | null;
|
|
52
|
+
}
|
|
53
|
+
interface SessionCredentials {
|
|
25
54
|
sessionId: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
55
|
+
userId: string;
|
|
56
|
+
clientInformation?: OAuthClientInformationMixed | null;
|
|
57
|
+
tokens?: OAuthTokens | null;
|
|
58
|
+
codeVerifier?: string | null;
|
|
59
|
+
codeVerifierChallenge?: string | null;
|
|
60
|
+
codeVerifierNonce?: string | null;
|
|
61
|
+
clientId?: string | null;
|
|
62
|
+
oauthState?: OAuthState | null;
|
|
63
|
+
}
|
|
64
|
+
type SessionMutationType = 'create' | 'update' | 'delete';
|
|
65
|
+
interface SessionMutationEvent {
|
|
66
|
+
type: SessionMutationType;
|
|
67
|
+
userId: string;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
session?: Session;
|
|
71
|
+
patch?: Partial<Session>;
|
|
34
72
|
}
|
|
73
|
+
type SessionMutationListener = (event: SessionMutationEvent) => void | Promise<void>;
|
|
35
74
|
/**
|
|
36
|
-
*
|
|
37
|
-
* Stores OAuth tokens, client information, and PKCE verifiers using the configured SessionStore
|
|
75
|
+
* Interface for MCP session stores.
|
|
38
76
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
private readonly logoUri?;
|
|
47
|
-
private readonly policyUri?;
|
|
48
|
-
private readonly clientSecret?;
|
|
49
|
-
private _authUrl;
|
|
50
|
-
private _clientId;
|
|
51
|
-
private onRedirectCallback?;
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new session-backed OAuth provider
|
|
54
|
-
* @param options - Provider configuration
|
|
55
|
-
*/
|
|
56
|
-
constructor(options: StorageOAuthClientProviderOptions);
|
|
57
|
-
get clientMetadata(): OAuthClientMetadata;
|
|
58
|
-
get clientId(): string | undefined;
|
|
59
|
-
set clientId(clientId_: string | undefined);
|
|
60
|
-
/**
|
|
61
|
-
* Loads OAuth credentials from the session store
|
|
62
|
-
* @private
|
|
77
|
+
type GetOptions = {
|
|
78
|
+
includeCredentials?: boolean;
|
|
79
|
+
};
|
|
80
|
+
type SessionResult = Session;
|
|
81
|
+
interface SessionStore {
|
|
82
|
+
/**
|
|
83
|
+
* Optional initialization (e.g., database connection)
|
|
63
84
|
*/
|
|
64
|
-
|
|
85
|
+
init?(): Promise<void>;
|
|
65
86
|
/**
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
87
|
+
* Generates a unique session ID
|
|
88
|
+
*/
|
|
89
|
+
generateSessionId(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new session. Throws if session already exists.
|
|
92
|
+
* @param session - Session data to create
|
|
93
|
+
*/
|
|
94
|
+
create(session: Session): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Updates an existing session with partial data. Throws if session does not exist.
|
|
97
|
+
* @param userId - User identifier
|
|
98
|
+
* @param sessionId - Session identifier
|
|
99
|
+
* @param data - Partial session data to update
|
|
100
|
+
*/
|
|
101
|
+
update(userId: string, sessionId: string, data: Partial<Session>): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Patches runtime credentials for an existing session.
|
|
104
|
+
* These values are separated from connection metadata in durable SQL stores.
|
|
105
|
+
*/
|
|
106
|
+
patchCredentials(userId: string, sessionId: string, data: Partial<SessionCredentials>): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves a session, optionally including its credential fields in one round-trip.
|
|
109
|
+
* When includeCredentials is true, the returned session has credential fields
|
|
110
|
+
* (clientInformation, tokens, codeVerifier, etc.) populated from storage.
|
|
111
|
+
* When false or undefined, credential fields are left as undefined.
|
|
112
|
+
*/
|
|
113
|
+
get(userId: string, sessionId: string, options?: GetOptions): Promise<SessionResult | null>;
|
|
114
|
+
/**
|
|
115
|
+
* Retrieves runtime credentials for a session.
|
|
116
|
+
*/
|
|
117
|
+
getCredentials(userId: string, sessionId: string): Promise<SessionCredentials | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Clears runtime credentials without removing connection metadata.
|
|
70
120
|
*/
|
|
71
|
-
|
|
121
|
+
clearCredentials(userId: string, sessionId: string): Promise<void>;
|
|
72
122
|
/**
|
|
73
|
-
*
|
|
123
|
+
* Gets full session data for all sessions owned by a user
|
|
74
124
|
*/
|
|
75
|
-
|
|
125
|
+
list(userId: string): Promise<Session[]>;
|
|
76
126
|
/**
|
|
77
|
-
*
|
|
127
|
+
* Removes a session
|
|
78
128
|
*/
|
|
79
|
-
|
|
129
|
+
delete(userId: string, sessionId: string): Promise<void>;
|
|
80
130
|
/**
|
|
81
|
-
*
|
|
131
|
+
* Gets all session IDs owned by a user
|
|
132
|
+
*/
|
|
133
|
+
listIds(userId: string): Promise<string[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Gets all session IDs across all users (Admin)
|
|
136
|
+
*/
|
|
137
|
+
listAllIds(): Promise<string[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Clears all sessions (Admin)
|
|
82
140
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
redirectToAuthorization(authUrl: URL): Promise<void>;
|
|
93
|
-
invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier"): Promise<void>;
|
|
94
|
-
saveCodeVerifier(verifier: string): Promise<void>;
|
|
95
|
-
codeVerifier(): Promise<string>;
|
|
96
|
-
deleteCodeVerifier(): Promise<void>;
|
|
97
|
-
tokens(): Promise<OAuthTokens | undefined>;
|
|
141
|
+
clearAll(): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Clean up expired sessions
|
|
144
|
+
*/
|
|
145
|
+
cleanupExpired(): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Disconnect from storage backend
|
|
148
|
+
*/
|
|
149
|
+
disconnect(): Promise<void>;
|
|
98
150
|
}
|
|
99
151
|
|
|
100
152
|
/**
|
|
@@ -118,6 +170,27 @@ interface MCPOAuthClientOptions {
|
|
|
118
170
|
clientUri?: string;
|
|
119
171
|
logoUri?: string;
|
|
120
172
|
policyUri?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Credentials already loaded by the caller (e.g. via get({includeCredentials: true})).
|
|
175
|
+
* When provided, the StorageOAuthClientProvider uses these cached values to
|
|
176
|
+
* skip redundant DB reads for tokens() calls during reconnection.
|
|
177
|
+
*/
|
|
178
|
+
cachedCredentials?: {
|
|
179
|
+
tokens?: OAuthTokens;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* When true, skips the redundant session-existence check in ensureSession().
|
|
183
|
+
* Set by callers that have already confirmed the session exists in storage
|
|
184
|
+
* (e.g. getOrCreateClient, getSession, finishAuth in sse-handler).
|
|
185
|
+
* Saves one round-trip per reconnection.
|
|
186
|
+
*/
|
|
187
|
+
hasSession?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Custom session store override. When provided, all storage operations
|
|
190
|
+
* (get/create/update/delete) use this store instead of the default global.
|
|
191
|
+
* Used for wrapping with DB observability or other decorators.
|
|
192
|
+
*/
|
|
193
|
+
sessionStore?: SessionStore;
|
|
121
194
|
}
|
|
122
195
|
/**
|
|
123
196
|
* MCP Client with OAuth 2.1 authentication support
|
|
@@ -126,25 +199,12 @@ interface MCPOAuthClientOptions {
|
|
|
126
199
|
*/
|
|
127
200
|
declare class MCPClient {
|
|
128
201
|
private client;
|
|
129
|
-
oauthProvider:
|
|
202
|
+
oauthProvider: OAuthClientProvider | null;
|
|
130
203
|
private transport;
|
|
131
|
-
private
|
|
132
|
-
private serverId?;
|
|
133
|
-
private sessionId;
|
|
134
|
-
private serverName?;
|
|
135
|
-
private transportType;
|
|
136
|
-
private serverUrl;
|
|
137
|
-
private callbackUrl;
|
|
138
|
-
private onRedirect;
|
|
139
|
-
private clientId?;
|
|
140
|
-
private clientSecret?;
|
|
141
|
-
private headers?;
|
|
142
|
-
/** OAuth Client Metadata */
|
|
143
|
-
private clientName?;
|
|
144
|
-
private clientUri?;
|
|
145
|
-
private logoUri?;
|
|
146
|
-
private policyUri?;
|
|
204
|
+
private config;
|
|
147
205
|
private createdAt?;
|
|
206
|
+
private _serverInfo;
|
|
207
|
+
private _store;
|
|
148
208
|
/** Event emitters for connection lifecycle */
|
|
149
209
|
private readonly _onConnectionEvent;
|
|
150
210
|
readonly onConnectionEvent: Event<McpConnectionEvent>;
|
|
@@ -157,6 +217,8 @@ declare class MCPClient {
|
|
|
157
217
|
* @param options - Client configuration options
|
|
158
218
|
*/
|
|
159
219
|
constructor(options: MCPOAuthClientOptions);
|
|
220
|
+
/** Shared session-shaped data for ensureSession and saveSession */
|
|
221
|
+
private get session();
|
|
160
222
|
/**
|
|
161
223
|
* Emit a connection state change event
|
|
162
224
|
* @private
|
|
@@ -353,7 +415,15 @@ declare class MCPClient {
|
|
|
353
415
|
*/
|
|
354
416
|
getTransportType(): TransportType;
|
|
355
417
|
/**
|
|
356
|
-
* Gets the
|
|
418
|
+
* Gets the full server metadata from the MCP initialize response.
|
|
419
|
+
* Includes name, version, icons, title, description, and website URL.
|
|
420
|
+
* Returns undefined if the client hasn't connected yet.
|
|
421
|
+
*/
|
|
422
|
+
getServerInfo(): Implementation | undefined;
|
|
423
|
+
/**
|
|
424
|
+
* Gets the human-readable server name.
|
|
425
|
+
* Prefers the server's reported title/name from the initialize response,
|
|
426
|
+
* falling back to the name provided at construction or session metadata.
|
|
357
427
|
* @returns Server name or undefined
|
|
358
428
|
*/
|
|
359
429
|
getServerName(): string | undefined;
|
|
@@ -369,134 +439,6 @@ declare class MCPClient {
|
|
|
369
439
|
getSessionId(): string;
|
|
370
440
|
}
|
|
371
441
|
|
|
372
|
-
interface OAuthState {
|
|
373
|
-
nonce: string;
|
|
374
|
-
sessionId: string;
|
|
375
|
-
serverId: string;
|
|
376
|
-
createdAt: number;
|
|
377
|
-
}
|
|
378
|
-
type SessionStatus = 'pending' | 'active';
|
|
379
|
-
type ToolPolicyMode = 'all' | 'allowlist' | 'denylist';
|
|
380
|
-
interface ToolPolicy {
|
|
381
|
-
mode: ToolPolicyMode;
|
|
382
|
-
toolIds: string[];
|
|
383
|
-
updatedAt: number;
|
|
384
|
-
}
|
|
385
|
-
interface Session {
|
|
386
|
-
sessionId: string;
|
|
387
|
-
serverId?: string;
|
|
388
|
-
serverName?: string;
|
|
389
|
-
serverUrl: string;
|
|
390
|
-
transportType: 'sse' | 'streamable-http';
|
|
391
|
-
callbackUrl: string;
|
|
392
|
-
createdAt: number;
|
|
393
|
-
updatedAt?: number;
|
|
394
|
-
/**
|
|
395
|
-
* Storage-owned expiration timestamp for pending/inactive sessions.
|
|
396
|
-
* Active sessions use updatedAt-based dormancy cleanup instead.
|
|
397
|
-
*/
|
|
398
|
-
expiresAt?: number | null;
|
|
399
|
-
userId: string;
|
|
400
|
-
headers?: Record<string, string>;
|
|
401
|
-
authUrl?: string | null;
|
|
402
|
-
/**
|
|
403
|
-
* Session status marker used for lifecycle cleanup:
|
|
404
|
-
* - pending: short-lived intermediate/auth-pending session state
|
|
405
|
-
* - active: restorable session after successful connection/auth completion
|
|
406
|
-
*/
|
|
407
|
-
status?: SessionStatus;
|
|
408
|
-
toolPolicy?: ToolPolicy;
|
|
409
|
-
}
|
|
410
|
-
interface SessionCredentials {
|
|
411
|
-
sessionId: string;
|
|
412
|
-
userId: string;
|
|
413
|
-
clientInformation?: OAuthClientInformationMixed | null;
|
|
414
|
-
tokens?: OAuthTokens | null;
|
|
415
|
-
codeVerifier?: string | null;
|
|
416
|
-
clientId?: string | null;
|
|
417
|
-
oauthState?: OAuthState | null;
|
|
418
|
-
}
|
|
419
|
-
type SessionMutationType = 'create' | 'update' | 'delete';
|
|
420
|
-
interface SessionMutationEvent {
|
|
421
|
-
type: SessionMutationType;
|
|
422
|
-
userId: string;
|
|
423
|
-
sessionId: string;
|
|
424
|
-
timestamp: number;
|
|
425
|
-
session?: Session;
|
|
426
|
-
patch?: Partial<Session>;
|
|
427
|
-
}
|
|
428
|
-
type SessionMutationListener = (event: SessionMutationEvent) => void | Promise<void>;
|
|
429
|
-
/**
|
|
430
|
-
* Interface for MCP session stores.
|
|
431
|
-
*/
|
|
432
|
-
interface SessionStore {
|
|
433
|
-
/**
|
|
434
|
-
* Optional initialization (e.g., database connection)
|
|
435
|
-
*/
|
|
436
|
-
init?(): Promise<void>;
|
|
437
|
-
/**
|
|
438
|
-
* Generates a unique session ID
|
|
439
|
-
*/
|
|
440
|
-
generateSessionId(): string;
|
|
441
|
-
/**
|
|
442
|
-
* Creates a new session. Throws if session already exists.
|
|
443
|
-
* @param session - Session data to create
|
|
444
|
-
*/
|
|
445
|
-
create(session: Session): Promise<void>;
|
|
446
|
-
/**
|
|
447
|
-
* Updates an existing session with partial data. Throws if session does not exist.
|
|
448
|
-
* @param userId - User identifier
|
|
449
|
-
* @param sessionId - Session identifier
|
|
450
|
-
* @param data - Partial session data to update
|
|
451
|
-
*/
|
|
452
|
-
update(userId: string, sessionId: string, data: Partial<Session>): Promise<void>;
|
|
453
|
-
/**
|
|
454
|
-
* Patches runtime credentials for an existing session.
|
|
455
|
-
* These values are separated from connection metadata in durable SQL stores.
|
|
456
|
-
*/
|
|
457
|
-
patchCredentials(userId: string, sessionId: string, data: Partial<SessionCredentials>): Promise<void>;
|
|
458
|
-
/**
|
|
459
|
-
* Retrieves a session
|
|
460
|
-
*/
|
|
461
|
-
get(userId: string, sessionId: string): Promise<Session | null>;
|
|
462
|
-
/**
|
|
463
|
-
* Retrieves runtime credentials for a session.
|
|
464
|
-
*/
|
|
465
|
-
getCredentials(userId: string, sessionId: string): Promise<SessionCredentials | null>;
|
|
466
|
-
/**
|
|
467
|
-
* Clears runtime credentials without removing connection metadata.
|
|
468
|
-
*/
|
|
469
|
-
clearCredentials(userId: string, sessionId: string): Promise<void>;
|
|
470
|
-
/**
|
|
471
|
-
* Gets full session data for all sessions owned by a user
|
|
472
|
-
*/
|
|
473
|
-
list(userId: string): Promise<Session[]>;
|
|
474
|
-
/**
|
|
475
|
-
* Removes a session
|
|
476
|
-
*/
|
|
477
|
-
delete(userId: string, sessionId: string): Promise<void>;
|
|
478
|
-
/**
|
|
479
|
-
* Gets all session IDs owned by a user
|
|
480
|
-
*/
|
|
481
|
-
listIds(userId: string): Promise<string[]>;
|
|
482
|
-
/**
|
|
483
|
-
* Gets all session IDs across all users (Admin)
|
|
484
|
-
*/
|
|
485
|
-
listAllIds(): Promise<string[]>;
|
|
486
|
-
/**
|
|
487
|
-
* Clears all sessions (Admin)
|
|
488
|
-
*/
|
|
489
|
-
clearAll(): Promise<void>;
|
|
490
|
-
/**
|
|
491
|
-
* Clean up expired sessions
|
|
492
|
-
*/
|
|
493
|
-
cleanupExpired(): Promise<void>;
|
|
494
|
-
/**
|
|
495
|
-
* Disconnect from storage backend
|
|
496
|
-
*/
|
|
497
|
-
disconnect(): Promise<void>;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
442
|
interface MultiSessionOptions {
|
|
501
443
|
/**
|
|
502
444
|
* Connection timeout in milliseconds.
|
|
@@ -513,6 +455,12 @@ interface MultiSessionOptions {
|
|
|
513
455
|
* @default 1000
|
|
514
456
|
*/
|
|
515
457
|
retryDelay?: number;
|
|
458
|
+
/**
|
|
459
|
+
* Custom session store. When provided, all DB operations go through
|
|
460
|
+
* this store instead of the default global `sessions` singleton.
|
|
461
|
+
* Useful for wrapping with `withDbObservability()` for debugging.
|
|
462
|
+
*/
|
|
463
|
+
sessionStore?: SessionStore;
|
|
516
464
|
/**
|
|
517
465
|
* Custom session provider. When provided, `connect()` calls this
|
|
518
466
|
* instead of querying the storage backend. Useful when sessions are
|
|
@@ -522,6 +470,11 @@ interface MultiSessionOptions {
|
|
|
522
470
|
* Default: reads from the storage backend via `sessions.list(userId)`.
|
|
523
471
|
*/
|
|
524
472
|
sessionProvider?: () => Promise<Session[]>;
|
|
473
|
+
/**
|
|
474
|
+
* Attached to each MCPClient before connect() so all connection lifecycle
|
|
475
|
+
* events (INITIALIZING, CONNECTING, CONNECTED, etc.) are captured.
|
|
476
|
+
*/
|
|
477
|
+
onObservabilityEvent?: McpObservabilityEventHandler;
|
|
525
478
|
/**
|
|
526
479
|
* Called after a session is successfully connected.
|
|
527
480
|
*/
|
|
@@ -536,6 +489,8 @@ interface MultiSessionOptions {
|
|
|
536
489
|
*/
|
|
537
490
|
onSessionFailed?: (sessionId: string, error: unknown) => void;
|
|
538
491
|
}
|
|
492
|
+
/** @internal */
|
|
493
|
+
type McpObservabilityEventHandler = (event: McpObservabilityEvent) => void;
|
|
539
494
|
/**
|
|
540
495
|
* Manages multiple MCP client connections for a single user.
|
|
541
496
|
*
|
|
@@ -556,6 +511,7 @@ declare class MultiSessionClient implements ToolClientProvider {
|
|
|
556
511
|
* @param options - Optional tuning and lifecycle hooks.
|
|
557
512
|
*/
|
|
558
513
|
constructor(userId: string, options?: MultiSessionOptions);
|
|
514
|
+
private _store;
|
|
559
515
|
/**
|
|
560
516
|
* Fetches active sessions and establishes connections to all of them.
|
|
561
517
|
*
|
|
@@ -641,4 +597,4 @@ declare class MultiSessionClient implements ToolClientProvider {
|
|
|
641
597
|
private establishConnectionWithRetries;
|
|
642
598
|
}
|
|
643
599
|
|
|
644
|
-
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
|
|
600
|
+
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 };
|