AlgoViz

Local servers, gateways and remote replicas

medium 6 min

A host may run a local server over stdio or call remote peers over Streamable HTTP.

Video lesson · Chapter 1 of 4

The second lookup lands on another worker

0:00 / 3:51

Theory

Read or listen first. About 2 min.

What it is

A host may run a local server over stdio or call remote peers over Streamable HTTP. A local process inherits the permissions granted by its launcher. A remote call crosses network, identity and application boundaries. July 2026 requests expose routing information at the HTTP layer and carry versioned protocol context. Gateways can meter by method or tool while the destination validates the operation.

Why it exists

Keep downstream credentials and application state scoped independently of whichever replica serves the call. Distinct servers may both expose a tool called lookup. Associate the result with the intended server, request and tenant before it can enter a model context. When a request times out after dispatch, reconcile the effect before trying a state-changing operation again.

Route a read across two stateless replicas

Service selection → HTTP gateway (scoped request). HTTP gateway → Service replica (route to replica B). Service replica → Business ledger (read item revision). Service replica → Service selection (correlated result)
Service selection → HTTP gateway (scoped request). HTTP gateway → Service replica (route to replica B). Service replica → Business ledger (read item revision). Service replica → Service selection (correlated result)

Inside this chapter

Chapter sources
Local stdio boundaries
A subprocess exchanges protocol messages over standard input and output. Put diagnostic logs on stderr and allow only the file and environment access needed for the job. Process locality alone does not establish caller permission.

With stdio, the host starts the server as a child process and exchanges messages over its standard input and output. The process inherits whatever the launcher grants: environment variables, file system reach and user permissions. That makes the launch configuration the security boundary, so pass only the directories and secrets the job needs. Being local proves where the server runs, not that the person behind the request is allowed a given action.

Example. A local manual reader gets a documents directory and has no need for purchasing credentials.

A local server gets only what its launcher hands it

Anything printed to stdout that is not a protocol message corrupts the stream, so logs go to stderr.
Gateway routing
For Streamable HTTP the July specification defines method and applicable name headers for routing. Validate the protocol request at the receiving boundary and apply policy using authenticated identity. Treat routing labels as descriptions of the request.

Exposing the method and tool name at the HTTP layer lets a gateway route, rate-limit and meter without parsing every body. Those headers are claims made by the client, so the receiving service must validate the actual protocol message and check that the headers match it. Authorisation always uses the authenticated identity, never a routing label.

Example. A gateway meters catalog reads separately from reservations. The reservation service still checks buyer and warehouse at execution.

Route on headers, decide on the body

Headers describe the request for routing and metering. The destination still enforces the rules.
Multiple servers and credentials
Namespace capabilities and results by server identity and principal. A shared host can consult different servers without sharing all credentials or returning one server’s results to the wrong call.

Tool names are only unique within one server, so a host that merges catalogues needs its own namespacing. Each client should hold just the credential for its server. Tag every result with the server, request and tenant it came from before it enters the model context, otherwise a support answer could be presented as inventory data, or one customer's record could appear in another's conversation.

Example. Both inventory and support expose lookup. A support credential cannot read the inventory store merely because the method names match.

Same tool name, separate worlds

Namespace tools as inventory.lookup and support.lookup inside the host so results cannot cross.
Replica independence
Route a later request to a different instance using the current protocol context. Keep durable business state and deduplication records where each authorized replica can resolve them. Timeouts remain ambiguous about committed effects.

Stateless protocol handling lets any replica serve any request, but the business still has state: orders, holds, deduplication records. Keep them in storage every authorised replica can read. When a call times out after dispatch, the only safe next step for a state-changing operation is to look up what was recorded, then decide whether to retry.

Example. Replica A records an order before its connection closes. B consults the business record before considering a retry.

Another example. A payment tool times out after the provider charged the card. Before retrying, the service queries its payment record by operation key, finds the successful charge and returns it, so the customer is billed once.

A retry that checks before acting
  1. 1Replica A records O5order written to the ledger
  2. 2Connection closesclient never sees the reply
  3. 3Retry routed to Bsame operation key
  4. 4B reads the ledgerO5 already exists
  5. 5Return existing O5no second order

A timeout says the reply was lost, not whether the effect happened.

