distributed-mcp-gateway
Establish a distributed Model Context Protocol (MCP) server instance leveraging Cloudflare Workers, secured via OAuth authentication. This component furnishes a robust conduit for linking Large Language Models (LLMs) with diverse external utilities and live datasets by offering a streamlined communication path to MCP client applications.
Author

Cam10001110101
Quick Info
Actions
Tags
Deployed MCP Backend running on Cloudflare Workers
This guide details the process for launching a remote MCP endpoint on Cloudflare Workers, incorporating OAuth for secure access controls.
Local Development Setup
# Obtain the source repository
git clone git@github.com:cloudflare/ai.git
# Navigate into the directory and install necessary packages
cd ai
npm install
# Initiate local execution for the remote server component
npx nx dev remote-mcp-server
You should find the service accessible via your web browser at http://localhost:8787/.
Integrating the MCP Inspector Client
To thoroughly examine the functionality of your newly established MCP API, utilize the MCP Inspector tool.
- Launch the inspector application from your terminal:
npx @modelcontextprotocol/inspector - Once the inspector UI loads (typically at
http://localhost:5173), configure the Transport Type toSSE. - Provide the endpoint URL for the MCP server:
http://localhost:8787/sse, and press "Connect". - You will encounter a simulated login interface. Supplying any dummy email and password credentials will suffice for authentication.
- Upon successful validation, the inspector will refresh, allowing you to list and invoke any registered tools.
Linking Claude Desktop to the Locally Hosted Server
While the inspector is useful, the primary goal is often integration with Claude. Refer to Anthropic's Quickstart documentation. Within the Claude Desktop application, navigate to Settings > Developer > Edit Config to locate and open the configuration file.
Replace the existing content of this file with the following structure:
{
"mcpServers": {
"math": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8787/sse"
]
}
}
}
This configuration establishes a local proxy mechanism enabling Claude to communicate with your MCP backend over standard HTTP.
When Claude initializes, a browser window should prompt you to authenticate. Following login, the available tools should appear in the lower-right section of the interface. Claude should subsequently invoke the appropriate tool when presented with a relevant query.
Production Deployment on Cloudflare
- Provision a new KV Namespace:
npx wrangler kv namespace create OAUTH_KV - Follow Wrangler's instructions to inject the generated KV namespace ID into your
wrangler.jsoncconfiguration file. - Initiate the deployment process:
npm run deploy
Consuming the Deployed Remote MCP Backend
Mirror the initial steps from the "Local Development Setup" section by launching the MCP Inspector:
npx @modelcontextprotocol/inspector@latest
In the inspector UI, use the publicly accessible URL of your deployed Worker (e.g., worker-name.account-name.workers.dev/sse) as the MCP Server URL and establish the connection.
You have now successfully linked a remote MCP client to your newly provisioned cloud-based MCP server.
Connecting Claude Desktop to the Remote Endpoint
Modify your Claude configuration file to reference the live workers.dev endpoint (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 Issues
If connectivity problems arise, a common first step is to terminate and relaunch Claude. Additionally, attempting a direct command-line connection to bypass potential client-side caching can be diagnostic:
npx mcp-remote http://localhost:8787/sse
In infrequent instances, clearing locally cached authentication artifacts stored in ~/.mcp-auth might resolve persistent errors:
rm -rf ~/.mcp-auth
