A local stdio server is a personal tool. A deployed remote server is a service with users, credentials, and availability expectations. This guide covers the mechanics of a small, honest deployment: one container, a TLS proxy, secrets injected at runtime, and verification with a real MCP client.
Choose the deployment shape
| Shape | Use when | Operational cost |
|---|---|---|
| Local stdio | One user, local data, simple distribution | Low; user manages runtime |
| Single remote container | Shared team tool, public API | TLS, auth, logs, upgrades |
| Multi-replica service | High availability or scale | State, session behavior, load balancing |
Do not deploy a remote service because it sounds more advanced. If the data should stay local, stdio is a feature, not a limitation.
Containerize the server
A TypeScript example:
FROM node:22-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY tsconfig.json ./
COPY src ./src
RUN npm run build && npm prune --omit=dev
FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/package.json ./
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
USER node
EXPOSE 3000
CMD ["node", "dist/server.js"]
A Python example:
FROM python:3.12-slim
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
COPY pyproject.toml uv.lock ./
RUN pip install uv && uv sync --frozen --no-dev
COPY server.py ./
RUN useradd --create-home appuser
USER appuser
EXPOSE 8000
CMD ["uv", "run", "--frozen", "--no-dev", "python", "server.py"]
Pin base images and dependencies. Run as a non-root user. Do not copy .env files or build secrets into the image.
Inject secrets at runtime
Use the platform’s secret store or environment injection. Never bake credentials into an image, a repository, or a client config that is shared.
At startup, validate required variables and fail with a clear message that names the missing key but not its value. Rotate secrets without rebuilding the image. Give the server a dedicated credential, not a human’s personal token.
Put TLS and authentication in front
Terminate TLS at a reverse proxy or managed load balancer. Then:
- Require authentication on every MCP request.
- Validate Origin for browser-reachable endpoints.
- Preserve
MCP-Protocol-Version,Mcp-Method, and related headers. - Disable response buffering for streaming.
- Limit request body size and rate.
- Set timeouts for connect, read, and upstream calls.
- Keep the container port off the public internet.
If you use OAuth, test the full login, token exchange, expiry, and revocation flow. A valid token with the wrong audience is still an authentication failure.
Health checks and readiness
Expose a separate health endpoint that reports process liveness. Do not pretend it validates MCP tool calls. A readiness check can verify that required dependencies are reachable, but it must not run privileged write operations.
For remote MCP, the real smoke test is a protocol exchange from a client. Run it after every deployment, from outside the container, with a test identity and read-only tool.
Rollout and rollback
- Build an immutable image with a version tag.
- Deploy to a staging environment with test credentials.
- Run a client smoke test: server discovery, tools/list, one read-only call (initialize only on legacy revisions).
- Exercise an auth failure and a timeout.
- Promote the same image to production.
- Verify the read-only call with the production identity.
- Keep the previous image available for rollback.
Schema and protocol changes need a migration note for clients. If a tool is renamed, keep the old name for a deprecation window or coordinate the client update.
Observability
Emit structured logs with request id, tool name, duration, and outcome. Do not log tokens, full arguments, or sensitive results. Export metrics for request rate, latency, errors, timeouts, and upstream failures. Create alerts for sustained error rates and authentication failures.
Collect audit events for write tools: actor, action, resource, time, and result. Retain them according to policy and protect them from tampering.
Post-deployment verification
- The endpoint is reachable only through TLS.
- Unauthenticated requests receive 401.
- An invalid Origin is rejected where applicable.
- A real MCP client completes initialization and tool discovery.
- A read-only tool call succeeds.
- A permission failure is reported as a tool error.
- Logs contain no secrets.
- Rollback has been tested.
Record the exact image digest, protocol revision, client version, and test time. “Deployed” is not the same as “verified.”
What not to do
- Do not expose a hobby server directly to the internet with no auth.
- Do not run a container as root to avoid fixing permissions.
- Do not disable TLS verification or check out of certificate errors.
- Do not add
--no-sandboxor broad privileged mounts to make a container start. - Do not claim production status from a successful build.
For the transport layer, read Streamable HTTP and MCP transports explained. For security controls, read securing MCP servers.
Sources
Sources were checked on Oct 23, 2026. Versions and client behavior can change; confirm the current documentation before relying on a configuration.