You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/agents/model-context-protocol/transport.mdx
+95-6Lines changed: 95 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,105 @@ sidebar:
6
6
---
7
7
8
8
import { Render } from"~/components";
9
+
import { TabItem, Tabs } from"~/components";
9
10
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:
11
12
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.
14
16
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
+
[](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:
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
+
exportdefaultnewOAuthProvider({
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`.
16
100
17
101
:::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.
19
109
20
110
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).
0 commit comments