Skip to content

Commit 2449e35

Browse files
committed
Update docs with latest changes
1 parent 80edce8 commit 2449e35

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/content/docs/agents/capabilities/mcp-server.mdx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
---
22
pcx_content_type: tutorial
3-
title: Build MCP Server on Cloudflare Workers
3+
title: Build an MCP Server
44
sidebar:
55
order: 1
66
group:
77
hideIndex: true
88
description: Build and deploy an MCP server on Cloudflare Workers
99
---
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.
1011

11-
# Building an MCP Server on Cloudflare Workers
12+
## Building an MCP Server on Cloudflare Workers
1213

13-
Model Context Protocol (MCP) is an open standard for interacting with AI services and applications. MCP is like a standardized interface that LLMs can use to connect to various data sources and tools. With Cloudflare Workers, you can easily build and deploy an MCP server that grants AI assistants access to your service’s functionality.
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.
1416

15-
## Why Build an MCP Server on Cloudflare Workers?
17+
## Benefits
1618

17-
Using Cloudflare Workers to run your MCP server offers several key benefits:
18-
19-
- **Minimal setup & built-in boilerplate:** Workers automatically handle API routing, server management, and protocol compliance. The [workers-mcp](https://www.npmjs.com/package/workers-mcp) package bootstraps your MCP server, so you can focus on your service logic.
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.
2020
- **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 automatically handles traffic spikes and high load, ensuring your service remains responsive regardless of demand.
22-
- **Expand MCP Server capabilities:** Easily connect to Workers AI, D1 databases, Durable Objects, and other Cloudflare services to add more functionality to your MCP Server.
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.
2323

2424
## Get Started
2525

2626
Follow these steps to create and deploy your own MCP server on Cloudflare Workers.
2727

2828

29-
### 1. Create a New Worker Project
29+
### 1. Create a new Worker
3030

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

@@ -42,7 +42,7 @@ cd my-mcp-project
4242
```
4343

4444
### 2. Install the MCP Tooling
45-
Inside your project directory, install the workers-mcp package:
45+
Inside your project directory, install the [workers-mcp](https://github.com/cloudflare/workers-mcp) package:
4646

4747
```bash
4848
npm install workers-mcp
@@ -51,20 +51,12 @@ npm install workers-mcp
5151
This package provides the tools needed to run your Worker as an MCP server.
5252

5353
### 3. Set up the MCP Server on Workers
54-
Replace the contents of your src/index.ts (or index.js) with the following boilerplate code:
54+
Replace the contents of your src/index.ts with the following boilerplate code:
5555

56-
<TypeScriptExample filename="index.ts">
5756
```ts
5857
import { WorkerEntrypoint } from 'cloudflare:workers';
5958
import { ProxyToSelf } from 'workers-mcp';
6059

61-
/**
62-
* Extend the Env interface to declare KV, secrets, or other bindings from your wrangler.toml.
63-
*/
64-
export interface Env {
65-
// Example: MY_KV: KVNamespace
66-
}
67-
6860
export default class MyWorker extends WorkerEntrypoint<Env> {
6961
/**
7062
* A warm, friendly greeting from your new MCP server.
@@ -84,9 +76,15 @@ export default class MyWorker extends WorkerEntrypoint<Env> {
8476
}
8577
}
8678
```
87-
</TypeScriptExample>
8879

89-
**Note:** Every public method (like sayHello) that is annotated with JSDoc becomes an MCP tool that is discoverable by AI assistants.
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+
9088

9189
### 4. Deploy the MCP Server
9290
Update your wrangler.toml with the appropriate configuration then deploy your Worker:
@@ -97,7 +95,7 @@ wrangler deploy
9795
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.
9896

9997
### Expanding the MCP Server capabilities
100-
Use existing Cloudflare products to expand the functionality of your MCP Server. You can:
98+
Use existing Cloudflare products to expand the functionality of your MCP server. You can:
10199
- Send emails using [Email Routing](/email-routing/)
102100
- Capture and share website previews using [Browser Rendering](/browser-rendering/)
103101
- Store and manage sessions, user data, or other persistent information with [Durable Objects](/durable-objects/)

0 commit comments

Comments
 (0)