Google Cloud Run Deployment
1. Multi-Stage Dockerfile
Section titled “1. Multi-Stage Dockerfile”The included Dockerfile builds a minimal, static Go binary packaged inside an Alpine/scratch base image (~15MB):
FROM golang:1.25-alpine AS builderWORKDIR /appCOPY go.mod go.sum ./RUN go mod downloadCOPY . .RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /mcp-server .
FROM alpine:3.21RUN apk --no-cache add ca-certificatesCOPY --from=builder /mcp-server /mcp-serverEXPOSE 8080ENV PORT=8080ENTRYPOINT ["/mcp-server"]2. Deploying via gcloud
Section titled “2. Deploying via gcloud”export GCP_PROJECT="your-project-id"
gcloud run deploy mcp-server \ --source . \ --project $GCP_PROJECT \ --region us-central1 \ --allow-unauthenticated \ --port 8080 \ --memory 256Mi \ --cpu 1 \ --session-affinityWhy --session-affinity?
Section titled “Why --session-affinity?”While Streamable HTTP is completely stateless, --session-affinity ensures legacy clients relying on long-lived SSE connections route subsequent requests to the same container instance.