Skip to content

fix: send mcp-server-cloudflare/<server> User-Agent on every outbound Cloudflare request - #504

Merged
mattzcarey merged 2 commits into
mainfrom
fix/user-agent-all-requests
Oct 1, 2026
Merged

mattzcarey merged 2 commits into
mainfrom
fix/user-agent-all-requests

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

None of this repo's outbound requests to Cloudflare set a User-Agent, so the API couldn't tell this traffic apart. Each server now sends User-Agent: mcp-server-cloudflare/<serverId> (for example, mcp-server-cloudflare/workers-bindings), so traffic can be broken down by server.

// Each app names itself (serverId = its apps/ directory name)
const app = createAuthenticatedMcpApp<Env>({
	serverId: 'workers-bindings',
	serviceHostnames: ['bindings-staging.mcp.cloudflare.com', 'bindings.mcp.cloudflare.com'],
	// ...
})

// packages/mcp-common/src/user-agent.ts
export function cloudflareFetch(input: RequestInfo | URL, init?: RequestInit<RequestInitCfProperties>) {
	const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined))
	headers.set('User-Agent', getUserAgent()) // mcp-server-cloudflare/<serverId>
	return fetch(input, { ...init, headers })
}
  • serverId is required. The app factory passes it to setUserAgentServer() once, when the module loads. It must be lowercase kebab-case.
Path Change
Cloudflare SDK (getCloudflareClient) defaultHeaders: { 'User-Agent': getUserAgent() } replaces the SDK's own UA
fetchCloudflareApi cloudflareFetch
OAuth code exchange + refresh (dash.cloudflare.com/oauth2/token) cloudflareFetch
Identity probe (/user, /accounts) cloudflareFetch
Direct fetch in Radar, URL Scanner, GraphQL, DEX WARP diag, Blog, docs guide/prompt cloudflareFetch
  • If a caller passes its own User-Agent, cloudflareFetch replaces it.

@mattzcarey mattzcarey changed the title fix: send a User-Agent on every outbound Cloudflare request fix: send mcp-server-cloudflare/<server> User-Agent on every outbound Cloudflare request Oct 1, 2026
@mattzcarey
mattzcarey enabled auto-merge (squash) October 1, 2026 09:21
@mattzcarey
mattzcarey merged commit ab883e5 into main Oct 1, 2026
6 checks passed
@mattzcarey
mattzcarey deleted the fix/user-agent-all-requests branch October 1, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant