shokupan 0.16.2 → 0.16.4

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.
@@ -51,7 +51,7 @@ const node_stream = require("node:stream");
51
51
  const zlib = require("node:zlib");
52
52
  const Ajv = require("ajv");
53
53
  const addFormats = require("ajv-formats");
54
- const crypto = require("crypto");
54
+ const crypto$1 = require("crypto");
55
55
  const events = require("events");
56
56
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
57
57
  function _interopNamespaceDefault(e) {
@@ -2152,7 +2152,7 @@ function serveStatic(config, prefix) {
2152
2152
  }
2153
2153
  }
2154
2154
  walk(rootPath).then(_resolveReady).catch((err) => {
2155
- if (process.env.NODE_ENV !== "test") this.logger.error("[serveStatic] Cache population error:", err);
2155
+ if (process.env.NODE_ENV !== "test") console.error("[serveStatic] Cache population error:", err);
2156
2156
  _resolveReady();
2157
2157
  });
2158
2158
  } else {
@@ -2744,145 +2744,270 @@ class NotFoundError extends HttpError {
2744
2744
  this.name = "NotFoundError";
2745
2745
  }
2746
2746
  }
2747
- class McpProtocol {
2748
- tools = /* @__PURE__ */ new Map();
2749
- prompts = /* @__PURE__ */ new Map();
2750
- resources = /* @__PURE__ */ new Map();
2751
- constructor(tools = [], prompts = [], resources = []) {
2752
- tools.forEach((t) => this.tools.set(t.name, t));
2753
- prompts.forEach((p) => this.prompts.set(p.name, p));
2754
- resources.forEach((r) => this.resources.set(r.uri, r));
2747
+ class McpSession {
2748
+ constructor(sessionId, protocol) {
2749
+ this.protocol = protocol;
2750
+ this.sessionId = sessionId;
2755
2751
  }
2756
- addTool(tool) {
2757
- this.tools.set(tool.name, tool);
2752
+ sessionId;
2753
+ initialized = false;
2754
+ writeController;
2755
+ activeRequests = /* @__PURE__ */ new Map();
2756
+ pendingCallbacks = /* @__PURE__ */ new Map();
2757
+ nextMessageId = 1;
2758
+ attachStream(controller) {
2759
+ this.writeController = controller;
2758
2760
  }
2759
- addPrompt(prompt) {
2760
- this.prompts.set(prompt.name, prompt);
2761
+ close() {
2762
+ if (this.writeController) {
2763
+ try {
2764
+ this.writeController.close();
2765
+ } catch (e) {
2766
+ }
2767
+ }
2768
+ this.activeRequests.forEach((controller) => {
2769
+ controller.abort(new Error("Session closed"));
2770
+ });
2771
+ this.activeRequests.clear();
2772
+ this.pendingCallbacks.forEach(({ reject }) => {
2773
+ reject(new Error("Session closed"));
2774
+ });
2775
+ this.pendingCallbacks.clear();
2776
+ this.initialized = false;
2761
2777
  }
2762
- addResource(resource) {
2763
- this.resources.set(resource.uri, resource);
2778
+ send(message) {
2779
+ if (!this.writeController) return;
2780
+ try {
2781
+ this.writeController.enqueue(`event: message
2782
+ data: ${JSON.stringify(message)}
2783
+
2784
+ `);
2785
+ } catch (e) {
2786
+ this.close();
2787
+ }
2764
2788
  }
2765
- merge(other) {
2766
- other.tools.forEach((t) => this.tools.set(t.name, t));
2767
- other.prompts.forEach((p) => this.prompts.set(p.name, p));
2768
- other.resources.forEach((r) => this.resources.set(r.uri, r));
2789
+ async sendRequest(method, params) {
2790
+ const id = this.nextMessageId++;
2791
+ return new Promise((resolve, reject) => {
2792
+ this.pendingCallbacks.set(id, { resolve, reject });
2793
+ this.send({ jsonrpc: "2.0", id, method, params });
2794
+ });
2795
+ }
2796
+ sendNotification(method, params) {
2797
+ this.send({ jsonrpc: "2.0", method, params });
2798
+ }
2799
+ /**
2800
+ * Request the current roots from the client.
2801
+ */
2802
+ async listRoots() {
2803
+ return this.sendRequest("roots/list");
2804
+ }
2805
+ /**
2806
+ * Request the client to sample an LLM completion.
2807
+ */
2808
+ async createMessageSampling(params) {
2809
+ return this.sendRequest("sampling/createMessage", params);
2769
2810
  }
2770
2811
  async handleMessage(message) {
2771
- if (message.jsonrpc !== "2.0") {
2772
- return this.error(message.id, -32600, "Invalid Request");
2812
+ if (!message || typeof message !== "object" || message.jsonrpc !== "2.0") {
2813
+ return this.error(message?.id ?? null, -32600, "Invalid Request");
2814
+ }
2815
+ if ("result" in message || "error" in message) {
2816
+ const cb = this.pendingCallbacks.get(message.id);
2817
+ if (cb) {
2818
+ this.pendingCallbacks.delete(message.id);
2819
+ if (message.error) {
2820
+ cb.reject(new Error(message.error.message));
2821
+ } else {
2822
+ cb.resolve(message.result);
2823
+ }
2824
+ }
2825
+ return null;
2826
+ }
2827
+ const req = message;
2828
+ const isNotification = !("id" in req);
2829
+ if (isNotification) {
2830
+ if (req.method === "notifications/cancel") {
2831
+ const requestId = req.params?.requestId;
2832
+ if (requestId) {
2833
+ const controller = this.activeRequests.get(requestId);
2834
+ if (controller) {
2835
+ controller.abort(new Error("Cancelled by client"));
2836
+ this.activeRequests.delete(requestId);
2837
+ }
2838
+ }
2839
+ } else if (req.method === "notifications/initialized") {
2840
+ this.initialized = true;
2841
+ } else if (req.method === "notifications/progress") ;
2842
+ return null;
2773
2843
  }
2774
2844
  try {
2775
- switch (message.method) {
2845
+ const controller = new AbortController();
2846
+ this.activeRequests.set(req.id, controller);
2847
+ const context = {
2848
+ session: this,
2849
+ signal: controller.signal,
2850
+ onProgress: (progress, total) => {
2851
+ const progressToken = req.params?.meta?.progressToken;
2852
+ if (progressToken) {
2853
+ this.sendNotification("notifications/progress", {
2854
+ progressToken,
2855
+ progress,
2856
+ total
2857
+ });
2858
+ }
2859
+ }
2860
+ };
2861
+ let result;
2862
+ switch (req.method) {
2776
2863
  case "initialize":
2777
- return this.success(message.id, {
2864
+ result = {
2778
2865
  protocolVersion: "2024-11-05",
2779
2866
  serverInfo: {
2780
2867
  name: "Shokupan MCP",
2781
2868
  version: "1.0.0"
2782
2869
  },
2783
2870
  capabilities: {
2784
- tools: this.tools.size > 0 ? {} : void 0,
2785
- prompts: this.prompts.size > 0 ? {} : void 0,
2786
- resources: this.resources.size > 0 ? {} : void 0
2871
+ tools: this.protocol.hasTools() ? {} : void 0,
2872
+ prompts: this.protocol.hasPrompts() ? {} : void 0,
2873
+ resources: this.protocol.hasResources() ? {} : void 0
2787
2874
  }
2788
- });
2875
+ };
2876
+ break;
2789
2877
  case "ping":
2790
- return this.success(message.id, {});
2878
+ result = {};
2879
+ break;
2791
2880
  case "tools/list":
2792
- if (this.tools.size === 0) return this.success(message.id, { tools: [] });
2793
- return this.success(message.id, {
2794
- tools: Array.from(this.tools.values()).map((t) => ({
2795
- name: t.name,
2796
- description: t.description,
2797
- inputSchema: t.inputSchema || { type: "object", properties: {} }
2798
- }))
2799
- });
2800
- case "tools/call": {
2801
- if (!message.params || !message.params.name) {
2802
- return this.error(message.id, -32602, "Invalid params: name required");
2803
- }
2804
- const tool = this.tools.get(message.params.name);
2805
- if (!tool) {
2806
- return this.error(message.id, -32601, `Tool not found: ${message.params.name}`);
2807
- }
2808
- try {
2809
- const result = await tool.handler(message.params.arguments || {});
2810
- return this.success(message.id, result);
2811
- } catch (e) {
2812
- return {
2813
- jsonrpc: "2.0",
2814
- id: message.id ?? null,
2815
- result: {
2816
- isError: true,
2817
- content: [{ type: "text", text: e.message || String(e) }]
2818
- }
2819
- };
2820
- }
2821
- }
2881
+ result = this.protocol.listTools(req.params?.cursor);
2882
+ break;
2883
+ case "tools/call":
2884
+ if (!req.params || !req.params.name) throw new Error("Invalid params: name required");
2885
+ result = await this.protocol.callTool(req.params.name, req.params.arguments, context);
2886
+ break;
2822
2887
  case "prompts/list":
2823
- if (this.prompts.size === 0) return this.success(message.id, { prompts: [] });
2824
- return this.success(message.id, {
2825
- prompts: Array.from(this.prompts.values()).map((p) => ({
2826
- name: p.name,
2827
- description: p.description,
2828
- arguments: p.arguments
2829
- }))
2830
- });
2831
- case "prompts/get": {
2832
- if (!message.params || !message.params.name) {
2833
- return this.error(message.id, -32602, "Invalid params: name required");
2834
- }
2835
- const prompt = this.prompts.get(message.params.name);
2836
- if (!prompt) {
2837
- return this.error(message.id, -32601, `Prompt not found: ${message.params.name}`);
2838
- }
2839
- const result = await prompt.handler(message.params.arguments || {});
2840
- return this.success(message.id, result);
2841
- }
2888
+ result = this.protocol.listPrompts(req.params?.cursor);
2889
+ break;
2890
+ case "prompts/get":
2891
+ if (!req.params || !req.params.name) throw new Error("Invalid params: name required");
2892
+ result = await this.protocol.getPrompt(req.params.name, req.params.arguments, context);
2893
+ break;
2842
2894
  case "resources/list":
2843
- if (this.resources.size === 0) return this.success(message.id, { resources: [] });
2844
- return this.success(message.id, {
2845
- resources: Array.from(this.resources.values()).map((r) => ({
2846
- uri: r.uri,
2847
- name: r.name,
2848
- description: r.description,
2849
- mimeType: r.mimeType
2850
- }))
2851
- });
2852
- case "resources/read": {
2853
- if (!message.params || !message.params.uri) {
2854
- return this.error(message.id, -32602, "Invalid params: uri required");
2855
- }
2856
- let resource = this.resources.get(message.params.uri);
2857
- if (!resource) {
2858
- return this.error(message.id, -32601, `Resource not found: ${message.params.uri}`);
2859
- }
2860
- const result = await resource.handler(message.params.uri);
2861
- return this.success(message.id, result);
2862
- }
2895
+ result = this.protocol.listResources(req.params?.cursor);
2896
+ break;
2897
+ case "resources/read":
2898
+ if (!req.params || !req.params.uri) throw new Error("Invalid params: uri required");
2899
+ result = await this.protocol.readResource(req.params.uri, context);
2900
+ break;
2863
2901
  default:
2864
- if (message.id === void 0) return null;
2865
- return this.error(message.id, -32601, "Method not found");
2902
+ return this.error(req.id, -32601, "Method not found");
2866
2903
  }
2904
+ this.activeRequests.delete(req.id);
2905
+ return this.success(req.id, result);
2867
2906
  } catch (err) {
2868
- return this.error(message.id, -32603, "Internal Error", err.message);
2907
+ this.activeRequests.delete(req.id);
2908
+ if (req.method === "tools/call") {
2909
+ return this.success(req.id, {
2910
+ isError: true,
2911
+ content: [{ type: "text", text: err.message || String(err) }]
2912
+ });
2913
+ }
2914
+ return this.error(req.id, -32603, "Internal Error", err.message);
2869
2915
  }
2870
2916
  }
2871
2917
  success(id, result) {
2872
2918
  return {
2873
2919
  jsonrpc: "2.0",
2874
- id: id ?? null,
2920
+ id,
2875
2921
  result
2876
2922
  };
2877
2923
  }
2878
2924
  error(id, code, message, data) {
2879
2925
  return {
2880
2926
  jsonrpc: "2.0",
2881
- id: id ?? null,
2927
+ id,
2882
2928
  error: { code, message, data }
2883
2929
  };
2884
2930
  }
2885
2931
  }
2932
+ class McpProtocol {
2933
+ tools = /* @__PURE__ */ new Map();
2934
+ prompts = /* @__PURE__ */ new Map();
2935
+ resources = /* @__PURE__ */ new Map();
2936
+ constructor(tools = [], prompts = [], resources = []) {
2937
+ tools.forEach((t) => this.tools.set(t.name, t));
2938
+ prompts.forEach((p) => this.prompts.set(p.name, p));
2939
+ resources.forEach((r) => this.resources.set(r.uri, r));
2940
+ }
2941
+ hasTools() {
2942
+ return this.tools.size > 0;
2943
+ }
2944
+ hasPrompts() {
2945
+ return this.prompts.size > 0;
2946
+ }
2947
+ hasResources() {
2948
+ return this.resources.size > 0;
2949
+ }
2950
+ addTool(tool) {
2951
+ this.tools.set(tool.name, tool);
2952
+ }
2953
+ addPrompt(prompt) {
2954
+ this.prompts.set(prompt.name, prompt);
2955
+ }
2956
+ addResource(resource) {
2957
+ this.resources.set(resource.uri, resource);
2958
+ }
2959
+ merge(other) {
2960
+ other.tools.forEach((t) => this.tools.set(t.name, t));
2961
+ other.prompts.forEach((p) => this.prompts.set(p.name, p));
2962
+ other.resources.forEach((r) => this.resources.set(r.uri, r));
2963
+ }
2964
+ createSession(sessionId) {
2965
+ return new McpSession(sessionId, this);
2966
+ }
2967
+ listTools(cursor) {
2968
+ return {
2969
+ tools: Array.from(this.tools.values()).map((t) => ({
2970
+ name: t.name,
2971
+ description: t.description,
2972
+ inputSchema: t.inputSchema || { type: "object", properties: {} }
2973
+ }))
2974
+ };
2975
+ }
2976
+ async callTool(name, args, context) {
2977
+ const tool = this.tools.get(name);
2978
+ if (!tool) throw new Error(`Tool not found: ${name}`);
2979
+ return await tool.handler(args || {}, context);
2980
+ }
2981
+ listPrompts(cursor) {
2982
+ return {
2983
+ prompts: Array.from(this.prompts.values()).map((p) => ({
2984
+ name: p.name,
2985
+ description: p.description,
2986
+ arguments: p.arguments
2987
+ }))
2988
+ };
2989
+ }
2990
+ async getPrompt(name, args, context) {
2991
+ const prompt = this.prompts.get(name);
2992
+ if (!prompt) throw new Error(`Prompt not found: ${name}`);
2993
+ return await prompt.handler(args || {}, context);
2994
+ }
2995
+ listResources(cursor) {
2996
+ return {
2997
+ resources: Array.from(this.resources.values()).map((r) => ({
2998
+ uri: r.uri,
2999
+ name: r.name,
3000
+ description: r.description,
3001
+ mimeType: r.mimeType
3002
+ }))
3003
+ };
3004
+ }
3005
+ async readResource(uri, context) {
3006
+ const resource = this.resources.get(uri);
3007
+ if (!resource) throw new Error(`Resource not found: ${uri}`);
3008
+ return await resource.handler(uri, context);
3009
+ }
3010
+ }
2886
3011
  class MiddlewareTracker {
2887
3012
  static wrap(handler, context) {
2888
3013
  const { file, line, name, isBuiltin, pluginName } = context;
@@ -4763,7 +4888,7 @@ class ApiExplorerPlugin extends ShokupanRouter {
4763
4888
  }
4764
4889
  }
4765
4890
  static getBasePath() {
4766
- const dir = path$1.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-DGW-KI1t.cjs", document.baseURI).href));
4891
+ const dir = path$1.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-BLdx5fql.cjs", document.baseURI).href));
4767
4892
  if (dir.endsWith("dist")) {
4768
4893
  return dir + "/plugins/application/api-explorer";
4769
4894
  }
@@ -5567,7 +5692,7 @@ class AsyncApiPlugin extends ShokupanRouter {
5567
5692
  this.init();
5568
5693
  }
5569
5694
  static getBasePath() {
5570
- const dir = path$1.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-DGW-KI1t.cjs", document.baseURI).href));
5695
+ const dir = path$1.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-BLdx5fql.cjs", document.baseURI).href));
5571
5696
  if (dir.endsWith("dist")) {
5572
5697
  return dir + "/plugins/application/asyncapi";
5573
5698
  }
@@ -6091,7 +6216,7 @@ function createHTTPLogger() {
6091
6216
  return result;
6092
6217
  };
6093
6218
  }
6094
- const require$1 = node_module.createRequire(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-DGW-KI1t.cjs", document.baseURI).href);
6219
+ const require$1 = node_module.createRequire(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-BLdx5fql.cjs", document.baseURI).href);
6095
6220
  const http = require$1("node:http");
6096
6221
  const https = require$1("node:https");
6097
6222
  class FetchInterceptor {
@@ -6698,7 +6823,7 @@ class Dashboard {
6698
6823
  }
6699
6824
  // Get base path for dashboard files - works in both dev (src/) and production (dist/)
6700
6825
  static getBasePath() {
6701
- const dir = path$1.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-DGW-KI1t.cjs", document.baseURI).href));
6826
+ const dir = path$1.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index-BLdx5fql.cjs", document.baseURI).href));
6702
6827
  if (dir.endsWith("dist")) {
6703
6828
  return dir + "/plugins/application/dashboard";
6704
6829
  }
@@ -9745,7 +9870,7 @@ class Shokupan extends ShokupanRouter {
9745
9870
  const { SecurityHeaders: SecurityHeaders2 } = require("./plugins/middleware/security-headers");
9746
9871
  this.use(SecurityHeaders2(this.applicationConfig.defaultSecurityHeaders === true ? {} : this.applicationConfig.defaultSecurityHeaders));
9747
9872
  }
9748
- if (this.applicationConfig.adapter !== "wintercg") {
9873
+ if (this.applicationConfig.adapter !== "wintercg" && this.applicationConfig.datastore) {
9749
9874
  this.dbPromise = this.initDatastore().catch((err) => {
9750
9875
  this.logger?.debug("Shokupan", "Failed to initialize default datastore", { error: err });
9751
9876
  });
@@ -9801,24 +9926,24 @@ class Shokupan extends ShokupanRouter {
9801
9926
  try {
9802
9927
  switch (adapterName) {
9803
9928
  case "sqlite": {
9804
- const { SqliteAdapter } = await Promise.resolve().then(() => require("./sqlite-Z7Jt65XL.cjs"));
9929
+ const { SqliteAdapter } = await Promise.resolve().then(() => require("./sqlite-Tbm9zDxt.cjs"));
9805
9930
  this.datastore = new SqliteAdapter(options);
9806
9931
  break;
9807
9932
  }
9808
9933
  case "level": {
9809
- const { LevelAdapter } = await Promise.resolve().then(() => require("./level-14ZzYhXc.cjs"));
9934
+ const { LevelAdapter } = await Promise.resolve().then(() => require("./level-ySRat4Qf.cjs"));
9810
9935
  this.datastore = new LevelAdapter(options);
9811
9936
  break;
9812
9937
  }
9813
9938
  case "surrealdb": {
9814
- const { SurrealAdapter } = await Promise.resolve().then(() => require("./surreal-BglaabNG.cjs"));
9939
+ const { SurrealAdapter } = await Promise.resolve().then(() => require("./surreal-DGDSgKuP.cjs"));
9815
9940
  const legacyConfig = this.applicationConfig.surreal || {};
9816
9941
  const effectiveOptions = { ...legacyConfig, ...options };
9817
9942
  this.datastore = new SurrealAdapter(effectiveOptions);
9818
9943
  break;
9819
9944
  }
9820
9945
  default: {
9821
- const { SurrealAdapter } = await Promise.resolve().then(() => require("./surreal-BglaabNG.cjs"));
9946
+ const { SurrealAdapter } = await Promise.resolve().then(() => require("./surreal-DGDSgKuP.cjs"));
9822
9947
  const legacy = this.applicationConfig.surreal;
9823
9948
  this.datastore = new SurrealAdapter(options || legacy || {});
9824
9949
  }
@@ -10022,13 +10147,14 @@ class Shokupan extends ShokupanRouter {
10022
10147
  * @param port - The port to listen on. If not specified, the port from the configuration is used. If that is not specified, port 3000 is used.
10023
10148
  * @returns The server instance.
10024
10149
  */
10025
- async listen(port) {
10150
+ async listen(port, callback) {
10026
10151
  this.httpServer = new ShokupanServer(this);
10027
10152
  this.server = await this.httpServer.listen(port);
10028
10153
  const protocol = this.applicationConfig.tls || this.applicationConfig.development ? "https" : "http";
10029
10154
  const url = `${protocol}://${this.applicationConfig.hostname}:${this.applicationConfig.port}`;
10030
10155
  const hyperlinkedUrl = `\x1B]8;;${url}\x07${url}\x1B]8;;\x07`;
10031
10156
  this.logger.info("Shokupan", `Server running on ${hyperlinkedUrl}`);
10157
+ callback?.();
10032
10158
  return this.server;
10033
10159
  }
10034
10160
  /**
@@ -11114,19 +11240,26 @@ class MCPServerPlugin {
11114
11240
  };
11115
11241
  collect(app);
11116
11242
  }
11243
+ sessions = /* @__PURE__ */ new Map();
11117
11244
  setupRoutes() {
11118
11245
  this.router.get("", (ctx) => {
11119
- const endpointUrl = `${ctx.protocol}://${ctx.host}${this.options.path}`;
11120
- const enc = new TextEncoder();
11246
+ const sessionId = crypto.randomUUID();
11247
+ const session = this.router.mcpProtocol.createSession(sessionId);
11248
+ this.sessions.set(sessionId, session);
11249
+ const base = ctx.request.url.replace(/\/$/, "");
11250
+ const endpointUrl = `${base}/message?sessionId=${sessionId}`;
11121
11251
  return new Response(
11122
11252
  new ReadableStream({
11123
11253
  start(controller) {
11124
- controller.enqueue(enc.encode(`event: endpoint
11125
- data: ${JSON.stringify(endpointUrl)}
11254
+ session.attachStream(controller);
11255
+ controller.enqueue(`event: endpoint
11256
+ data: ${endpointUrl}
11126
11257
 
11127
- `));
11258
+ `);
11128
11259
  },
11129
- cancel() {
11260
+ cancel: () => {
11261
+ session.close();
11262
+ this.sessions.delete(sessionId);
11130
11263
  }
11131
11264
  }),
11132
11265
  {
@@ -11138,7 +11271,16 @@ data: ${JSON.stringify(endpointUrl)}
11138
11271
  }
11139
11272
  );
11140
11273
  });
11141
- this.router.post("", async (ctx) => {
11274
+ this.router.post("/message", async (ctx) => {
11275
+ const url = new URL(ctx.request.url);
11276
+ const sessionId = url.searchParams.get("sessionId");
11277
+ if (!sessionId) {
11278
+ return ctx.text("Missing sessionId", 400);
11279
+ }
11280
+ const session = this.sessions.get(sessionId);
11281
+ if (!session) {
11282
+ return ctx.text("Session not found", 404);
11283
+ }
11142
11284
  let parsedBody;
11143
11285
  try {
11144
11286
  parsedBody = await ctx.body();
@@ -11149,7 +11291,7 @@ data: ${JSON.stringify(endpointUrl)}
11149
11291
  error: { code: -32700, message: "Parse error" }
11150
11292
  }, 400);
11151
11293
  }
11152
- const response = await this.router.mcpProtocol.handleMessage(parsedBody);
11294
+ const response = await session.handleMessage(parsedBody);
11153
11295
  if (response) {
11154
11296
  return ctx.json(response);
11155
11297
  }
@@ -12568,7 +12710,7 @@ class MemoryStore extends events.EventEmitter {
12568
12710
  function sign(val, secret) {
12569
12711
  if (typeof val !== "string") throw new TypeError("Cookie value must be provided as a string.");
12570
12712
  if (typeof secret !== "string") throw new TypeError("Secret string must be provided.");
12571
- return val + "." + crypto.createHmac("sha256", secret).update(val).digest("base64").replace(/\=+$/, "");
12713
+ return val + "." + crypto$1.createHmac("sha256", secret).update(val).digest("base64").replace(/\=+$/, "");
12572
12714
  }
12573
12715
  function unsign(input, secret) {
12574
12716
  if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
@@ -12581,7 +12723,7 @@ function unsign(input, secret) {
12581
12723
  Buffer.from(expectedInput).copy(paddedExpected);
12582
12724
  Buffer.from(input).copy(paddedInput);
12583
12725
  try {
12584
- const valid = crypto.timingSafeEqual(paddedExpected, paddedInput);
12726
+ const valid = crypto$1.timingSafeEqual(paddedExpected, paddedInput);
12585
12727
  return valid ? tentValue : false;
12586
12728
  } catch {
12587
12729
  return false;
@@ -12591,7 +12733,7 @@ function Session(options) {
12591
12733
  const store = options.store || new MemoryStore();
12592
12734
  const name = options.name || "connect.sid";
12593
12735
  const secrets = Array.isArray(options.secret) ? options.secret : [options.secret];
12594
- const generateId = options.genid || (() => crypto.randomUUID());
12736
+ const generateId = options.genid || (() => crypto$1.randomUUID());
12595
12737
  const resave = options.resave === void 0 ? true : options.resave;
12596
12738
  const saveUninitialized = options.saveUninitialized === void 0 ? true : options.saveUninitialized;
12597
12739
  const rolling = options.rolling || false;
@@ -12925,4 +13067,4 @@ exports.traceMiddleware = traceMiddleware;
12925
13067
  exports.useExpress = useExpress;
12926
13068
  exports.valibot = valibot;
12927
13069
  exports.validate = validate;
12928
- //# sourceMappingURL=index-DGW-KI1t.cjs.map
13070
+ //# sourceMappingURL=index-BLdx5fql.cjs.map