Skip to content

Latest commit

 

History

History
171 lines (129 loc) · 4.49 KB

File metadata and controls

171 lines (129 loc) · 4.49 KB

Environment: Google Cloud Platform

Deploy on Cloud Run (serverless) with Google Cloud Storage for files and Memcached (Memory Store) for async callback caching.

This guide covers running openapi-mcp-sdk on Google Cloud Platform. The codebase supports GCP-specific variables for compatibility with existing deployments; this guide documents both that approach and the recommended explicit configuration.


Architecture

Internet → Cloud Run (openapi-mcp-sdk server)
               │
               ├── Google Cloud Storage (file downloads)
               └── Memorystore Memcached (async callback cache, VPC-internal)

Environment variables

# Core
MCP_PORT=8080
MCP_ENV=production
MCP_BASE_URL=https://mcp.example.com
MCP_CALLBACK_URL=https://mcp.example.com/callbacks
MCP_OPENAPI_ENV=                        # dev, test, sandbox (alias of test), or empty for production

# Storage
MCP_STORAGE_BACKEND=gcs
MCP_STORAGE_BUCKET=my-cloud-run-service     # name of the GCS bucket

# Cache
MCP_CACHE_BACKEND=memcached
MCP_CACHE_HOST=10.x.x.x                 # Memorystore VPC-internal IP
MCP_CACHE_PORT=11211

Cloud Run deployment

Cloud Run service YAML

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: mcp-openapi-com
spec:
  template:
    metadata:
      annotations:
        run.googleapis.com/vpc-access-connector: projects/MY_PROJECT/locations/REGION/connectors/MY_CONNECTOR
        run.googleapis.com/vpc-access-egress: all-traffic
    spec:
      containers:
        - image: gcr.io/MY_PROJECT/openapi-mcp-sdk:latest
          ports:
            - containerPort: 8080
          env:
            - name: MCP_PORT
              value: "8080"
            - name: MCP_BASE_URL
              value: "https://mcp.example.com"
            - name: MCP_STORAGE_BACKEND
              value: "gcs"
            - name: MCP_STORAGE_BUCKET
              value: "mcp-openapi-com"
            - name: MCP_CACHE_BACKEND
              value: "memcached"
            - name: MCP_CACHE_HOST
              value: "10.x.x.x"

Build and deploy

# Build
gcloud builds submit --tag gcr.io/MY_PROJECT/openapi-mcp-sdk

# Deploy
gcloud run deploy mcp-openapi-com \
  --image gcr.io/MY_PROJECT/openapi-mcp-sdk \
  --region europe-west1 \
  --platform managed \
  --allow-unauthenticated \
  --port 8080

Storage: Google Cloud Storage

  1. Create a bucket (name it after the service for legacy compatibility, or use any name + set MCP_STORAGE_BUCKET):

    gsutil mb -l europe-west1 gs://mcp-openapi-com
  2. Grant the Cloud Run service account write access:

    gsutil iam ch serviceAccount:MY_SA@MY_PROJECT.iam.gserviceaccount.com:objectAdmin \
      gs://mcp-openapi-com
  3. Set the env vars:

    MCP_STORAGE_BACKEND=gcs
    MCP_STORAGE_BUCKET=mcp-openapi-com

Downloaded files are stored at gs://MCP_STORAGE_BUCKET/<request_id>/<filename> and served via the /status/{id}/files/{name} endpoint.


Cache: Memorystore Memcached

Memcached is used to share async callback results across multiple Cloud Run instances (which are stateless and ephemeral).

  1. Create a Memorystore Memcached instance inside the same VPC.

  2. Set:

    MCP_CACHE_BACKEND=memcached
    MCP_CACHE_HOST=10.x.x.x        # discovery IP from Memorystore console
    MCP_CACHE_PORT=11211
  3. Connect Cloud Run to the VPC via a Serverless VPC Access connector so it can reach the private IP.

Tip: Redis (Memorystore for Redis) is a simpler alternative with better support for persistence. Use MCP_CACHE_BACKEND=redis and MCP_CACHE_URL=redis://IP:6379.


Notes

Remove legacy dependency — pymemcache ties the app to a VPC-internal Memcached instance with hardcoded IPs (see memory_store.py). Replace with an in-process dict for dev and a Redis client (redis-py) for production via MCP_CACHE_URL env var.

pymemcache

Remove legacy dependency — google-cloud-storage ties file storage to GCS. Replace with a storage-agnostic solution (local filesystem for dev, pluggable via MCP_STORAGE_BACKEND env var).

google-cloud-storage

Remove legacy dependency — pymemcache is tied to the Google Cloud VPC-internal Memcached instance (hardcoded IPs X.X.X.X / X.X.X.X). Replace with an environment-agnostic cache abstraction: use a simple in-process dict for local/dev, and allow plugging in Redis (e.g. via redis-py + MCP_CACHE_URL env var) or any other backend for production.

pymemcache