mcp-use 1.34.6 → 1.34.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/.tsbuildinfo +1 -1
- package/dist/{chunk-DDMBF2UU.js → chunk-6ERGZHCN.js} +1 -1
- package/dist/{chunk-DI4WNZQC.js → chunk-E7PWRUQZ.js} +1 -1
- package/dist/{chunk-GLMTGH37.js → chunk-ESSZPKPU.js} +1 -1
- package/dist/{chunk-7R56RSZ6.js → chunk-LOSPF4H5.js} +1 -1
- package/dist/{chunk-FRPS4EPQ.js → chunk-PJARRPKP.js} +5 -5
- package/dist/{chunk-FOGBXW3W.js → chunk-QEYINRZL.js} +4 -4
- package/dist/{chunk-J4VRW5ND.js → chunk-RRCHCSPQ.js} +2 -2
- package/dist/{chunk-V64O255P.js → chunk-SGT4D4LO.js} +1 -1
- package/dist/{chunk-3XAZE4TX.js → chunk-XILMNNJF.js} +7 -7
- package/dist/{chunk-NF3GBT4Z.js → chunk-XRLI6ZYX.js} +1 -1
- package/dist/{chunk-XHHLR7B5.js → chunk-YGL37XKG.js} +2 -2
- package/dist/{client-JFSDQX2A.js → client-Y2ZVEDQC.js} +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +33 -33
- package/dist/src/agents/index.cjs +1 -1
- package/dist/src/agents/index.js +6 -6
- package/dist/src/browser-agent.cjs +1 -1
- package/dist/src/browser-agent.js +2 -2
- package/dist/src/browser.cjs +1 -1
- package/dist/src/browser.js +4 -4
- package/dist/src/client.cjs +1 -1
- package/dist/src/client.js +6 -6
- package/dist/src/react/index.cjs +1 -1
- package/dist/src/react/index.js +4 -4
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +120 -86
- package/dist/src/server/index.js +127 -93
- package/dist/src/version.d.ts +1 -1
- package/dist/{stdio-Q655HD2H.js → stdio-3JX4DSGH.js} +2 -2
- package/dist/{stdio-KQEZC3W4.js → stdio-BJKCQSAY.js} +4 -4
- package/dist/{tool-execution-helpers-5OCWDSO5.js → tool-execution-helpers-YOE4JC6H.js} +3 -3
- package/package.json +3 -3
|
@@ -661,7 +661,7 @@ var VERSION;
|
|
|
661
661
|
var init_version = __esm({
|
|
662
662
|
"src/version.ts"() {
|
|
663
663
|
"use strict";
|
|
664
|
-
VERSION = "1.34.
|
|
664
|
+
VERSION = "1.34.7";
|
|
665
665
|
__name(getPackageVersion, "getPackageVersion");
|
|
666
666
|
}
|
|
667
667
|
});
|
|
@@ -13713,7 +13713,9 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
13713
13713
|
}
|
|
13714
13714
|
const acceptHeader = c.req.header("Accept") || c.req.header("accept") || "";
|
|
13715
13715
|
const clientSupportsSSE = acceptHeader.includes("text/event-stream");
|
|
13716
|
-
const
|
|
13716
|
+
const sessionId = c.req.header("mcp-session-id");
|
|
13717
|
+
const isSessionDelete = c.req.method === "DELETE" && !!sessionId;
|
|
13718
|
+
const useStatelessMode = config.stateless || !clientSupportsSSE && !isSessionDelete;
|
|
13717
13719
|
if (useStatelessMode) {
|
|
13718
13720
|
if (c.req.method === "HEAD") {
|
|
13719
13721
|
return new Response(null, { status: 200 });
|
|
@@ -13756,7 +13758,6 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
13756
13758
|
throw error2;
|
|
13757
13759
|
}
|
|
13758
13760
|
} else {
|
|
13759
|
-
const sessionId = c.req.header("mcp-session-id");
|
|
13760
13761
|
if (c.req.method === "HEAD") {
|
|
13761
13762
|
if (sessionId && await sessionStore.has(sessionId)) {
|
|
13762
13763
|
const session = await sessionStore.get(sessionId);
|
|
@@ -13775,8 +13776,8 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
13775
13776
|
console.log(
|
|
13776
13777
|
`[MCP] Session metadata found but transport lost (restart/hot-reload): ${sessionId} - recovering`
|
|
13777
13778
|
);
|
|
13778
|
-
const
|
|
13779
|
-
const
|
|
13779
|
+
const server = mcpServerInstance.getServerForSession(sessionId);
|
|
13780
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
13780
13781
|
sessionIdGenerator: /* @__PURE__ */ __name(() => sessionId, "sessionIdGenerator"),
|
|
13781
13782
|
onsessioninitialized: /* @__PURE__ */ __name(async (sid) => {
|
|
13782
13783
|
if (getDebugLevel() !== "info") {
|
|
@@ -13795,15 +13796,15 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
13795
13796
|
mcpServerInstance.cleanupSessionRefs?.(sid);
|
|
13796
13797
|
}, "onsessionclosed")
|
|
13797
13798
|
});
|
|
13798
|
-
wrapTransportForStreamManager(
|
|
13799
|
-
await
|
|
13800
|
-
|
|
13801
|
-
|
|
13802
|
-
transports.set(sessionId,
|
|
13799
|
+
wrapTransportForStreamManager(transport, sessionId, streamManager);
|
|
13800
|
+
await server.connect(transport);
|
|
13801
|
+
transport._initialized = true;
|
|
13802
|
+
transport.sessionId = sessionId;
|
|
13803
|
+
transports.set(sessionId, transport);
|
|
13803
13804
|
const metadata = await sessionStore.get(sessionId);
|
|
13804
13805
|
const sessionData = {
|
|
13805
|
-
transport
|
|
13806
|
-
server
|
|
13806
|
+
transport,
|
|
13807
|
+
server,
|
|
13807
13808
|
lastAccessedAt: Date.now(),
|
|
13808
13809
|
context: c,
|
|
13809
13810
|
honoContext: c,
|
|
@@ -13815,11 +13816,11 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
13815
13816
|
}
|
|
13816
13817
|
const recoveryResponse = await runWithContext(
|
|
13817
13818
|
c,
|
|
13818
|
-
async () =>
|
|
13819
|
+
async () => transport.handleRequest(c.req.raw),
|
|
13819
13820
|
sessionId
|
|
13820
13821
|
);
|
|
13821
13822
|
if (c.req.method === "GET") {
|
|
13822
|
-
await registerSseStream(
|
|
13823
|
+
await registerSseStream(transport, sessionId, streamManager);
|
|
13823
13824
|
}
|
|
13824
13825
|
return recoveryResponse;
|
|
13825
13826
|
}
|
|
@@ -13837,7 +13838,7 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
13837
13838
|
);
|
|
13838
13839
|
}
|
|
13839
13840
|
if (sessionId && transports.has(sessionId)) {
|
|
13840
|
-
const
|
|
13841
|
+
const transport = transports.get(sessionId);
|
|
13841
13842
|
const metadata = await sessionStore.get(sessionId);
|
|
13842
13843
|
if (metadata) {
|
|
13843
13844
|
metadata.lastAccessedAt = Date.now();
|
|
@@ -13854,89 +13855,122 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
13854
13855
|
}
|
|
13855
13856
|
const existingResponse = await runWithContext(
|
|
13856
13857
|
c,
|
|
13857
|
-
async () =>
|
|
13858
|
+
async () => transport.handleRequest(c.req.raw),
|
|
13858
13859
|
sessionId
|
|
13859
13860
|
);
|
|
13860
13861
|
if (c.req.method === "GET") {
|
|
13861
|
-
await registerSseStream(
|
|
13862
|
+
await registerSseStream(transport, sessionId, streamManager);
|
|
13862
13863
|
}
|
|
13863
13864
|
return existingResponse;
|
|
13864
13865
|
}
|
|
13865
13866
|
const newSessionId = generateUUID();
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
|
|
13875
|
-
|
|
13876
|
-
|
|
13877
|
-
|
|
13878
|
-
|
|
13879
|
-
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
|
|
13884
|
-
|
|
13885
|
-
|
|
13886
|
-
|
|
13887
|
-
|
|
13888
|
-
|
|
13889
|
-
|
|
13890
|
-
|
|
13891
|
-
|
|
13892
|
-
|
|
13893
|
-
|
|
13894
|
-
await sessionStore.
|
|
13895
|
-
if (
|
|
13896
|
-
|
|
13897
|
-
|
|
13898
|
-
|
|
13899
|
-
);
|
|
13867
|
+
let allocatedServer;
|
|
13868
|
+
let allocatedTransport;
|
|
13869
|
+
let sessionEstablished = false;
|
|
13870
|
+
try {
|
|
13871
|
+
const server = mcpServerInstance.getServerForSession(newSessionId);
|
|
13872
|
+
allocatedServer = server;
|
|
13873
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
13874
|
+
sessionIdGenerator: /* @__PURE__ */ __name(() => newSessionId, "sessionIdGenerator"),
|
|
13875
|
+
onsessioninitialized: /* @__PURE__ */ __name(async (sid) => {
|
|
13876
|
+
if (getDebugLevel() !== "info") {
|
|
13877
|
+
console.log(`[MCP] Session initialized: ${sid}`);
|
|
13878
|
+
}
|
|
13879
|
+
transports.set(sid, transport);
|
|
13880
|
+
const sessionData = {
|
|
13881
|
+
transport,
|
|
13882
|
+
server,
|
|
13883
|
+
lastAccessedAt: Date.now(),
|
|
13884
|
+
context: c,
|
|
13885
|
+
honoContext: c
|
|
13886
|
+
};
|
|
13887
|
+
sessions.set(sid, sessionData);
|
|
13888
|
+
await sessionStore.set(sid, {
|
|
13889
|
+
lastAccessedAt: Date.now()
|
|
13890
|
+
});
|
|
13891
|
+
server.server.oninitialized = async () => {
|
|
13892
|
+
const clientCapabilities = server.server.getClientCapabilities();
|
|
13893
|
+
const clientInfo = server.server.getClientVersion?.() || server.server.getClientInfo?.() || {};
|
|
13894
|
+
const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
|
|
13895
|
+
const metadata = await sessionStore.get(sid);
|
|
13896
|
+
if (metadata) {
|
|
13897
|
+
metadata.clientCapabilities = clientCapabilities;
|
|
13898
|
+
metadata.clientInfo = clientInfo;
|
|
13899
|
+
metadata.protocolVersion = String(protocolVersion);
|
|
13900
|
+
await sessionStore.set(sid, metadata);
|
|
13901
|
+
if (getDebugLevel() !== "info") {
|
|
13902
|
+
console.log(
|
|
13903
|
+
`[MCP] Captured client capabilities for session ${sid}:`,
|
|
13904
|
+
clientCapabilities ? Object.keys(clientCapabilities) : "none"
|
|
13905
|
+
);
|
|
13906
|
+
}
|
|
13900
13907
|
}
|
|
13908
|
+
const sessionData2 = sessions.get(sid);
|
|
13909
|
+
if (sessionData2) {
|
|
13910
|
+
sessionData2.clientCapabilities = clientCapabilities;
|
|
13911
|
+
sessionData2.clientInfo = clientInfo;
|
|
13912
|
+
}
|
|
13913
|
+
Telemetry.getInstance().trackServerInitialize({
|
|
13914
|
+
protocolVersion: String(protocolVersion),
|
|
13915
|
+
clientInfo: clientInfo || {},
|
|
13916
|
+
clientCapabilities: clientCapabilities || {},
|
|
13917
|
+
sessionId: sid
|
|
13918
|
+
}).catch(
|
|
13919
|
+
(e) => console.debug(`Failed to track server initialize: ${e}`)
|
|
13920
|
+
);
|
|
13921
|
+
};
|
|
13922
|
+
}, "onsessioninitialized"),
|
|
13923
|
+
onsessionclosed: /* @__PURE__ */ __name(async (sid) => {
|
|
13924
|
+
if (getDebugLevel() !== "info") {
|
|
13925
|
+
console.log(`[MCP] Session closed: ${sid}`);
|
|
13901
13926
|
}
|
|
13902
|
-
|
|
13903
|
-
|
|
13904
|
-
|
|
13905
|
-
|
|
13927
|
+
transports.delete(sid);
|
|
13928
|
+
await streamManager.delete(sid);
|
|
13929
|
+
await sessionStore.delete(sid);
|
|
13930
|
+
sessions.delete(sid);
|
|
13931
|
+
mcpServerInstance.cleanupSessionSubscriptions?.(sid);
|
|
13932
|
+
mcpServerInstance.cleanupSessionRefs?.(sid);
|
|
13933
|
+
}, "onsessionclosed")
|
|
13934
|
+
});
|
|
13935
|
+
allocatedTransport = transport;
|
|
13936
|
+
wrapTransportForStreamManager(transport, newSessionId, streamManager);
|
|
13937
|
+
await server.connect(transport);
|
|
13938
|
+
const newSessionResponse = await runWithContext(
|
|
13939
|
+
c,
|
|
13940
|
+
async () => transport.handleRequest(c.req.raw),
|
|
13941
|
+
newSessionId
|
|
13942
|
+
);
|
|
13943
|
+
if (c.req.method === "GET") {
|
|
13944
|
+
await registerSseStream(transport, newSessionId, streamManager);
|
|
13945
|
+
}
|
|
13946
|
+
sessionEstablished = newSessionResponse.ok && sessions.has(newSessionId) && !c.req.raw.signal.aborted;
|
|
13947
|
+
return newSessionResponse;
|
|
13948
|
+
} finally {
|
|
13949
|
+
if (!sessionEstablished) {
|
|
13950
|
+
transports.delete(newSessionId);
|
|
13951
|
+
sessions.delete(newSessionId);
|
|
13952
|
+
const cleanups = await Promise.allSettled([
|
|
13953
|
+
Promise.resolve().then(
|
|
13954
|
+
() => mcpServerInstance.cleanupSessionSubscriptions?.(newSessionId)
|
|
13955
|
+
),
|
|
13956
|
+
Promise.resolve().then(
|
|
13957
|
+
() => mcpServerInstance.cleanupSessionRefs?.(newSessionId)
|
|
13958
|
+
),
|
|
13959
|
+
Promise.resolve().then(() => streamManager.delete(newSessionId)),
|
|
13960
|
+
Promise.resolve().then(() => sessionStore.delete(newSessionId)),
|
|
13961
|
+
Promise.resolve().then(() => allocatedServer?.close()),
|
|
13962
|
+
Promise.resolve().then(() => allocatedTransport?.close())
|
|
13963
|
+
]);
|
|
13964
|
+
for (const cleanup of cleanups) {
|
|
13965
|
+
if (cleanup.status === "rejected") {
|
|
13966
|
+
console.warn(
|
|
13967
|
+
`[MCP] Error cleaning up unsuccessful session ${newSessionId}:`,
|
|
13968
|
+
cleanup.reason
|
|
13969
|
+
);
|
|
13906
13970
|
}
|
|
13907
|
-
Telemetry.getInstance().trackServerInitialize({
|
|
13908
|
-
protocolVersion: String(protocolVersion),
|
|
13909
|
-
clientInfo: clientInfo || {},
|
|
13910
|
-
clientCapabilities: clientCapabilities || {},
|
|
13911
|
-
sessionId: sid
|
|
13912
|
-
}).catch(
|
|
13913
|
-
(e) => console.debug(`Failed to track server initialize: ${e}`)
|
|
13914
|
-
);
|
|
13915
|
-
};
|
|
13916
|
-
}, "onsessioninitialized"),
|
|
13917
|
-
onsessionclosed: /* @__PURE__ */ __name(async (sid) => {
|
|
13918
|
-
if (getDebugLevel() !== "info") {
|
|
13919
|
-
console.log(`[MCP] Session closed: ${sid}`);
|
|
13920
13971
|
}
|
|
13921
|
-
|
|
13922
|
-
await streamManager.delete(sid);
|
|
13923
|
-
await sessionStore.delete(sid);
|
|
13924
|
-
sessions.delete(sid);
|
|
13925
|
-
mcpServerInstance.cleanupSessionSubscriptions?.(sid);
|
|
13926
|
-
mcpServerInstance.cleanupSessionRefs?.(sid);
|
|
13927
|
-
}, "onsessionclosed")
|
|
13928
|
-
});
|
|
13929
|
-
wrapTransportForStreamManager(transport, newSessionId, streamManager);
|
|
13930
|
-
await server.connect(transport);
|
|
13931
|
-
const newSessionResponse = await runWithContext(
|
|
13932
|
-
c,
|
|
13933
|
-
async () => transport.handleRequest(c.req.raw),
|
|
13934
|
-
newSessionId
|
|
13935
|
-
);
|
|
13936
|
-
if (c.req.method === "GET") {
|
|
13937
|
-
await registerSseStream(transport, newSessionId, streamManager);
|
|
13972
|
+
}
|
|
13938
13973
|
}
|
|
13939
|
-
return newSessionResponse;
|
|
13940
13974
|
}
|
|
13941
13975
|
}, "handleRequest");
|
|
13942
13976
|
for (const endpoint of ["/mcp", "/sse"]) {
|
package/dist/src/server/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
findSessionContext,
|
|
18
18
|
isValidLogLevel,
|
|
19
19
|
supportsApps
|
|
20
|
-
} from "../../chunk-
|
|
20
|
+
} from "../../chunk-E7PWRUQZ.js";
|
|
21
21
|
import {
|
|
22
22
|
getRequestContext,
|
|
23
23
|
hasRequestContext,
|
|
@@ -59,8 +59,7 @@ import {
|
|
|
59
59
|
Telemetry,
|
|
60
60
|
VERSION,
|
|
61
61
|
getPackageVersion
|
|
62
|
-
} from "../../chunk-
|
|
63
|
-
import "../../chunk-BXZHMYMM.js";
|
|
62
|
+
} from "../../chunk-QEYINRZL.js";
|
|
64
63
|
import {
|
|
65
64
|
fsHelpers,
|
|
66
65
|
generateUUID,
|
|
@@ -70,6 +69,7 @@ import {
|
|
|
70
69
|
pathHelpers
|
|
71
70
|
} from "../../chunk-MTHLLDCX.js";
|
|
72
71
|
import "../../chunk-QWQYAQCK.js";
|
|
72
|
+
import "../../chunk-BXZHMYMM.js";
|
|
73
73
|
import {
|
|
74
74
|
__name
|
|
75
75
|
} from "../../chunk-3GQAWCBQ.js";
|
|
@@ -3332,7 +3332,7 @@ function registerPrompt(promptDefinition, callback) {
|
|
|
3332
3332
|
}
|
|
3333
3333
|
const wrappedCallback = /* @__PURE__ */ __name(async (params, extra) => {
|
|
3334
3334
|
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-KMOAHEL7.js");
|
|
3335
|
-
const { findSessionContext: findSessionContext2, createClientCapabilityChecker } = await import("../../tool-execution-helpers-
|
|
3335
|
+
const { findSessionContext: findSessionContext2, createClientCapabilityChecker } = await import("../../tool-execution-helpers-YOE4JC6H.js");
|
|
3336
3336
|
const initialRequestContext = getRequestContext2();
|
|
3337
3337
|
const sessions = this.sessions || /* @__PURE__ */ new Map();
|
|
3338
3338
|
const { requestContext, session } = findSessionContext2(
|
|
@@ -3537,7 +3537,7 @@ function registerResource(resourceDefinition, callback) {
|
|
|
3537
3537
|
const explicitMimeType = resourceDefinition.mimeType;
|
|
3538
3538
|
const wrappedCallback = /* @__PURE__ */ __name(async () => {
|
|
3539
3539
|
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-KMOAHEL7.js");
|
|
3540
|
-
const { findSessionContext: findSessionContext2, createClientCapabilityChecker } = await import("../../tool-execution-helpers-
|
|
3540
|
+
const { findSessionContext: findSessionContext2, createClientCapabilityChecker } = await import("../../tool-execution-helpers-YOE4JC6H.js");
|
|
3541
3541
|
const initialRequestContext = getRequestContext2();
|
|
3542
3542
|
const sessions = this.sessions || /* @__PURE__ */ new Map();
|
|
3543
3543
|
const { requestContext, session } = findSessionContext2(
|
|
@@ -3625,7 +3625,7 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
|
|
|
3625
3625
|
async (uri) => {
|
|
3626
3626
|
const params = this.parseTemplateUri(uriTemplate, uri.toString());
|
|
3627
3627
|
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-KMOAHEL7.js");
|
|
3628
|
-
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-
|
|
3628
|
+
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-YOE4JC6H.js");
|
|
3629
3629
|
const initialRequestContext = getRequestContext2();
|
|
3630
3630
|
const sessions = this.sessions || /* @__PURE__ */ new Map();
|
|
3631
3631
|
const { requestContext } = findSessionContext2(
|
|
@@ -5862,7 +5862,9 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
5862
5862
|
}
|
|
5863
5863
|
const acceptHeader = c.req.header("Accept") || c.req.header("accept") || "";
|
|
5864
5864
|
const clientSupportsSSE = acceptHeader.includes("text/event-stream");
|
|
5865
|
-
const
|
|
5865
|
+
const sessionId = c.req.header("mcp-session-id");
|
|
5866
|
+
const isSessionDelete = c.req.method === "DELETE" && !!sessionId;
|
|
5867
|
+
const useStatelessMode = config.stateless || !clientSupportsSSE && !isSessionDelete;
|
|
5866
5868
|
if (useStatelessMode) {
|
|
5867
5869
|
if (c.req.method === "HEAD") {
|
|
5868
5870
|
return new Response(null, { status: 200 });
|
|
@@ -5905,7 +5907,6 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
5905
5907
|
throw error2;
|
|
5906
5908
|
}
|
|
5907
5909
|
} else {
|
|
5908
|
-
const sessionId = c.req.header("mcp-session-id");
|
|
5909
5910
|
if (c.req.method === "HEAD") {
|
|
5910
5911
|
if (sessionId && await sessionStore.has(sessionId)) {
|
|
5911
5912
|
const session = await sessionStore.get(sessionId);
|
|
@@ -5924,8 +5925,8 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
5924
5925
|
console.log(
|
|
5925
5926
|
`[MCP] Session metadata found but transport lost (restart/hot-reload): ${sessionId} - recovering`
|
|
5926
5927
|
);
|
|
5927
|
-
const
|
|
5928
|
-
const
|
|
5928
|
+
const server = mcpServerInstance.getServerForSession(sessionId);
|
|
5929
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
5929
5930
|
sessionIdGenerator: /* @__PURE__ */ __name(() => sessionId, "sessionIdGenerator"),
|
|
5930
5931
|
onsessioninitialized: /* @__PURE__ */ __name(async (sid) => {
|
|
5931
5932
|
if (getDebugLevel() !== "info") {
|
|
@@ -5944,15 +5945,15 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
5944
5945
|
mcpServerInstance.cleanupSessionRefs?.(sid);
|
|
5945
5946
|
}, "onsessionclosed")
|
|
5946
5947
|
});
|
|
5947
|
-
wrapTransportForStreamManager(
|
|
5948
|
-
await
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
transports.set(sessionId,
|
|
5948
|
+
wrapTransportForStreamManager(transport, sessionId, streamManager);
|
|
5949
|
+
await server.connect(transport);
|
|
5950
|
+
transport._initialized = true;
|
|
5951
|
+
transport.sessionId = sessionId;
|
|
5952
|
+
transports.set(sessionId, transport);
|
|
5952
5953
|
const metadata = await sessionStore.get(sessionId);
|
|
5953
5954
|
const sessionData = {
|
|
5954
|
-
transport
|
|
5955
|
-
server
|
|
5955
|
+
transport,
|
|
5956
|
+
server,
|
|
5956
5957
|
lastAccessedAt: Date.now(),
|
|
5957
5958
|
context: c,
|
|
5958
5959
|
honoContext: c,
|
|
@@ -5964,11 +5965,11 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
5964
5965
|
}
|
|
5965
5966
|
const recoveryResponse = await runWithContext(
|
|
5966
5967
|
c,
|
|
5967
|
-
async () =>
|
|
5968
|
+
async () => transport.handleRequest(c.req.raw),
|
|
5968
5969
|
sessionId
|
|
5969
5970
|
);
|
|
5970
5971
|
if (c.req.method === "GET") {
|
|
5971
|
-
await registerSseStream(
|
|
5972
|
+
await registerSseStream(transport, sessionId, streamManager);
|
|
5972
5973
|
}
|
|
5973
5974
|
return recoveryResponse;
|
|
5974
5975
|
}
|
|
@@ -5986,7 +5987,7 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
5986
5987
|
);
|
|
5987
5988
|
}
|
|
5988
5989
|
if (sessionId && transports.has(sessionId)) {
|
|
5989
|
-
const
|
|
5990
|
+
const transport = transports.get(sessionId);
|
|
5990
5991
|
const metadata = await sessionStore.get(sessionId);
|
|
5991
5992
|
if (metadata) {
|
|
5992
5993
|
metadata.lastAccessedAt = Date.now();
|
|
@@ -6003,89 +6004,122 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
6003
6004
|
}
|
|
6004
6005
|
const existingResponse = await runWithContext(
|
|
6005
6006
|
c,
|
|
6006
|
-
async () =>
|
|
6007
|
+
async () => transport.handleRequest(c.req.raw),
|
|
6007
6008
|
sessionId
|
|
6008
6009
|
);
|
|
6009
6010
|
if (c.req.method === "GET") {
|
|
6010
|
-
await registerSseStream(
|
|
6011
|
+
await registerSseStream(transport, sessionId, streamManager);
|
|
6011
6012
|
}
|
|
6012
6013
|
return existingResponse;
|
|
6013
6014
|
}
|
|
6014
6015
|
const newSessionId = generateUUID();
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
await sessionStore.
|
|
6044
|
-
if (
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
);
|
|
6016
|
+
let allocatedServer;
|
|
6017
|
+
let allocatedTransport;
|
|
6018
|
+
let sessionEstablished = false;
|
|
6019
|
+
try {
|
|
6020
|
+
const server = mcpServerInstance.getServerForSession(newSessionId);
|
|
6021
|
+
allocatedServer = server;
|
|
6022
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
6023
|
+
sessionIdGenerator: /* @__PURE__ */ __name(() => newSessionId, "sessionIdGenerator"),
|
|
6024
|
+
onsessioninitialized: /* @__PURE__ */ __name(async (sid) => {
|
|
6025
|
+
if (getDebugLevel() !== "info") {
|
|
6026
|
+
console.log(`[MCP] Session initialized: ${sid}`);
|
|
6027
|
+
}
|
|
6028
|
+
transports.set(sid, transport);
|
|
6029
|
+
const sessionData = {
|
|
6030
|
+
transport,
|
|
6031
|
+
server,
|
|
6032
|
+
lastAccessedAt: Date.now(),
|
|
6033
|
+
context: c,
|
|
6034
|
+
honoContext: c
|
|
6035
|
+
};
|
|
6036
|
+
sessions.set(sid, sessionData);
|
|
6037
|
+
await sessionStore.set(sid, {
|
|
6038
|
+
lastAccessedAt: Date.now()
|
|
6039
|
+
});
|
|
6040
|
+
server.server.oninitialized = async () => {
|
|
6041
|
+
const clientCapabilities = server.server.getClientCapabilities();
|
|
6042
|
+
const clientInfo = server.server.getClientVersion?.() || server.server.getClientInfo?.() || {};
|
|
6043
|
+
const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
|
|
6044
|
+
const metadata = await sessionStore.get(sid);
|
|
6045
|
+
if (metadata) {
|
|
6046
|
+
metadata.clientCapabilities = clientCapabilities;
|
|
6047
|
+
metadata.clientInfo = clientInfo;
|
|
6048
|
+
metadata.protocolVersion = String(protocolVersion);
|
|
6049
|
+
await sessionStore.set(sid, metadata);
|
|
6050
|
+
if (getDebugLevel() !== "info") {
|
|
6051
|
+
console.log(
|
|
6052
|
+
`[MCP] Captured client capabilities for session ${sid}:`,
|
|
6053
|
+
clientCapabilities ? Object.keys(clientCapabilities) : "none"
|
|
6054
|
+
);
|
|
6055
|
+
}
|
|
6049
6056
|
}
|
|
6057
|
+
const sessionData2 = sessions.get(sid);
|
|
6058
|
+
if (sessionData2) {
|
|
6059
|
+
sessionData2.clientCapabilities = clientCapabilities;
|
|
6060
|
+
sessionData2.clientInfo = clientInfo;
|
|
6061
|
+
}
|
|
6062
|
+
Telemetry.getInstance().trackServerInitialize({
|
|
6063
|
+
protocolVersion: String(protocolVersion),
|
|
6064
|
+
clientInfo: clientInfo || {},
|
|
6065
|
+
clientCapabilities: clientCapabilities || {},
|
|
6066
|
+
sessionId: sid
|
|
6067
|
+
}).catch(
|
|
6068
|
+
(e) => console.debug(`Failed to track server initialize: ${e}`)
|
|
6069
|
+
);
|
|
6070
|
+
};
|
|
6071
|
+
}, "onsessioninitialized"),
|
|
6072
|
+
onsessionclosed: /* @__PURE__ */ __name(async (sid) => {
|
|
6073
|
+
if (getDebugLevel() !== "info") {
|
|
6074
|
+
console.log(`[MCP] Session closed: ${sid}`);
|
|
6050
6075
|
}
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6076
|
+
transports.delete(sid);
|
|
6077
|
+
await streamManager.delete(sid);
|
|
6078
|
+
await sessionStore.delete(sid);
|
|
6079
|
+
sessions.delete(sid);
|
|
6080
|
+
mcpServerInstance.cleanupSessionSubscriptions?.(sid);
|
|
6081
|
+
mcpServerInstance.cleanupSessionRefs?.(sid);
|
|
6082
|
+
}, "onsessionclosed")
|
|
6083
|
+
});
|
|
6084
|
+
allocatedTransport = transport;
|
|
6085
|
+
wrapTransportForStreamManager(transport, newSessionId, streamManager);
|
|
6086
|
+
await server.connect(transport);
|
|
6087
|
+
const newSessionResponse = await runWithContext(
|
|
6088
|
+
c,
|
|
6089
|
+
async () => transport.handleRequest(c.req.raw),
|
|
6090
|
+
newSessionId
|
|
6091
|
+
);
|
|
6092
|
+
if (c.req.method === "GET") {
|
|
6093
|
+
await registerSseStream(transport, newSessionId, streamManager);
|
|
6094
|
+
}
|
|
6095
|
+
sessionEstablished = newSessionResponse.ok && sessions.has(newSessionId) && !c.req.raw.signal.aborted;
|
|
6096
|
+
return newSessionResponse;
|
|
6097
|
+
} finally {
|
|
6098
|
+
if (!sessionEstablished) {
|
|
6099
|
+
transports.delete(newSessionId);
|
|
6100
|
+
sessions.delete(newSessionId);
|
|
6101
|
+
const cleanups = await Promise.allSettled([
|
|
6102
|
+
Promise.resolve().then(
|
|
6103
|
+
() => mcpServerInstance.cleanupSessionSubscriptions?.(newSessionId)
|
|
6104
|
+
),
|
|
6105
|
+
Promise.resolve().then(
|
|
6106
|
+
() => mcpServerInstance.cleanupSessionRefs?.(newSessionId)
|
|
6107
|
+
),
|
|
6108
|
+
Promise.resolve().then(() => streamManager.delete(newSessionId)),
|
|
6109
|
+
Promise.resolve().then(() => sessionStore.delete(newSessionId)),
|
|
6110
|
+
Promise.resolve().then(() => allocatedServer?.close()),
|
|
6111
|
+
Promise.resolve().then(() => allocatedTransport?.close())
|
|
6112
|
+
]);
|
|
6113
|
+
for (const cleanup of cleanups) {
|
|
6114
|
+
if (cleanup.status === "rejected") {
|
|
6115
|
+
console.warn(
|
|
6116
|
+
`[MCP] Error cleaning up unsuccessful session ${newSessionId}:`,
|
|
6117
|
+
cleanup.reason
|
|
6118
|
+
);
|
|
6055
6119
|
}
|
|
6056
|
-
Telemetry.getInstance().trackServerInitialize({
|
|
6057
|
-
protocolVersion: String(protocolVersion),
|
|
6058
|
-
clientInfo: clientInfo || {},
|
|
6059
|
-
clientCapabilities: clientCapabilities || {},
|
|
6060
|
-
sessionId: sid
|
|
6061
|
-
}).catch(
|
|
6062
|
-
(e) => console.debug(`Failed to track server initialize: ${e}`)
|
|
6063
|
-
);
|
|
6064
|
-
};
|
|
6065
|
-
}, "onsessioninitialized"),
|
|
6066
|
-
onsessionclosed: /* @__PURE__ */ __name(async (sid) => {
|
|
6067
|
-
if (getDebugLevel() !== "info") {
|
|
6068
|
-
console.log(`[MCP] Session closed: ${sid}`);
|
|
6069
6120
|
}
|
|
6070
|
-
|
|
6071
|
-
await streamManager.delete(sid);
|
|
6072
|
-
await sessionStore.delete(sid);
|
|
6073
|
-
sessions.delete(sid);
|
|
6074
|
-
mcpServerInstance.cleanupSessionSubscriptions?.(sid);
|
|
6075
|
-
mcpServerInstance.cleanupSessionRefs?.(sid);
|
|
6076
|
-
}, "onsessionclosed")
|
|
6077
|
-
});
|
|
6078
|
-
wrapTransportForStreamManager(transport, newSessionId, streamManager);
|
|
6079
|
-
await server.connect(transport);
|
|
6080
|
-
const newSessionResponse = await runWithContext(
|
|
6081
|
-
c,
|
|
6082
|
-
async () => transport.handleRequest(c.req.raw),
|
|
6083
|
-
newSessionId
|
|
6084
|
-
);
|
|
6085
|
-
if (c.req.method === "GET") {
|
|
6086
|
-
await registerSseStream(transport, newSessionId, streamManager);
|
|
6121
|
+
}
|
|
6087
6122
|
}
|
|
6088
|
-
return newSessionResponse;
|
|
6089
6123
|
}
|
|
6090
6124
|
}, "handleRequest");
|
|
6091
6125
|
for (const endpoint of ["/mcp", "/sse"]) {
|
|
@@ -6987,7 +7021,7 @@ var MCPServerClass = class _MCPServerClass {
|
|
|
6987
7021
|
onSampling: /* @__PURE__ */ __name(async (params) => {
|
|
6988
7022
|
try {
|
|
6989
7023
|
const { getRequestContext: getRequestContext2 } = await import("../../context-storage-KMOAHEL7.js");
|
|
6990
|
-
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-
|
|
7024
|
+
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-YOE4JC6H.js");
|
|
6991
7025
|
const ctx = getRequestContext2();
|
|
6992
7026
|
if (!ctx) throw new Error("No request context");
|
|
6993
7027
|
const { session } = findSessionContext2(
|
|
@@ -7015,7 +7049,7 @@ var MCPServerClass = class _MCPServerClass {
|
|
|
7015
7049
|
onElicitation: /* @__PURE__ */ __name(async (params) => {
|
|
7016
7050
|
try {
|
|
7017
7051
|
const { getRequestContext: getRequestContext2 } = await import("../../context-storage-KMOAHEL7.js");
|
|
7018
|
-
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-
|
|
7052
|
+
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-YOE4JC6H.js");
|
|
7019
7053
|
const ctx = getRequestContext2();
|
|
7020
7054
|
if (!ctx) throw new Error("No request context");
|
|
7021
7055
|
const { session } = findSessionContext2(
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StdioConnector
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LOSPF4H5.js";
|
|
4
4
|
import "./chunk-GKPKUKD6.js";
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-BXZHMYMM.js";
|
|
5
|
+
import "./chunk-SGT4D4LO.js";
|
|
6
|
+
import "./chunk-QEYINRZL.js";
|
|
8
7
|
import "./chunk-MTHLLDCX.js";
|
|
9
8
|
import "./chunk-QWQYAQCK.js";
|
|
9
|
+
import "./chunk-BXZHMYMM.js";
|
|
10
10
|
import "./chunk-3GQAWCBQ.js";
|
|
11
11
|
export {
|
|
12
12
|
StdioConnector
|