Skip to content

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

Open
hy212 opened this issue Apr 22, 2025 · 5 comments
Open

Can the stream http mode be supported for use at the edge? #383

hy212 opened this issue Apr 22, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@hy212
Copy link

hy212 commented Apr 22, 2025

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

@hy212 hy212 added the enhancement New feature or request label Apr 22, 2025
@mhart
Copy link
Contributor

mhart commented Apr 22, 2025

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

@hy212
Copy link
Author

hy212 commented Apr 23, 2025

我刚刚使用 Hono 和 StreamableHTTPServerTransport 创建了一个示例:

https://github.com/mhart/mcp-hono-stateless

希望能够得到官方支持,我会发布一个问题

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

@mhart
Copy link
Contributor

mhart commented Apr 23, 2025

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

Well that doesn't support StreamableHTTPServerTransport yet AFAIK: modelcontextprotocol/inspector#221

@QuantGeekDev
Copy link

QuantGeekDev commented Apr 23, 2025

我刚刚使用 Hono 和 StreamableHTTPServerTransport 创建了一个示例:
https://github.com/mhart/mcp-hono-stateless
希望能够得到官方支持,我会发布一个问题

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

try npx mcp-debug while we wait for official inspector updates

@hy212
Copy link
Author

hy212 commented May 7, 2025

我按照你提供的代码示例使用了,但是失败了,这里测试接口,没有达到预期的效果。
测试工具:https://github.com/modelcontextprotocol/inspector

嗯,据我所知,它还不支持 StreamableHTTPServerTransport:modelcontextprotocol/inspector#221

The test tool already supports the StreamableHTTP mode:(express example)
Image

The hono service run directly did not succeed. Could you help me see how to adjust it ?

Image

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}`)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants