distributed-mcp-host
Establish a remote Model Context Protocol (MCP) endpoint hosted on Cloudflare Workers, featuring secure OAuth authentication. This setup facilitates safeguarded HTTP access to a suite of resources and tools, enabling interaction via the MCP Inspector for both local and remote clients.
Author

Omarzipan
Quick Info
Actions
Tags
Deployable MCP Backend on Cloudflare Workers
Let's initiate a distributed MCP server instance using Cloudflare Workers, incorporating robust OAuth credential verification!
Local Development Setup
# Obtain the source repository
git clone git@github.com:cloudflare/ai.git
# Navigate and install prerequisites
cd ai
npm install
# Initiate local development server
npx nx dev remote-mcp-server
You should now be able to access the service at http://localhost:8787/ via a web browser.
Integrating the MCP Inspector Client
To visually examine your newly established MCP interface, utilize the MCP Inspector.
- Launch it using the command:
npx @modelcontextprotocol/inspector - Within the Inspector interface (typically accessible at http://localhost:5173), configure the Transport Type to
SSEand inputhttp://localhost:8787/sseas the target URL for the MCP service, then activate "Connect". - A simulated authentication prompt will appear. Enter arbitrary credentials (email/password) to proceed.
- Upon successful authentication, you will return to the Inspector, ready to enumerate and invoke any registered functionalities!
Linking Claude Desktop to Your On-Premises MCP Instance
While the Inspector is useful, the primary goal is integration with Claude. Adhere to Anthropic's Quickstart Guide. In the Claude Desktop application, navigate to Settings > Developer > Edit Config to locate and open your configuration manifest.
Modify the file content to incorporate the following JSON structure:
{
"mcpServers": {
"math": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8787/sse"
]
}
}
}
This configuration establishes a localized intermediary proxy, enabling Claude to communicate with your MCP backend over HTTP.
When Claude initializes, a browser window should prompt you for login. Subsequently, the available tools will appear in the bottom-right panel. Given an appropriate user input, Claude should request invocation of the specified tool.
Production Deployment on Cloudflare
- Provision the required key-value store:
npx wrangler kv namespace create OAUTH_KV - Update
wrangler.jsoncto reference the generated KV namespace ID as instructed. - Execute the deployment routine:
npm run deploy
Accessing Your Deployed Remote MCP Service from Another Client
Repeat the procedure used in the "Local Development Setup" section for the MCP Inspector:
npx @modelcontextprotocol/inspector@latest
Then, in the Inspector, substitute the URL of the Worker (e.g., worker-name.account-name.workers.dev/sse) as the MCP server endpoint and initiate the connection.
You have successfully linked a distant MCP client to your newly deployed service.
Connecting Claude Desktop to the Hosted MCP Endpoint
Update the configuration file used for Claude Desktop to point to your deployed workers.dev address (e.g., worker-name.account-name.workers.dev/sse) and restart the Claude application:
{
"mcpServers": {
"math": {
"command": "npx",
"args": [
"mcp-remote",
"https://worker-name.account-name.workers.dev/sse"
]
}
}
}
Troubleshooting
If operational issues arise, an initial step is to terminate and relaunch Claude. Alternatively, direct command-line verification against the local server is recommended:
npx mcp-remote http://localhost:8787/sse
In seldom instances, purging the cached authentication artifacts located in ~/.mcp-auth might resolve connectivity problems:
rm -rf ~/.mcp-auth
