Extend Cloudflare Workers with Claude MCP server integration for seamless function invocation and documentation generation
Workers MCP Server is a proof-of-concept implementation of the Model Context Protocol (MCP) in a Cloudflare Worker environment. It allows AI applications like Claude Desktop to extend their functionality by invoking custom functions written on the server side using Cloudflare's new RPC syntax. By combining TypeScript, JSDoc annotations, and Web Workers, this server provides a robust framework for integrating various data sources and tools seamlessly into AI application ecosystems.
Workers MCP Server leverages the latest advancements in cloud technology to offer several key features:
src/index.ts
file, which are then exposed as part of an MCP server for invocation by AI applications like Claude Desktop.The architecture of Workers MCP Server is designed to follow the Model Context Protocol (MCP) specifications closely. The core components include:
scripts/generate-docs.ts
parses TypeScript files with JSDoc annotations and generates an output that adheres to the MCP server tools specifications.lib/WorkerMCP.ts
, this component creates a fetch handler /rpc
that enables MCP clients like Claude Desktop to execute methods on the Worker Entrypoint.scripts/local-proxy.ts
, this file uses the @modelcontextprotocol/sdk
library to act as a local MCP server, facilitating communication with remote workers.graph TD;
A[AI Application] -->|MCP Client| B[Worker Entrypoint]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
graph LR;
subgraph "MCP Server"
B[Worker Entrypoint]
C[MCP Documentation]
B -->|Fetch Request| C
end
subgraph "Client Application"
A[MCP Client (e.g., Claude Desktop)]
end
D[Data Resource/Tool]
A --> B
B --> C
C --> D
style B fill:#f3e5f5
style D fill:#e8f5e8
To set up and run the Workers MCP Server, follow these steps:
pnpm install
wrangler.json
and comment out or adjust any sections for APIs you don't have access to, such as Email Routing (/email
) and Browser Rendering (/pages
).pnpm deploy:worker
npx workers-mcp secret generate && npx workers-mcp secret upload
To install this server in Claude Desktop, run:
npx workers-mcp install <server-alias> <worker-url>
Developers can create a Worker Entrypoint that fetches data from an external API and displays it within AI applications. For instance, you could write TypeScript functions to retrieve real-time stock prices or weather conditions, which can be queried using MCP.
// Example in src/index.ts
export async function getStockPrice(symbol: string): Promise<number> {
const response = await fetch(`https://api.example.com/stock/${symbol}`);
return parseFloat(await response.text());
}
By integrating custom functions, developers can enhance AI applications with context-specific prompts. For example, you could create a function that generates personalized job recommendations based on user input and data from various sources.
// Example in src/index.ts
export async function generateJobRecommends(profile: string): Promise<string[]> {
// Custom logic to build job recommendations based on profile
return ["Backend Developer", "Product Manager"];
}
The Workers MCP Server supports multiple MCP clients, including:
graph TB;
A[Workers MCP Server] --> B["Claude Desktop"];
C["Continue"] -->|Compatibility| D;
E["Cursor"] --> F;
style A fill:#f3e5f5
style D fill:#e8f5e8
style F fill:#e1f5fe
The performance and compatibility of the Workers MCP Server have been tested with various hardware configurations and AI applications. While it is compatible across multiple platforms, developers should monitor system requirements to ensure smooth operation.
{
"mcpServers": {
"stockServer": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/worker"],
"env": {
"STOCK_API_KEY": "your-stock-api-key"
}
}
}
}
For advanced use cases, developers can configure the Worker with environment variables and custom security settings. This includes setting up API keys for third-party services and configuring access control to ensure secure communication.
Q: How does this server enhance AI applications?
Q: Which MCP clients are compatible with this server?
Q: Can I use zod or other schema libraries for validation instead of JSDoc blocks?
Q: How do I handle authentication and security with this server?
Q: Are there plans to support additional MCP clients in the future?
Contributors are welcome to submit issues and pull requests on GitHub. To contribute:
git checkout -b feature/new-feature
.Explore the vast resources available within the Model Context Protocol (MCP) ecosystem, including official documentation, community forums, and additional implementation guides. These resources serve as valuable tools for developers looking to integrate Workers MCP Server into their AI projects.
Workers MCP Server offers a robust framework for developers building AI applications that require seamless integration with various data sources and tools. By leveraging the Model Context Protocol (MCP), this server ensures compatibility across multiple clients, enhancing functionality through custom function definitions and live documentation generation.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods