mcp-use 1.10.5 → 1.10.6

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.
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  BaseConnector
3
- } from "./chunk-YOHGE3NK.js";
3
+ } from "./chunk-KIWNNI6F.js";
4
4
  import {
5
5
  Tel,
6
6
  generateUUID,
7
7
  getPackageVersion
8
- } from "./chunk-IY632ZQS.js";
8
+ } from "./chunk-JH3ZOGLI.js";
9
9
  import {
10
10
  logger
11
11
  } from "./chunk-34R6SIER.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BaseConnector
3
- } from "./chunk-YOHGE3NK.js";
3
+ } from "./chunk-KIWNNI6F.js";
4
4
  import {
5
5
  __name
6
6
  } from "./chunk-3GQAWCBQ.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  BrowserMCPClient
3
- } from "./chunk-C7WHRUWQ.js";
3
+ } from "./chunk-44DFBJUL.js";
4
4
  import {
5
5
  BrowserOAuthClientProvider,
6
6
  sanitizeUrl
7
7
  } from "./chunk-J75I2C26.js";
8
8
  import {
9
9
  Tel
10
- } from "./chunk-IY632ZQS.js";
10
+ } from "./chunk-JH3ZOGLI.js";
11
11
  import {
12
12
  __name
13
13
  } from "./chunk-3GQAWCBQ.js";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  Telemetry,
6
6
  generateUUID
7
- } from "./chunk-IY632ZQS.js";
7
+ } from "./chunk-JH3ZOGLI.js";
8
8
  import {
9
9
  __name
10
10
  } from "./chunk-3GQAWCBQ.js";
@@ -2,7 +2,7 @@ import {
2
2
  Telemetry,
3
3
  extractModelInfo,
4
4
  getPackageVersion
5
- } from "./chunk-IY632ZQS.js";
5
+ } from "./chunk-JH3ZOGLI.js";
6
6
  import {
7
7
  logger
8
8
  } from "./chunk-34R6SIER.js";
@@ -92,7 +92,7 @@ function generateUUID() {
92
92
  __name(generateUUID, "generateUUID");
93
93
 
94
94
  // src/version.ts
95
- var VERSION = "1.10.5";
95
+ var VERSION = "1.10.6";
96
96
  function getPackageVersion() {
97
97
  return VERSION;
98
98
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Telemetry
3
- } from "./chunk-IY632ZQS.js";
3
+ } from "./chunk-JH3ZOGLI.js";
4
4
  import {
5
5
  logger
6
6
  } from "./chunk-34R6SIER.js";
package/dist/index.cjs CHANGED
@@ -2876,7 +2876,7 @@ __name(generateUUID, "generateUUID");
2876
2876
  init_logging();
2877
2877
 
2878
2878
  // src/version.ts
2879
- var VERSION = "1.10.5";
2879
+ var VERSION = "1.10.6";
2880
2880
  function getPackageVersion() {
2881
2881
  return VERSION;
2882
2882
  }
package/dist/index.js CHANGED
@@ -16,13 +16,13 @@ import {
16
16
  ReleaseMCPServerConnectionTool,
17
17
  RemoteAgent,
18
18
  ServerManager
19
- } from "./chunk-MO5FM5B2.js";
19
+ } from "./chunk-FDKY2O5P.js";
20
20
  import "./chunk-CPG2WZUL.js";
21
21
  import "./chunk-JQKKMUCT.js";
22
22
  import {
23
23
  CodeModeConnector,
24
24
  PROMPTS
25
- } from "./chunk-XG7SR6G4.js";
25
+ } from "./chunk-BLWPCOUZ.js";
26
26
  import {
27
27
  ErrorBoundary,
28
28
  Image,
@@ -34,21 +34,21 @@ import {
34
34
  useWidgetProps,
35
35
  useWidgetState,
36
36
  useWidgetTheme
37
- } from "./chunk-UD5FSFEZ.js";
37
+ } from "./chunk-D5WOXLJ2.js";
38
38
  import {
39
39
  BaseMCPClient,
40
40
  ConnectionManager,
41
41
  HttpConnector,
42
42
  MCPSession,
43
43
  WebSocketConnector
44
- } from "./chunk-C7WHRUWQ.js";
44
+ } from "./chunk-44DFBJUL.js";
45
45
  import {
46
46
  BrowserOAuthClientProvider,
47
47
  onMcpAuthorization
48
48
  } from "./chunk-J75I2C26.js";
49
49
  import {
50
50
  BaseConnector
51
- } from "./chunk-YOHGE3NK.js";
51
+ } from "./chunk-KIWNNI6F.js";
52
52
  import {
53
53
  ElicitationDeclinedError,
54
54
  ElicitationTimeoutError,
@@ -60,7 +60,7 @@ import {
60
60
  VERSION,
61
61
  getPackageVersion,
62
62
  setTelemetrySource
63
- } from "./chunk-IY632ZQS.js";
63
+ } from "./chunk-JH3ZOGLI.js";
64
64
  import {
65
65
  Logger,
66
66
  logger
@@ -1417,7 +1417,7 @@ __name(generateUUID, "generateUUID");
1417
1417
  init_logging();
1418
1418
 
1419
1419
  // src/version.ts
1420
- var VERSION = "1.10.5";
1420
+ var VERSION = "1.10.6";
1421
1421
  function getPackageVersion() {
1422
1422
  return VERSION;
1423
1423
  }
@@ -4,13 +4,13 @@ import {
4
4
  import {
5
5
  MCPAgent,
6
6
  RemoteAgent
7
- } from "../../chunk-MO5FM5B2.js";
7
+ } from "../../chunk-FDKY2O5P.js";
8
8
  import "../../chunk-CPG2WZUL.js";
9
9
  import {
10
10
  PROMPTS
11
- } from "../../chunk-XG7SR6G4.js";
12
- import "../../chunk-YOHGE3NK.js";
13
- import "../../chunk-IY632ZQS.js";
11
+ } from "../../chunk-BLWPCOUZ.js";
12
+ import "../../chunk-KIWNNI6F.js";
13
+ import "../../chunk-JH3ZOGLI.js";
14
14
  import "../../chunk-34R6SIER.js";
15
15
  import "../../chunk-3GQAWCBQ.js";
16
16
  export {
@@ -1607,7 +1607,7 @@ __name(generateUUID, "generateUUID");
1607
1607
  init_logging();
1608
1608
 
1609
1609
  // src/version.ts
1610
- var VERSION = "1.10.5";
1610
+ var VERSION = "1.10.6";
1611
1611
  function getPackageVersion() {
1612
1612
  return VERSION;
1613
1613
  }
@@ -9,28 +9,28 @@ import {
9
9
  MCPAgent,
10
10
  ObservabilityManager,
11
11
  RemoteAgent
12
- } from "../chunk-MO5FM5B2.js";
12
+ } from "../chunk-FDKY2O5P.js";
13
13
  import "../chunk-CPG2WZUL.js";
14
14
  import {
15
15
  BrowserMCPClient,
16
16
  HttpConnector,
17
17
  MCPSession,
18
18
  WebSocketConnector
19
- } from "../chunk-C7WHRUWQ.js";
19
+ } from "../chunk-44DFBJUL.js";
20
20
  import {
21
21
  BrowserOAuthClientProvider,
22
22
  onMcpAuthorization
23
23
  } from "../chunk-J75I2C26.js";
24
24
  import {
25
25
  BaseConnector
26
- } from "../chunk-YOHGE3NK.js";
26
+ } from "../chunk-KIWNNI6F.js";
27
27
  import {
28
28
  Tel,
29
29
  Telemetry,
30
30
  VERSION,
31
31
  getPackageVersion,
32
32
  setTelemetrySource
33
- } from "../chunk-IY632ZQS.js";
33
+ } from "../chunk-JH3ZOGLI.js";
34
34
  import {
35
35
  Logger,
36
36
  logger
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  PROMPTS
3
- } from "../../chunk-XG7SR6G4.js";
4
- import "../../chunk-YOHGE3NK.js";
5
- import "../../chunk-IY632ZQS.js";
3
+ } from "../../chunk-BLWPCOUZ.js";
4
+ import "../../chunk-KIWNNI6F.js";
5
+ import "../../chunk-JH3ZOGLI.js";
6
6
  import "../../chunk-34R6SIER.js";
7
7
  import "../../chunk-3GQAWCBQ.js";
8
8
  export {
@@ -876,7 +876,7 @@ function generateUUID() {
876
876
  __name(generateUUID, "generateUUID");
877
877
 
878
878
  // src/version.ts
879
- var VERSION = "1.10.5";
879
+ var VERSION = "1.10.6";
880
880
  function getPackageVersion() {
881
881
  return VERSION;
882
882
  }
@@ -9,17 +9,17 @@ import {
9
9
  useWidgetProps,
10
10
  useWidgetState,
11
11
  useWidgetTheme
12
- } from "../../chunk-UD5FSFEZ.js";
13
- import "../../chunk-C7WHRUWQ.js";
12
+ } from "../../chunk-D5WOXLJ2.js";
13
+ import "../../chunk-44DFBJUL.js";
14
14
  import {
15
15
  onMcpAuthorization
16
16
  } from "../../chunk-J75I2C26.js";
17
- import "../../chunk-YOHGE3NK.js";
17
+ import "../../chunk-KIWNNI6F.js";
18
18
  import {
19
19
  Tel,
20
20
  Telemetry,
21
21
  setTelemetrySource
22
- } from "../../chunk-IY632ZQS.js";
22
+ } from "../../chunk-JH3ZOGLI.js";
23
23
  import "../../chunk-34R6SIER.js";
24
24
  import "../../chunk-3GQAWCBQ.js";
25
25
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"mount-mcp.d.ts","sourceRoot":"","sources":["../../../../src/server/endpoints/mount-mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAW,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,QAAQ,EACb,iBAAiB,EAAE;IACjB,mBAAmB,EAAE,MAAM,OAAO,iDAAiD,EAAE,SAAS,CAAC;IAC/F,2BAA2B,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3D,EAAE,2DAA2D;AAC9D,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EAClC,MAAM,EAAE,YAAY,EACpB,gBAAgB,EAAE,OAAO,GACxB,OAAO,CAAC;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,OAAO,CAAA;CAAE,CAAC,CAgHxE"}
1
+ {"version":3,"file":"mount-mcp.d.ts","sourceRoot":"","sources":["../../../../src/server/endpoints/mount-mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAW,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,QAAQ,EACb,iBAAiB,EAAE;IACjB,mBAAmB,EAAE,MAAM,OAAO,iDAAiD,EAAE,SAAS,CAAC;IAC/F,2BAA2B,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3D,EAAE,2DAA2D;AAC9D,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EAClC,MAAM,EAAE,YAAY,EACpB,gBAAgB,EAAE,OAAO,GACxB,OAAO,CAAC;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,OAAO,CAAA;CAAE,CAAC,CAmIxE"}
@@ -761,7 +761,7 @@ var VERSION;
761
761
  var init_version = __esm({
762
762
  "src/version.ts"() {
763
763
  "use strict";
764
- VERSION = "1.10.5";
764
+ VERSION = "1.10.6";
765
765
  __name(getPackageVersion, "getPackageVersion");
766
766
  }
767
767
  });
@@ -4665,7 +4665,7 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
4665
4665
  const idleTimeoutMs = config.sessionIdleTimeoutMs ?? 3e5;
4666
4666
  const transports = /* @__PURE__ */ new Map();
4667
4667
  let idleCleanupInterval;
4668
- if (idleTimeoutMs > 0) {
4668
+ if (!config.stateless && idleTimeoutMs > 0) {
4669
4669
  idleCleanupInterval = startIdleCleanup(
4670
4670
  sessions,
4671
4671
  idleTimeoutMs,
@@ -4673,67 +4673,84 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
4673
4673
  );
4674
4674
  }
4675
4675
  const handleRequest = /* @__PURE__ */ __name(async (c) => {
4676
- const sessionId = c.req.header("mcp-session-id");
4677
- if (sessionId && transports.has(sessionId)) {
4678
- const transport2 = transports.get(sessionId);
4679
- if (sessions.has(sessionId)) {
4680
- const session = sessions.get(sessionId);
4681
- session.lastAccessedAt = Date.now();
4682
- session.context = c;
4683
- session.honoContext = c;
4684
- }
4685
- return transport2.handleRequest(c.req.raw);
4686
- }
4687
- const server = mcpServerInstance.getServerForSession();
4688
- const transport = new FetchStreamableHTTPServerTransport({
4689
- sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
4690
- onsessioninitialized: /* @__PURE__ */ __name((sid) => {
4691
- console.log(`[MCP] Session initialized: ${sid}`);
4692
- transports.set(sid, transport);
4693
- sessions.set(sid, {
4694
- transport,
4695
- server,
4696
- lastAccessedAt: Date.now(),
4697
- context: c,
4698
- honoContext: c
4699
- });
4700
- server.server.oninitialized = () => {
4701
- const clientCapabilities = server.server.getClientCapabilities();
4702
- const clientInfo = server.server.getClientInfo?.() || {};
4703
- const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
4704
- if (clientCapabilities && sessions.has(sid)) {
4705
- const session = sessions.get(sid);
4706
- session.clientCapabilities = clientCapabilities;
4707
- console.log(
4708
- `[MCP] Captured client capabilities for session ${sid}:`,
4709
- Object.keys(clientCapabilities)
4676
+ if (config.stateless) {
4677
+ const server = mcpServerInstance.getServerForSession();
4678
+ const transport = new FetchStreamableHTTPServerTransport({
4679
+ sessionIdGenerator: void 0
4680
+ // No session tracking
4681
+ });
4682
+ try {
4683
+ await server.connect(transport);
4684
+ return await transport.handleRequest(c.req.raw);
4685
+ } catch (error2) {
4686
+ console.error("[MCP] Stateless request error:", error2);
4687
+ transport.close();
4688
+ server.close();
4689
+ throw error2;
4690
+ }
4691
+ } else {
4692
+ const sessionId = c.req.header("mcp-session-id");
4693
+ if (sessionId && transports.has(sessionId)) {
4694
+ const transport2 = transports.get(sessionId);
4695
+ if (sessions.has(sessionId)) {
4696
+ const session = sessions.get(sessionId);
4697
+ session.lastAccessedAt = Date.now();
4698
+ session.context = c;
4699
+ session.honoContext = c;
4700
+ }
4701
+ return transport2.handleRequest(c.req.raw);
4702
+ }
4703
+ const server = mcpServerInstance.getServerForSession();
4704
+ const transport = new FetchStreamableHTTPServerTransport({
4705
+ sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
4706
+ onsessioninitialized: /* @__PURE__ */ __name((sid) => {
4707
+ console.log(`[MCP] Session initialized: ${sid}`);
4708
+ transports.set(sid, transport);
4709
+ sessions.set(sid, {
4710
+ transport,
4711
+ server,
4712
+ lastAccessedAt: Date.now(),
4713
+ context: c,
4714
+ honoContext: c
4715
+ });
4716
+ server.server.oninitialized = () => {
4717
+ const clientCapabilities = server.server.getClientCapabilities();
4718
+ const clientInfo = server.server.getClientInfo?.() || {};
4719
+ const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
4720
+ if (clientCapabilities && sessions.has(sid)) {
4721
+ const session = sessions.get(sid);
4722
+ session.clientCapabilities = clientCapabilities;
4723
+ console.log(
4724
+ `[MCP] Captured client capabilities for session ${sid}:`,
4725
+ Object.keys(clientCapabilities)
4726
+ );
4727
+ }
4728
+ Telemetry.getInstance().trackServerInitialize({
4729
+ protocolVersion: String(protocolVersion),
4730
+ clientInfo: clientInfo || {},
4731
+ clientCapabilities: clientCapabilities || {},
4732
+ sessionId: sid
4733
+ }).catch(
4734
+ (e) => console.debug(`Failed to track server initialize: ${e}`)
4710
4735
  );
4711
- }
4712
- Telemetry.getInstance().trackServerInitialize({
4713
- protocolVersion: String(protocolVersion),
4714
- clientInfo: clientInfo || {},
4715
- clientCapabilities: clientCapabilities || {},
4716
- sessionId: sid
4717
- }).catch(
4718
- (e) => console.debug(`Failed to track server initialize: ${e}`)
4719
- );
4720
- };
4721
- }, "onsessioninitialized"),
4722
- onsessionclosed: /* @__PURE__ */ __name((sid) => {
4723
- console.log(`[MCP] Session closed: ${sid}`);
4724
- transports.delete(sid);
4725
- sessions.delete(sid);
4726
- mcpServerInstance.cleanupSessionSubscriptions?.(sid);
4727
- }, "onsessionclosed")
4728
- });
4729
- await server.connect(transport);
4730
- return transport.handleRequest(c.req.raw);
4736
+ };
4737
+ }, "onsessioninitialized"),
4738
+ onsessionclosed: /* @__PURE__ */ __name((sid) => {
4739
+ console.log(`[MCP] Session closed: ${sid}`);
4740
+ transports.delete(sid);
4741
+ sessions.delete(sid);
4742
+ mcpServerInstance.cleanupSessionSubscriptions?.(sid);
4743
+ }, "onsessionclosed")
4744
+ });
4745
+ await server.connect(transport);
4746
+ return transport.handleRequest(c.req.raw);
4747
+ }
4731
4748
  }, "handleRequest");
4732
4749
  for (const endpoint of ["/mcp", "/sse"]) {
4733
4750
  app.on(["GET", "POST", "DELETE"], endpoint, handleRequest);
4734
4751
  }
4735
4752
  console.log(
4736
- `[MCP] Server mounted at /mcp and /sse (using FetchStreamableHTTPServerTransport - Web Standard APIs)`
4753
+ `[MCP] Server mounted at /mcp and /sse (${config.stateless ? "stateless" : "stateful"} mode)`
4737
4754
  );
4738
4755
  return { mcpMounted: true, idleCleanupInterval };
4739
4756
  }
@@ -5099,6 +5116,12 @@ var MCPServerClass = class {
5099
5116
  */
5100
5117
  constructor(config) {
5101
5118
  this.config = config;
5119
+ if (this.config.stateless === void 0) {
5120
+ this.config.stateless = isDeno;
5121
+ if (this.config.stateless) {
5122
+ console.log("[MCP] Deno detected - using stateless mode (no sessions)");
5123
+ }
5124
+ }
5102
5125
  this.serverHost = config.host || "localhost";
5103
5126
  this.serverBaseUrl = config.baseUrl;
5104
5127
  this.nativeServer = new import_mcp2.McpServer(
@@ -7,7 +7,7 @@ import {
7
7
  createEnhancedContext,
8
8
  findSessionContext,
9
9
  isValidLogLevel
10
- } from "../../chunk-E42PSMPK.js";
10
+ } from "../../chunk-EEUJZMOP.js";
11
11
  import {
12
12
  convertToolResultToResourceResult
13
13
  } from "../../chunk-362PI25Z.js";
@@ -25,7 +25,7 @@ import {
25
25
  getPackageVersion,
26
26
  isDeno,
27
27
  pathHelpers
28
- } from "../../chunk-IY632ZQS.js";
28
+ } from "../../chunk-JH3ZOGLI.js";
29
29
  import "../../chunk-34R6SIER.js";
30
30
  import {
31
31
  __name
@@ -2091,7 +2091,7 @@ function registerResource(resourceDefinition, callback) {
2091
2091
  const explicitMimeType = resourceDefinition.mimeType;
2092
2092
  const wrappedCallback = /* @__PURE__ */ __name(async () => {
2093
2093
  const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-NA4MHWOZ.js");
2094
- const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-XTDKRH6N.js");
2094
+ const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-4X6A63AS.js");
2095
2095
  const initialRequestContext = getRequestContext2();
2096
2096
  const sessions = this.sessions || /* @__PURE__ */ new Map();
2097
2097
  const { requestContext } = findSessionContext2(
@@ -2169,7 +2169,7 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
2169
2169
  async (uri) => {
2170
2170
  const params = this.parseTemplateUri(uriTemplate, uri.toString());
2171
2171
  const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-NA4MHWOZ.js");
2172
- const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-XTDKRH6N.js");
2172
+ const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-4X6A63AS.js");
2173
2173
  const initialRequestContext = getRequestContext2();
2174
2174
  const sessions = this.sessions || /* @__PURE__ */ new Map();
2175
2175
  const { requestContext } = findSessionContext2(
@@ -2224,7 +2224,7 @@ function registerPrompt(promptDefinition, callback) {
2224
2224
  }
2225
2225
  const wrappedCallback = /* @__PURE__ */ __name(async (params, extra) => {
2226
2226
  const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-NA4MHWOZ.js");
2227
- const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-XTDKRH6N.js");
2227
+ const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-4X6A63AS.js");
2228
2228
  const initialRequestContext = getRequestContext2();
2229
2229
  const sessions = this.sessions || /* @__PURE__ */ new Map();
2230
2230
  const { requestContext } = findSessionContext2(
@@ -2526,7 +2526,7 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
2526
2526
  const idleTimeoutMs = config.sessionIdleTimeoutMs ?? 3e5;
2527
2527
  const transports = /* @__PURE__ */ new Map();
2528
2528
  let idleCleanupInterval;
2529
- if (idleTimeoutMs > 0) {
2529
+ if (!config.stateless && idleTimeoutMs > 0) {
2530
2530
  idleCleanupInterval = startIdleCleanup(
2531
2531
  sessions,
2532
2532
  idleTimeoutMs,
@@ -2534,67 +2534,84 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
2534
2534
  );
2535
2535
  }
2536
2536
  const handleRequest = /* @__PURE__ */ __name(async (c) => {
2537
- const sessionId = c.req.header("mcp-session-id");
2538
- if (sessionId && transports.has(sessionId)) {
2539
- const transport2 = transports.get(sessionId);
2540
- if (sessions.has(sessionId)) {
2541
- const session = sessions.get(sessionId);
2542
- session.lastAccessedAt = Date.now();
2543
- session.context = c;
2544
- session.honoContext = c;
2537
+ if (config.stateless) {
2538
+ const server = mcpServerInstance.getServerForSession();
2539
+ const transport = new FetchStreamableHTTPServerTransport({
2540
+ sessionIdGenerator: void 0
2541
+ // No session tracking
2542
+ });
2543
+ try {
2544
+ await server.connect(transport);
2545
+ return await transport.handleRequest(c.req.raw);
2546
+ } catch (error2) {
2547
+ console.error("[MCP] Stateless request error:", error2);
2548
+ transport.close();
2549
+ server.close();
2550
+ throw error2;
2545
2551
  }
2546
- return transport2.handleRequest(c.req.raw);
2547
- }
2548
- const server = mcpServerInstance.getServerForSession();
2549
- const transport = new FetchStreamableHTTPServerTransport({
2550
- sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
2551
- onsessioninitialized: /* @__PURE__ */ __name((sid) => {
2552
- console.log(`[MCP] Session initialized: ${sid}`);
2553
- transports.set(sid, transport);
2554
- sessions.set(sid, {
2555
- transport,
2556
- server,
2557
- lastAccessedAt: Date.now(),
2558
- context: c,
2559
- honoContext: c
2560
- });
2561
- server.server.oninitialized = () => {
2562
- const clientCapabilities = server.server.getClientCapabilities();
2563
- const clientInfo = server.server.getClientInfo?.() || {};
2564
- const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
2565
- if (clientCapabilities && sessions.has(sid)) {
2566
- const session = sessions.get(sid);
2567
- session.clientCapabilities = clientCapabilities;
2568
- console.log(
2569
- `[MCP] Captured client capabilities for session ${sid}:`,
2570
- Object.keys(clientCapabilities)
2552
+ } else {
2553
+ const sessionId = c.req.header("mcp-session-id");
2554
+ if (sessionId && transports.has(sessionId)) {
2555
+ const transport2 = transports.get(sessionId);
2556
+ if (sessions.has(sessionId)) {
2557
+ const session = sessions.get(sessionId);
2558
+ session.lastAccessedAt = Date.now();
2559
+ session.context = c;
2560
+ session.honoContext = c;
2561
+ }
2562
+ return transport2.handleRequest(c.req.raw);
2563
+ }
2564
+ const server = mcpServerInstance.getServerForSession();
2565
+ const transport = new FetchStreamableHTTPServerTransport({
2566
+ sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
2567
+ onsessioninitialized: /* @__PURE__ */ __name((sid) => {
2568
+ console.log(`[MCP] Session initialized: ${sid}`);
2569
+ transports.set(sid, transport);
2570
+ sessions.set(sid, {
2571
+ transport,
2572
+ server,
2573
+ lastAccessedAt: Date.now(),
2574
+ context: c,
2575
+ honoContext: c
2576
+ });
2577
+ server.server.oninitialized = () => {
2578
+ const clientCapabilities = server.server.getClientCapabilities();
2579
+ const clientInfo = server.server.getClientInfo?.() || {};
2580
+ const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
2581
+ if (clientCapabilities && sessions.has(sid)) {
2582
+ const session = sessions.get(sid);
2583
+ session.clientCapabilities = clientCapabilities;
2584
+ console.log(
2585
+ `[MCP] Captured client capabilities for session ${sid}:`,
2586
+ Object.keys(clientCapabilities)
2587
+ );
2588
+ }
2589
+ Telemetry.getInstance().trackServerInitialize({
2590
+ protocolVersion: String(protocolVersion),
2591
+ clientInfo: clientInfo || {},
2592
+ clientCapabilities: clientCapabilities || {},
2593
+ sessionId: sid
2594
+ }).catch(
2595
+ (e) => console.debug(`Failed to track server initialize: ${e}`)
2571
2596
  );
2572
- }
2573
- Telemetry.getInstance().trackServerInitialize({
2574
- protocolVersion: String(protocolVersion),
2575
- clientInfo: clientInfo || {},
2576
- clientCapabilities: clientCapabilities || {},
2577
- sessionId: sid
2578
- }).catch(
2579
- (e) => console.debug(`Failed to track server initialize: ${e}`)
2580
- );
2581
- };
2582
- }, "onsessioninitialized"),
2583
- onsessionclosed: /* @__PURE__ */ __name((sid) => {
2584
- console.log(`[MCP] Session closed: ${sid}`);
2585
- transports.delete(sid);
2586
- sessions.delete(sid);
2587
- mcpServerInstance.cleanupSessionSubscriptions?.(sid);
2588
- }, "onsessionclosed")
2589
- });
2590
- await server.connect(transport);
2591
- return transport.handleRequest(c.req.raw);
2597
+ };
2598
+ }, "onsessioninitialized"),
2599
+ onsessionclosed: /* @__PURE__ */ __name((sid) => {
2600
+ console.log(`[MCP] Session closed: ${sid}`);
2601
+ transports.delete(sid);
2602
+ sessions.delete(sid);
2603
+ mcpServerInstance.cleanupSessionSubscriptions?.(sid);
2604
+ }, "onsessionclosed")
2605
+ });
2606
+ await server.connect(transport);
2607
+ return transport.handleRequest(c.req.raw);
2608
+ }
2592
2609
  }, "handleRequest");
2593
2610
  for (const endpoint of ["/mcp", "/sse"]) {
2594
2611
  app.on(["GET", "POST", "DELETE"], endpoint, handleRequest);
2595
2612
  }
2596
2613
  console.log(
2597
- `[MCP] Server mounted at /mcp and /sse (using FetchStreamableHTTPServerTransport - Web Standard APIs)`
2614
+ `[MCP] Server mounted at /mcp and /sse (${config.stateless ? "stateless" : "stateful"} mode)`
2598
2615
  );
2599
2616
  return { mcpMounted: true, idleCleanupInterval };
2600
2617
  }
@@ -2960,6 +2977,12 @@ var MCPServerClass = class {
2960
2977
  */
2961
2978
  constructor(config) {
2962
2979
  this.config = config;
2980
+ if (this.config.stateless === void 0) {
2981
+ this.config.stateless = isDeno;
2982
+ if (this.config.stateless) {
2983
+ console.log("[MCP] Deno detected - using stateless mode (no sessions)");
2984
+ }
2985
+ }
2963
2986
  this.serverHost = config.host || "localhost";
2964
2987
  this.serverBaseUrl = config.baseUrl;
2965
2988
  this.nativeServer = new OfficialMcpServer(