modality-mcp-kit 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,15 +23,15 @@
23
23
  * https://github.com/modelcontextprotocol/modelcontextprotocol/tree/main/schema
24
24
  * https://modelcontextprotocol.io/specification/2025-11-25/schema
25
25
  */
26
- import { ModalityFastMCP } from "./util_mcp_tools_converter.js";
27
- import { createMcpConnectionDemoHandler } from "./util_mcp_connection_demo.js";
28
- import { JSONRPCManager, getLoggerInstance, } from "modality-kit";
29
- import { sseNotification, sseError, SSE_HEADERS, createSSEStream, } from "./sse-wrapper.js";
30
- import { McpSessionManager } from "./McpSessionManager.js";
31
- import { handleToolCall } from "./handlers/tools-call-handler.js";
26
+ import { JSONRPCManager, getLoggerInstance } from "modality-kit";
27
+ import { ModalityFastMCP } from "./util_mcp_tools_converter";
28
+ import { createMcpConnectionDemoHandler } from "./util_mcp_connection_demo";
29
+ import { sseNotification, sseError, SSE_HEADERS, createSSEStream, } from "./sse-wrapper";
30
+ import { McpSessionManager } from "./McpSessionManager";
31
+ import { handleToolCall } from "./handlers/tools-call-handler";
32
32
  const defaultMcpPath = "/mcp";
33
33
  const defaultMcpDemoPath = "/";
34
- const mcpSchemaVersion = "2025-11-25";
34
+ const defaultMcpSchemaVersion = "2025-11-25";
35
35
  // Initialize FastMCP instance for internal use (NO SERVER)
36
36
  export class FastHonoMcp extends ModalityFastMCP {
37
37
  logger;
@@ -90,6 +90,7 @@ export class FastHonoMcp extends ModalityFastMCP {
90
90
  "Access-Control-Allow-Origin": "*",
91
91
  "Access-Control-Allow-Methods": "POST, OPTIONS, DELETE",
92
92
  "Access-Control-Allow-Headers": "content-type,mcp-protocol-version,mcp-session-id",
93
+ "Access-Control-Expose-Headers": "mcp-session-id",
93
94
  "Access-Control-Max-Age": "86400",
94
95
  };
95
96
  }
