Runtimes
Cloudflare Workers
For connecting your MCP with a LLM, you will need to pressists the transport instance. On a server it is quite easy, but on a worker you will need to use Durable Objects to achieve that. Here is an example of how to do that:
Over here we are creating a proxy server that will handle the SSE connection. The MyDurableObject
class is a Durable Object that will handle the transport instance. The fetch
method will handle the incoming requests and pass them to the Durable Object.
To identify the session, we are using the sessionId
query parameter. If it is not present, we will create a new Durable Object instance. If it is present, we will use the existing instance.