Deployment

Guide

How to run the server as a Docker container, with Docker Compose, on Google Cloud Run, behind nginx, as a systemd service, or on AWS Fargate with CloudFormation, and what each shipped template needs changed first.

Status
stable
Trust tier
unverified
Generated
claude-code/claude-opus-5-5, 2026-12-05
Tags
deploymentdockerdocker-composecloud-runnginxsystemdaws

The repository ships a Dockerfile, two Docker Compose files, and templates under deployment/ for Google Cloud Run, nginx, systemd and AWS CloudFormation.1 This guide describes what each one does and what you must change before you use it.

The most important fact for every remote deployment: the server speaks stdio unless it is told to use HTTP. The image’s default command is node build/index.js, and the server switches to HTTP only with --http or MCP_TRANSPORT=http.2 3 Every deployment that is reached by URL, probed on /health, or put behind a load balancer or nginx must set MCP_TRANSPORT=http. The shipped templates all set it.

Checklist for a remote deployment

  1. Set MCP_TRANSPORT=http.
  2. Bind to all interfaces with HOST=0.0.0.0 (the image already sets it).2
  3. Set MCP_ALLOWED_HOSTS to the public host name. Without it, a server that is not bound to loopback has the Host check turned off.4
  4. Put a proxy or load balancer in front for TLS and access control. The server has no authentication and no CORS handling.1
  5. Probe GET /health. It returns 200 with {"status":"ok","version":"..."} and is not subject to the Host check.4
  6. Replace the placeholder image name ghcr.io/user/nsf-awards-mcp:latest in the templates with your image.5 6 7

HTTP transport explains the Host and Origin checks in detail.

Docker image

docker build -t nsf-awards-mcp .

The Dockerfile has three stages:2

Stage Base What it does
ts-builder node:22-alpine, on the build machine’s own platform (--platform=$BUILDPLATFORM) Runs npm ci, npm run build and npm run type-check, then npm prune --omit=dev. Tests do not run here; CI runs them.
go-builder golang:1.21-alpine A placeholder for a possible Go port. It only copies the TypeScript build.
runtime node:22-alpine The final image.

The runtime image:2

Setting Value
User nsf (uid 1001, group nsf, gid 1001), not root
Extra packages ca-certificates, dumb-init, curl
ENTRYPOINT /usr/bin/dumb-init --, for signal handling
CMD node build/index.js (stdio)
ENV NODE_ENV=production, LOG_LEVEL=info, HOST=0.0.0.0, PORT=3000
EXPOSE 3000
Logs /app/logs, owned by nsf. With NODE_ENV=production the server writes logs/error.log and logs/combined.log there, in addition to stderr.8
Health check None in the image, because the default command speaks stdio and has nothing to probe. HTTP deployments probe /health.

In a local docker build, the image labels say version="1.1.0" and point at https://github.com/user/nsf-awards-mcp. They are static and are not the package version (2.0.0 in package.json).2 9 Images built by CI get correct OCI source and version labels from docker/metadata-action, which override the Dockerfile’s; the bare version="1.1.0" label stays.10 The developer guide says these static labels must be bumped by hand.11 The build arguments BUILD_DATE, VCS_REF and VERSION fill the OCI created, revision and version labels.2

Run over stdio

The container speaks MCP on stdin and stdout, so run it with -i:1

docker run -i --rm nsf-awards-mcp

Connecting clients shows the client entry that starts the container this way.

Run over HTTP

docker run -d --name nsf-awards-mcp -p 3000:3000 -e MCP_TRANSPORT=http nsf-awards-mcp
curl http://localhost:3000/health

Because the image binds 0.0.0.0, the Host check is off unless you pass -e MCP_ALLOWED_HOSTS=your.host.name.1

Images built by CI

