Skip to content

Commit 372d342

Browse files
committed
Update Agents dev docs and add MCP server page
1 parent 9c3e1c3 commit 372d342

File tree

5 files changed

+106
-4
lines changed

5 files changed

+106
-4
lines changed

src/content/docs/agents/capabilities/control-web-browsers.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcx_content_type: navigation
33
title: Control Web Browsers (Browser Rendering API)
44
external_link: /browser-rendering/
55
sidebar:
6-
order: 1
6+
order: 2
77
head: []
88
description: The Workers Browser Rendering API allows developers to programmatically control and interact with a headless browser instance and create automation flows for their applications and products.
99

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
pcx_content_type: tutorial
3+
title: Build an MCP Server
4+
sidebar:
5+
order: 1
6+
group:
7+
hideIndex: true
8+
description: Build and deploy an MCP server on Cloudflare Workers
9+
---
10+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI assistants & LLMs to interact with services directly. If you want users to access your service or product straight from their AI assistant, you can enable this by spinning up an MCP server for your application.
11+
12+
## Building an MCP Server on Cloudflare Workers
13+
14+
Normally, setting up an MCP server requires handling infrastructure, API routing, and understanding the MCP protocol. But with [Cloudflare Workers](/workers/), all the heavy lifting is done for you, so all you need to do is define your service’s functionality.
15+
Once deployed, your Worker becomes an MCP server that AI assistants (as long as they support MCP) can connect to and use to interact with your service.
16+
17+
## Benefits
18+
19+
- **Minimal setup & built-in boilerplate:** The Worker automatically handles API routing, server management, and MCP protocol compliance. The [workers-mcp](https://www.npmjs.com/package/workers-mcp) package bootstraps your MCP server, allowing you to focus on your service logic.
20+
- **Automatic documentation:** Public methods annotated with JSDoc are automatically documented and exposed as MCP tools. This means AI assistants can quickly understand how to interact with your service, making tool discovery and integration much easier.
21+
- **Scalability & performance:** Deploy your MCP server on Cloudflare’s global edge network so that users can make fast, performant requests from their LLMs. Cloudflare will handle traffic spikes and high load, ensuring your service remains available and responsive.
22+
- **Expand MCP server capabilities:** Easily connect to Workers AI, D1, Durable Objects, and other Cloudflare services to add more functionality to your MCP Server.
23+
24+
## Get Started
25+
26+
Follow these steps to create and deploy your own MCP server on Cloudflare Workers.
27+
28+
29+
### 1. Create a new Worker
30+
31+
If you haven't already, install [Wrangler](https://developers.cloudflare.com/workers/wrangler/) and log in:
32+
33+
```bash
34+
npm install -g wrangler
35+
wrangler login
36+
```
37+
38+
Initialize a new project:
39+
```bash
40+
wrangler init my-mcp-project
41+
cd my-mcp-project
42+
```
43+
44+
### 2. Install the MCP Tooling
45+
Inside your project directory, install the [workers-mcp](https://github.com/cloudflare/workers-mcp) package:
46+
47+
```bash
48+
npm install workers-mcp
49+
```
50+
51+
This package provides the tools needed to run your Worker as an MCP server.
52+
53+
### 3. Set up the MCP Server on Workers
54+
Replace the contents of your src/index.ts with the following boilerplate code:
55+
56+
```ts
57+
import { WorkerEntrypoint } from 'cloudflare:workers';
58+
import { ProxyToSelf } from 'workers-mcp';
59+
60+
export default class MyWorker extends WorkerEntrypoint<Env> {
61+
/**
62+
* A warm, friendly greeting from your new MCP server.
63+
* @param name {string} The name of the person to greet.
64+
* @return {string} The greeting message.
65+
*/
66+
sayHello(name: string) {
67+
return `Hello from an MCP Worker, ${name}!`;
68+
}
69+
70+
/**
71+
* @ignore
72+
*/
73+
async fetch(request: Request): Promise<Response> {
74+
// ProxyToSelf handles MCP protocol compliance.
75+
return new ProxyToSelf(this).fetch(request);
76+
}
77+
}
78+
```
79+
80+
This converts your Cloudflare Worker into an MCP server, enabling interactions with AI assistants. The key components are:
81+
- **WorkerEntrypoint:** The WorkerEntrypoint class handles all incoming request management and routing. This provides the structure needed to expose MCP tools within the Worker.
82+
- **Tool Definition:** Methods (e.g. sayHello) are annotated with JSDoc, which automatically registers the method it as an MCP tool. AI assistants can call this method dynamically, passing a name and receiving a greeting in response. Additional tools can be defined using the same pattern.
83+
- **ProxyToSelf:** MCP servers must follow a specific request/response format. ProxyToSelf ensures that incoming requests are properly routed to the correct MCP tools. Without this, you would need to manually parse requests and validate responses.
84+
85+
86+
**Note:** Every public method that is annotated with JSDoc becomes an MCP tool that is discoverable by AI assistants.
87+
88+
89+
### 4. Deploy the MCP Server
90+
Update your wrangler.toml with the appropriate configuration then deploy your Worker:
91+
```bash
92+
wrangler deploy
93+
```
94+
95+
Your MCP server is now deployed globally and all your public class methods are exposed as MCP tools that AI assistants can now interact with.
96+
97+
### Expanding the MCP Server Capabilities
98+
Use existing Cloudflare products to expand the functionality of your MCP server. You can:
99+
- Send emails using [Email Routing](/email-routing/)
100+
- Capture and share website previews using [Browser Rendering](/browser-rendering/)
101+
- Store and manage sessions, user data, or other persistent information with [Durable Objects](/durable-objects/)
102+
- Query and update data using a [D1 database](/d1/)

src/content/docs/agents/capabilities/run-models.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcx_content_type: navigation
33
title: Run models (Workers AI)
44
external_link: /workers-ai/
55
sidebar:
6-
order: 2
6+
order: 3
77
head: []
88
description: Run popular open-source AI models on Cloudflare's network.
99
---

src/content/docs/agents/capabilities/send-email.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcx_content_type: navigation
33
title: Send Email
44
external_link: /email-routing/email-workers/send-email-workers/
55
sidebar:
6-
order: 2
6+
order: 4
77
head: []
88
description: Send emails from your Worker for async updates to a user.
99
---

src/content/docs/agents/capabilities/webrtc-realtime.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcx_content_type: navigation
33
title: Realtime voice (WebRTC)
44
external_link: /calls/
55
sidebar:
6-
order: 4
6+
order: 5
77
head: []
88
description: Build real-time serverless video, audio and data applications.
99
---

0 commit comments

Comments
 (0)