Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/content/docs/agents/model-context-protocol/transport.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ sidebar:
order: 5
---

import { Render } from "~/components";
import { TabItem, Tabs } from "~/components";
import { Render, TabItem, Tabs } from "~/components";

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:

1. **stdio, communication over standard in and standard out** — designed for local MCP connections.
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.
1. **stdio, communication over standard in and standard out** — designed for local MCP connections.
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.
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 is currently gaining adoption among remote MCP clients, but it is expected to become the standard transport in the future.

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.
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.

## Implementing remote MCP transport

Expand All @@ -34,11 +33,11 @@ If you're manually configuring your MCP server, here's how to use the `McpAgent`
export default {
fetch(request: Request, env: Env, ctx: ExecutionContext) {
const { pathname } = new URL(request.url);

if (pathname.startsWith('/sse')) {
return MyMcpAgent.serveSSE('/sse').fetch(request, env, ctx);
}

if (pathname.startsWith('/mcp')) {
return MyMcpAgent.serve('/mcp').fetch(request, env, ctx);
}
Expand All @@ -52,15 +51,15 @@ export default {
export default {
fetch(request: Request, env: Env, ctx: ExecutionContext): Response | Promise<Response> {
const { pathname } = new URL(request.url);

if (pathname.startsWith('/sse')) {
return MyMcpAgent.serveSSE('/sse').fetch(request, env, ctx);
}

if (pathname.startsWith('/mcp')) {
return MyMcpAgent.serve('/mcp').fetch(request, env, ctx);
}

// Handle case where no path matches
return new Response('Not found', { status: 404 });
},
Expand All @@ -78,7 +77,7 @@ export default app
```
</TabItem> </Tabs>

#### MCP Server with Authentication
#### MCP server with authentication
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.

```js
Expand All @@ -91,7 +90,7 @@ export default new OAuthProvider({
})
```

### Upgrading an Existing Remote MCP Server
### Upgrading an existing remote MCP server
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:
- Use `MyMcpAgent.serveSSE('/sse')` for the existing SSE transport. Previously, this would have been `MyMcpAgent.mount('/sse')`, which has been kept as an alias.
- Add a new path with `MyMcpAgent.serve('/mcp')` to support the new Streamable HTTP transport.
Expand All @@ -104,7 +103,7 @@ To use apiHandlers, update to @cloudflare/workers-oauth-provider v0.0.4 or later

With these few changes, your MCP server will support both transport methods, making it compatible with both existing and new clients.

### Testing with MCP Clients
### Testing with MCP clients
While most MCP clients have not 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.

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).
Loading