modality-mcp-kit 0.5.0 → 0.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.
package/dist/FastHonoMcp.js
CHANGED
|
@@ -27,12 +27,14 @@ import { ModalityFastMCP } from "modality-mcp-kit";
|
|
|
27
27
|
import { JSONRPCManager, getLoggerInstance, } from "modality-kit";
|
|
28
28
|
import { sseNotification, sseError, SSE_HEADERS, createSSEStream, } from "./sse-wrapper.js";
|
|
29
29
|
import { McpSessionManager } from "./McpSessionManager.js";
|
|
30
|
+
const defaultMcpPath = "mcp";
|
|
30
31
|
// Initialize FastMCP instance for internal use (NO SERVER)
|
|
31
32
|
export class FastHonoMcp extends ModalityFastMCP {
|
|
32
33
|
logger;
|
|
33
34
|
config;
|
|
34
35
|
sessions = new McpSessionManager();
|
|
35
36
|
currentSessionId = "";
|
|
37
|
+
mcpPath = defaultMcpPath;
|
|
36
38
|
constructor(config) {
|
|
37
39
|
super();
|
|
38
40
|
this.config = config;
|
|
@@ -67,12 +69,12 @@ export class FastHonoMcp extends ModalityFastMCP {
|
|
|
67
69
|
this.logger || getLoggerInstance("HonoMcpMiddleware", "debug");
|
|
68
70
|
const url = new URL(c.req.url);
|
|
69
71
|
// Only handle MCP routes
|
|
70
|
-
if (!url.pathname.startsWith(
|
|
72
|
+
if (!url.pathname.startsWith(`/${this.mcpPath}`)) {
|
|
71
73
|
return next();
|
|
72
74
|
}
|
|
73
75
|
try {
|
|
74
76
|
// Handle DELETE for session disconnect
|
|
75
|
-
if (c.req.method === "DELETE" && url.pathname ===
|
|
77
|
+
if (c.req.method === "DELETE" && url.pathname === `/${this.mcpPath}`) {
|
|
76
78
|
const requestSessionId = c.req.header("mcp-session-id");
|
|
77
79
|
// Validate session ID matches
|
|
78
80
|
if (requestSessionId && requestSessionId !== this.currentSessionId) {
|
|
@@ -85,7 +87,7 @@ export class FastHonoMcp extends ModalityFastMCP {
|
|
|
85
87
|
return c.json({ error: "Session not found" }, 404);
|
|
86
88
|
}
|
|
87
89
|
// Handle main MCP endpoint
|
|
88
|
-
if (c.req.method === "POST" && url.pathname ===
|
|
90
|
+
if (c.req.method === "POST" && url.pathname === `/${this.mcpPath}`) {
|
|
89
91
|
// Ensure session exists (creates new one if disconnected)
|
|
90
92
|
this.ensureSession();
|
|
91
93
|
const headers = {
|
|
@@ -112,16 +114,17 @@ export class FastHonoMcp extends ModalityFastMCP {
|
|
|
112
114
|
writer.send(result);
|
|
113
115
|
}, headers);
|
|
114
116
|
}
|
|
115
|
-
return c.json({ error:
|
|
117
|
+
return c.json({ error: `${url.pathname} endpoint not implemented` }, 501);
|
|
116
118
|
}
|
|
117
119
|
catch (error) {
|
|
118
|
-
this.logger.error(
|
|
120
|
+
this.logger.error(`FastHonoMcp (${url.pathname}) Middleware Error`, error);
|
|
119
121
|
const message = error instanceof Error ? error.message : "Internal error";
|
|
120
122
|
return c.text(sseError(null, -32603, message), 500, SSE_HEADERS);
|
|
121
123
|
}
|
|
122
124
|
};
|
|
123
125
|
}
|
|
124
|
-
initHono(app, path =
|
|
126
|
+
initHono(app, path = defaultMcpPath) {
|
|
127
|
+
this.mcpPath = path;
|
|
125
128
|
const middlewareHandler = this.handler();
|
|
126
129
|
app.use(`/${path}`, middlewareHandler);
|
|
127
130
|
app.use(`/${path}/*`, middlewareHandler);
|
package/package.json
CHANGED