-
Notifications
You must be signed in to change notification settings - Fork 544
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
Add SSEEdgeTransport #178
Add SSEEdgeTransport #178
Conversation
// Note: to support multiple simultaneous connections, these messages will | ||
// need to be routed to a specific matching transport. (This logic isn't | ||
// implemented here, for simplicity.) | ||
await transport.handlePostMessage(req, res); |
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.
The doc is not correct here, maybe we need to pass c(Context) to handlePostMessage?
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.
Oh yeah you are correct! Will fix
Since testing this over a long amount of time I have discovered that the DO implementation breaks due to timeouts. Do MCP clients have a concept of reconnect? Is there something I need to implement in my transport? Right now Cursor just assumes the server is down and never tries again (although maybe that is a cursor problem?). Sadly CF's story for SSE is not great. |
I've been playing with SSE over DO (based on this transport, thank you for pushing it!) and reconnection is definitely an issue, not just for Cloudflare/DO and SSE but any remote server talking SSE or WS. It might happen more often on CF due to our architecture but connections will drop, and Cursor (or any client) needs to reestablish them. I think a
The exact strategy depends on the kinds of auth tokens you're issuing but thankfully that's all internal to the server, so you can make that consistent with the way you're addressing the DOs (one DO per user might be fine, for example). |
Oh! Just saw #158 has been merged and released in |
Might be unrelated, but I've been using WS on Cloudflare Workers for my users without much hassle and haven't heard too many complaints. Not saying we shouldn't do SSE with CF/DO, but might just much more simpler to support WS for edge as its been working for me EDIT: If theres enough interest, I can push up my |
Please push it. I've been "wrangling" cloudflare workers for a day trying to find a workaround. WS makes sense. Would love to see your take on its implementation |
We'd prefer to focus efforts on the new Streamable HTTP transport in the SDK going forward. |
Adds a transport which can be used in environments like Vercel and Cloudflare Workers. I called this SSEEdgeTransport but imagine there is some better naming.
I also added documentation to the readme on how to use it (with Hono which is a popular web framework for Cloudflare) and a section on using it with Cloudflare Durable Objects to keep track of different servers.
Motivation and Context
The current documentation & transport only really work with Node or Express which is pretty limiting in my experience. I think Durable Objects offer a viable quick way to get something spun up, and regardless a Transport which works in Edge environments is useful.
How Has This Been Tested?
Ran locally, deployed to cloudflare and tested with Cursor and a basic MCP Server (the greeting one).
I didn't test disconnects too much because I am not super familiar with MCP's reconnection protocol. But assuming the client keeps sending the same SessionID it will get directed to the same Durable Object (as described in the README, this is independent of the actual code change).
Breaking Changes
None
Types of changes
Checklist
Additional context