@@ -129,16 +130,23 @@ export class FastHonoMcp extends ModalityFastMCP {
129
130
  const requestSessionId = c.req.header("mcp-session-id");
130
131
  const sessionId = this.ensureSession(requestSessionId);
131
132
  c.header("mcp-session-id", sessionId);
132
- const bodyText = await c.req.text();
133
- this.logger.info("MCP Middleware Received Body", { bodyText });
133
+ const requestData = await c.req.json();
134
+ const requestProtocolVersion = requestData?.params?.protocolVersion;
135
+ this.logger.info("MCP Middleware Received Body", {
136
+ requestData,
137
+ sessionId,
138
+ });
139
+ // Store protocol version in session if provided
140
+ if (requestProtocolVersion) {
141
+ this.sessions.setProtocolVersion(sessionId, requestProtocolVersion);
142
+ }
134
143
  // Handle notifications/initialized
135
144
  try {
136
- const requestData = JSON.parse(bodyText);
137
145
  if (requestData?.method === "notifications/initialized") {
138
146
  Object.entries(SSE_HEADERS).forEach(([key, value]) => {
139
147
  c.header(key, value);
140
148
  });
141
- return c.text(sseNotification(), 200);
149
+ return c.text(sseNotification(), 202);
142
150
  }
143
151
  }
144
152
  catch {
@@ -150,7 +158,7 @@ export class FastHonoMcp extends ModalityFastMCP {
150
158
  ...corsHeaders,
151
159
  };
152
160
  return createSSEStream(async (writer) => {
153
- const result = await createJsonRpcManager(this).validateMessage(bodyText);
161
+ const result = await createJsonRpcManager(this, sessionId).validateMessage(requestData);
154
162
  await writer.send(result);
155
163
  await writer.close();
156
164
  }, responseHeaders);
@@ -173,7 +181,7 @@ class HonoJSONRPCManager extends JSONRPCManager {
173
181
  return message;
174
182
  }
175
183
  }
176
- function createJsonRpcManager(middleware) {
184
+ function createJsonRpcManager(middleware, sessionId) {
177
185
  const mcpTools = middleware.getTools();
178
186
  const mcpPrompts = middleware.getPrompts();
179
187
  const jsonrpc = new HonoJSONRPCManager();
@@ -189,9 +197,12 @@ function createJsonRpcManager(middleware) {
189
197
  if (!params.protocolVersion) {
190
198
  throw new Error("Missing required parameter: protocolVersion");
191
199
  }
200
+ // Get protocol version from session or use default
201
+ const session = middleware.sessions.get(sessionId);
202
+ const responseProtocolVersion = session?.protocolVersion || defaultMcpSchemaVersion;
192
203
  // Return valid InitializeResult
193
204
  return {
194
- protocolVersion: mcpSchemaVersion,
205
+ protocolVersion: responseProtocolVersion,
195
206
  capabilities: {
196
207
  tools: { listChanged: true },
197
208
  ...(mcpPrompts.length > 0 && { prompts: { listChanged: true } }),
@@ -31,6 +31,15 @@ export class McpSessionManager {
31
31
  session.lastActivity = new Date();
32
32
  }
33
33
  }
34
+ /**
35
+ * Set protocol version for a session
36
+ */
37
+ setProtocolVersion(sessionId, protocolVersion) {
38
+ const session = this.sessions.get(sessionId);
39
+ if (session) {
40
+ session.protocolVersion = protocolVersion;
41
+ }
42
+ }
34
43
  /**
35
44
  * Remove a session
36
45
  */
@@ -24,9 +24,9 @@
24
24
  * https://modelcontextprotocol.io/specification/2025-11-25/schema
25
25
  */
26
26
  import type { MiddlewareHandler, Hono } from "hono";
27
- import { ModalityFastMCP } from "./util_mcp_tools_converter.js";
28
27
  import { getLoggerInstance } from "modality-kit";
29
- import { McpSessionManager } from "./McpSessionManager.js";
28
+ import { ModalityFastMCP } from "./util_mcp_tools_converter";
29
+ import { McpSessionManager } from "./McpSessionManager";
30
30
  export interface FastHonoMcpConfig extends Record<string, unknown> {
31
31
  name: string;
32
32
  version: string;
@@ -5,6 +5,7 @@ export interface McpSession {
5
5
  id: string;
6
6
  createdAt: Date;
7
7
  lastActivity: Date;
8
+ protocolVersion?: string;
8
9
  }
9
10
  export declare class McpSessionManager {
10
11
  private sessions;
@@ -20,6 +21,10 @@ export declare class McpSessionManager {
20
21
  * Update last activity timestamp
21
22
  */
22
23
  touch(sessionId: string): void;
24
+ /**
25
+ * Set protocol version for a session
26
+ */
27
+ setProtocolVersion(sessionId: string, protocolVersion: string): void;
23
28
  /**
24
29
  * Remove a session
25
30
  */
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.3",
2
+ "version": "1.5.0",
3
3
  "name": "modality-mcp-kit",
4
4
  "repository": {
5
5
  "type": "git",
@@ -28,13 +28,13 @@
28
28
  "dependencies": {
29
29
  "@valibot/to-json-schema": "^1.5.0",
30
30
  "effect": "^3.19.14",
31
- "modality-kit": "^0.14.17",
31
+ "modality-kit": "^0.16.0",
32
32
  "sury": "^11.0.0-alpha.4",
33
33
  "xsschema": "0.3.5",
34
34
  "zod-to-json-schema": "^3.25.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@types/bun": "^1.3.5",
37
+ "@types/bun": "^1.3.6",
38
38
  "typescript": "^5.9.3"
39
39
  },
40
40
  "exports": {