Request flow

From MCP client to Google API and back.

Overview

graph TB
    subgraph Client
        CC[Claude Code / MCP Client]
    end

    subgraph "MCP Server"
        subgraph Transport
            STDIO[Stdio Transport]
            HTTP[HTTP Transport - POST /mcp]
            SSE[SSE Stream - GET /mcp]
        end

        PROTO[Protocol Layer - JSON-RPC 2.0]
        META[Metadata - _meta and Trace Context]
        DISPATCH[Request Dispatch]

        subgraph "Tool Execution"
            POLICY[Policy Engine]
            HELPERS[Helper Dispatch]
            EXEC[Execute - URL building and API calls]
            TASKS[Task Manager]
        end

        subgraph Discovery
            CACHE[Discovery Cache]
            TOOLS[Tool Builder]
        end
    end

    subgraph "Google Workspace"
        GAPI[Google APIs]
        DISC[Discovery Service]
    end

    CC -->|stdio or HTTP| Transport
    Transport --> PROTO
    PROTO --> META
    META --> DISPATCH
    DISPATCH --> POLICY
    POLICY --> HELPERS
    HELPERS --> EXEC
    EXEC --> GAPI
    DISPATCH --> TASKS
    DISPATCH --> TOOLS
    TOOLS --> CACHE
    CACHE --> DISC

How a request flows

  1. Transport -- The client sends a JSON-RPC message over stdio or HTTP
  2. Protocol -- The message is parsed, validated, and assigned an error code category
  3. Metadata -- _meta is extracted for protocol version, client info, and W3C Trace Context
  4. Dispatch -- The method is routed to the appropriate handler (tools/call, tasks/get, etc.)
  5. Policy -- The policy engine checks service allow-list, method denylist, parameter constraints, and read-only mode
  6. Helper dispatch -- Services with helpers (Drive, Docs, Sheets, Slides, Gmail) route to purpose-built tool functions instead of the generic executor
  7. Execute -- The Google API URL is built, OAuth token is obtained (cached), and the request is sent
  8. Response -- The Google API response is returned to the client as MCP tool result content

Multi-user deployment

Each user gets their own server instance with isolated credentials and policy:

graph LR
    subgraph "User A"
        PA[Policy A] --> DA[Pod A]
        CA[Credentials A] --> DA
    end
    subgraph "User B"
        PB[Policy B] --> DB[Pod B]
        CB[Credentials B] --> DB
    end
    DA --> G[Google APIs]
    DB --> G

Module map

ModulePurpose
main.rsCLI args, templates, interactive wizard, policy checker
handler.rsrmcp ServerHandler: tools, prompts, resources, completions, tasks, elicitation, subscriptions
server.rsTool dispatch business logic, request explanation
tools.rsTool list builder, lazy filtering, compact schema mode
execute.rsGoogle API execution, URL building, pagination, resumable uploads, rate limiting
helpers.rsGoogle Docs enrichment (9 tools)
sheets_helpers.rsGoogle Sheets enrichment (14 tools)
drive_helpers.rsGoogle Drive enrichment (9 tools)
slides_helpers.rsGoogle Slides enrichment (9 tools)
gmail_helpers.rsGmail enrichment (10 tools)
format.rsMarkdown/Plain to Docs batchUpdate, doc to Markdown reverse converter
cache.rsLRU + TTL in-memory cache for Sheets reads
rate_limit.rsPer-service sliding-window rate limiter
policy.rsJSON policy engine, constraint enforcement
http.rsAxum HTTP server, SSE, probes, metrics, webhooks
resources.rsMCP resources: gws:// URI scheme, resource templates
completions.rsMCP completions: autocomplete for resource URIs and prompt arguments
elicitation.rsMCP elicitation: structured user input
subscriptions.rsMCP subscriptions: Drive watch channels, webhooks
prompts.rsMCP prompts: external Markdown files, argument substitution
tasks.rsTask lifecycle for resumable uploads and chunked downloads
metrics.rsPrometheus counters, histograms, gauges
meta.rsRequest metadata, W3C Trace Context
auth.rsOAuth2 credential chain with token caching
audit.rsStructured JSONL audit log writer
image_gen.rsGemini image generation and Drive upload
marp.rsMarp Markdown to Google Slides conversion

Edit this page on GitHub