@mcp-ts/sdk 2.4.3 → 2.4.5
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 -3
- package/dist/adapters/agui-adapter.d.ts +3 -3
- package/dist/adapters/agui-middleware.d.mts +3 -3
- package/dist/adapters/agui-middleware.d.ts +3 -3
- package/dist/adapters/ai-adapter.d.mts +3 -3
- package/dist/adapters/ai-adapter.d.ts +3 -3
- package/dist/adapters/langchain-adapter.d.mts +3 -3
- package/dist/adapters/langchain-adapter.d.ts +3 -3
- package/dist/adapters/mastra-adapter.d.mts +2 -2
- package/dist/adapters/mastra-adapter.d.ts +2 -2
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/react.d.mts +4 -5
- package/dist/client/react.d.ts +4 -5
- package/dist/client/react.js +2 -6
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +2 -6
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +4 -5
- package/dist/client/vue.d.ts +4 -5
- package/dist/client/vue.js.map +1 -1
- package/dist/client/vue.mjs.map +1 -1
- package/dist/{index-B8kJSrBJ.d.ts → index-CZk2gu2E.d.ts} +1 -1
- package/dist/{index-DiJsm_lK.d.mts → index-CkM3p0eE.d.mts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +96 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -104
- package/dist/index.mjs.map +1 -1
- package/dist/{multi-session-client-DOBvtaQV.d.ts → multi-session-client-ChQrBZhF.d.mts} +4 -5
- package/dist/{multi-session-client-B6hsYO8V.d.mts → multi-session-client-QOOPdEVp.d.ts} +4 -5
- package/dist/server/index.d.mts +4 -4
- package/dist/server/index.d.ts +4 -4
- package/dist/server/index.js +96 -104
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +96 -104
- 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 +2 -6
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +2 -6
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-CbG4Tum6.d.mts → tool-router-CGs3IDOJ.d.mts} +1 -1
- package/dist/{tool-router-ChIhPwgP.d.ts → tool-router-DQ-HrD7W.d.ts} +1 -1
- package/dist/{types-CjczQwNX.d.mts → types-Bf-7GOLW.d.mts} +0 -2
- package/dist/{types-CjczQwNX.d.ts → types-Bf-7GOLW.d.ts} +0 -2
- package/package.json +1 -1
- package/src/client/react/use-mcp.ts +0 -1
- package/src/client/vue/use-mcp.ts +0 -1
- package/src/server/handlers/sse-handler.ts +2 -2
- package/src/server/mcp/oauth-client.ts +94 -121
- package/src/server/storage/index.ts +1 -1
- package/src/shared/events.ts +0 -2
- package/src/shared/utils.ts +16 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as Event, M as McpConnectionEvent, t as McpObservabilityEvent, s as McpConnectionState, A as ToolClientProvider } from './types-
|
|
1
|
+
import { m as Event, M as McpConnectionEvent, t as McpObservabilityEvent, s as McpConnectionState, A as ToolClientProvider } from './types-Bf-7GOLW.mjs';
|
|
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';
|
|
@@ -184,12 +184,11 @@ declare class MCPClient {
|
|
|
184
184
|
*/
|
|
185
185
|
private getTransport;
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* This method is idempotent and safe to call multiple times
|
|
187
|
+
* Ensures session metadata and OAuth provider are loaded.
|
|
188
|
+
* Does NOT create the SDK Client — callers that need one create it themselves.
|
|
190
189
|
* @private
|
|
191
190
|
*/
|
|
192
|
-
private
|
|
191
|
+
private ensureSession;
|
|
193
192
|
/**
|
|
194
193
|
* Saves current session state to the session store
|
|
195
194
|
* Creates new session if it doesn't exist, updates if it does
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as Event, M as McpConnectionEvent, t as McpObservabilityEvent, s as McpConnectionState, A as ToolClientProvider } from './types-
|
|
1
|
+
import { m as Event, M as McpConnectionEvent, t as McpObservabilityEvent, s as McpConnectionState, A as ToolClientProvider } from './types-Bf-7GOLW.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';
|
|
@@ -184,12 +184,11 @@ declare class MCPClient {
|
|
|
184
184
|
*/
|
|
185
185
|
private getTransport;
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* This method is idempotent and safe to call multiple times
|
|
187
|
+
* Ensures session metadata and OAuth provider are loaded.
|
|
188
|
+
* Does NOT create the SDK Client — callers that need one create it themselves.
|
|
190
189
|
* @private
|
|
191
190
|
*/
|
|
192
|
-
private
|
|
191
|
+
private ensureSession;
|
|
193
192
|
/**
|
|
194
193
|
* Saves current session state to the session store
|
|
195
194
|
* Creates new session if it doesn't exist, updates if it does
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as SessionMutationListener, e as SessionStore } from '../multi-session-client-
|
|
2
|
-
export { M as MCPClient, a as MultiSessionClient, S as Session, b as SessionMutationEvent, d as SessionMutationType, f as StorageOAuthClientProvider } from '../multi-session-client-
|
|
1
|
+
import { c as SessionMutationListener, e as SessionStore } from '../multi-session-client-ChQrBZhF.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-ChQrBZhF.mjs';
|
|
3
3
|
export { U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-DELRKQPU.mjs';
|
|
4
|
-
import { M as McpConnectionEvent, t as McpObservabilityEvent, x as McpRpcResponse, w as McpRpcRequest } from '../types-
|
|
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-
|
|
4
|
+
import { M as McpConnectionEvent, t as McpObservabilityEvent, x as McpRpcResponse, w as McpRpcRequest } from '../types-Bf-7GOLW.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-Bf-7GOLW.mjs';
|
|
6
6
|
export { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
7
7
|
export { CallToolResult, ListToolsResult, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
8
8
|
import '@modelcontextprotocol/sdk/client/auth.js';
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as SessionMutationListener, e as SessionStore } from '../multi-session-client-
|
|
2
|
-
export { M as MCPClient, a as MultiSessionClient, S as Session, b as SessionMutationEvent, d as SessionMutationType, f as StorageOAuthClientProvider } from '../multi-session-client-
|
|
1
|
+
import { c as SessionMutationListener, e as SessionStore } from '../multi-session-client-QOOPdEVp.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-QOOPdEVp.js';
|
|
3
3
|
export { U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-DELRKQPU.js';
|
|
4
|
-
import { M as McpConnectionEvent, t as McpObservabilityEvent, x as McpRpcResponse, w as McpRpcRequest } from '../types-
|
|
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-
|
|
4
|
+
import { M as McpConnectionEvent, t as McpObservabilityEvent, x as McpRpcResponse, w as McpRpcRequest } from '../types-Bf-7GOLW.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-Bf-7GOLW.js';
|
|
6
6
|
export { OAuthClientInformation, OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
7
7
|
export { CallToolResult, ListToolsResult, Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
8
8
|
import '@modelcontextprotocol/sdk/client/auth.js';
|
package/dist/server/index.js
CHANGED
|
@@ -159,13 +159,9 @@ init_cjs_shims();
|
|
|
159
159
|
// src/shared/utils.ts
|
|
160
160
|
init_cjs_shims();
|
|
161
161
|
var OAUTH_STATE_SEPARATOR = ".";
|
|
162
|
-
var
|
|
163
|
-
"
|
|
164
|
-
|
|
165
|
-
);
|
|
166
|
-
var rest = nanoid.customAlphabet(
|
|
167
|
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|
168
|
-
11
|
|
162
|
+
var serverIdAlphabet = nanoid.customAlphabet(
|
|
163
|
+
"abcdefghijklmnopqrstuvwxyz0123456789",
|
|
164
|
+
12
|
|
169
165
|
);
|
|
170
166
|
function sanitizeServerLabel(name) {
|
|
171
167
|
let sanitized = name.replace(/[^a-zA-Z0-9-_]/g, "_").replace(/_{2,}/g, "_").toLowerCase();
|
|
@@ -175,7 +171,10 @@ function sanitizeServerLabel(name) {
|
|
|
175
171
|
return sanitized;
|
|
176
172
|
}
|
|
177
173
|
function generateSessionId() {
|
|
178
|
-
return
|
|
174
|
+
return "sess_" + nanoid.nanoid(21);
|
|
175
|
+
}
|
|
176
|
+
function generateServerId() {
|
|
177
|
+
return serverIdAlphabet();
|
|
179
178
|
}
|
|
180
179
|
function formatOAuthState(nonce, sessionId) {
|
|
181
180
|
return `${nonce}${OAUTH_STATE_SEPARATOR}${sessionId}`;
|
|
@@ -2149,7 +2148,7 @@ var MCPClient = class {
|
|
|
2149
2148
|
* @param options - Client configuration options
|
|
2150
2149
|
*/
|
|
2151
2150
|
constructor(options) {
|
|
2152
|
-
__publicField(this, "client"
|
|
2151
|
+
__publicField(this, "client");
|
|
2153
2152
|
__publicField(this, "oauthProvider", null);
|
|
2154
2153
|
__publicField(this, "transport", null);
|
|
2155
2154
|
__publicField(this, "userId");
|
|
@@ -2190,6 +2189,21 @@ var MCPClient = class {
|
|
|
2190
2189
|
this.clientUri = options.clientUri;
|
|
2191
2190
|
this.logoUri = options.logoUri;
|
|
2192
2191
|
this.policyUri = options.policyUri;
|
|
2192
|
+
this.client = new index_js.Client(
|
|
2193
|
+
{
|
|
2194
|
+
name: MCP_CLIENT_NAME,
|
|
2195
|
+
version: MCP_CLIENT_VERSION
|
|
2196
|
+
},
|
|
2197
|
+
{
|
|
2198
|
+
capabilities: {
|
|
2199
|
+
extensions: {
|
|
2200
|
+
"io.modelcontextprotocol/ui": {
|
|
2201
|
+
mimeTypes: ["text/html+mcp"]
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
);
|
|
2193
2207
|
}
|
|
2194
2208
|
/**
|
|
2195
2209
|
* Emit a connection state change event
|
|
@@ -2315,13 +2329,12 @@ var MCPClient = class {
|
|
|
2315
2329
|
}
|
|
2316
2330
|
}
|
|
2317
2331
|
/**
|
|
2318
|
-
*
|
|
2319
|
-
*
|
|
2320
|
-
* This method is idempotent and safe to call multiple times
|
|
2332
|
+
* Ensures session metadata and OAuth provider are loaded.
|
|
2333
|
+
* Does NOT create the SDK Client — callers that need one create it themselves.
|
|
2321
2334
|
* @private
|
|
2322
2335
|
*/
|
|
2323
|
-
async
|
|
2324
|
-
if (this.
|
|
2336
|
+
async ensureSession() {
|
|
2337
|
+
if (this.oauthProvider) {
|
|
2325
2338
|
return;
|
|
2326
2339
|
}
|
|
2327
2340
|
this.emitStateChange("INITIALIZING");
|
|
@@ -2364,30 +2377,21 @@ var MCPClient = class {
|
|
|
2364
2377
|
}
|
|
2365
2378
|
});
|
|
2366
2379
|
}
|
|
2367
|
-
if (!this.client) {
|
|
2368
|
-
this.client = new index_js.Client(
|
|
2369
|
-
{
|
|
2370
|
-
name: MCP_CLIENT_NAME,
|
|
2371
|
-
version: MCP_CLIENT_VERSION
|
|
2372
|
-
},
|
|
2373
|
-
{
|
|
2374
|
-
capabilities: {
|
|
2375
|
-
extensions: {
|
|
2376
|
-
"io.modelcontextprotocol/ui": {
|
|
2377
|
-
mimeTypes: ["text/html+mcp"]
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
);
|
|
2383
|
-
}
|
|
2384
2380
|
if (existingSession === null) {
|
|
2385
2381
|
existingSession = await sessions.get(this.userId, this.sessionId);
|
|
2386
2382
|
}
|
|
2387
2383
|
if (!existingSession && this.serverId && this.serverUrl && this.callbackUrl) {
|
|
2388
2384
|
this.createdAt = Date.now();
|
|
2389
2385
|
const updatedAt = this.createdAt;
|
|
2390
|
-
|
|
2386
|
+
this._onObservabilityEvent.fire({
|
|
2387
|
+
type: "mcp:client:session_created",
|
|
2388
|
+
level: "info",
|
|
2389
|
+
message: `Creating pending session ${this.sessionId} for connection setup`,
|
|
2390
|
+
sessionId: this.sessionId,
|
|
2391
|
+
serverId: this.serverId,
|
|
2392
|
+
timestamp: Date.now(),
|
|
2393
|
+
id: nanoid.nanoid()
|
|
2394
|
+
});
|
|
2391
2395
|
await sessions.create({
|
|
2392
2396
|
sessionId: this.sessionId,
|
|
2393
2397
|
userId: this.userId,
|
|
@@ -2497,17 +2501,16 @@ var MCPClient = class {
|
|
|
2497
2501
|
* @throws {Error} When connection fails for other reasons
|
|
2498
2502
|
*/
|
|
2499
2503
|
async connect() {
|
|
2500
|
-
if (this.client
|
|
2504
|
+
if (this.client.transport) {
|
|
2501
2505
|
this.transport = null;
|
|
2502
2506
|
try {
|
|
2503
2507
|
await this.client.close();
|
|
2504
2508
|
} catch {
|
|
2505
2509
|
}
|
|
2506
|
-
this.client = null;
|
|
2507
2510
|
}
|
|
2508
|
-
await this.
|
|
2509
|
-
if (!this.
|
|
2510
|
-
const error = "
|
|
2511
|
+
await this.ensureSession();
|
|
2512
|
+
if (!this.oauthProvider) {
|
|
2513
|
+
const error = "OAuth provider not initialized";
|
|
2511
2514
|
this.emitError(error, "connection");
|
|
2512
2515
|
this.emitStateChange("FAILED");
|
|
2513
2516
|
throw new Error(error);
|
|
@@ -2518,7 +2521,15 @@ var MCPClient = class {
|
|
|
2518
2521
|
this.transportType = transportType;
|
|
2519
2522
|
this.emitStateChange("CONNECTED");
|
|
2520
2523
|
this.emitProgress("Connected successfully");
|
|
2521
|
-
|
|
2524
|
+
this._onObservabilityEvent.fire({
|
|
2525
|
+
type: "mcp:client:session_saved",
|
|
2526
|
+
level: "info",
|
|
2527
|
+
message: `Saving active session ${this.sessionId} (connect success)`,
|
|
2528
|
+
sessionId: this.sessionId,
|
|
2529
|
+
serverId: this.serverId,
|
|
2530
|
+
timestamp: Date.now(),
|
|
2531
|
+
id: nanoid.nanoid()
|
|
2532
|
+
});
|
|
2522
2533
|
await this.saveSession("active");
|
|
2523
2534
|
} catch (error) {
|
|
2524
2535
|
if (error instanceof auth_js.UnauthorizedError || error instanceof Error && error.message.toLowerCase().includes("unauthorized")) {
|
|
@@ -2535,7 +2546,15 @@ var MCPClient = class {
|
|
|
2535
2546
|
throw new Error(message);
|
|
2536
2547
|
}
|
|
2537
2548
|
this.emitStateChange("AUTHENTICATING");
|
|
2538
|
-
|
|
2549
|
+
this._onObservabilityEvent.fire({
|
|
2550
|
+
type: "mcp:client:session_saved",
|
|
2551
|
+
level: "info",
|
|
2552
|
+
message: `Saving pending OAuth session ${this.sessionId}`,
|
|
2553
|
+
sessionId: this.sessionId,
|
|
2554
|
+
serverId: this.serverId,
|
|
2555
|
+
timestamp: Date.now(),
|
|
2556
|
+
id: nanoid.nanoid()
|
|
2557
|
+
});
|
|
2539
2558
|
await this.saveSession("pending");
|
|
2540
2559
|
if (this.serverId) {
|
|
2541
2560
|
this._onConnectionEvent.fire({
|
|
@@ -2574,7 +2593,7 @@ var MCPClient = class {
|
|
|
2574
2593
|
async finishAuth(authCode, state) {
|
|
2575
2594
|
this.emitStateChange("AUTHENTICATING");
|
|
2576
2595
|
this.emitProgress("Exchanging authorization code for tokens...");
|
|
2577
|
-
await this.
|
|
2596
|
+
await this.ensureSession();
|
|
2578
2597
|
if (!this.oauthProvider) {
|
|
2579
2598
|
const error = "OAuth provider not initialized";
|
|
2580
2599
|
this.emitError(error, "auth");
|
|
@@ -2610,27 +2629,25 @@ var MCPClient = class {
|
|
|
2610
2629
|
this.emitStateChange("AUTHENTICATED");
|
|
2611
2630
|
authenticatedStateEmitted = true;
|
|
2612
2631
|
}
|
|
2613
|
-
this.emitProgress("Creating authenticated client...");
|
|
2614
|
-
this.client = new index_js.Client(
|
|
2615
|
-
{
|
|
2616
|
-
name: MCP_CLIENT_NAME,
|
|
2617
|
-
version: MCP_CLIENT_VERSION
|
|
2618
|
-
},
|
|
2619
|
-
{
|
|
2620
|
-
capabilities: {
|
|
2621
|
-
extensions: {
|
|
2622
|
-
"io.modelcontextprotocol/ui": {
|
|
2623
|
-
mimeTypes: ["text/html+mcp"]
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
);
|
|
2629
2632
|
this.emitStateChange("CONNECTING");
|
|
2633
|
+
if (this.client.transport) {
|
|
2634
|
+
try {
|
|
2635
|
+
await this.client.close();
|
|
2636
|
+
} catch {
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2630
2639
|
await this.client.connect(this.transport);
|
|
2631
2640
|
this.transportType = currentType;
|
|
2632
2641
|
this.emitStateChange("CONNECTED");
|
|
2633
|
-
|
|
2642
|
+
this._onObservabilityEvent.fire({
|
|
2643
|
+
type: "mcp:client:session_saved",
|
|
2644
|
+
level: "info",
|
|
2645
|
+
message: `Saving active session ${this.sessionId} (OAuth complete)`,
|
|
2646
|
+
sessionId: this.sessionId,
|
|
2647
|
+
serverId: this.serverId,
|
|
2648
|
+
timestamp: Date.now(),
|
|
2649
|
+
id: nanoid.nanoid()
|
|
2650
|
+
});
|
|
2634
2651
|
await this.saveSession("active");
|
|
2635
2652
|
return;
|
|
2636
2653
|
} catch (error) {
|
|
@@ -2671,9 +2688,6 @@ var MCPClient = class {
|
|
|
2671
2688
|
* @throws {Error} When client is not connected
|
|
2672
2689
|
*/
|
|
2673
2690
|
async listTools() {
|
|
2674
|
-
if (!this.client) {
|
|
2675
|
-
throw new Error("Not connected to server");
|
|
2676
|
-
}
|
|
2677
2691
|
this.emitStateChange("DISCOVERING");
|
|
2678
2692
|
try {
|
|
2679
2693
|
const request = {
|
|
@@ -2711,9 +2725,6 @@ var MCPClient = class {
|
|
|
2711
2725
|
* @throws {Error} When client is not connected
|
|
2712
2726
|
*/
|
|
2713
2727
|
async callTool(toolName, toolArgs) {
|
|
2714
|
-
if (!this.client) {
|
|
2715
|
-
throw new Error("Not connected to server");
|
|
2716
|
-
}
|
|
2717
2728
|
const request = {
|
|
2718
2729
|
method: "tools/call",
|
|
2719
2730
|
params: {
|
|
@@ -2767,9 +2778,6 @@ var MCPClient = class {
|
|
|
2767
2778
|
* @throws {Error} When client is not connected
|
|
2768
2779
|
*/
|
|
2769
2780
|
async listPrompts() {
|
|
2770
|
-
if (!this.client) {
|
|
2771
|
-
throw new Error("Not connected to server");
|
|
2772
|
-
}
|
|
2773
2781
|
this.emitStateChange("DISCOVERING");
|
|
2774
2782
|
try {
|
|
2775
2783
|
const request = {
|
|
@@ -2797,9 +2805,6 @@ var MCPClient = class {
|
|
|
2797
2805
|
* @throws {Error} When client is not connected
|
|
2798
2806
|
*/
|
|
2799
2807
|
async getPrompt(name, args) {
|
|
2800
|
-
if (!this.client) {
|
|
2801
|
-
throw new Error("Not connected to server");
|
|
2802
|
-
}
|
|
2803
2808
|
const request = {
|
|
2804
2809
|
method: "prompts/get",
|
|
2805
2810
|
params: {
|
|
@@ -2817,9 +2822,6 @@ var MCPClient = class {
|
|
|
2817
2822
|
* @throws {Error} When client is not connected
|
|
2818
2823
|
*/
|
|
2819
2824
|
async listResources() {
|
|
2820
|
-
if (!this.client) {
|
|
2821
|
-
throw new Error("Not connected to server");
|
|
2822
|
-
}
|
|
2823
2825
|
this.emitStateChange("DISCOVERING");
|
|
2824
2826
|
try {
|
|
2825
2827
|
const request = {
|
|
@@ -2846,9 +2848,6 @@ var MCPClient = class {
|
|
|
2846
2848
|
* @throws {Error} When client is not connected
|
|
2847
2849
|
*/
|
|
2848
2850
|
async readResource(uri) {
|
|
2849
|
-
if (!this.client) {
|
|
2850
|
-
throw new Error("Not connected to server");
|
|
2851
|
-
}
|
|
2852
2851
|
const request = {
|
|
2853
2852
|
method: "resources/read",
|
|
2854
2853
|
params: {
|
|
@@ -2874,13 +2873,12 @@ var MCPClient = class {
|
|
|
2874
2873
|
return await fn();
|
|
2875
2874
|
} catch (error) {
|
|
2876
2875
|
if (!(error instanceof Error && error.message.includes("MCP_SESSION_EXPIRED"))) throw error;
|
|
2877
|
-
if (this.client) {
|
|
2876
|
+
if (this.client.transport) {
|
|
2878
2877
|
try {
|
|
2879
2878
|
await this.client.close();
|
|
2880
2879
|
} catch {
|
|
2881
2880
|
}
|
|
2882
2881
|
this.transport = null;
|
|
2883
|
-
this.client = null;
|
|
2884
2882
|
}
|
|
2885
2883
|
await this.reconnect();
|
|
2886
2884
|
return await fn();
|
|
@@ -2893,26 +2891,9 @@ var MCPClient = class {
|
|
|
2893
2891
|
* @throws {Error} When OAuth provider is not initialized
|
|
2894
2892
|
*/
|
|
2895
2893
|
async reconnect() {
|
|
2896
|
-
await this.
|
|
2897
|
-
if (!this.oauthProvider)
|
|
2898
|
-
|
|
2899
|
-
}
|
|
2900
|
-
if (this.client) {
|
|
2901
|
-
try {
|
|
2902
|
-
await this.client.close();
|
|
2903
|
-
} catch {
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
this.client = new index_js.Client(
|
|
2907
|
-
{
|
|
2908
|
-
name: MCP_CLIENT_NAME,
|
|
2909
|
-
version: MCP_CLIENT_VERSION
|
|
2910
|
-
},
|
|
2911
|
-
{ capabilities: {} }
|
|
2912
|
-
);
|
|
2913
|
-
const tt = this.transportType || "streamable-http";
|
|
2914
|
-
this.transport = this.getTransport(tt);
|
|
2915
|
-
await this.client.connect(this.transport);
|
|
2894
|
+
await this.ensureSession();
|
|
2895
|
+
if (!this.oauthProvider) throw new Error("OAuth provider not initialized");
|
|
2896
|
+
await this.connect();
|
|
2916
2897
|
}
|
|
2917
2898
|
/**
|
|
2918
2899
|
* Completely removes the session from Redis including all OAuth data
|
|
@@ -2920,9 +2901,18 @@ var MCPClient = class {
|
|
|
2920
2901
|
*/
|
|
2921
2902
|
async clearSession() {
|
|
2922
2903
|
try {
|
|
2923
|
-
await this.
|
|
2904
|
+
await this.ensureSession();
|
|
2924
2905
|
} catch (error) {
|
|
2925
|
-
|
|
2906
|
+
this._onObservabilityEvent.fire({
|
|
2907
|
+
type: "mcp:client:error",
|
|
2908
|
+
level: "warn",
|
|
2909
|
+
message: "Initialization failed during clearSession",
|
|
2910
|
+
sessionId: this.sessionId,
|
|
2911
|
+
serverId: this.serverId,
|
|
2912
|
+
payload: { error: String(error) },
|
|
2913
|
+
timestamp: Date.now(),
|
|
2914
|
+
id: nanoid.nanoid()
|
|
2915
|
+
});
|
|
2926
2916
|
}
|
|
2927
2917
|
if (this.oauthProvider) {
|
|
2928
2918
|
await this.oauthProvider.invalidateCredentials("all");
|
|
@@ -2935,7 +2925,7 @@ var MCPClient = class {
|
|
|
2935
2925
|
* @returns True if connected, false otherwise
|
|
2936
2926
|
*/
|
|
2937
2927
|
isConnected() {
|
|
2938
|
-
return this.client !==
|
|
2928
|
+
return this.client.transport !== void 0;
|
|
2939
2929
|
}
|
|
2940
2930
|
/**
|
|
2941
2931
|
* Disconnects from the MCP server and cleans up resources.
|
|
@@ -2953,10 +2943,12 @@ var MCPClient = class {
|
|
|
2953
2943
|
} catch {
|
|
2954
2944
|
}
|
|
2955
2945
|
}
|
|
2956
|
-
if (this.client) {
|
|
2957
|
-
|
|
2946
|
+
if (this.client.transport) {
|
|
2947
|
+
try {
|
|
2948
|
+
await this.client.close();
|
|
2949
|
+
} catch {
|
|
2950
|
+
}
|
|
2958
2951
|
}
|
|
2959
|
-
this.client = null;
|
|
2960
2952
|
this.oauthProvider = null;
|
|
2961
2953
|
this.transport = null;
|
|
2962
2954
|
if (this.serverId) {
|
|
@@ -3402,7 +3394,7 @@ var SSEConnectionManager = class {
|
|
|
3402
3394
|
async connect(params) {
|
|
3403
3395
|
const { serverName, serverUrl, callbackUrl, transportType } = params;
|
|
3404
3396
|
const headers = normalizeHeaders(params.headers);
|
|
3405
|
-
const serverId = params.serverId && params.serverId.length <= 12 ? params.serverId :
|
|
3397
|
+
const serverId = params.serverId && params.serverId.length <= 12 ? params.serverId : generateServerId();
|
|
3406
3398
|
const existingSessions = await sessions.list(this.userId);
|
|
3407
3399
|
const duplicate = existingSessions.find(
|
|
3408
3400
|
(s) => s.serverId === serverId || s.serverUrl === serverUrl
|