njdancer/remote-mcp-server-authless
If you are the rightful owner of remote-mcp-server-authless and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This document provides a comprehensive overview of setting up a remote Model Context Protocol (MCP) server on Cloudflare without authentication.
Building a Remote MCP Server on Cloudflare with OAuth
This example allows you to deploy a remote MCP server with OAuth 2.0 authentication on Cloudflare Workers.
Get started:
This will deploy your MCP server to a URL like: remote-mcp-server-authless.<your-account>.workers.dev/sse
Alternatively, you can use the command line below to get the remote MCP Server created on your local machine:
npm create cloudflare@latest -- my-mcp-server --template=cloudflare/ai/demos/remote-mcp-authless
Authentication
This MCP server uses OAuth 2.0 Authorization Code Flow for secure authentication.
Test Credentials
- Username:
admin - Password:
test123
OAuth Endpoints
- Authorization Endpoint:
https://your-worker.workers.dev/oauth/authorize - Token Endpoint:
https://your-worker.workers.dev/oauth/token - Metadata Endpoint:
https://your-worker.workers.dev/.well-known/oauth-authorization-server
How OAuth Flow Works
- Client initiates authorization by redirecting to
/oauth/authorizewithclient_id,redirect_uri, andresponse_type=code - User sees a login page and enters credentials
- On successful login, user is redirected back with an authorization code
- Client exchanges the authorization code for an access token at
/oauth/token - Client uses the access token in the
Authorization: Bearer <token>header for all MCP requests
Customizing your MCP Server
To add your own tools to the MCP server, define each tool inside the init() method of src/index.ts using this.server.tool(...).
Connecting to the OAuth-Protected MCP Server
Using OAuth with MCP Clients
To connect to this OAuth-protected MCP server, your client needs to:
- Implement OAuth 2.0 Authorization Code Flow
- Store and use the access token in the
Authorization: Bearer <token>header
Example: Manual OAuth Flow
You can test the OAuth flow manually:
-
Get an authorization code:
https://your-worker.workers.dev/oauth/authorize?client_id=test-client&redirect_uri=http://localhost:3000/callback&response_type=code- Login with
admin/test123 - You'll be redirected with a code parameter
- Login with
-
Exchange code for access token:
curl -X POST https://your-worker.workers.dev/oauth/token \ -d "grant_type=authorization_code" \ -d "code=YOUR_CODE_HERE" \ -d "redirect_uri=http://localhost:3000/callback" \ -d "client_id=test-client" -
Use the access token:
curl https://your-worker.workers.dev/sse \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN_HERE"
Connect Claude Desktop to your MCP server
Note: Standard MCP clients like mcp-remote don't currently support OAuth out of the box. You'll need to either:
- Use a custom OAuth-aware MCP client that handles the OAuth flow
- Pre-authenticate and inject the token into the client configuration
- Build a proxy that handles OAuth and forwards authenticated requests
For development/testing with Claude Desktop, you may need to temporarily disable auth or use a tool that handles OAuth for you.
Connect to Cloudflare AI Playground
The Cloudflare AI Playground may require OAuth configuration. Check their documentation for OAuth integration:
- Go to https://playground.ai.cloudflare.com/
- Configure OAuth settings with your authorization and token endpoints
- Enter your deployed MCP server URL (
remote-mcp-server-authless.<your-account>.workers.dev/sse)
Security Notes
⚠️ Important: This implementation uses:
- Hardcoded credentials for testing (
admin/test123) - In-memory storage for codes and tokens (lost on worker restart)
- A static secret key for JWT signing
For production use, you should:
- Move credentials to environment variables or Cloudflare Secrets
- Use Cloudflare KV or Durable Objects for persistent token storage
- Use a secure, randomly generated secret key from environment variables
- Implement proper client registration and client secrets
- Add rate limiting and brute force protection
- Consider using refresh tokens for long-lived access