High availability

Covers FrontMCP 1.12.2 as of

Several copies of a server behind a load balancer keep serving when one of them stops. A client on MCP 2026-07-28 doesn't care which copy answers: every request carries what it needs, so the copies only have to share their secrets. A client on an older protocol version has a session, and the copy that didn't create it needs to find it: that's what a shared Redis is for. In the default mode, any copy loads the session from Redis. In distributed mode, the copy that made a session keeps serving it, the others relay its requests to that copy through Redis, and when that copy stops, another takes its sessions over. Running Several Instances teaches the default mode step by step.

@FrontMcp({ info, apps, redis: { url: process.env.REDIS_URL } })  // the same on every instance
MCP_SESSION_SECRET=… FRONTMCP_BIND_ADDRESS=all node dist/node/help-desk.bundle.js   # the same secret everywhere

Reference

What instances share

WhatEvery instance needsWithout it
MCP_SESSION_SECRETThe same value, for clients before MCP 2026-07-28Changed in 1.11.3: before, startup did not check this secret. Production HTTP refuses startup with a legacy fallback. With a 2026-07-28 fallback it starts with a warning and a degraded session-secret probe; older clients’ initialize still answers 500. An id made under another secret gets 404 invalid session id. See secrets. Changed in 1.12.1: before, distributed development could encrypt session ids without this secret. It now requires the secret for session encryption too.
JWT_SECRET, VAULT_SECRETThe same values, with local or remote auth, or tools that ask the user more than onceTokens and answers from one instance fail on another. A production server with redis and neither secret warns at startup: requestState is signed with a per-process key. See running several instances.
local.signKey, local.jwks (public mode: signKey, jwks)Compatible signing and verification keys when configuredA token signed on one instance must verify on every instance. See signing keys.
redisThe same RedisSessions of older clients, background tasks and pending questions stay in the instance that created them.
auth.tokenStorage, throttle.storageRedis too, if you use local/remote auth or rate limitsSign-ins that change instance fail, and each instance counts its own limits.
The same info.name, with redisFor a duty or worker with scope: "cluster", and for scheduled workflowsLeases are kept per server name, so instances with different names each run the work. Without redis, a "cluster" duty or worker stops startup, and each machine runs its own scheduled workflows. See background work across instances.
The same buildTools, resources and promptsA client sees a different server depending on where it lands. Compare toolsHash in /readyz: see checking replicas.

Clients on MCP 2026-07-28 open no sessions, so for them redis only matters when a tool starts a background task or asks a question.

How a session moves between instances

With redis set, a session is written to Redis when a client opens it, with the id of the instance that holds it (its nodeId). When a request of that session reaches an instance that doesn't have it in memory, that instance reads it from Redis, logs Recreating transport from stored session, serves the request, and writes it back. So a load balancer can send an older client's requests anywhere, without affinity, and a restarted or replaced instance picks up where the old one left off. It does that only for an id it can decrypt, so every instance needs the same MCP_SESSION_SECRET (caveats).

A session's key lives an hour, or redis.defaultTtlMs, and the instance that holds the session pushes it out while it serves the session's requests (how long sessions last). An instance that can't reach Redis when it starts keeps sessions in memory, retries the connection, and uses Redis once it answers, with no restart. Its /readyz answers 503 until then, so a load balancer that checks readiness sends it no traffic (when Redis can't be reached).

Distributed mode

FRONTMCP_DEPLOYMENT_MODE=distributed, which frontmcp build --target distributed sets in its entry (node dist/distributed/index.js), puts the server in distributed mode:

  • It listens on every interface, unless http.security.bindAddress or FRONTMCP_BIND_ADDRESS says otherwise. The audit says BIND_ALL_INTERFACES_DISTRIBUTED.
  • /healthz reports "deployment": "distributed".
  • Every response carries the id of the instance that served it, X-FrontMCP-Machine-Id: <id>, for load balancers that route by it: MCP answers of every protocol version, /healthz and 404s. An older client's initialize also sets a cookie, __frontmcp_node=<id>; Path=/; Max-Age=86400; HttpOnly; SameSite=Strict. (In 1.8.7 only the responses to older clients had the header.)
  • With redis, it starts the HA manager ([HA] Manager started for distributed deployment): a heartbeat key for each instance (mcp:ha:heartbeat:<id>), refreshed every 10 seconds and expiring after 30; a scanner for the sessions of stopped instances, every 10 seconds; a bus that records which instance holds each session (mcp:bus:session:<session id>); and the relay, [HA] Request relay ready — sessions owned by other nodes are served through them. It also stores SSE events in Redis, under mcp:events:.

How a session's requests are served

The request reachesWhat happens
The instance that holds the sessionIt serves it.
Another instance, while the holder runsIt relays the request to the holder through Redis, and streams the answer back. The holder runs it, and the answer's X-FrontMCP-Machine-Id names the holder.
Another instance, after the holder shut down (SIGTERM or SIGINT)The instance takes the session over from Redis at once, serves it, and from then on holds it.
Another instance, after the holder died without shutting down (a crash, SIGKILL, a lost machine)Until the holder's heartbeat expires: 503, with Retry-After set to the heartbeat's lifetime (30) and {"code":-32000,"message":"This MCP session is served by another instance of the server, which did not answer the relayed request. Retry after 30s; if that instance has stopped, the session is taken over by another instance once its heartbeat expires."}. After that, it takes the session over as above.

A server that shuts down deletes its heartbeat key (stopping). When instance desk-a was stopped with SIGTERM, it exited 0, only desk-b's heartbeat was left in Redis, and the session's next request, sent to desk-b a tenth of a second later, was answered 200, with [HA] Session owner is gone — the session will be taken over, Recreating transport from stored session and [HA] Took over session from a stopped node { …, previousNodeId: 'desk-a' } in its log. Before 1.9.2 the heartbeat stayed until it expired, so after a SIGTERM the session answered 503 for 30 seconds. An instance that crashes still leaves its heartbeat behind: after desk-a died, desk-b answered 503 with Retry-After: 30.

A load balancer doesn't need to route by the header or the cookie: round-robin works, and routing by them saves the relay through Redis. Every instance needs the same MCP_SESSION_SECRET, as in the default mode. Relayed requests pass through Redis with their headers, so keep Redis on a private network. Distributed mode without redis works on one instance: it only adds the header and the cookie.

deployments[].ha in frontmcp.config tunes the HA manager: heartbeatIntervalMs, heartbeatTtlMs, takeoverGracePeriodMs and redisKeyPrefix. The distributed build writes them into serverless-setup.js as FRONTMCP_HA_* variables, which a variable already set wins over. With ha: { heartbeatIntervalMs: 2000, heartbeatTtlMs: 6000 }, the 503 said Retry after 6s and the takeover came six seconds after the holder stopped. deployments[].server.cookies sets the cookie's name, Domain and SameSite: cookies: { affinity: "desk_node", sameSite: "Lax" } gave desk_node=<id>; …; SameSite=Lax.

Background work across instances

A timer started in a provider runs in every instance. FrontMCP's own background work is declared with a scope instead, and instances agree on who runs it through a lease: a key one process holds and renews, in a store they share. scope: "cluster", cron schedules, workers and scheduled workflows are new in 1.12.0.

WorkWithout a top-level redisWith the same top-level redis on every instance
@Duty or @Worker, scope: "cluster"The server does not start: ClusterScopeNeedsRedisErrorOne instance runs it
@Duty or @Worker, scope: "machine"One process per machine runs it, through a SQLite file on that machineOne process per hostname runs it. Containers and pods have hostnames of their own, so each runs it.
@Duty or @Worker, scope: "workspace"One process per machine and project rootOne per hostname and project root
@Worker, scope: "process"Every instance runs itEvery instance runs it
@Workflow({ trigger: "schedule" })One process per machine and project root starts the runsOne instance starts each scheduled run
  • The lease is per server name. Its key is made from info.name and the duty's, worker's or workflow's name: frontmcp:cluster:duty:<info.name>:<name>, frontmcp:cluster:worker:… and frontmcp:cluster:schedule:…. Instances share it when they have the same info.name on the same Redis and Redis database.
  • Every instance contends, one holds. The holder renews the lease every third of its lifetime, and the others try to take it at the same pace. /readyz shows who holds what: duty:<name> has "holdsLease": true in one instance, and worker:<name> has "state": "running" in one and "standby" in the others. All of them are healthy (health checks).
  • A holder that shuts down hands over. On SIGTERM it aborts the run's signal, waits for the run, and releases the lease, so another instance takes over at its next check: during a rolling deploy the work moves with it. A holder that crashed is taken over once its lease expires, within the lease's lifetime plus a third of it. The lifetime is leaseMs: three intervals between 3 and 60 seconds for an interval duty, 60 seconds for a cron duty and for a scheduled workflow, 15 seconds for a worker.
  • One holder at a time is not exactly once. A process paused longer than its lease finds it gone when it wakes, while another already runs. A cron duty takes each scheduled time before it runs, so a holder that dies during the run loses that run. A scheduled workflow's run is recovered instead, when the instances share a job store.
  • A missed schedule is caught up once. An instance that gets the lease of a cron duty or a scheduled workflow after a scheduled time passed runs once at once, however many times were missed, then continues on schedule.
  • Events are published once. A duty or a leased worker that publishes an event does so from the instance that holds it. A "process" worker publishes from every instance.
  • A "cluster" cron duty reads the schedule by the clock of the instance that holds it. Keep the instances' clocks in sync.

This was checked with FrontMCP 1.12.0-rc.1: two and three processes of a Node server on one machine, sharing Valkey 8 in Docker for the "cluster" leases and a SQLite file for the "machine" ones, with the holder killed and stopped with SIGTERM. No Kubernetes was used.

Machine ids

Each instance has an id. It's the nodeId of the sessions it creates, and the value of the header and cookie in distributed mode.

SourceWhen
setMachineIdOverride(id)Whenever your code has called it, over MACHINE_ID too. See below.
MACHINE_IDWhenever it's set.
HOSTNAME, else the operating system's host nameIn distributed mode. Kubernetes sets HOSTNAME to the pod's name.
A random id per processIn serverless mode.
A random id, new on every startOtherwise. FrontMCP's source mentions .frontmcp/machine-id, in the working folder outside production, and a file that MACHINE_ID_PATH names; starting the node build in its project folder wrote no such file.

Outside production on a non-distributed deployment, FrontMCP encrypts session ids with a key made from the machine id when MCP_SESSION_SECRET isn't set, so without MACHINE_ID the key changes on every start: after a restart, an old session id gets 404 invalid session id, Redis or not. Production requires the secret for sessions, so there the machine id only names the instance: sharing MACHINE_ID between instances doesn't share anything else.

Your code reads the id with getMachineId() from @frontmcp/utils, the function FrontMCP itself calls, and replaces it for the whole process with setMachineIdOverride(id); setMachineIdOverride(undefined) goes back to the sources above. Call it before the server starts. The header follows a later call, but the heartbeat doesn't: in distributed mode with redis, an instance started as help-desk-7b8f9, then given desk-a, kept mcp:ha:heartbeat:help-desk-7b8f9 while its responses said X-FrontMCP-Machine-Id: desk-a.

main.ts
import "reflect-metadata";
import { getMachineId, setMachineIdOverride } from "@frontmcp/utils";

setMachineIdOverride(`desk-${process.env.REGION}-${process.pid}`); // before @FrontMcp starts the server

// later, anywhere in the process
console.log(getMachineId()); // desk-eu-west-1-4182

@frontmcp/utils is installed with @frontmcp/sdk; add it to your own dependencies, at the same version, to import it. create({ machineId }) sets the same override for one in-process server, in CommonJS and ES module projects alike. Changed in 1.9.5: before, in a CommonJS project it set the override on a copy of @frontmcp/utils that the server never read, so the id stayed as it was. The override was checked with FrontMCP 1.9.4 on Node, against distributed mode's header and Redis heartbeat.

Caveats

  • In the default mode, sessions are shared, streams aren't: a client that holds an event stream open, like the older SSE transport, holds it with one instance. Give such clients affinity at the load balancer.
  • An instance serves a session id only when it decrypts under its own MCP_SESSION_SECRET. An id made under another secret gets 404 invalid session id, and the log says mcp-session-id is not a session this server verified: give every instance the same secret. After you rotate it, a client with an old id gets that 404 once and starts a new session. (In 1.8.5, a public server served such an id from Redis.)
  • In the default mode, a DELETE of a session ends it on the instance that receives it and deletes it from Redis; a later request there gets 404 Session not found. Another instance that has the session in memory, because it created the session or served it before, checks with Redis (EXISTS) on each of the session's requests that the session is still stored, and drops it when it isn't: its next request got 404 {"code":-32001,"message":"session expired"}, and its log said The stored session is gone — dropping its transport here. A session whose key expired gets the same 404, on the instance that holds it too (how long sessions last). (Changed in 1.9.3: in 1.9.2 such an instance kept serving a deleted or expired session, and answered its next request 200.) In distributed mode the DELETE is relayed to the holder, which answers 204 with its own X-FrontMCP-Machine-Id and deletes the stored session, and the session is gone everywhere.
  • That check doesn't make a session depend on Redis. When Redis refuses connections, or doesn't answer within transport.persistence.sessionCheckTimeoutMs (500 ms by default), the instance serves the session from memory, logs [TransportService] Could not confirm the session is still stored — serving it here, and checks again on the session's next request. With the Redis container paused, which keeps the connection open and answers nothing, each call on a session the instance held answered 200 after half a second, with The session store did not answer within 500 ms in the log; with sessionCheckTimeoutMs: 2000, after two seconds. A request for a session the instance doesn't hold has no copy to fall back on, and waits for Redis: it got no answer while Redis was paused, and was answered once it came back. (Changed in 1.9.4: in 1.9.3 a call on a session the instance held waited for a paused Redis too, and got no answer in three minutes.) See when Redis can't be reached.
  • This was checked with FrontMCP 1.9.4: two instances of a Node build on one machine sharing Valkey 8 in Docker, with a DELETE on one, and Redis stopped and paused, and two of the distributed build sharing it: relayed calls, a relayed DELETE and a holder stopped with SIGTERM. The crash was seen with 1.9.2. Two Node instances behind nginx in Docker Compose, and a shorter heartbeat from deployments[].ha, were last run with 1.9.1. No Kubernetes was used, and no load balancer routed by the cookie or the header.
  • A question to the user waits on the instance that asked. For clients before 2026-07-28, a tool's this.elicit() waits on the instance it runs on, and the answer reaches it from another instance through Redis publish and subscribe, encrypted when MCP_ELICITATION_SECRET (or MCP_SESSION_SECRET) is set, so every instance needs the same secret: see Several instances and encryption.

Usage

Running two instances that share sessions

The server has redis set from the environment, as in Redis. Start two instances with the same secret, on two ports:

export MCP_SESSION_SECRET="$(openssl rand -hex 32)"
MACHINE_ID=desk-a PORT=4001 REDIS_URL=redis://127.0.0.1:6379 node dist/node/help-desk.bundle.js &
MACHINE_ID=desk-b PORT=4002 REDIS_URL=redis://127.0.0.1:6379 node dist/node/help-desk.bundle.js &

A client on MCP 2025-06-18 sends initialize to port 4001, and gets an Mcp-Session-Id. It sends its next tools/call, with that id, to port 4002, which has never seen it: the call succeeds, and the second instance logs:

[TransportService] Recreating transport from stored session
[StreamableHttpAdapter] Marked transport as pre-initialized for session recreation

Without redis, the second instance answers 404 session not initialized, and the client has to initialize again. In a container, add FRONTMCP_BIND_ADDRESS=all so the load balancer can reach each instance.

Checking that replicas serve the same tools

/readyz has a hash of the tool names, the same on every instance built from the same code:

curl -s http://127.0.0.1:4001/readyz | jq -r .catalog.toolsHash
curl -s http://127.0.0.1:4002/readyz | jq -r .catalog.toolsHash
<the same 64 hex characters>
<the same 64 hex characters>

During a rolling deploy, two hashes mean two versions are serving. It covers tool names only, not their schemas.

Running a report once among the instances

Give the duty scope: "cluster" and the server a redis, the same on every instance:

main.ts
@Provider()
@Duty({ name: "weekday-report", cron: "0 9 * * 1-5", timezone: "Europe/Berlin", scope: "cluster" })
class WeekdayReport {
  async run({ signal }: DutyRunContext) { /* … */ }
}