Choosing stdio or Streamable HTTP
Use stdio for a server that runs on the same machine as the host for one user, such as a local file reader. Use Streamable HTTP for a shared remote service that many hosts reach over the network, with its own authentication, scaling and operations.

The transport choice determines where trust is decided. Locally, the operating system and launch settings limit damage. Remotely, every request crosses a network and must prove who it is for. A server can support both, but the authorisation design should be written for the remote case.

Example. A developer's local manual reader runs over stdio. The company inventory service runs over Streamable HTTP behind a gateway with several replicas.

Two transports, two kinds of boundary

AspectstdioStreamable HTTP
Where it runschild process of the hostremote service, often replicated
Who it servesone host, one usermany hosts and users
Main controllaunch config: files, env, permissionsauthentication and per-request authorisation
Scalingone processgateways and replicas
Typical riskover-broad local accessconfused identities across tenants
November 2025 protocol notes

Route two identically named tools to different servers

A host may connect to both local subprocesses and remote HTTP servers. Each connection has its own protocol lifecycle, capabilities and authority. A gateway may add another boundary between a server and a downstream business API.

Trace the destination and credentials associated with one call. Similar names, reconnects or a shared host must not allow results, permissions or pending operations to leak across server boundaries.

Local Integration Patterns
A local stdio server exchanges protocol messages on standard input and output. Send diagnostic logs to stderr so they do not corrupt the message stream. The server runs with the process privileges it receives; local placement is not an authorization policy. Write a diagnostic line to stderr and one protocol response to stdout. The client should parse only the response as a protocol message.
External API Gateways
A gateway can translate a tool invocation into a narrowly scoped upstream API operation. Validate both the requesting principal and the requested resource. Distinguish an upstream timeout, access denial and successful empty response. Preserve request identity when safely retrying idempotent work. The downstream catalog returns an empty authorized result. Preserve that outcome instead of converting it to a gateway timeout.
The Multi-Server Mesh
A host can connect to several MCP servers through distinct clients. Resolve naming collisions and keep each server’s credentials, capabilities and results scoped to its connection. A result from one server is evidence, not an instruction to disclose data to another server. Two servers both advertise lookup. Bind one to catalog and one to orders, and check the selected connection before dispatch.
Remote Protocol Engineering
Streamable HTTP supports remote MCP messaging over HTTP, with optional event streams as specified by the negotiated version. Handle lifecycle, reconnection, cancellation and correlation explicitly. A network reconnect does not by itself establish that the last application operation failed. A remote stream closes immediately after submitting a write. Inspect the operation record and transport contract before deciding whether it is safe to retry.
Compare both protocol walkthroughs

How it works

Step through the idea, or press Play.

Step 1 of 4

Service selection. Choose inventory lookup

Understand it

Worked example

Route a read across two stateless replicas

  1. 1

    Choose inventory lookup

    The host namespaces the selected tool to the inventory server and uses the proper buyer identity.

  2. 2

    Route the declared operation

    The gateway routes the request to a healthy inventory instance and applies its own traffic limits.

  3. 3

    Retrieve the authorized item

    B processes the request without an initialization session belonging to A. It enforces the resource check.

  4. 4

    Return the recorded revision

    The business record supplies stock revision 18. The host receives a result associated with this specific inventory request.

Follow the handoffs

Keep downstream credentials and application state scoped independently of whichever replica serves the call. Distinct servers may both expose a tool called lookup. Associate the result with the intended server, request and tenant before it can enter a model context. When a request times out after dispatch, reconcile the effect before trying a state-changing operation again.

Who checks what on the way to stock revision 18

HopIdentity usedCheck performed
Buyer hostbuyer's sessiontool namespaced to inventory server
HTTP gatewayauthenticated callerrouting and traffic limits only
Replica Bbuyer's tokenresource check on the item
Business ledgerservice accountreturns revision 18 for this item
No hop relies on an initialisation session from replica A.

Summary

The whole topic in one minute.

Connection loss describes transport. The durable business record establishes whether the action committed.

Keep downstream credentials and application state scoped independently of whichever replica serves the call. Distinct servers may both expose a tool called lookup. Associate the result with the intended server, request and tenant before it can enter a model context. When a request times out after dispatch, reconcile the effect before trying a state-changing operation again.

Sources