The CI workflow builds the image for linux/amd64 and linux/arm64. On pushes to main, develop and claude/** branches and on v* tags (not on pull requests), it is configured to push the image to the GitHub Container Registry under the repository name, ghcr.io/tyson-swetnam/nsf-awards-mcp. The tags come from the branch or pull request, the semantic version of a v* tag (full, major.minor and major), latest on the default branch, and the commit SHA.10 CI then smoke-tests the image: an MCP initialize handshake over stdio, and the same handshake over HTTP after /health answers.10

The release notes that CI writes for a v* tag suggest docker run --rm <image> without -i, and they use the git tag name (for example :v2.0.0) as the image tag, while the semantic-version tags CI pushes have no v prefix (:2.0.0, :2.0, :2). That command cannot serve a stdio client and names a tag that does not exist. Use docker run -i --rm ghcr.io/tyson-swetnam/nsf-awards-mcp:2.0.0, or set -e MCP_TRANSPORT=http and publish the port.10

Docker Compose

docker-compose.yml defines these services:12

Service Profile What it is
nsf-awards-mcp (always) The runtime image, tagged nsf-awards-mcp:latest, with MCP_TRANSPORT=http, HOST=0.0.0.0, NODE_ENV=production and LOG_LEVEL (default info). Port 3000:3000.
nsf-awards-mcp-dev dev The ts-builder stage running npm run dev with NODE_ENV=development, LOG_LEVEL=debug, the source mounted at /app, on host port 3001.
redis cache redis:7-alpine. Marked “future enhancement”; the server does not use it.
prometheus monitoring prom/prometheus:latest. Marked “future enhancement”. It mounts ./monitoring/prometheus.yml, which is not in the repository.

Details of the main nsf-awards-mcp service:12

  • Health check: curl -f http://localhost:3000/health every 30 s, timeout 10 s, 3 retries, 40 s start period.
  • Restart policy unless-stopped; resource limits 512 MB memory and 0.5 CPU (reservations 256 MB and 0.25 CPU).
  • Volumes: ./logs to /app/logs, and ./mcp-config.json to /app/mcp-config.json (read-only). The server does not read mcp-config.json.
  • Docker logging: json-file, at most 3 files of 10 MB.
  • The VERSION build argument defaults to 1.0.0, and the app.version label is 1.0.0; neither is the package version.

MCP_ALLOWED_HOSTS is not set, so the Host check is off. Add it under environment when the service is reachable from other machines.4

docker-compose.override.yml is loaded automatically by docker compose up. It turns the main service into a development container: the ts-builder stage running npm run dev, NODE_ENV=development, LOG_LEVEL=debug, the source mounted, 1 GB and 1 CPU limits, and ports 3000 and 9229 (the Node.js debug port).13 So:1

docker compose -f docker-compose.yml up -d            # production-style service only
docker compose up                                     # development (with the override)
docker compose --profile dev up nsf-awards-mcp-dev    # separate dev service on port 3001

Caveat: neither development container starts as shipped. Both the override and the dev profile run npm run dev (tsx watch src/index.ts) on the ts-builder stage, but that stage ends with npm prune --omit=dev, so tsx, a devDependency, is not installed. Both also mount an anonymous volume at /app/node_modules, which Docker fills from the image’s pruned tree, so a host node_modules does not help. The command fails with tsx not found and the container exits.12 13 2 9 To fix it, add an unpruned development stage to the Dockerfile and point both target entries at it. (Dropping the anonymous /app/node_modules volume and running npm ci in the container also works, but it installs Linux binaries into the host’s node_modules through the bind mount.) Until then, run npm run dev on the host.

Google Cloud Run

deployment/gcp/cloud-run.yaml is a Knative service definition for Cloud Run.5

Setting Value
Image ghcr.io/user/nsf-awards-mcp:latest (placeholder: replace it)
Environment NODE_ENV=production, LOG_LEVEL=info, PORT=3000 (remove it: see the caveat below), MCP_TRANSPORT=http, HOST=0.0.0.0, and GOOGLE_CLOUD_PROJECT (from valueFrom.metadataResourceRef)
MCP_ALLOWED_HOSTS Commented out. Set it to the service’s public host name to turn the Host check on.
Container port 3000 (http1)
Probes Liveness, readiness and startup probes on GET /health, port 3000
Scaling minScale 1, maxScale 100, target 80; containerConcurrency 100; timeoutSeconds 300
Resources Limits 1 vCPU and 2 GiB; requests 0.5 vCPU and 1 GiB
Other Ingress all, gen2 execution environment, CPU throttling on, service account nsf-awards-mcp-sa

The same file also contains a Kubernetes ServiceAccount and a HorizontalPodAutoscaler (1 to 50 replicas at 70% CPU and 80% memory).5

Caveat: cloud-run.yaml names the service account nsf-awards-mcp-sa, but deploy.sh setup creates nsf-awards-mcp@<project>.iam.gserviceaccount.com, and deploy uses that account. Use the same account in both. Also remove the GOOGLE_CLOUD_PROJECT entry before you apply the file: its metadataResourceRef source is not a Cloud Run valueFrom field (Cloud Run supports only secretKeyRef there).14 Remove the PORT entry too: Cloud Run reserves PORT and sets it itself from the container port (3000), so a service that sets it is rejected.5 6 15

deployment/gcp/deploy.sh wraps gcloud:6

deployment/gcp/deploy.sh setup  -p my-project-id
deployment/gcp/deploy.sh deploy -p my-project-id -i <your-image> --allow-unauthenticated
deployment/gcp/deploy.sh status -p my-project-id
Command What it does
setup Sets the project, enables the Cloud Build, Cloud Run, Container Registry, Logging and Monitoring APIs, creates the nsf-awards-mcp service account, and grants it roles/logging.logWriter and roles/monitoring.metricWriter.
deploy (default) Runs gcloud run deploy with --port 3000, concurrency 100, timeout 300 and the service account, then curls <url>/health.
update gcloud run services update with a new image.
delete, status, logs Delete (asks for confirmation), or describe the service and recent revisions. logs is meant to read the last 50 log entries, but it calls gcloud logs read, which is not a gcloud command, so it fails. Change it to gcloud logging read in deploy.sh, or run gcloud logging read ... --limit=50 yourself.16

Options and defaults: -p/--project (or the gcloud default project), -r/--region (us-central1), -i/--image (ghcr.io/user/nsf-awards-mcp:latest), --min-instances (1), --max-instances (10), --memory (2Gi), --cpu (1), --allow-unauthenticated (off: the service requires authentication).6

deploy sets NODE_ENV=production,LOG_LEVEL=info,MCP_TRANSPORT=http with --set-env-vars, so the service serves HTTP on port 3000.6 To check the Host header, add MCP_ALLOWED_HOSTS with the service’s host name to that list.

nginx reverse proxy

deployment/nginx/nsf-awards-mcp.conf is an example nginx site for a server that runs in HTTP mode on 127.0.0.1:3000.17

Location Behavior
port 80 Redirects to HTTPS.
/mcp Proxies to the backend with buffering and caching off (responses can be SSE streams). Rate limit 5 requests/s per client address, burst 50, status 429 when exceeded. Timeouts: connect 30 s, send 120 s, read 300 s.
/health Proxies to /health. Rate limit 1 request/s, burst 5. 5 s timeouts, no caching, no access log.
/ Everything else, which the server answers with 404. Rate limit 10 requests/min, burst 20, with caching.
/docs Serves static files from /var/www/nsf-awards-mcp/docs.

Other settings: TLS 1.2 and 1.3 with certificates at /etc/ssl/certs/nsf-awards-mcp.crt and /etc/ssl/private/nsf-awards-mcp.key, OCSP stapling, HSTS and other security headers, at most 10 connections per client address, and keepalive 32 to the upstream. Requests for dot files and .env, .config and .log files are denied.17

To use it:

  1. Replace the server_name nsf-awards-mcp.example.com with your domain.
  2. Run the backend with MCP_TRANSPORT=http and MCP_ALLOWED_HOSTS=<your domain>. nginx passes the client’s Host header through, so without MCP_ALLOWED_HOSTS the loopback-bound backend rejects every proxied /mcp request with 403.17 4

deployment/scripts/setup-ssl.sh (run as root) automates the nginx side.18 It copies the config to /etc/nginx/sites-available/nsf-awards-mcp, replaces the example domain, links it into sites-enabled, checks it with nginx -t and reloads nginx. Then it either gets a Let’s Encrypt certificate with certbot (installing certbot on Debian or Red Hat systems if needed) and tries to add a renewal cron job (/etc/cron.d/nsf-awards-ssl-renewal), or makes a self-signed certificate for testing.

Caveat: the script runs nginx -t on the copied config before it creates any certificate, and the config points at /etc/ssl/certs/nsf-awards-mcp.crt, /etc/ssl/private/nsf-awards-mcp.key and /etc/ssl/certs/nsf-awards-mcp-chain.crt. On a fresh host those files do not exist, so nginx -t fails and the script exits, in both the Let’s Encrypt and the --self-signed modes. Pointing the config at certbot’s /etc/letsencrypt/live/<domain>/ files does not help, because those exist only after certbot runs, and the script runs certbot after nginx -t. Create placeholder files at the three /etc/ssl paths first, for example a temporary self-signed certificate made with openssl; certbot’s --nginx mode then installs the real certificate.18 17

sudo deployment/scripts/setup-ssl.sh -d your-domain.com -e admin@your-domain.com
sudo deployment/scripts/setup-ssl.sh --self-signed -d localhost

Options: -d/--domain, -e/--email, --staging (Let’s Encrypt staging), --self-signed, --renew-only.18

Caveat: the renewal cron job does not work. The script picks the hour with shuf -i 0-5,18-23 -n 1, which GNU shuf rejects as an invalid range. The command runs inside a heredoc, so set -e does not stop the script, and the cron line is written with an empty hour field. cron then reads root as the day of week and rejects the line, so renewal never runs. (The file’s comment also says “Runs twice daily”, but it writes only one entry.) Fix the cron line in setup-ssl.sh, for example by picking the hour with $(( RANDOM % 24 )) or by listing two fixed hours, or rely on the systemd timer or cron job that many certbot packages install themselves.18

systemd

deployment/systemd/nsf-awards-mcp.service runs /usr/bin/node build/index.js from /opt/nsf-awards-mcp as user nsf-mcp, with NODE_ENV=production and LOG_LEVEL=info.19 It restarts always (10 s delay, at most 3 starts in 60 s), sends output to the journal under the identifier nsf-awards-mcp, stops with SIGTERM (30 s timeout), and applies sandboxing (ProtectSystem=strict, ProtectHome=true, NoNewPrivileges=true and others) with write access only to /opt/nsf-awards-mcp/logs and /var/log/nsf-awards-mcp. Limits: MemoryMax=1G, LimitNOFILE=65536, TasksMax=4096.

deployment/scripts/install-systemd.sh (run with sudo) installs it:20

  1. Checks for systemd, Node.js and npm.
  2. Creates a system user (default nsf-awards-mcp), the install directory (default /opt/nsf-awards-mcp) and /var/log/nsf-awards-mcp.
  3. Copies the project into the install directory, runs npm ci --only=production, then npm run build.
  4. Installs the unit into /etc/systemd/system/, replacing the paths, user and group, and enables it.
  5. Adds a logrotate rule for /var/log/nsf-awards-mcp/*.log (daily, 30 rotations).
  6. Starts the service, unless you pass --no-start.

Options: --install-dir DIR, --user USER, --group GROUP, --no-start, --uninstall (stops and removes the unit and the logrotate rule, and asks before it deletes the directory, logs and user).20

Caveats before you use these files:

  • The unit sets MCP_TRANSPORT=http and PORT=3000, and keeps the default HOST (127.0.0.1), which matches the nginx upstream. Without HTTP mode the server would start in stdio mode, see end-of-input on systemd’s null stdin and exit at once.19 3 17 For the nginx setup above, uncomment Environment=MCP_ALLOWED_HOSTS=... and set your domain: nginx forwards the public Host header, which the loopback-bound server otherwise rejects with 403.4
  • The script tells you to install Node.js 18, but the package needs Node.js 20 or later.20 9
  • The script installs production dependencies only and then runs npm run build. The build runs tsc, and typescript is a devDependency.20 9
  • The server writes its log files to logs/ under its working directory (/opt/nsf-awards-mcp/logs), not to /var/log/nsf-awards-mcp, which is where the logrotate rule looks.8 20
  • The unit sets MemoryDenyWriteExecute=true, which systemd documents as incompatible with JIT engines such as Node’s V8. Remove it (or set it to false) if node fails to start under the unit.19 21
  • ExecReload sends SIGHUP. The server installs handlers only for SIGINT and SIGTERM.19 3

AWS CloudFormation

deployment/aws/cloudformation.yaml builds a complete Fargate stack.7

Parameter Default Notes
EnvironmentName nsf-awards-mcp Prefix for resource names
DomainName empty Optional. Only a condition reads it; no resource uses it.
CertificateArn empty ACM certificate; turns on the HTTPS listener
ImageUri ghcr.io/user/nsf-awards-mcp:latest Placeholder: replace it
DesiredCapacity 2 1 to 10 tasks
MinCapacity, MaxCapacity 1, 10 Auto-scaling bounds
InstanceType t3.medium No resource uses it; the tasks run on Fargate.
LogRetentionDays 30 CloudWatch Logs retention

Resources:7

  • A VPC (10.0.0.0/16) with two public and two private subnets in two availability zones, an internet gateway, and one NAT gateway per zone.
  • An internet-facing Application Load Balancer. Port 80 forwards to the tasks, or redirects to HTTPS when CertificateArn is set; port 443 uses the certificate.
  • A target group on port 3000 with health checks on /health every 30 s.
  • An ECS cluster with FARGATE and FARGATE_SPOT capacity (weights 1 and 4), and a service whose tasks run in the private subnets.
  • A task definition with 512 CPU units and 1024 MB, NODE_ENV=production and LOG_LEVEL=info, logs to CloudWatch, and a container health check curl -f http://localhost:3000/health.
  • Target-tracking auto scaling at 70% average CPU, and CloudWatch alarms for CPU above 80% and for unhealthy targets. The scaling target uses the IAM role application-autoscaling-ecs-service in your account.

The task environment sets MCP_TRANSPORT=http, so the container and target group health checks on /health reach the HTTP server; the image already sets HOST=0.0.0.0.7 2 To check the Host header, add MCP_ALLOWED_HOSTS with your domain or the load balancer’s DNS name to the container Environment list.

  1. Installation guide (INSTALL.md) ↩ ↩2 ↩3 ↩4 ↩5

  2. Dockerfile ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8

  3. Server entry point (src/index.ts) ↩ ↩2 ↩3

  4. Streamable HTTP transport (src/http.ts) ↩ ↩2 ↩3 ↩4 ↩5

  5. Cloud Run service definition ↩ ↩2 ↩3 ↩4

  6. Cloud Run deployment script ↩ ↩2 ↩3 ↩4 ↩5

  7. AWS CloudFormation template ↩ ↩2 ↩3 ↩4

  8. Logger configuration (src/utils/logger.ts) ↩ ↩2

  9. package.json (version, scripts, engines, dependencies) ↩ ↩2 ↩3 ↩4

  10. CI workflow (image build and push) ↩ ↩2 ↩3 ↩4

  11. Developer guide (DEVELOPMENT.md) ↩

  12. Docker Compose file ↩ ↩2 ↩3

  13. Docker Compose development override ↩ ↩2

  14. Cloud Run Admin API v1 reference, Container and EnvVar ↩

  15. Cloud Run documentation, configuring environment variables ↩

  16. gcloud logging read reference ↩

  17. nginx reverse proxy example ↩ ↩2 ↩3 ↩4 ↩5

  18. TLS setup script for nginx ↩ ↩2 ↩3 ↩4

  19. systemd unit file ↩ ↩2 ↩3 ↩4

  20. systemd installation script ↩ ↩2 ↩3 ↩4 ↩5

  21. systemd.exec manual ↩

Sources

  1. Dockerfile dockerfile
  2. Installation guide (INSTALL.md) install-guide
  3. Docker Compose file compose
  4. Docker Compose development override compose-override
  5. CI workflow (image build and push) ci-workflow
  6. Cloud Run service definition cloud-run
  7. Cloud Run deployment script gcp-deploy
  8. nginx reverse proxy example nginx-conf
  9. TLS setup script for nginx setup-ssl
  10. systemd unit file systemd-unit
  11. systemd installation script install-systemd
  12. AWS CloudFormation template cloudformation
  13. Server entry point (src/index.ts) entry-point
  14. Streamable HTTP transport (src/http.ts) http-transport
  15. Logger configuration (src/utils/logger.ts) logger
  16. package.json (version, scripts, engines, dependencies) package-json
  17. Developer guide (DEVELOPMENT.md) development-guide
  18. Cloud Run documentation, configuring environment variables (reserved variables) cloud-run-env-vars
  19. Cloud Run Admin API v1 reference, Container and EnvVar cloud-run-container-api
  20. gcloud logging read reference gcloud-logging-read
  21. systemd.exec manual (MemoryDenyWriteExecute=) systemd-exec