Extend Cloudflare Workers with Claude MCP Server for seamless plugin integration
The Workers MCP Server allows developers to extend Claude Desktop and other Model Context Protocol (MCP) clients by implementing custom functions within a Cloudflare Worker environment. This server leverages the new RPC syntax introduced in Cloudflare Workers, providing seamless integration between AI applications like Claude Desktop and third-party services hosted on Cloudflare or elsewhere.
Developers can implement custom functions using TypeScript (TS) within a WorkerEntrypoint
class. These functions are exposed to MCP clients, enabling rich interactions with the worker. For instance, a function like generating random numbers is straightforward:
export class ExampleWorkerMCP extends WorkerEntrypoint<Env> {
/**
* Generates a super-duper random number.
*
* @return {string} A message containing a randomly generated number.
* */
async getRandomNumber() {
return `Your random number is ${Math.random()}`
}
}
A key feature of this server is the automatic generation of documentation from TypeScript classes. This static extraction ensures that AI applications like Claude Desktop can understand and interact with the worker's capabilities accurately.
The Workers MCP Server comprises three core components:
Using ts-blank-space
and jsdoc-api
, the server parses TypeScript files and generates a structured JSON documentation file, docs.json
. This file serves as input for MCP clients to list available methods.
/**
* Send an email with text or HTML content.
*
* @param {string} recipient - The destination’s email address (must be verified).
* @param {string} subject - The subject of the email.
* @param {string} contentType - Either "text/plain" or "text/html", indicating content type.
* @param {string} body - The email's body, suitable for `contentType`.
* @return {Promise<string>} A success message upon completion.
*/
async sendEmail(recipient: string, subject: string, contentType: string, body: string) {
// Sending logic will be implemented here
}
This example JSDoc block translates into the corresponding JSON structure.
The lib/WorkerMCP.ts
file handles incoming RPC requests via a single endpoint /rpc
. It parses the request payload and delegates the method call to the appropriate worker class instance.
const workerEntrypoint = new ExampleWorkerMCP(env);
app.post('/rpc', cors(), async (req, res) => {
try {
const { method, args } = req.body;
if (!workerEntrypoint[method]) {
throw new Error(`Method ${method} not found`);
}
const result = await workerEntrypoint[method](...args);
res.json(result);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
The scripts/local-proxy.ts
script uses the @modelcontextprotocol/sdk
library to create a local proxy that simulates an MCP server. It handles tools/list
requests by sending JSON data generated from the worker’s methods, and tools/call
requests by making calls via /rpc
.
pnpm install:claude <server-alias> <worker-url>
The above command installs a server definition for Claude Desktop that points to the local proxy.
Download Claude Desktop: Available at Claude.ai.
Clone this repository.
Install dependencies:
pnpm install
Configure wrangler.json
: If necessary, comment out sections related to unsupported bindings.
Deploy the worker:
pnpm deploy:worker
Generate and upload secrets:
npx workers-mcp secret generate && npx workers-mcp secret upload
Start integration by installing a server definition for Claude Desktop.
Implement functions that fetch real-time data from various sources and process it using Cloudflare Workers. For example, a worker can pull stock prices from a financial API and return parsed results back to the MCP client.
Develop custom prompts for AI models by combining text generation and data retrieval. This could be integrated into MC clients like Continue or Cursor to provide tailored content creation tools.
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ❌ | Partial Support (Tools Only) |
Cursor | ❌ | ✅ | ❌ | Tools Only |
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
graph LR
subgraph "Worker Environment"
W[Worker Entrypoint]
C1[Cloudflare API Calls]
end
subgraph "MCP Client"
P[MCP Protocol]
S[Server (Local Proxy)]
end
A[Data Source/Tool]-->B[P]
B --> S
S --> W
W --> C1
{
"mcpServers": {
"[server-name]": {
"command": "npx @modelcontextprotocol/server-[name]",
"args": ["--api-key", "your-api-key"],
"env": {
"API_KEY": "your-api-key",
"SECURE_SECRET": "your-secure-secret"
}
}
}
}
Ensure all sensitive information is securely stored and managed.
Does this work with all MCP clients?
How do I troubleshoot connection issues?
Can I add more tools without re-deploying the codebase?
What if my data sources change frequently?
How do I ensure security of my API keys?
pnpm install
.WorkerEntrypoint
class.pnpm deploy:worker
.Explore more about MCP and its ecosystem at ModelContextProtocol.org.
For further reading and detailed documentation, visit:
This comprehensive guide highlights the capabilities and integration points of the Workers MCP Server, positioning it as an essential tool for developers looking to enhance AI applications through standardized protocols.
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Python MCP client for testing servers avoid message limits and customize with API key
AI Vision MCP Server offers AI-powered visual analysis, screenshots, and report generation for MCP-compatible AI assistants
Discover easy deployment and management of MCP servers with Glutamate platform for Windows Linux Mac
Analyze search intent with MCP API for SEO insights and keyword categorization