Deploy and connect remote MCP servers on Cloudflare Workers with OAuth using easy setup and integration
Remote MCP (Model Context Protocol) Server on Cloudflare is a powerful tool designed to enable seamless integration between various AI applications and specific data sources or tools through the standardized Model Context Protocol. By leveraging this server, developers can create flexible and robust workflows that enhance the capabilities of AI applications such as Claude Desktop, Continue, Cursor, and many others.
This remote MCP server stands out with its comprehensive set of features that include OAuth login for secure access, support for various transport types (e.g., SSE), real-time communication via WebSocket events, and easy deployment. The core architecture is built to ensure compatibility across a wide range of MCP clients, while offering advanced functionalities like data security, seamless tool invocation, and efficient performance.
The implementation of the Remote MCP Server involves deploying it on Cloudflare Workers, which provides a cloud-based infrastructure for running JavaScript code at scale. This setup ensures low latency, high availability, and easy maintenance. The server supports OAuth 2.0 authentication, enabling secure interactions with external services and applications. Additionally, the use of Server-Sent Events (SSE) facilitates real-time data streaming between the client and server.
The Remote MCP Server is architected to adhere strictly to the Model Context Protocol standards. The architecture consists of three primary components: the MCP Server itself, which handles incoming requests; the Data Sources/Tools that provide specific functionalities; and the Client(s) such as AI applications like Claude Desktop, Continue, Cursor, etc., that connect to these servers.
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
A[User] -->|Request Token| B["Authorized Redirect URI"]
B --> C[OAuth Provider]
C -->|Send Access Token| D[MCP Server - POST /auth/login]
D --> E[Return JWT Token]
Getting started with the Remote MCP Server involves several steps, from local development to deployment on Cloudflare. These instructions are designed to help you set up and run the server seamlessly.
git clone [email protected]:cloudflare/ai.git
cd ai
npm install
npx nx dev remote-mcp-server
Running this command will start a local instance of the Remote MCP Server, accessible via http://localhost:8787/
.
The Remote MCP Server is ideal for developers looking to integrate various tools and data sources into their AI workflows. Here are two real-world use cases showcasing its potential:
In a financial analysis context, the server can be used to connect custom data analysis tools with third-party APIs like stock market data feeds. For instance, users can input API credentials and have the server fetch live stock prices for specific companies.
import requests
def fetch_stock_prices(tickers):
url = "https://api.marketstack.com/v1/eod?" + \
f"access_key={API_KEY}&symbols={'+'.join(tickers)}"
response = requests.get(url)
return response.json()
In an image processing pipeline, the server can orchestrate various tools like resizing images and applying filters. For example, a developer might request the server to process multiple images with different filter settings.
import {createClient} from 'mcp-remote';
const client = createClient({url: "http://localhost:8787/sse"});
async function processImages(images) {
for (let image of images) {
await client.sendAction('resize', {width: 1024, height: 768}, image);
let filteredImage = await client.sendAction('applyFilter', {type: 'blur', strength: 3}, image);
console.log(filteredImage);
}
}
This section provides detailed instructions on how to integrate the Remote MCP Server with various MCP clients, such as Claude Desktop and Continue.
To use the server's capabilities within Claude Desktop, follow these steps:
npx @modelcontextprotocol/inspector@latest
SSE
and enter the URL of your Remote MCP Server:
http://localhost:8787/sse (for local development)
https://worker-name.account-name.workers.dev/sse (for production deployment)
The process for other clients is similar, involving the same steps of specifying the server's URL and transport type. Ensure that your configuration file points to the correct endpoint based on whether it’s local or remote.
The Remote MCP Server has been rigorously tested for compatibility with various MCP clients. The following table provides a summary of compatibility:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
To ensure optimal performance and security, the Remote MCP Server offers advanced configuration options. These include setting up environments securely via wrangler
, managing client access through OAuth tokens, and configuring the server to handle large amounts of data efficiently.
{
"type": "http",
"name": "ai-server",
"envoyConfigInline": {
"route": [
{ "match": [{"path": "/auth/login"}], "then": [{ "setResponseHeader": {"key": "Content-Type", "value": "application/json"}}] }
]
},
"cacheTtl": 604800,
"allowedHttpMethods": ["GET", "POST"]
}
It is recommended to use secure connections (HTTPS), enforce strong authentication mechanisms, and regularly review access logs for any suspicious activities.
A1: Yes, the server can be configured to support a wide range of MCP clients. Refer to the integration documentation for specific client configurations.
A2: The server implements OAuth 2.0 standards to ensure secure token issuance and management, protecting sensitive credentials.
A3: Review log files for any errors or warnings related to network connectivity or token validation. Clearing your local .mcp-auth
directory might also help resolve intermittent issues.
A4: Absolutely, you can add support for additional tools and data sources by integrating them into the server's API and ensuring they comply with the Model Context Protocol standards.
A5: Yes, while Cloudflare Workers provides convenient deployment options, the remote MCP server architecture is modular. You can deploy it on other cloud platforms like AWS or Google Cloud with minimal changes to the codebase.
Contributions to this project are encouraged and welcomed by the community. If you’re a developer looking to get involved:
Explore further resources provided by the Model Context Protocol ecosystem, including official documentation and community forums where you can learn more about advanced integrations and best practices.
By following these guidelines, developers can harness the power of this remote MCP server to build robust AI applications that leverage a wide range of tools and data sources.
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
AI Vision MCP Server offers AI-powered visual analysis, screenshots, and report generation for MCP-compatible AI assistants
Learn how to use MCProto Ruby gem to create and chain MCP servers for custom solutions
Analyze search intent with MCP API for SEO insights and keyword categorization
Connects n8n workflows to MCP servers for AI tool integration and data access
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication