hosted-mcp-service-runtime
Provision a backend Model Context Protocol (MCP) endpoint leveraging Cloudflare Workers architecture, secured via OAuth authentication. This infrastructure enables seamless integration of Large Language Models (LLMs) with external tooling and up-to-date information sources by serving as a robust bridge to MCP client applications.
Author

Cam10001110101
Quick Info
Actions
Tags
Deployed MCP Backend on Cloudflare Workers
This guide details setting up and operating a remote MCP server on Cloudflare Workers, featuring built-in OAuth for secure endpoint access.
Local Development Environment Setup
bash
Obtain the source code repository
git clone git@github.com:cloudflare/ai.git
Navigate to the project root and install dependencies
cd ai npm install
Start the local development server instance
npx nx dev remote-mcp-server
Access should be available locally at http://localhost:8787/.
Linking the MCP Inspector Client
To inspect the functionality of your newly deployed MCP API, utilize the official MCP Inspector.
- Launch the Inspector from your terminal:
npx @modelcontextprotocol/inspector - Within the Inspector UI (typically running at http://localhost:5173), configure the Transport Type to
SSE. - Set the MCP Server URL to
http://localhost:8787/sseand initiate the connection. - A simulated login prompt will appear; use any placeholder credentials (email/password) to proceed.
- Upon successful authentication, you will return to the Inspector, where you can now enumerate and invoke the defined tools.
Integrating with Claude Desktop Locally
While the Inspector is useful, the primary goal is connecting this backend to Claude. Consult Anthropic's Quickstart documentation for general setup. Then, in Claude Desktop, modify the configuration file located under Settings > Developer > Edit Config.
Replace the contents of that file with the following configuration block to establish a local HTTP proxy connection to your MCP server:
{ "mcpServers": { "math": { "command": "npx", "args": [ "mcp-remote", "http://localhost:8787/sse" ] } } }
Restarting Claude should trigger a browser login window. Once authenticated, the available tools will appear in the application interface, ready for prompt invocation.
Deployment to the Cloudflare Environment
- Provision the necessary Key-Value store:
npx wrangler kv namespace create OAUTH_KV - Integrate the resulting KV namespace ID into your
wrangler.jsoncconfiguration file as directed. - Execute the deployment script:
npm run deploy
Accessing the Deployed Backend from a Remote Client
Repeat the Inspector launch process as done previously:
npx @modelcontextprotocol/inspector@latest
In the Inspector interface, input the fully qualified URL of your deployed Worker (e.g., worker-name.account-name.workers.dev/sse) as the server address and connect.
You have successfully established a connection between a remote MCP client and your Cloudflare-hosted backend.
Connecting Claude Desktop to the Remote Service
Update the Claude configuration file to reference the public 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 Connection Issues
If connectivity problems arise, try restarting Claude or attempt a direct command-line connection to the local server for isolation:
bash npx mcp-remote http://localhost:8787/sse
In less frequent scenarios, purging locally cached authentication artifacts in the ~/.mcp-auth directory may resolve persistent issues:
bash rm -rf ~/.mcp-auth
