Skip to content

Commit 18e194e

Browse files
committed
URL structure
1 parent e9df63a commit 18e194e

File tree

11 files changed

+133
-122
lines changed

11 files changed

+133
-122
lines changed

src/content/docs/agents/examples/build-mcp-server.mdx

Lines changed: 100 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,41 @@ sidebar:
88
description: Build and deploy an MCP server on Cloudflare Workers
99
---
1010

11-
import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components";
12-
import { Aside } from '@astrojs/starlight/components';
11+
import {
12+
MetaInfo,
13+
Render,
14+
Type,
15+
TypeScriptExample,
16+
WranglerConfig,
17+
} from "~/components";
18+
import { Aside } from "@astrojs/starlight/components";
1319

1420
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI agents and assistants (like [Claude Desktop](https://claude.ai/download) or [Cursor](https://www.cursor.com/)) to interact with services directly. If you want users to access your service through an AI assistant, you can spin up an MCP server for your application.
1521

1622
### Building an MCP Server on Workers
1723

18-
With Cloudflare Workers and the [workers-mcp](https://github.com/cloudflare/workers-mcp/) package, you can turn any API or service into an MCP server with minimal setup. Just define your API methods as TypeScript functions, and workers-mcp takes care of tool discovery, protocol handling, and request routing. Once deployed, MCP clients like Claude can connect and interact with your service automatically.
24+
With Cloudflare Workers, you can turn any API or service into an MCP server with minimal setup.
1925

2026
Below we will run you through an example of building an MCP server that fetches weather data from an external API and exposes it as an MCP tool that Claude can call directly:
2127

2228
**How it works:**
23-
* **TypeScript methods as MCP tools:** Each public method in your class is exposed as an MCP tool that agents can call. In this example, getWeather is the tool that fetches data from an external weather API.
24-
* **Automatic tool documentation:** JSDoc comments define the tool description, parameters, and return values, so Claude knows exactly how to call your method and interpret the response.
25-
* **Build-in MCP compatibility:** The `ProxyToSelf` class translates incoming requests into relevant JS RPC methods
26-
* **Enforced type safety:** Parameter and return types are automatically derived from your TypeScript definitions
29+
30+
- **TypeScript methods as MCP tools:** Each public method in your class is exposed as an MCP tool that agents can call. In this example, getWeather is the tool that fetches data from an external weather API.
31+
- **Automatic tool documentation:** JSDoc comments define the tool description, parameters, and return values, so Claude knows exactly how to call your method and interpret the response.
32+
- **Build-in MCP compatibility:** The `ProxyToSelf` class translates incoming requests into relevant JS RPC methods
33+
- **Enforced type safety:** Parameter and return types are automatically derived from your TypeScript definitions
2734

2835
## Get Started
2936

3037
Follow these steps to create and deploy your own MCP server on Cloudflare Workers.
3138

3239
<Aside type="note">
33-
Remote MCP servers are not supported yet. The workers-mcp tooling creates a local proxy that forwards requests to your Worker, allowing the server to be used by an MCP client.
40+
Remote MCP servers are not supported yet. The workers-mcp tooling creates a
41+
local proxy that forwards requests to your Worker, allowing the server to be
42+
used by an MCP client.
3443
</Aside>
3544

36-
37-
### Create a new Worker
45+
### Create a new Worker
3846

3947
If you haven't already, install [Wrangler](https://developers.cloudflare.com/workers/wrangler/) and log in:
4048

@@ -44,6 +52,7 @@ wrangler login
4452
```
4553

4654
Initialize a new project:
55+
4756
```bash
4857
npx create-cloudflare@latest my-mcp-worker
4958
cd my-mcp-worker
@@ -54,15 +63,12 @@ cd my-mcp-worker
5463
When you run the setup command, it will build your Worker using the configuration in your wrangler.toml or wrangler.jsonc file. By default, no additional configuration is needed, but if you have multiple Cloudflare accounts, you'll need to specify your account ID as shown below.
5564

5665
<WranglerConfig>
57-
```toml
58-
name = "my-mcp-worker"
59-
main = "src/index.ts"
60-
compatibility_date = "2025-03-03"
61-
account_id = "your-account-id"
62-
```
66+
```toml name = "my-mcp-worker" main = "src/index.ts" compatibility_date =
67+
"2025-03-03" account_id = "your-account-id" ```
6368
</WranglerConfig>
6469

6570
### Install the MCP tooling
71+
6672
Inside your project directory, install the [workers-mcp](https://github.com/cloudflare/workers-mcp) package:
6773

6874
```bash
@@ -72,105 +78,116 @@ npm install workers-mcp
7278
This package provides the tools needed to run your Worker as an MCP server.
7379

7480
### Configure your Worker to support MCP
81+
7582
Run the following setup command:
7683

7784
```bash
7885
npx workers-mcp setup
7986
```
8087

8188
This guided installation process takes a brand new or existing Workers project and adds the required tooling to turn it into an MCP server:
89+
8290
- Automatic documentation generation
8391
- Shared-secret security using Wrangler Secrets
8492
- Installs a local proxy so you can access it from your MCP desktop clients (like Claude Desktop)
8593

8694
### Set up the MCP Server
95+
8796
The setup command will automatically update your src/index.ts with the following code:
8897

8998
```ts
90-
import { WorkerEntrypoint } from 'cloudflare:workers';
91-
import { ProxyToSelf } from 'workers-mcp';
99+
import { WorkerEntrypoint } from "cloudflare:workers";
100+
import { ProxyToSelf } from "workers-mcp";
92101

93102
export default class MyWorker extends WorkerEntrypoint<Env> {
94-
/**
95-
* A warm, friendly greeting from your new MCP server.
96-
* @param name {string} The name of the person to greet.
97-
* @return {string} The greeting message.
98-
*/
99-
sayHello(name: string) {
100-
return `Hello from an MCP Worker, ${name}!`;
101-
}
102-
103-
/**
104-
* @ignore
105-
*/
106-
async fetch(request: Request): Promise<Response> {
107-
// ProxyToSelf handles MCP protocol compliance.
108-
return new ProxyToSelf(this).fetch(request);
109-
}
103+
/**
104+
* A warm, friendly greeting from your new MCP server.
105+
* @param name {string} The name of the person to greet.
106+
* @return {string} The greeting message.
107+
*/
108+
sayHello(name: string) {
109+
return `Hello from an MCP Worker, ${name}!`;
110+
}
111+
112+
/**
113+
* @ignore
114+
*/
115+
async fetch(request: Request): Promise<Response> {
116+
// ProxyToSelf handles MCP protocol compliance.
117+
return new ProxyToSelf(this).fetch(request);
118+
}
110119
}
111120
```
112121

113122
This converts your Cloudflare Worker into an MCP server, enabling interactions with AI assistants. **The key components are:**
123+
114124
- **WorkerEntrypoint:** The WorkerEntrypoint class handles all incoming request management and routing. This provides the structure needed to expose MCP tools within the Worker.
115125
- **Tool Definition:** Methods, for example, sayHello, are annotated with JSDoc, which automatically registers the method 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.
116126
- **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.
117127

118-
119-
**Note:** Every public method that is annotated with JSDoc becomes an MCP tool that is discoverable by AI assistants.
128+
**Note:** Every public method that is annotated with JSDoc becomes an MCP tool that is discoverable by AI assistants.
120129

121130
### Add data fetching to the MCP
122131

123-
When building an MCP, in many cases, you will need to connect to a resource or an API to take an action. To do this you can use the `fetch` method to make direct API calls, such as in the example below for grabbing the current wearther:
132+
When building an MCP, in many cases, you will need to connect to a resource or an API to take an action. To do this you can use the `fetch` method to make direct API calls, such as in the example below for grabbing the current wearther:
124133

125134
```ts
126-
import { WorkerEntrypoint } from 'cloudflare:workers';
127-
import { ProxyToSelf } from 'workers-mcp';
135+
import { WorkerEntrypoint } from "cloudflare:workers";
136+
import { ProxyToSelf } from "workers-mcp";
128137

129138
export default class WeatherWorker extends WorkerEntrypoint<Env> {
130-
/**
131-
* Get current weather for a location
132-
* @param location {string} City name or zip code
133-
* @return {object} Weather information
134-
*/
135-
async getWeather(location: string) {
136-
// Connect to a weather API
137-
const response = await fetch(`https://api.weather.example/v1/${location}`);
138-
const data = await response.json();
139-
return {
140-
temperature: data.temp,
141-
conditions: data.conditions,
142-
forecast: data.forecast
143-
};
144-
}
145-
146-
/**
147-
* @ignore
148-
*/
149-
async fetch(request: Request): Promise<Response> {
150-
// ProxyToSelf handles MCP protocol compliance
151-
return new ProxyToSelf(this).fetch(request);
152-
}
139+
/**
140+
* Get current weather for a location
141+
* @param location {string} City name or zip code
142+
* @return {object} Weather information
143+
*/
144+
async getWeather(location: string) {
145+
// Connect to a weather API
146+
const response = await fetch(`https://api.weather.example/v1/${location}`);
147+
const data = await response.json();
148+
return {
149+
temperature: data.temp,
150+
conditions: data.conditions,
151+
forecast: data.forecast,
152+
};
153+
}
154+
155+
/**
156+
* @ignore
157+
*/
158+
async fetch(request: Request): Promise<Response> {
159+
// ProxyToSelf handles MCP protocol compliance
160+
return new ProxyToSelf(this).fetch(request);
161+
}
153162
}
154163
```
155164

156165
### Deploy the MCP server
166+
157167
Update your wrangler.toml with the appropriate configuration then deploy your Worker:
168+
158169
```bash
159170
npx wrangler deploy
160171
```
161172

162-
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.
173+
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.
163174

164175
#### Updating your MCP server
176+
165177
When you make changes to your MCP server, run the following command to update it:
178+
166179
```bash
167180
npm run deploy
168181
```
182+
169183
**Note:** If you change method names, parameters, or add/remove methods, Claude and other MCP clients will not see these updates until you restart them. This is because MCP clients cache the tool metadata for performance reasons.
184+
170185
### Connecting MCP clients to your server
186+
171187
The `workers-mcp setup` command automatically configures Claude Desktop to work with your MCP server. To use your MCP server through other [MCP clients](https://modelcontextprotocol.io/clients), you'll need to configure them manually.
172188

173189
#### Cursor
190+
174191
To get your Cloudflare MCP server working in [Cursor](https://modelcontextprotocol.io/clients#cursor), you need to combine the 'command' and 'args' from your config file into a single string and use type 'command'.
175192

176193
In Cursor, create an MCP server entry with:
@@ -179,33 +196,39 @@ type: command
179196
command: /path/to/workers-mcp run your-mcp-server-name https://your-server-url.workers.dev /path/to/your/project
180197

181198
For example, using the same configuration as above, your Cursor command would be:
199+
182200
```
183201
/Users/username/path/to/my-new-worker/node_modules/.bin/workers-mcp run my-new-worker https://my-new-worker.username.workers.dev /Users/username/path/to/my-new-worker
184202
```
185203

186204
#### Other MCP clients
205+
187206
For [Windsurf](https://modelcontextprotocol.io/clients#windsurf-editor) and other [MCP clients](https://modelcontextprotocol.io/clients#client-details), update your configuration file to include your worker using the same format as Claude Desktop:
207+
188208
```json
189209
{
190-
"mcpServers": {
191-
"your-mcp-server-name": {
192-
"command": "/path/to/workers-mcp",
193-
"args": [
194-
"run",
195-
"your-mcp-server-name",
196-
"https://your-server-url.workers.dev",
197-
"/path/to/your/project"
198-
],
199-
"env": {}
200-
}
201-
}
210+
"mcpServers": {
211+
"your-mcp-server-name": {
212+
"command": "/path/to/workers-mcp",
213+
"args": [
214+
"run",
215+
"your-mcp-server-name",
216+
"https://your-server-url.workers.dev",
217+
"/path/to/your/project"
218+
],
219+
"env": {}
220+
}
221+
}
202222
}
203223
```
204-
Make sure to replace the placeholders with your actual server name, URL, and project path.
224+
225+
Make sure to replace the placeholders with your actual server name, URL, and project path.
226+
205227
### Coming soon
228+
206229
The Model Context Protocol spec is [actively evolving](https://github.com/modelcontextprotocol/specification/discussions) and we're working on expanding Cloudflare's MCP support. Here's what we're working on:
207230

208231
- **Remote MCP support**: Connect to MCP servers directly without requiring a local proxy
209232
- **Authentication**: OAuth support for secure MCP server connections
210233
- **Real-time communication**: SSE (Server-Sent Events) and WebSocket support for persistent connections and stateful interactions between clients and servers
211-
- **Extended capabilities**: Native support for more MCP protocol capabilities like [resources](https://modelcontextprotocol.io/docs/concepts/resources), [prompts](https://modelcontextprotocol.io/docs/concepts/prompts) and [sampling](https://modelcontextprotocol.io/docs/concepts/sampling)
234+
- **Extended capabilities**: Native support for more MCP protocol capabilities like [resources](https://modelcontextprotocol.io/docs/concepts/resources), [prompts](https://modelcontextprotocol.io/docs/concepts/prompts) and [sampling](https://modelcontextprotocol.io/docs/concepts/sampling)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,39 @@ pcx_content_type: navigation
44
sidebar:
55
order: 4
66
group:
7-
hideIndex: true
7+
hideIndex: false
88
---
99

10-
import { DirectoryListing } from "~/components";
10+
# Deploy MCP Servers to Cloudflare
1111

12-
<DirectoryListing />
12+
You can build and deploy MCP servers on Cloudflare, using the [`workers-mcp` package](https://github.com/cloudflare/workers-mcp), which provides an SDK for [authorization](/agents/model-context-protocol/mcp-server/authorization/), [transport](/agents/model-context-protocol/mcp-server/transport/), and [tool definition and discovery](/agents/model-context-protocol/mcp-server/tools/).
13+
14+
The [getting started section](/agents/model-context-protocol/mcp-server/getting-started/) will guide you to build and deploy your first MCP server to Cloudflare.
15+
16+
### What is the Model Context Protocol (MCP)?
17+
18+
[Model Context Protocol (MCP)](https://modelcontextprotocol.io) is an open standard that connects AI systems with external applications. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various accessories, MCP provides a standardized way to connect AI agents to different services.
19+
20+
#### MCP Terminology
21+
22+
- **MCP Hosts**: AI assistants (like [Claude](http://claude.ai) or [Cursor](http://cursor.com)), AI agents, or applications that need to access external capabilities.
23+
- **MCP Clients**: Clients embedded within the MCP hosts that connect to MCP servers and invoke tools. Each MCP client instance has a single connection to an MCP server.
24+
- **MCP Servers**: Applications that expose [tools](/agents/model-context-protocol/mcp-server/tools/), [prompts](https://modelcontextprotocol.io/docs/concepts/prompts), and [resources](https://modelcontextprotocol.io/docs/concepts/resources) that MCP clients can use.
25+
26+
#### Remote vs. local MCP connections
27+
28+
The MCP standard supports two modes of operation:
29+
30+
- **Remote MCP connections**: MCP clients connect to MCP servers over the Internet, establishing a [long-lived connection using HTTP and Server-Sent Events (SSE)](/agents/model-context-protocol/mcp-server/transport/), and authorizing the MCP client access to resources on the user's account using [OAuth](/agents/model-context-protocol/mcp-server/authorization/).
31+
- **Local MCP connections**: MCP clients connect to MCP servers on the same machine, using [stdio](https://spec.modelcontextprotocol.io/specification/draft/basic/transports/#stdio) as a local transport method.
32+
33+
[`workers-mcp`](https://github.com/cloudflare/workers-mcp) is designed to support remote MCP connections. Remote MCP connections allow MCP clients that run in web browsers, mobile apps, and other environments outside of the end-user's machine to connect to your MCP server, such as [Claude.ai](https://www.anthropic.com/claude), and other AI agents.
34+
35+
### Why deploy your MCP server to Cloudflare?
36+
37+
- Authorization is [built-in](/agents/model-context-protocol/mcp-server/authorization/). Cloudflare handles the hard parts of the OAuth flow for you.
38+
- Transport over HTTP with Server-Sent Events (SSE) is [built-in](/agents/model-context-protocol/mcp-server/transport/)
39+
40+
### Next step — deploy your first MCP server to Cloudflare
41+
42+
Go to [getting started](/agents/model-context-protocol/mcp-server/getting-started/) to learn how to build and deploy MCP servers to Cloudflare.

src/content/docs/agents/model-context-protocol/mcp-server/index.mdx

Lines changed: 0 additions & 42 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)