cloudflare-mcp-dcr-bridge

cloudflare-mcp-dcr-bridge

Enables Gemini Enterprise to connect to Cloudflare Zero Trust MCP server portals via Dynamic Client Registration (DCR) and OAuth 2.0 proxying. It proxies MCP JSON-RPC/SSE traffic with Cloudflare Access service token authentication.

Category
访问服务器

README

Cloudflare MCP Portal DCR Bridge for Gemini Enterprise

Package repository for deploying a Cloudflare MCP Portal Bridge with Dynamic Client Registration (DCR) and OAuth 2.0 proxying on Google Cloud Run, enabling Gemini Enterprise (Google Cloud AI Companions / Agent Space) to connect seamlessly to Cloudflare Zero Trust MCP Server Portals.


Architecture & Header Flow

┌───────────────────────────┐         OAuth 2.0 + DCR / MCP JSON-RPC        ┌───────────────────────────────────┐         CF Access Service Token        ┌───────────────────────────────┐
│                           │  ───────────────────────────────────────────> │  cloudflare-mcp-dcr-bridge        │  ────────────────────────────────────> │ Cloudflare Zero Trust         │
│  Gemini Enterprise App    │   Authorization: Bearer <token>               │  (Google Cloud Run Service)       │   CF-Access-Client-Id: <ID>          │ MCP Server Portal             │
│  (Data Store Remote MCP)  │   Mcp-Session-Id: <session>                   │                                   │   CF-Access-Client-Secret: <SECRET>  │ (https://<portal>/mcp)        │
│                           │  <─────────────────────────────────────────── │                                   │   Mcp-Session-Id: <session>          │                               │
└───────────────────────────┘          Streamable HTTP / SSE                └───────────────────────────────────┘  <──────────────────────────────────── └───────────────────────────────┘
                                                                                                                                                                       │
                                                                                                                                                                       ▼
                                                                                                                                                        ┌───────────────────────────────┐
                                                                                                                                                        │ Upstream MCP Servers          │
                                                                                                                                                        │ (GitHub, Jira, Custom APIs)   │
                                                                                                                                                        └───────────────────────────────┘

Detailed Protocol & Header Specifications

1. Request Headers Forwarded to Cloudflare MCP Portal

When proxying /mcp requests, the bridge filters out hop-by-hop headers (Host, Connection, Transfer-Encoding, etc.) and forwards:

  • CF-Access-Client-Id: Injected from CF_ACCESS_CLIENT_ID env var.
  • CF-Access-Client-Secret: Injected from CF_ACCESS_CLIENT_SECRET env var.
  • Mcp-Session-Id / mcp-session-id: Forwarded if present for session continuity.
  • Accept: Set to application/json, text/event-stream to support both JSON-RPC and SSE streaming.
  • Content-Type: Defaults to application/json.
  • User-Agent & custom x-* / mcp-* headers: Preserved.

2. Response Headers Returned to Gemini Enterprise

  • Content-Type: Preserves original content type (e.g., application/json or text/event-stream).
  • Mcp-Session-Id: Preserved and exposed for client session tracking.
  • WWW-Authenticate: Preserved for 401 challenges.
  • CORS Expose-Headers: Configured for Mcp-Session-Id, mcp-version, CF-Access-Client-Id, CF-Access-Client-Secret, Authorization, and WWW-Authenticate.

3. Real-Time Streaming Support

The /mcp proxy uses httpx async stream generators and FastAPI StreamingResponse to deliver SSE event streams and chunked JSON-RPC responses in real-time without buffering.

4. OAuth 2.0 & DCR Compliance

  • Supports client_secret_post (JSON/form parameters) and client_secret_basic (Authorization: Basic <base64> header).
  • Guarantees refresh_token, expires_in, and token_type: "Bearer" in response JSON.
  • Provides /.well-known/oauth-authorization-server and /.well-known/mcp-configuration discovery metadata.

Target GCP Specifications

  • GCP Project: {YOUR_GCP_PROJECT_ID} (Configurable via GCP_PROJECT_ID env var)
  • Cloud Run Service: cloudflare-mcp-dcr-bridge (Region: us-central1)

Prerequisites

  1. Google Cloud SDK (gcloud CLI) installed and authenticated:

    gcloud auth login
    gcloud config set project <YOUR_PROJECT_ID>
    
  2. Cloudflare Zero Trust MCP Portal setup:

    • Navigate to Cloudflare Dashboard -> Zero Trust -> Access controls -> AI controls -> MCP Portals.
    • Copy your MCP Portal URL (e.g., https://<portal-name>.<team-domain>.cloudflareaccess.com/mcp or custom domain).
  3. Cloudflare Access Service Token (for machine-to-machine authentication):

    • Go to Zero Trust -> Access -> Service Tokens.
    • Click Add a Service Token, name it gemini-enterprise-mcp-bridge, and copy the Client ID and Client Secret.
    • Ensure a Service Auth policy is added to both the MCP Portal Access App and all downstream linked MCP servers.

Environment Setup (.env)

Copy .env.example to .env and fill in your GCP Project ID, Cloudflare MCP Portal URL, and Cloudflare Access Service Token credentials:

cp .env.example .env

.env configuration example:

# GCP Configuration
GCP_PROJECT_ID=my-gcp-project-id
GCP_REGION=us-central1
SERVICE_NAME=cloudflare-mcp-dcr-bridge

# Cloudflare MCP Portal Configuration
CLOUDFLARE_MCP_PORTAL_URL=https://my-portal.my-team.cloudflareaccess.com/mcp

# Cloudflare Access Service Token (Machine-to-Machine Auth)
CF_ACCESS_CLIENT_ID=1234567890abcdef.access
CF_ACCESS_CLIENT_SECRET=abcdef1234567890abcdef1234567890abcdef1234567890

# Optional Bridge Secret for DCR Token Validation
BRIDGE_SECRET=cloudflare-mcp-dcr-secret

Quick Deployment Command

chmod +x deploy.sh
./deploy.sh

or deploy directly via gcloud:

gcloud builds submit --tag us-central1-docker.pkg.dev/{YOUR_GCP_PROJECT_ID}/cloud-run-source-deploy/cloudflare-mcp-dcr-bridge:latest
gcloud run deploy cloudflare-mcp-dcr-bridge \
  --image us-central1-docker.pkg.dev/{YOUR_GCP_PROJECT_ID}/cloud-run-source-deploy/cloudflare-mcp-dcr-bridge:latest \
  --region us-central1 \
  --project {YOUR_GCP_PROJECT_ID} \
  --allow-unauthenticated \
  --set-env-vars "CLOUDFLARE_MCP_PORTAL_URL=https://my-portal.my-team.cloudflareaccess.com/mcp,CF_ACCESS_CLIENT_ID={CLIENT_ID},CF_ACCESS_CLIENT_SECRET={CLIENT_SECRET}"

Endpoints Provided

Endpoint Method Description
/.well-known/oauth-authorization-server GET OAuth 2.0 Authorization Server Metadata (RFC 8414)
/.well-known/mcp-configuration GET Remote MCP Server discovery metadata
/register POST Dynamic Client Registration (DCR, RFC 7591)
/authorize GET OAuth 2.0 Authorization Proxy for Gemini Enterprise
/token POST OAuth 2.0 Token Exchange for Gemini Enterprise (supports Basic & POST auth)
/mcp POST / GET / OPTIONS Streamable HTTP/SSE MCP Proxy (adds Cloudflare Access Headers & streams responses)
/health GET Service Health & Target Portal Status Check

How to Register / Generate Client ID for Gemini Enterprise

Option A: Automatically via Gemini Enterprise DCR

When configuring the Extension / Data Store in Gemini Enterprise, enter the Registration URL (https://{YOUR_CLOUD_RUN_SERVICE_URL}/register). Gemini Enterprise will automatically execute /register and populate the Client ID and Secret fields behind the scenes!

Option B: Via curl Command in Terminal (Manual)

Run this request to retrieve or generate a Client ID and Secret directly:

curl -X POST https://{YOUR_CLOUD_RUN_SERVICE_URL}/register \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "Gemini Enterprise App",
    "redirect_uris": ["https://cloudaicompanions.google.com/oauth/callback"]
  }'

JSON Output Example:

{
  "client_id": "cf-dcr-a1b2c3d4e5f67890",
  "client_secret": "cloudflare-mcp-dcr-secret-0123456789abcdef",
  "client_name": "Gemini Enterprise App",
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "scope": "mcp:read offline_access"
}

Connecting to Gemini Enterprise

  1. Open Google Cloud Console -> Gemini Enterprise (or Agent Space / Discovery Engine).
  2. Go to Connected data stores -> + New data store -> Add MCP server and enter these parameters:
Setting Field Value to Enter
MCP Server URL https://{YOUR_CLOUD_RUN_SERVICE_URL}/mcp
Authorization URL https://{YOUR_CLOUD_RUN_SERVICE_URL}/authorize
Token URL https://{YOUR_CLOUD_RUN_SERVICE_URL}/token
Registration URL (DCR) https://{YOUR_CLOUD_RUN_SERVICE_URL}/register
Client ID cf-dcr-... (or auto-generated via DCR)
Client Secret cloudflare-mcp-dcr-secret-... (or auto-generated via DCR)
Scopes offline_access
Enable PKCE Support CHECK / ENABLE ✅
Use HTTP Basic Authentication UNCHECK / DISABLE ❌ (or ENABLE if using client_secret_basic)
  1. After saving the Connected data store, click Actions and select Reload custom actions.
  2. Gemini Enterprise can now invoke tools provided by your Cloudflare MCP Server Portal!

License

MIT License.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选