Building an Enterprise AI Engineering Stack with Internal Agents and MCP Infrastructure

cloudflare · Tech · 2026 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Enterprise AI engineering infrastructure

Cloudflare needed to make AI coding tools usable and governable across R&D by centralizing authentication, model routing, MCP tool access, repository context, code review, and future cloud agents on its own platform.

Constraints:

Architecture

Cloudflare built an internal AI engineering stack using Cloudflare Access, a proxy Worker, AI Gateway, Workers AI, MCP portals, AGENTS.md files, and an AI Code Reviewer. Requests authenticate through Access, route through a Worker that injects provider keys server-side and forwards to AI Gateway, while MCP servers expose internal tools through a unified portal. AGENTS.md files give coding agents repo-specific context, and a GitLab CI review coordinator delegates to specialized review agents.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  developer[Developer] --> opencode-client[OpenCode Client]
  opencode-client --> proxy-worker[Proxy Worker]
  cloudflare-access[Cloudflare Access] --> proxy-worker[Proxy Worker]
  proxy-worker --> ai-gateway[AI Gateway]
  ai-gateway --> workers-ai[Workers AI]
  cloudflare-access --> mcp-portal[MCP Portal]
  mcp-portal --> mcp-servers[MCP Servers]
  agents-md-context[AGENTS.md Context] --> ai-code-reviewer[AI Code Reviewer]
  mcp-servers --> ai-code-reviewer[AI Code Reviewer]
  ai-code-reviewer --> ai-gateway[AI Gateway]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Developer Cloudflare engineer using AI coding tools. OpenCode Client
OpenCode Client Local coding assistant client configured by discovery endpoint. Proxy Worker
Proxy Worker Central control plane for auth, config, provider routing, attribution, and permission enforcement. Cloudflare Access, AI Gateway
Cloudflare Access Zero-trust authentication and policy enforcement. Proxy Worker, MCP Portal
AI Gateway Model routing, provider keys, analytics, cost tracking, and retention policy. Proxy Worker, Workers AI
Workers AI Same-network open-source inference for lower-cost internal workloads. AI Gateway
MCP Portal Unified access to production MCP servers and internal tools. Cloudflare Access, MCP Servers
MCP Servers 13 production MCP servers exposing internal tools. MCP Portal, AI Code Reviewer
AGENTS.md Context Repository-specific high-signal instructions for coding agents. AI Code Reviewer
AI Code Reviewer GitLab CI multi-agent reviewer for quality, security, docs, performance, release impact, and Codex rules. AI Gateway, AGENTS.md Context, MCP Servers

Data flow

Developers authenticate with Cloudflare Access. OpenCode sends model requests to a proxy Worker, which validates JWTs, anonymizes user attribution, injects provider credentials, and routes through AI Gateway. Agents use MCP servers and repository AGENTS.md context; merge requests trigger a multi-agent reviewer that posts structured comments.

“Everything starts with Cloudflare Access, which handles all authentication and zero-trust policy enforcement. Once authenticated, every LLM request routes through AI Gateway.”article, stated
“When OpenCode sends a request like POST /anthropic/v1/messages, the Worker validates the Cloudflare Access JWT”article, stated

Why this architecture

Cloudflare chose a single proxy Worker and AI Gateway from day one because centralized routing created a control plane for attribution, model catalog management, permission enforcement, and no local API keys. AGENTS.md and MCP portals give agents codebase and tool context, while AI Gateway lets Cloudflare mix frontier models with Workers AI by task.

“centralizing through a Worker meant we could add per-user attribution, model catalog management, and permission enforcement later”article, stated
“The request goes to AI Gateway, which routes it to the appropriate provider. The response passes straight through with zero buffering. The apiKey field in the client config is empty because the Worker injects the real key server-side. No API keys exist on user machines.”article, stated

Models used: Kimi K2.5 · Opus 4.6 · GPT 5.4 · Workers AI open-source models · frontier models

Scale

Alternatives considered (roads not taken)

Clients connect directly to AI Gateway.

Rejected because: Direct connection would not provide the later control-plane features.

“We could have had clients connect directly to AI Gateway, which would have been simpler to set up initially. But centralizing through a Worker meant we could add per-user attribution, model catalog management, and permission enforcement later without touching any client configs.”article, stated

Agents infer repo instructions from code alone.

Rejected because: They produced plausible but wrong changes without test commands and conventions.

“in the rollout, we kept seeing the same failure mode: coding agents produced changes that looked plausible and were still wrong for the repo. Usually the problem was local context: the model didn't know the right test command, the team's current conventions, or which parts of the codebase”article, stated

Use frontier models for all workloads.

Rejected because: Workers AI handles cheaper documentation and lightweight tasks where same-network latency matters.

“Workers AI handles about 15% of the reviewer's traffic, primarily for documentation review tasks where Kimi K2.5 performs well at a fraction of the cost of frontier models.”article, stated

Patterns

model-routing (platform)

AI Gateway routes requests across frontier providers and Workers AI with cost and retention controls.

“AI Gateway analytics show how monthly usage is distributed across model providers.”article, stated

tool-use-orchestration (mcp)

MCP portals unify 13 production MCP servers and 182-plus tools under one endpoint.

“This unifies access and simplifies everything giving us one endpoint”article, stated

agent-memory (codebase-context)

AGENTS.md provides short, high-signal repository context inside the model window.

“a short, structured file in each repo that tells coding agents how the codebase actually works”article, stated

Tradeoffs

Control plane

Chose Proxy Worker plus AI Gateway over Direct client-to-provider or direct Gateway setup.

Rationale: The proxy enabled attribution, permissions, model catalog, server-side keys, and future tool expansion.

“Every feature described in the bootstrap section below exists because we had that single choke point.”article, stated

Model economics

Chose Workers AI for some tasks and frontier models for complex reviews over One model tier everywhere.

Rationale: Capability, cost, and latency differ by workload.

“reasoning capability matters most.”article, stated

Gotchas (what bit them)

Direct model access is easy but hard to govern later.

Root cause: Clients would own config, attribution, keys, and provider details.

Resolution: Centralize through a proxy Worker and AI Gateway.

“The proxy pattern gives you a control plane that direct connections don't”article, stated

Stale agent context can be worse than no context.

Root cause: Repository instructions drift when tests, conventions, or boundaries change.

Resolution: Use AI Code Reviewer to flag AGENTS.md updates when repo changes suggest drift.

“A stale AGENTS.md can be worse than no file at all.”article, stated

Evaluation

Cloudflare measures adoption, requests, token routing, merge-request velocity, reviewer traffic mix, and repository readiness through AGENTS.md coverage.

Metrics: R&D adoption · Internal users · AI requests · Tokens routed · Merge requests · MCP tools · AGENTS.md repositories

“we’ve never seen a quarter-to-quarter increase in merge requests to this degree.”article, stated

Outcomes

The source reports 3,683 internal users, 47.95M AI requests, 241.37B AI Gateway tokens, 51.83B Workers AI tokens, 13 MCP servers, 182+ tools, and ~3,900 repositories.

“From launching this effort to 93% R&D adoption took less than a year.”article, stated