Back to KB
Difficulty
Intermediate
Read Time
9 min

Genkit 2.0 GA: Build and Deploy a TypeScript MCP Server to Cloud Run

By Codcompass Team··9 min read

Architecting Production-Ready Agent Tools: From Local MCP Discovery to Cloud Run Deployment

Current Situation Analysis

The modern AI engineering stack has a persistent gap: local agent tooling works flawlessly in isolation, but crossing the boundary into production introduces architectural friction that most teams underestimate. Developers routinely build Model Context Protocol (MCP) servers using frameworks like Genkit, verify tool discovery over stdio, and assume the application is ready for deployment. This assumption collapses when the tool must handle authenticated traffic, integrate with cloud observability, manage dependency surface area, and enforce strict authorization policies.

The problem is overlooked because local verification masks production complexity. A stdio-based MCP server requires zero network configuration, zero IAM policies, and zero container orchestration. It also hides the reality that agent-discoverable tools are fundamentally different from authenticated service endpoints. When teams attempt to lift a local MCP server directly to Cloud Run, they encounter unbounded invocation surfaces, missing trace context, unscoped secrets, and dependency vulnerabilities that only surface under load.

Data from recent sandbox validations confirms this friction. A minimal Genkit + MCP setup using genkit@1.36.0, @genkit-ai/mcp@1.36.0, and @modelcontextprotocol/sdk@1.29.0 on Node.js v25.9.0 pulls 486 total dependencies. Running npm audit --omit=dev surfaces 23 vulnerabilities, including 7 high-severity items. While these warnings do not automatically invalidate the framework, they demonstrate that AI tooling inherits the same supply-chain risks as any internet-facing Node service. Production teams cannot treat dependency review as optional. Furthermore, the official Genkit documentation explicitly separates local MCP exposure from Cloud Run deployment, requiring startFlowServer from @genkit-ai/express, IAM authorization, Secret Manager integration, and Cloud Trace configuration. The architectural shift from local discovery to production execution is not incremental; it is structural.

WOW Moment: Key Findings

The critical insight is that MCP and Cloud Run serve fundamentally different purposes in the AI application lifecycle. MCP is a discovery and integration protocol for agents. Cloud Run is a managed execution boundary for authenticated workflows. Confusing the two leads to premature exposure, uncontrolled costs, and untraceable agent behavior.

Deployment SurfaceDiscovery MechanismAuthorization ModelObservability DepthDeployment ComplexityIdeal Stage
Local MCP (stdio)Process launch, tool listingNone (process-bound)Console logs onlyMinimalDevelopment & contract validation
Remote MCP (HTTP)Endpoint registration, agent handshakeApp-level tokens or OAuthCustom logging onlyHigh (network, auth, scaling)Controlled agent ecosystems
Cloud Run FlowDirect HTTPS routingIAM + App-level policiesCloud Trace, Metrics, LoggingModerate (container, IAM, secrets)Production execution

This finding matters because it forces teams to decouple tool definition from tool exposure. You define and verify tools locally using MCP stdio. You then expose the production workflow as an authenticated Cloud Run flow endpoint. Remote MCP surfaces should only be deployed when you have a narrow client roster, explicit authorization policies, and audit trails. Treating MCP as a production API gateway is a structural anti-pattern.

Core Solution

Building a production-ready AI tool requires a phased architecture: deterministic contract definition, local MCP verification, HTTP flow transition, and platform integration. Each phase isolates a specific risk domain.

Step 1: Define a Strict, Deterministic Tool Contract

Start with a tool that has a clear business boundary and deterministic logic. Avoid model calls until t

🎉 Mid-Year Sale — Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register — Start Free Trial

7-day free trial · Cancel anytime · 30-day money-back