Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

MCP Server Portal: OAuth, Code Mode, Gateway Routing, and Sessions

How MCP server portals unify Model Context Protocol servers behind zero-trust access, OAuth, curated tools, and observability.

This page summarizes Cloudflare documentation on MCP server portals: a single HTTP endpoint where approved Model Context Protocol (MCP) servers are combined, users authenticate through Cloudflare Access, and administrators curate which tools and prompts reach AI clients.

MCP server portal: what it is and when you need one

Section titled “MCP server portal: what it is and when you need one”

An MCP server portal centralizes multiple MCP servers onto one URL (for example https://<subdomain>.<domain>/mcp). Organizations use it when employees connect many SaaS or internal MCP servers from Claude Desktop, Windsurf, or other clients, and IT needs one governed entry point instead of scattered direct URLs.

An MCP server portal centralizes multiple Model Context Protocol (MCP) servers onto a single HTTP endpoint. Key benefits include: Streamlined access to multiple MCP servers […] Customized tools per portal […] Observability: Once the user’s AI agent is connected to the portal, Cloudflare Access logs the individual requests made using the tools in the portal.

— Cloudflare, MCP server portals (changelog)

MCP server portals are now generally available to all Cloudflare customers. The portal’s Access application logs tool, prompt, and resource activity; optional Gateway routing adds HTTP logs and DLP inspection.

Per MCP server portals, the client connects to the portal URL, gets OAuth discovery metadata on 401, the user signs in through Access (or presents a service token), the portal exposes namespaced tools from enabled upstream servers, and tool calls are proxied with the right credentials—through Gateway when routing is enabled.

Add upstream MCP servers: public, private, and OAuth types

Section titled “Add upstream MCP servers: public, private, and OAuth types”

In Zero Trust → Access controls → MCP Portals → MCP servers, add the server HTTP URL (remote Streamable HTTP endpoint, not stdio-only servers). Assign Allow policies so only intended users see the server in portals. Servers in Ready status have synchronized tools and prompts; Error, Sync Required, or Waiting need troubleshooting on the same page.

Private MCP server: reach internal hostnames without public exposure

Section titled “Private MCP server: reach internal hostnames without public exposure”

MCP server portals can connect to private-network MCP servers via Cloudflare Gateway when Route traffic through Cloudflare Gateway is on—typically after Cloudflare Tunnel, Cloudflare Mesh, or another Cloudflare One connector.

OAuth authorization server endpoints, such as the authorization and token endpoints, must be accessible on the public Internet. If Cloudflare automatically registers the OAuth client through Dynamic Client Registration (DCR), the registration endpoint must also be accessible on the public Internet.

— Cloudflare, Private MCP server support

Automatic (DCR) vs manual OAuth credentials

Section titled “Automatic (DCR) vs manual OAuth credentials”
Mode When to use User auth
Automatic (DCR) Upstream supports Dynamic Client Registration Per-user or admin credential
Manual credentials Slack, GitHub, or other providers without DCR Per-user OAuth required; server may stay Waiting until first user authorizes

Static OAuth client credentials let administrators enter client_id, encrypted client_secret, custom endpoints, scopes, and client_secret_post or client_secret_basic. Redirect URI allowlisting is described under upstream OAuth callbacks in MCP server portals.

Create an MCP portal: domain, tools, and Access policies

Section titled “Create an MCP portal: domain, tools, and Access policies”

Create the portal under MCP Portals → Add MCP server portal, choose a custom domain on your zone, attach servers, and optionally disable individual tools or use API default_disabled allowlists. Tool names exposed to clients are prefixed with {server_id}_ to avoid collisions (server IDs cannot contain underscores).

Require user auth (API: on_behalf: true) prompts each user to complete upstream OAuth. Turning it off lets the portal use the admin credential—required for service token bots.

Tool and prompt aliases rename tools and descriptions at portal or server level without changing upstream code; portal-level aliases win. Upstream renames can clear aliases on the next sync.

MCP client authentication: managed OAuth vs service tokens

Section titled “MCP client authentication: managed OAuth vs service tokens”

managed OAuth for humans and coding agents

Section titled “managed OAuth for humans and coding agents”

Cloudflare Access supports managed OAuth, which allows non-browser clients — such as CLIs, AI agents, SDKs, and scripts — to authenticate with Access-protected applications using a standard OAuth 2.0 authorization code flow.

— Cloudflare, Managed OAuth for Cloudflare Access

Clients receive 401 with WWW-Authenticate pointing at discovery endpoints (RFC 8414 and RFC 9728), open a browser for IdP login, then use an opaque oauth: access token. Access policies match browser login; managed OAuth is a transport change, not a separate auth path. New MCP server portals enable managed OAuth by default; existing self-hosted apps remain opt-in. Details: Managed OAuth and Authenticate coding agents.

Service token sessions use CF-Access-Client-Id and CF-Access-Client-Secret on the portal and on each linked MCP server Access app via Service Auth policies. Set Require user auth off (on_behalf: false) per server so the portal uses the admin credential. Servers that still require per-user OAuth are omitted from the bot’s tool list.

Method Identity Best for
Managed OAuth End user via IdP Interactive agents, CLIs with browser
Service token Machine only Cron, CI, headless automation

Comparison table from Managed OAuth vs service tokens.

MCP servers calling internal apps (Linked App Token)

Section titled “MCP servers calling internal apps (Linked App Token)”

When an MCP server must call internal APIs as the user, use Allow MCP servers to access self-hosted applications or Linked App Token: self-hosted MCP servers forward Cf-Access-Jwt-Assertion as Cf-Access-Token on downstream requests. If the client used managed OAuth, the origin must read Cf-Access-Jwt-Assertion, not forward the opaque bearer token.

Code Mode and optimize_context: reduce tool-definition tokens

Section titled “Code Mode and optimize_context: reduce tool-definition tokens”

Code Mode replaces many upstream tool definitions with one code execution path; JavaScript calling codemode.* runs in an isolated Dynamic Worker so secrets stay out of model context.

Policy API code_mode Client override
Off off Ignored
Opt-in opt_in ?codemode=search_and_execute
On by default default_on ?codemode=off avoids nested Code Mode
Enforced enforced Ignored

Admins can turn on Code Mode by default; allow_code_mode is deprecated. Do not attach upstream servers that already run their own Code Mode.

Context optimization uses optimize_context on the portal URL:

  • minimize_tools — names only plus portal_query_tools; up to 5× token savings.
  • search_and_execute — only query/execute tools; initial tool list stays small.

These interact with portal-native tools documented in MCP server portals.

Gateway routing, logs, and protocol support

Section titled “Gateway routing, logs, and protocol support”

Route portal traffic through Cloudflare Gateway

Section titled “Route portal traffic through Cloudflare Gateway”

When enabled, portal outbound calls appear in Gateway HTTP logs; standard DLP profiles can block sensitive payloads. DLP AI prompt profiles do not apply to MCP portal traffic (Gateway routing changelog). SSE-only upstream paths may fail through Gateway; prefer Streamable HTTP.

The portal /mcp endpoint accepts stateless MCP 2026-07-28 and falls back for 2025 Streamable HTTP upstreams; client and server upgrades are independent (MCP 2026-07-28 support).

Session management lets users return to a server selection page via MCP elicitation (/authorize?elicitationId=...), toggle servers (shrinking context), or reauthenticate per upstream OAuth. Managed OAuth is required for automatic prompts when admins add servers.

The portal homepage at the portal domain (not /mcp in a browser) shows the MCP URL, client setup steps, and Sign out, which revokes portal grants and upstream OAuth state.

For organizational strategy—approved portals vs shadow MCP—see MCP governance and Detect MCP traffic in Gateway logs.

  • No allowed servers available — portal and each server need Allow policies; server must be Ready (troubleshooting).
  • Redirect URI errors — wrong callback URL in upstream OAuth allowlist.
  • Service token sees few tools — missing Service Auth on server apps or Require user auth still on.
  • Admin token expired — server Error / Sync Required without admin notification; reauthenticate and sync.
  • 80 servers per portal maximum; stdio-only servers need a self-hosted HTTP wrapper.
  • API/Terraform portal creation requires a proxied CNAME to gateway.agents.cloudflare.com or the portal returns 522 (MCP server portals).
  1. Open Zero Trust → Access controls → MCP Portals, confirm each portal and linked server shows Ready and policies match the users or service tokens you expect (MCP server portals).

  2. Visit the portal homepage (portal root URL, not /mcp), copy the MCP endpoint, and connect from Workers AI Playground or your MCP client; complete Access and per-server OAuth if required.

  3. Run an initialize request with service token headers if you use bots (Connect with a service token) and confirm expected namespaced tools appear.

  4. If Gateway routing is on, inspect Gateway HTTP logs or follow Detect MCP traffic in Gateway logs; optionally query tool-call analytics with response_status=all (Filter MCP tool-call analytics).

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about so it can be corrected quickly.