-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add stateless streamable http mode (#8) #15
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
base: main
Are you sure you want to change the base?
feat: add stateless streamable http mode (#8) #15
Conversation
mcp_run_python/deno/src/main.ts
Outdated
| res.end() | ||
| } | ||
|
|
||
| function createPathMatcher(req: http.IncomingMessage, url: URL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a factory?
mcp_run_python/deno/src/main.ts
Outdated
| } | ||
| } | ||
|
|
||
| function pathMatch(req: http.IncomingMessage, url: URL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be inlined as well?
|
@PeterRodenkirchAA Sorry for the delay here! @Kludex As our resident MCP maintainer, do you have any concerns with this? |
mcp_run_python/deno/src/main.ts
Outdated
| } else if (match('GET', '/mcp')) { | ||
| // SSE notifications not supported in stateless mode | ||
| httpSetJsonResponse(res, 405, 'Method not allowed.', -32000) | ||
| } else if (match('DELETE', '/mcp')) { | ||
| // Session termination not needed in stateless mode | ||
| httpSetJsonResponse(res, 405, 'Method not allowed.', -32000) | ||
| } else if (pathMatch(req, url)) { | ||
| httpSetTextResponse(res, 405, 'Method not allowed') | ||
| } else { | ||
| httpSetTextResponse(res, 404, 'Page not found') | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing so much manually? Doesn't the MCP package handles those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this is already handled by handleRequest() from the MCP SDK. I adapted this part now.
Conceptually this seems fine. |
|
@PeterRodenkirchAA Thanks Peter, looks good to me! @Kludex Can you have a final look too please? Feel free to merge and release. |
|
@Kludex just a small ping since we currently depend on the fork, would this be fine to merge? |
|
I just ran into this too 🙏 |
Related Issue: #8
Why?
The overhead of a stateful streamable HTTP mode might not be necessary for a lot of use cases that submit a simple code execution task via POST request.
We observed some issue with the stateful mode concerning pending GET requests and supporting a stateless mode would simplify the MCP server integration.
What?
New mode:
streamable_http_statelessPOST /mcp.GET /mcpandDELETE /mcpreturn 405 -> server-to-client notifications are not supported.CLI and Python API
streamable-http-statelessas a mode:uvx mcp-run-python streamable-http-stateless --port 3001TypeScript part:
runStreamableHttpdelegates to:createStatefulHttpServer(...)createStatelessHttpServer(...)createPathMatcher(req, url)andpathMatch(req, url)Usage