Skip to content

All posts

KubernetesAI

How to set liveness and readiness probes for MCP server pods

Ritesh Patel

Kubernetes: How to set liveness and readiness probes for MCP server pods

A liveness probe tells the kubelet when to restart a container. A readiness probe tells Kubernetes when to stop sending it traffic. For an MCP server, liveness catches a process that is running but stuck, and readiness covers startup and overload. Both need a check the server answers within a set timeout.

What each probe does when it fails

Kubernetes defines three probe types. The Pod Lifecycle concept page says what each one does on failure, and the table below summarizes it.

Probe Question it answers What a failure does
Startup Has the application finished starting? Liveness and readiness wait until it succeeds. If it never succeeds, the kubelet kills the container and the restart policy applies.
Liveness Is the container stuck in a state it cannot leave? After failures exceed the tolerance, the kubelet restarts the container.
Readiness Can the container accept traffic now? The EndpointSlice controller removes the Pod’s IP from the EndpointSlices of every Service that matches the Pod.

The distinction matters for an MCP server. A hung server that makes no progress is a liveness problem, and restarting it can help. A server that is still loading tools or waiting on an upstream service is a readiness problem. Kubernetes should stop sending it requests, not restart it. The lifecycle page also says readiness probes run for the whole life of the container, and liveness probes do not wait for readiness to succeed.

Pick a probe mechanism

Each probe uses one of four mechanisms. The probes task page defines what success means for each.

Mechanism Success means Fit for an MCP server
exec The command exits with 0 A check you write inside the container. It needs no open port.
httpGet A status code from 200 up to, but not including, 400 A health route that the server serves beside its MCP endpoint.
tcpSocket The kubelet can open a connection to the port Weak for MCP. A process can accept connections and still fail to answer requests.
grpc The gRPC health check succeeds Servers that implement the gRPC Health Checking Protocol. The page says every error counts as a failure.

By default, httpGet sends an HTTP GET request. The probes page also describes newer options, such as HTTP/2 cleartext for httpGet and TLS for gRPC. Those are alpha and behind feature gates on the cluster versions the page describes, so keep to the defaults unless you have checked your cluster.

Configure the three probes for an HTTP server

  1. Expose the server on a named container port. The probes page says named ports work for HTTP and TCP probes, but not for gRPC probes.
  2. Add a startup probe sized for the slowest start. The page gives the rule as failureThreshold times periodSeconds.
  3. Add a liveness probe that checks the server process. It runs after the startup probe succeeds.
  4. Add a readiness probe for warm-up and dependencies. It runs for the whole container lifetime.
apiVersion: v1
kind: Pod
metadata:
  name: mcp-server
spec:
  containers:
  - name: mcp-server
    image: example/mcp-server:1.0.0
    ports:
    - name: http
      containerPort: 8080
    startupProbe:
      httpGet:
        path: /healthz
        port: http
      periodSeconds: 10
      failureThreshold: 30
    livenessProbe:
      httpGet:
        path: /healthz
        port: http
      periodSeconds: 10
      timeoutSeconds: 2
    readinessProbe:
      httpGet:
        path: /ready
        port: http
      periodSeconds: 5
      timeoutSeconds: 2

The API reference sets the defaults for the timing fields. periodSeconds defaults to 10 seconds. timeoutSeconds defaults to 1 second, which is tight for a busy server, so the example sets 2. failureThreshold defaults to 3. successThreshold defaults to 1, and it must be 1 for liveness and startup probes. The startup example gives 30 failures at 10-second intervals, so the server has 300 seconds to finish starting.

Do not point the probe at the MCP endpoint

The Streamable HTTP transport in the MCP specification exposes one endpoint that accepts both POST and GET. For a GET, the server must either open an event stream or return 405 Method Not Allowed. A kubelet httpGet probe sends GET. Kubernetes counts any code outside 200 to 399 as a failure. A healthy server that answers that GET with 405 therefore fails its liveness probe, and the kubelet restarts it.

Serve a separate health route, such as /healthz, and point the probe there. The transports page defines no health check, so the route and its response are your design. Keep the MCP endpoint for MCP clients.

Probes for servers that only speak stdio

Under the stdio transport, the client launches the MCP server as a subprocess and exchanges messages over stdin and stdout. A server that uses only stdio may not listen on any port. In that case httpGet and tcpSocket probes have nothing to reach.

The exec probe runs a command inside the container and treats exit code 0 as healthy. You can use it to test a file or process that your server keeps current. The MCP specification does not define such a check, so you have to write it for your server and test it on a cluster before you rely on it.

Keep liveness and readiness separate

The docs give each probe its own job. Readiness is for waiting on external services after startup. Liveness is for deadlocks, where the process runs but cannot make progress. If a liveness check calls a database, one database outage fails every pod’s liveness at the same time, and the kubelet restarts those containers. Keep external dependency checks in readiness, and keep the liveness check local to the process.

Each restart also increments the RESTARTS column. The probes page notes that the counter rises as soon as a failed container runs again, so a climbing count is the first sign of a bad liveness check. For the resource settings that go with the same pod, see how to set resource limits on AI agent pods.

Checklist before you ship a probe

  1. Apply the manifest to a test cluster and run kubectl describe pod to check the probe events.
  2. Confirm that no probe uses the MCP endpoint path.
  3. Size the startup window to the slowest start you have measured.
  4. Move external dependency checks into the readiness probe.
  5. Raise timeoutSeconds above 1 second if the server slows under load.
  6. Watch RESTARTS after each rollout.

For the broader MCP security picture, see the MCP security guide. Pod policy is a separate question, and the open source policy engine’s page is at Kyverno.

Frequently asked questions

What is the difference between a liveness probe and a readiness probe?

A liveness probe decides when the kubelet restarts a container. A readiness probe decides whether the Pod's IP stays in the EndpointSlices of the Services that match it. A failing liveness probe restarts the container once it passes the failure tolerance. A failing readiness probe only stops new traffic and leaves the container running, which suits a server that is still loading data or waiting on a dependency.

Why does my MCP server pod restart even though the server works?

One cause on an HTTP server is a liveness probe that sends GET to the MCP endpoint. The MCP transport specification lets a server answer that GET with 405 Method Not Allowed. Kubernetes counts any status outside 200 to 399 as a failure. Run kubectl describe pod to find Unhealthy events, then point the liveness probe at a separate health route.

How long should a startup probe allow?

Set failureThreshold times periodSeconds to cover the slowest start you have measured. The probes page uses 30 failures at 10 seconds, which gives 300 seconds. If the startup probe never succeeds in that window, the kubelet kills the container and the restart policy applies. Measure your own start time first, because the example values are not defaults.

Can an exec probe check a server that only speaks stdio?

Yes, if the command runs inside the container, tests something real about the server, and exits with 0 when the server is healthy. The probes page treats exit code 0 as success and any other value as failure. The MCP specification does not define a health check, so write the command against your server and test it on a cluster before you rely on it.

Ritesh Patel, Founder & VP Product, Nirmata

Ritesh Patel is a founder of Nirmata and leads its products. He writes about governing AI coding agents, MCP security and Kubernetes policy as code.

LinkedIn

Govern AI agents with AIControlsControl what AI agents do, and prove it.
Share

Stay up-to-date with the latest in AI, governance, and infrastructure

Subscribe to our free monthly newsletter to get industry news, DevOps tips, and articles right to your inbox on Kyverno, containerization, Kubernetes deployment & management and more.