@FrontMcp({
  info: { name: "help-desk", version: "1.0.0" },
  apps: [HelpDesk], // WeekdayReport is in its providers
  redis: { url: process.env.REDIS_URL },
})
export default class Server {}

The first instance to start logs that it runs the duty, and the others that they wait:

Duty "weekday-report" runs in this process on cron "0 9 * * 1-5" (Europe/Berlin)
Duty "weekday-report" already runs elsewhere (lease "help-desk:weekday-report"); this one takes it over if that one stops

Their /readyz says the same: {"duty:weekday-report":{"status":"healthy","details":{"holdsLease":true}}} in the first, "holdsLease":false in the others. With a cron of every three seconds and leaseMs: 3000, the second of two instances took the duty over three seconds after the first was killed, ran once for the scheduled time that was missed, and continued on schedule. The cron duty's default lease is 60 seconds, so a takeover after a crash comes within 80.

Routing by instance, in distributed mode without Redis

A load balancer that pins a client to an instance can use the cookie distributed mode sets on initialize:

FRONTMCP_DEPLOYMENT_MODE=distributed HOSTNAME=help-desk-7b8f9-abc12 node dist/node/help-desk.bundle.js
X-FrontMCP-Machine-Id: help-desk-7b8f9-abc12
Set-Cookie: __frontmcp_node=help-desk-7b8f9-abc12; Path=/; Max-Age=86400; HttpOnly; SameSite=Strict

Without redis, sessions stay in memory, so this only helps clients that return to the same instance, and one that stops takes its sessions with it. With redis, any instance serves a session, by relaying it to the instance that holds it (above), and the cookie saves that relay.


Troubleshooting

A request answers 500, and the log says RemoteTransporter.handleRequest() is not implemented

Distributed mode with redis before 1.9, and the request's Mcp-Session-Id belongs to a session another instance created. Upgrade: since 1.9 the request is relayed to that instance. See distributed mode.

503, This MCP session is served by another instance of the server, which did not answer the relayed request

Distributed mode: the instance that holds the session didn't answer the relay, most often because it died without shutting down, and its heartbeat hasn't expired yet. Retry after Retry-After seconds; once the heartbeat expires, the instance that gets the request takes the session over. The log says Relay to session owner failed. If the holder is running, check that it reaches the same Redis. See how a session's requests are served.

TypeError: socket.destroySoon is not a function, and the instance exits

The instance served a request relayed from another instance, in distributed mode with redis, on FrontMCP 1.9.1 or 1.9.2. Upgrade to 1.9.3, where it keeps running. On those versions, route each session's requests to the instance that holds it, by the __frontmcp_node cookie or the X-FrontMCP-Machine-Id header, so that nothing is relayed. See how a session's requests are served.

[HA] Failed to start HA manager — running without HA, this.redis.hset is not a function or [HA] Orphan scan failed

Distributed mode with redis before 1.8.7. Upgrade: it starts and opens sessions from 1.8.7 on.

A duty or a worker runs on every instance

It has scope: "machine". On one machine that gives one holder, but with redis the lease is per hostname, and each container or pod has its own. Use scope: "cluster". A "cluster" duty that still runs everywhere has instances with different info.names, or instances that reach different Redis servers or databases. See background work across instances.

… has scope 'cluster', which keeps one lease for every machine in Redis, and none is configured

A duty or worker with scope: "cluster" on a server without a top-level redis: startup fails with ClusterScopeNeedsRedisError. Set redis, the same on every instance, or use scope: "machine".

Another instance answers 404 session not initialized

It can read the session id but can't find the session: redis isn't set on every instance, points at another Redis or database, uses another keyPrefix, or couldn't be reached when that instance started. Check each instance's startup log for Session store connection validated successfully.

404 invalid session id from an instance that has Redis

The id wasn't made under this instance's MCP_SESSION_SECRET: the instances have different secrets, or the secret was rotated after the client started its session. The client starts a new one. Give every instance the same secret.

signature verification failed on some requests

The instances have different JWT_SECRETs. Give them the same one. See running several instances.

Report a docs issue · Report a security concern privately