Skip to content

1.2 Wrapping Enterprise Systems as MCP Tool Servers

In 1.1 Two Teams, Two Agents, the CX orchestrator handed Camila Rocha's order support request over to the AI CoE's Order Ops Specialist (order-ops-specialist). Now the specialist needs real facts—the details and shipping status of order ORD-2026-4102, Camila's customer profile and loyalty tier, and whether the order is still eligible for a refund under Garimpo's return policy.

In a quick laptop prototype, a developer would write those functions—get_order(), get_customer(), and check_refund_eligibility()—directly inside the agent's codebase. In an enterprise, that shortcut quickly becomes a bottleneck: backend teams can't update a database query without forcing the AI team to redeploy their agent, other departments can't reuse the connectors, and the agent container accumulates broad credentials to every core system in the company.

This section explains how Esmeralda wraps enterprise systems as standalone Model Context Protocol (MCP) microservices on private Cloud Run (esm-<env>-mcps-<sfx>), how their schemas (tools.json) register in the central Agent Registry, and how developers can still run the entire stack on a laptop with a single uv run esmeralda query command.


1. Turning Legacy Backends into Governed Building Blocks

What is MCP (and FastMCP)?

The Model Context Protocol (MCP) is an open standard that acts like a universal USB-C port for AI tools. Any MCP server can advertise the tools it offers (tools/list) and execute them (tools/call) over standard HTTP/JSON-RPC; FastMCP is the lightweight Python framework Esmeralda uses to build those servers in a few dozen lines of code.

How Garimpo's Order Support Uses Five MCP Servers

When support-assistant and order-ops-specialist handle Camila Rocha's order question, they call five decoupled FastMCP microservices owned by the Backend / AppDev Tools track:

MCP Microservice Store System It Wraps (synthetic data) Internal Endpoint Operations Declared in tools.json
knowledge-base (apps/services/knowledge-base/) Store policy documents https://knowledge-base.esmeralda.internal/mcp search_policies, get_policy
orders (apps/services/orders/) Order management and shipping https://orders.esmeralda.internal/mcp get_order, list_customer_orders, get_shipment_status
customers (apps/services/customers/) Customer accounts (validates delegated X-User-Token headers) https://customers.esmeralda.internal/mcp get_customer, lookup_customer_by_email
refunds (apps/services/refunds/) Refunds (sensitive write actions with approval thresholds) https://refunds.esmeralda.internal/mcp check_refund_eligibility, initiate_refund
notifications (apps/services/notifications/) Customer notifications and support notes (in-memory audit trail) https://notifications.esmeralda.internal/mcp send_customer_update, create_support_ticket_note, list_notifications

The sample MCP servers are routed through the Envoy gateway adapter on Cloud Run.

Every tool call from the specialist travels out through the Central Agent Gateway (which checks that the target URL is registered in the Agent Registry) and arrives through the private entry point (*.esmeralda.internal), which routes the request directly to the Cloud Run service:

flowchart TD
    subgraph Clients["Authorized Callers"]
        A2AAgent["order-ops-specialist<br/>(AI CoE Agents Project)"]
        TestVM["Verification Test VM (test-vm-#60;env#62;)"]
    end

    AGW["Central Agent Gateway<br/>(Agent Registry allowlist + iap.egressor)"]

    subgraph Gateway["Gateway Project"]
        ILB["Entry Point Internal HTTPS LB (direct)<br/>*.esmeralda.internal<br/>serverless NEG per MCP service"]
    end

    subgraph Tools["esm-#60;env#62;-mcps-#60;sfx#62; (Private Cloud Run)"]
        Orders["orders (port 8080)<br/>• get_order<br/>• get_shipment_status"]
        Customers["customers (port 8080)<br/>• get_customer<br/>• lookup_customer_by_email"]
        Refunds["refunds (port 8080)<br/>• check_refund_eligibility<br/>• initiate_refund"]
        Notify["notifications (port 8080)<br/>• send_customer_update<br/>• create_support_ticket_note"]
    end

    subgraph Catalog["Governance Project"]
        Registry["Agent Registry<br/>(MCP server entries, TOOL_SPEC)"]
    end

    A2AAgent -->|"1. https://#60;svc#62;.esmeralda.internal/mcp + ID token"| AGW
    AGW -->|"2. PSC network attachment (Authorization unchanged)"| ILB
    TestVM -->|1. Direct inside Shared VPC| ILB
    ILB -->|"3. Routes by Host; Cloud Run IAM checks caller's ID token"| Orders & Customers & Refunds & Notify
    Registry -.->|checked by| AGW

2. Why We Designed It This Way: Key Decisions & Trade-offs

Decision Why We Made It What We Avoided
ADR-04.2: Standalone Cloud Run MCP Servers vs. Embedded Python Functions Lets backend teams build, patch, and scale connectors in any language (Python FastMCP, Go, TypeScript) on their own release schedule, scaling to zero when idle. Redeploying and re-running LLM-as-judge evaluations on the AI agent every time a backend API changes; duplicating connector code across teams.
Per-Tool IAM Invoker Lists Driven by catalog (env.yaml) Grants roles/run.invoker on each Cloud Run service only to the specific callers listed in env.yaml, and registers each tool's exact URL and tools.json schema in the Agent Registry. Broad project-wide permissions where every agent can invoke every corporate tool by default.
End-to-End Caller Identity with Custom Audiences (direct Backend) Configures each Cloud Run service to accept Google OIDC ID tokens minted for https://<name>.esmeralda.internal, passed through unchanged by both the Agent Gateway and the entry point. Mandatory token-swapping reverse proxies that obscure which agent actually called the tool.
Auto-Started Local MCP Subprocesses (esmeralda query) The esmeralda CLI reads the agent's config and launches local FastMCP servers over stdio/HTTP automatically when running on a laptop. Requiring developers to deploy to GCP or maintain complex docker-compose files just to test a prompt change.

Clear Team Boundaries

Engineering Persona Role & Daily Responsibilities What They Own What They NEVER Touch
Backend / Tools Engineer Wrapping enterprise APIs in FastMCP, maintaining tool schemas (tools.json), and writing unit tests. apps/services/<tool>/ (Python/FastMCP code, Dockerfile, tools.json). Terraform infrastructure, Shared VPC subnets, or KMS keyrings.
SecOps / Platform Engineer Governing tool authentication (roles/run.invoker), private ingress, Agent Registry entries, and roles/iap.egressor grants. infrastructure/modules/5-workloads/services/<tool>/, Cloud Run IAM policies, and catalog callers in env.yaml. Tool Python business logic or agent prompts.
AI Reasoning Engineer (AI CoE Team) Discovering and invoking MCP tools from the specialist agent. MCP URLs in agent.yaml (ORDERS_MCP_URL, CUSTOMERS_MCP_URL, REFUNDS_MCP_URL, NOTIFICATIONS_MCP_URL) and ADK toolsets in agent/tools.py. Tool container hosting or backend system credentials.

3. How It Works & CLI in Practice

Cloud Run Service Contract (modules/5-workloads/services/<tool>/)

Each MCP microservice is built via Cloud Build into the shared Layer 0 Artifact Registry (uv run esmeralda build services or uv run esmeralda build <image>, e.g. customers; shortcut make build-services) and deployed by immutable digest (uv run esmeralda deploy services/<name> --env <env>; shortcut make deploy-services ENV=<env> for all of them):

  • Internal-Only Ingress: INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER ensures the Cloud Run service cannot be reached from the public internet; all traffic arrives through the private entry point (*.esmeralda.internal).
  • Cross-Project Serverless NEG (direct Backend): With the default direct backend, Terraform creates a serverless Network Endpoint Group (NEG) and a regional backend service inside the MCPs project (since a serverless NEG must reside in the same project as its Cloud Run service) and attaches it cross-project to the entry point's URL map in the gateway project. See 1.3 Entry Point → The direct Backend.
  • Direct VPC Egress: Sets vpc_access { egress = "ALL_TRAFFIC" } on the Shared VPC core subnet (sb-esmeralda-core-<env>) so the tool can reach private enterprise databases or internal APIs.
  • Custom OIDC Audiences & Envoy Passthrough: Each service registers https://<name>.esmeralda.internal (plus legacy *.internal.gateway names) as a custom audience alongside its default run.app URI. Callers mint an ID token for https://<name>.esmeralda.internal, whether the host is routed via direct or the optional Envoy adapter. On MCP routes, Envoy forwards the caller's own ID token unchanged (so Cloud Run IAM and CallerGuard still verify the real caller and Envoy needs no roles/run.invoker on the MCP service) while emitting esmeralda.usage gateway records and local rate limiting without requiring Apigee. Today Envoy runs on Cloud Run; the same pattern is portable to GKE sidecars in the future.
  • Least-Privilege IAM & End-to-End Identity: Only identities listed in invoker_service_accounts—derived automatically from the service's callers list in the catalog—receive roles/run.invoker; an agent caller is listed as its Agent Identity principal (principal://…/reasoningEngines/<ENGINE_ID>). At runtime, the specialist mints an unbound ID token as its own Agent Identity (see Outbound tokens and the Agent Gateway), which traverses the Agent Gateway and entry point untouched.

Note

The Cloud Run service modules currently run under the MCPs project's default compute service account. Layer 3 provisions a dedicated sa-esmeralda-mcps-<env> account ready for attachment when backend-specific IAM roles are added.


Registering Tools in the Central Agent Registry

What the Agent Registry Does: The Central Agent Registry in the governance project (esm-<env>-governance-<sfx>) is the organization's authoritative catalog of approved MCP servers and A2A agents. The Central Agent Gateway treats it as a deny-by-default allowlist: an agent can only egress to a hostname registered there with an exact URL match (see 2.1 Central Agent Gateway §3.3).

Deploy-Time Registration in Terraform: Each MCP service module registers its https://<svc>.esmeralda.internal/mcp endpoint and its apps/services/<tool>/tools.json schema in the governance project at deploy time:

resource "google_agent_registry_service" "governance_mcp" {
  project    = var.governance_project_id
  service_id = "customers"
  interfaces {
    url              = "https://${var.internal_hostname}/mcp"   # e.g. https://customers.esmeralda.internal/mcp
    protocol_binding = "JSONRPC"
  }
  mcp_server_spec {
    type    = "TOOL_SPEC"
    content = file(var.tools_spec_path)   # apps/services/<tool>/tools.json
  }
}

Once the registry entries exist, the iap-egress unit (uv run esmeralda deploy iap-egress --env <env>, or make deploy-iap-egress) grants roles/iap.egressor on those entries to the authorized agent principal sets.

(For local convenience, each module also invokes apps/services/register_mcp.py, which writes the Cloud Run URL into a local, gitignored apps/services/mcp_registry.json file without calling any external API.)


Running & Verifying MCP Tools in Practice

1. Local Full-Stack Execution (uv run esmeralda query --local-mcp)

Developers never need a cloud deployment just to test tool interactions. With --local-mcp, esmeralda query starts the local FastMCP tool servers the agent's agent.yaml local_env points at (knowledge-base on port 8011, orders on 8012, customers on 8013, refunds on 8014, notifications on 8015, bound to 127.0.0.1), waits until they answer /health, runs the agent in-process against them, and stops them afterwards (also on Ctrl+C). Servers already running on those ports are reused and left running:

# Run the specialist locally against local FastMCP servers
uv run esmeralda query --agent-dir apps/agents/order-ops-specialist --local-mcp \
  "What is the status of order ORD-2026-4102, and is it eligible for a refund?"

# Or run the full CX orchestrator -> AI CoE specialist -> MCP chain locally
uv run esmeralda query --agent-dir apps/agents/support-assistant --local-mcp \
  "What is the status of order ORD-2026-4102?"

# Plan or apply an individual MCP service in GCP
uv run esmeralda plan layer-5-workloads/services/customers --env dev
uv run esmeralda apply layer-5-workloads/services/customers --env dev

# Probe all deployed MCP routes and agents in dev
uv run esmeralda verify --env dev

2. Manual JSON-RPC Probe from the Private Test VM

To inspect raw FastMCP JSON-RPC responses over the Shared VPC entry point (copy the internal Root CA to the VM first, as shown in 1.3 Entry Point → Verification and Runbook):

CX_PROJ="$(uv run esmeralda status --env dev --unit layer-1-projects --output cx_agents_project_id)"
gcloud compute ssh test-vm-dev --zone=us-central1-f --project=$CX_PROJ --tunnel-through-iap

# Inside the VM: call the orders MCP server through the entry point via FastMCP JSON-RPC
HOST=orders.esmeralda.internal
TOKEN=$(curl -s -H "Metadata-Flavor: Google" \
  "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience=https://${HOST}")

curl -s --cacert /tmp/root-ca.pem -X POST https://${HOST}/mcp \
    -H "Authorization: Bearer ${TOKEN}" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "get_order", "arguments": {"order_id": "ORD-2026-4102"}}, "id": 1}' | jq .

To run the automated MCP initialize probe for one host only (from the same test VM, with the same TLS checks), use uv run esmeralda verify --env dev --probe orders.


Now that we have met the two agents (1.1) and the five MCP tool servers (1.2), how do friendly hostnames like order-ops-specialist.esmeralda.internal and customers.esmeralda.internal actually route to the right backend without extra proxy VMs? Turn to 1.3 The Private Front Door & Pluggable Gateways.