modality-mcp-kit 1.4.4 → 1.5.1

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;
@@ -130,16 +130,23 @@ export class FastHonoMcp extends ModalityFastMCP {
130
130
  const requestSessionId = c.req.header("mcp-session-id");
131
131
  const sessionId = this.ensureSession(requestSessionId);
132
132
  c.header("mcp-session-id", sessionId);
133
- const bodyText = await c.req.text();
134
- 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
+ }
135
143
  // Handle notifications/initialized
136
144
  try {
137
- const requestData = JSON.parse(bodyText);
138
145
  if (requestData?.method === "notifications/initialized") {
139
146
  Object.entries(SSE_HEADERS).forEach(([key, value]) => {
140
147
  c.header(key, value);
141
148
  });
142
- return c.text(sseNotification(), 200);
149
+ return c.text(sseNotification(), 202);
143
150
  }
144
151
  }
145
152
  catch {
@@ -151,7 +158,7 @@ export class FastHonoMcp extends ModalityFastMCP {
151
158
  ...corsHeaders,
152
159
  };
153
160
  return createSSEStream(async (writer) => {
154
- const result = await createJsonRpcManager(this).validateMessage(bodyText);
161
+ const result = await createJsonRpcManager(this, sessionId).validateMessage(requestData);
155
162
  await writer.send(result);
156
163
  await writer.close();
157
164
  }, responseHeaders);
@@ -174,7 +181,7 @@ class HonoJSONRPCManager extends JSONRPCManager {
174
181
  return message;
175
182
  }
176
183
  }
177
- function createJsonRpcManager(middleware) {
184
+ function createJsonRpcManager(middleware, sessionId) {
178
185
  const mcpTools = middleware.getTools();
179
186
  const mcpPrompts = middleware.getPrompts();
180
187
  const jsonrpc = new HonoJSONRPCManager();
@@ -190,9 +197,12 @@ function createJsonRpcManager(middleware) {
190
197
  if (!params.protocolVersion) {
191
198
  throw new Error("Missing required parameter: protocolVersion");
192
199
  }
200
+ // Get protocol version from session or use default
201
+ const session = middleware.sessions.get(sessionId);
202
+ const responseProtocolVersion = session?.protocolVersion || defaultMcpSchemaVersion;
193
203
  // Return valid InitializeResult
194
204
  return {
195
- protocolVersion: mcpSchemaVersion,
205
+ protocolVersion: responseProtocolVersion,
196
206
  capabilities: {
197
207
  tools: { listChanged: true },
198
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
  */
@@ -210,6 +210,25 @@ export const mcpProxyHandler = (MCP_SERVERS) => async (c) => {
210
210
  availableServers: Object.keys(MCP_SERVERS),
211
211
  }, 400);
212
212
  }
213
+ // Handle /_cache sub-routes (matched via app.use prefix routing)
214
+ const cachePathMatch = c.req.path.match(/\/_cache(?:\/(.+))?$/);
215
+ if (cachePathMatch) {
216
+ const cache = serverCaches.get(mcpName);
217
+ if (!cache) {
218
+ return c.json({ error: "No cache for this MCP server", keys: [] });
219
+ }
220
+ const cacheKey = cachePathMatch[1]
221
+ ? decodeURIComponent(cachePathMatch[1])
222
+ : undefined;
223
+ if (cacheKey) {
224
+ const entry = cache.get(cacheKey, true);
225
+ if (!entry) {
226
+ return c.json({ error: "Cache key not found", cacheKey }, 404);
227
+ }
228
+ return c.json({ cacheKey, value: entry });
229
+ }
230
+ return c.json({ keys: cache.keys() });
231
+ }
213
232
  // Handle CORS preflight
214
233
  if (c.req.method === "OPTIONS") {
215
234
  return new Response(null, {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.4",
2
+ "version": "1.5.1",
3
3
  "name": "modality-mcp-kit",
4
4
  "repository": {
5
5
  "type": "git",
@@ -28,7 +28,7 @@
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"