The Workers MCP server is a high-performance Model Context Protocol implementation built on Cloudflare Workers. It enables you to serve AI models via MCP, a protocol designed for efficient interaction between clients and model backends with context-aware streaming.
To get started with the Workers MCP server, follow these steps:
Clone the repository:
git clone https://github.com/cloudflare/workers-mcp.git
cd workers-mcp
Install dependencies:
npm install
Set up your development environment:
npm run dev
Configure your MCP server by editing the src/models.ts
file. This file contains the definitions for all models your server will expose.
Here's an example configuration:
export const models: Model[] = [
{
id: "my-model-v1",
provider: "openai",
name: "My Custom Model",
version: "1.0",
contextWindow: 8192,
capabilities: ["chat", "embeddings"],
parameters: {
apiKey: "YOUR_OPENAI_API_KEY",
model: "gpt-4-turbo-preview"
}
}
]
Create a .dev.vars
file in the project root for local development:
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
Once your server is running, you can interact with it using any MCP-compatible client. The server exposes several endpoints:
/api/providers
: Lists all available model providers/api/models
: Lists all configured models/api/chat
: Endpoint for chat completions/api/embeddings
: Endpoint for generating embeddingsHere's how to send a chat completion request:
curl -X POST http://localhost:8787/api/chat \
-H "Content-Type: application/json" \
-d '{
"model": "my-model-v1",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, how are you?"}
]
}'
Generate embeddings with:
curl -X POST http://localhost:8787/api/embeddings \
-H "Content-Type: application/json" \
-d '{
"model": "my-model-v1",
"input": "The quick brown fox jumps over the lazy dog"
}'
To deploy your MCP server to Cloudflare Workers:
Configure your wrangler.toml
file with the appropriate settings:
name = "mcp-server"
main = "src/index.ts"
compatibility_date = "2023-10-30"
Set up your environment variables in the Cloudflare dashboard or via Wrangler:
wrangler secret put OPENAI_API_KEY
Deploy to Cloudflare Workers:
npm run deploy
After deployment, your MCP server will be available at your Cloudflare Workers URL.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.