-
Notifications
You must be signed in to change notification settings - Fork 747
Can the stream http mode be supported for use at the edge? #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I just created an example using Hono and StreamableHTTPServerTransport: https://github.com/mhart/mcp-hono-stateless Would love for this to be officially supported, I'll post an issue |
I used it according to the code example you provided, but failed. Testing the interface here is not as expected. test tools : https://github.com/modelcontextprotocol/inspector Actually, I want to implement a function similar to another issue #178 SSEEdgeTransport in the edge environment, but it's a stateless request |
Well that doesn't support StreamableHTTPServerTransport yet AFAIK: modelcontextprotocol/inspector#221 |
try |
The test tool already supports the StreamableHTTP mode:(express example) The hono service run directly did not succeed. Could you help me see how to adjust it ? ![]() The code example is as follows: import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
import { toFetchResponse, toReqRes } from "fetch-to-node";
import {serve} from "@hono/node-server";
import { Hono } from 'hono'
import { z } from "zod";
const BASE_URL = "";
const app = new Hono().basePath(BASE_URL)
function getServer() {
const server = new McpServer({
name: "add-tool-server",
version: "1.0.0",
description: 'An MCP service for getting the sum of two numbers',
});
server.tool(
"add-tool",
"Get the sum of two numbers",
{
a: z.number(),
b: z.number()
},
async ({ a, b }) => ({
content: [{
type: "text",
text: String(a + b)
}]
})
);
return server;
}
app.post('/mcp', async (ctx) => {
try{
const { req, res } = toReqRes(ctx.req.raw);
const transport: StreamableHTTPServerTransport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined, // set to undefined for stateless servers
});
const server = getServer();
await server.connect(transport);
await transport.handleRequest(req, res, await ctx.req.json());
res.on('close', () => {
console.log('Request closed');
transport.close();
server.close();
});
return toFetchResponse(res);
}catch(err: any){
return ctx.json(
{
jsonrpc: "2.0",
error: {
code: -32603,
message: "Internal server error",
},
id: null,
},
{ status: 500 }
);
}
})
serve({
fetch: app.fetch,
port: 3000,
}, (info) => {
console.log(`Server is running on http://localhost:${info.port}`)
}) |
Currently, the stream http mode seems to only be supported for use in the express framework. For example, I want to use it in hono or edge applications
The text was updated successfully, but these errors were encountered: