Skip to content

Commit 2f01168

Browse files
dinasaur404GregBrimble
authored andcommitted
Add streamable HTTP support to MCP transport documentation (#22081)
1 parent 994265e commit 2f01168

File tree

1 file changed

+95
-6
lines changed

1 file changed

+95
-6
lines changed

src/content/docs/agents/model-context-protocol/transport.mdx

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,105 @@ sidebar:
66
---
77

88
import { Render } from "~/components";
9+
import { TabItem, Tabs } from "~/components";
910

10-
The Model Context Protocol (MCP) specification defines [two standard transport mechanisms](https://spec.modelcontextprotocol.io/specification/draft/basic/transports/):
11+
The Model Context Protocol (MCP) specification defines three standard [transport mechanisms](https://spec.modelcontextprotocol.io/specification/draft/basic/transports/) for communication between clients and servers:
1112

12-
1. **stdio, communication over standard in and standard out** — designed for local MCP connections
13-
2. **HTTP with Server-Sent Events (SSE)** — designed for remote MCP connections
13+
1. **stdio, communication over standard in and standard out** — designed for local MCP connections.
14+
2. **Server-Sent Events (SSE)** — Currently supported by most remote MCP clients, but is expected to be replaced by Streamable HTTP over time. It requires two endpoints: one for sending requests, another for receiving streamed responses.
15+
3. **Streamable HTTP** — New transport method [introduced](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http) in March 2025. It simplifies the communication by using a single HTTP endpoint for bidirectional messaging. It's currently gaining adoption among remote MCP clients, but is expected to become the standard transport in the future.
1416

15-
MCP Servers deployed to Cloudflare support remote MCP connections, using HTTP with Server-Sent Events (SSE) as transport. SSE requires a persistent HTTP connection, which is supported by Cloudflare [Durable Objects](/durable-objects/) and the [Agents SDK](/agents). Transport is configured and handled automatically by the [`McpAgent` class](https://github.com/cloudflare/agents/blob/2f82f51784f4e27292249747b5fbeeef94305552/packages/agents/src/mcp.ts). You don't need to configure anything — it just works.
17+
MCP servers built with the [Agents SDK](/agents) can support both remote transport methods (SSE and Streamable HTTP), with the [`McpAgent` class](https://github.com/cloudflare/agents/blob/2f82f51784f4e27292249747b5fbeeef94305552/packages/agents/src/mcp.ts) automatically handling the transport configuration.
18+
19+
## Implementing remote MCP transport
20+
21+
If you're building a new MCP server or upgrading an existing one on Cloudflare, we recommend supporting both remote transport methods (SSE and Streamable HTTP) concurrently to ensure compatibility with all MCP clients.
22+
23+
#### Get started quickly
24+
You can use the "Deploy to Cloudflare" button to create a remote MCP server that automatically supports both SSE and Streamable HTTP transport methods.
25+
26+
[![Deploy to Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/ai/tree/main/demos/remote-mcp-authless)
27+
28+
#### Remote MCP server (without authentication)
29+
If you're manually configuring your MCP server, here's how to use the `McpAgent` class to handle both transport methods:
30+
31+
<Tabs syncKey="workersExamples"> <TabItem label="JavaScript" icon="seti:javascript">
32+
33+
```js
34+
export default {
35+
fetch(request: Request, env: Env, ctx: ExecutionContext) {
36+
const { pathname } = new URL(request.url);
37+
38+
if (pathname.startsWith('/sse')) {
39+
return MyMcpAgent.serveSSE('/sse').fetch(request, env, ctx);
40+
}
41+
42+
if (pathname.startsWith('/mcp')) {
43+
return MyMcpAgent.serve('/mcp').fetch(request, env, ctx);
44+
}
45+
},
46+
};
47+
```
48+
49+
</TabItem> <TabItem label="TypeScript" icon="seti:typescript">
50+
51+
```ts
52+
export default {
53+
fetch(request: Request, env: Env, ctx: ExecutionContext): Response | Promise<Response> {
54+
const { pathname } = new URL(request.url);
55+
56+
if (pathname.startsWith('/sse')) {
57+
return MyMcpAgent.serveSSE('/sse').fetch(request, env, ctx);
58+
}
59+
60+
if (pathname.startsWith('/mcp')) {
61+
return MyMcpAgent.serve('/mcp').fetch(request, env, ctx);
62+
}
63+
64+
// Handle case where no path matches
65+
return new Response('Not found', { status: 404 });
66+
},
67+
};
68+
```
69+
</TabItem>
70+
<TabItem label="Hono" icon="seti:typescript">
71+
```ts
72+
const app = new Hono()
73+
74+
app.mount('/sse', MyMCP.serveSSE('/sse').fetch, { replaceRequest: false })
75+
app.mount('/mcp', MyMCP.serve('/mcp').fetch, { replaceRequest: false )
76+
77+
export default app
78+
```
79+
</TabItem> </Tabs>
80+
81+
#### MCP Server with Authentication
82+
If your MCP server implements authentication & authorization using the [Workers OAuth Provider](https://github.com/cloudflare/workers-oauth-provider) Library, then you can configure it to support both transport methods using the `apiHandlers` property.
83+
84+
```js
85+
export default new OAuthProvider({
86+
apiHandlers: {
87+
'/sse': MyMCP.serveSSE('/sse'),
88+
'/mcp': MyMCP.serve('/mcp'),
89+
},
90+
// ... other OAuth configuration
91+
})
92+
```
93+
94+
### Upgrading an Existing Remote MCP Server
95+
If you've already built a remote MCP server using the Cloudflare Agents SDK, make the following changes to support the new Streamable HTTP transport while maintaining compatibility with remote MCP clients using SSE:
96+
- Use `MyMcpAgent.serveSSE('/sse')` for the existing SSE transport. Previously, this would have been `MyMcpAgent.mount('/sse')`, which has been kept as an alias.
97+
- Add a new path with `MyMcpAgent.serve('/mcp')` to support the new Streamable HTTP transport.
98+
99+
If you have an MCP server with authentication/authorization using the Workers OAuth Provider, [update the configuration](http://localhost:1111/agents/model-context-protocol/transport/#mcp-server-with-authentication) to use the `apiHandlers` property, which replaces `apiRoute` and `apiHandler`.
16100
17101
:::note
18-
Even if the MCP client you are using only supports local MCP connections, you can still connect it to a remote MCP server.
102+
To use apiHandlers, update to @cloudflare/workers-oauth-provider v0.0.4 or later.
103+
:::
104+
105+
With these few changes, your MCP server will support both transport methods, making it compatible with both existing and new clients.
106+
107+
### Testing with MCP Clients
108+
While most MCP clients haven't yet adopted the new Streamable HTTP transport, you can start testing it today using [`mcp-remote`](https://www.npmjs.com/package/mcp-remote), an adapter that lets MCP clients that otherwise only support local connections work with remote MCP servers.
19109
20110
Follow [this guide](/agents/guides/test-remote-mcp-server/) for instructions on how to connect to your remote MCP server from Claude Desktop, Cursor, Windsurf, and other local MCP clients, using the [`mcp-remote` local proxy](https://www.npmjs.com/package/mcp-remote).
21-
:::

0 commit comments

Comments
 (0)