An MCP server I run in production behind FrankenPHP started answering tool calls with other tool calls' results. Not every time. An agent that fired six calls at once got most of them right, a few came back as an empty 202 Accepted, and a few carried the answer to a different request id. Thirty rounds of six parallel calls on one session gave 137 correct answers, 21 foreign ones and 22 empty under FrankenPHP worker mode, and 150, 17 and 13 under php-fpm. Nothing in the logs. The same calls one at a time never failed.

The server ran symfony/mcp-bundle 0.14.1 on mcp/sdk 0.8.1, the official PHP SDK for the Model Context Protocol. The cause is a lost-update race on the session that the SDK kept for every Streamable HTTP client, and the fix upstream took three pull requests and two releases. This article walks through the race with the 0.8.1 code, reproduces it with ten parallel calls against php -S, shows what 0.9.0 and 0.10.0 changed, and explains why the MCP server in mattleads/agent-publishing-bundle keeps no session at all.

Prerequisites

  • PHP 8.4.22, with PHP_CLI_SERVER_WORKERS=8 php -S as the multi-process server for the reproduction. The race needs several workers and a session store they share; php-fpm and FrankenPHP worker mode behave the same.
  • mcp/sdk 0.8.1 (released 29 August 2026), 0.9.0 (18 October 2026) and 0.10.0 (10 November 2026), each cloned at its tag with composer install for the dev dependencies, which include nyholm/psr7 and laminas/laminas-httphandlerrunner.
  • symfony/mcp-bundle 0.14.1, which requires mcp/sdk ^0.8.1, and 0.15.0, which requires ^0.9 and adds a session.lock option.
  • mattleads/agent-publishing-bundle 0.3.1 for the stateless server, with its demo app from the previous article.

1. What a Streamable HTTP session is

The Streamable HTTP transport in the MCP specification (revision 2025-06-18) is one HTTP endpoint. Every client message is a POST. A notification or a response gets 202 Accepted with no body. A request gets either Content-Type: application/json with one JSON-RPC object, or an SSE stream that eventually carries the response. The client may also open a GET for server-initiated messages.

Sessions are optional on the server side. The spec says a server "MAY assign a session ID at initialization time" through an Mcp-Session-Id response header. If it does, the client must send that header on every later request, the server may end the session whenever it likes and answer 404, and a client that sees 404 starts over with a new initialize. A server that never sends the header has no session, and the client has nothing to carry.

What a session is for is the other direction of the conversation. If the server wants to ask the client something (an elicitation, a sampling request), push a notifications/resources/updated, or let the client resume a stream after a disconnect, it needs somewhere to park those messages between HTTP requests. That somewhere is the session, keyed by the id in the header. A server that only answers tools/call has nothing to park.

2. What mcp/sdk 0.8.1 kept in the session

The 0.8.1 server parks everything there, including the answer to the request it is currently handling. The relevant pieces are in Mcp\Server\Protocol and Mcp\Server\Transport\StreamableHttpTransport.

A POST arrives, Protocol::doProcessInput() loads the session named by the header, handles each message, and saves the session once at the end:

// mcp/sdk 0.8.1, src/Server/Protocol.php, doProcessInput() $session = $this->resolveSession($transport, $sessionId, $messages); // ... foreach ($messages as $message) { // ... handleRequest() / handleResponse() / handleNotification() } $session->save(); 

When a tool handler returns, handleRequest() calls sendResponse(). With a session present the response is not sent. It is queued inside the session under the key _mcp.outgoing_queue:

// src/Server/Protocol.php, 0.8.1 private const SESSION_OUTGOING_QUEUE = '_mcp.outgoing_queue'; private function sendResponse(TransportInterface $transport, Response|Error $response, ?SessionInterface $session, array $context = []): void { if (null === $session) { // ... json_encode and $transport->send($encoded, $context); } else { $this->queueOutgoing($response, ['type' => 'response'], $session); } } private function queueOutgoing(Request|Notification|Response|Error $message, array $context, SessionInterface $session): void { // ... $queue = $session->get(self::SESSION_OUTGOING_QUEUE, []); $queue[] = ['message' => $encoded, 'context' => $context]; $session->set(self::SESSION_OUTGOING_QUEUE, $queue); } 

The transport then builds the HTTP response by reading the queue back, through Protocol::consumeOutgoingMessages(), which loads the session again, takes the whole queue, writes an empty queue and saves:

// src/Server/Protocol.php, 0.8.1 public function consumeOutgoingMessages(Uuid $sessionId): array { $session = $this->sessionManager->createWithId($sessionId); $queue = $session->get(self::SESSION_OUTGOING_QUEUE, []); $session->set(self::SESSION_OUTGOING_QUEUE, []); $session->save(); return $queue; } 
// src/Server/Transport/StreamableHttpTransport.php, 0.8.1, createJsonResponse() $outgoingMessages = $this->getOutgoingMessages($this->sessionId); if (empty($outgoingMessages)) { return $this->responseFactory->createResponse(202) ->withHeader('Content-Type', 'application/json'); } $messages = array_column($outgoingMessages, 'message'); $responseBody = 1 === \count($messages) ? $messages[0] : '['.implode(',', $messages).']'; 

Two more details complete the picture. Session::readData() reads the store once and caches the array for the life of the object, so the session a request works on is a snapshot taken when it was first touched. And Session::save() in 0.8.1 is json_encode($this->readData()) written back whole, every key, not only the ones this request changed.

With one worker and one request at a time this is fine. The queue is read, appended, saved, read, emptied, saved, and the POST that carried the request gets its response. The design assumes the requests of a session are sequential. Nothing in PHP's deployment model guarantees that.

3. The race, step by step

Take two workers, A and B, each handling one tools/call of the same session, with a shared FileSessionStore. Each step reads or writes the whole session blob.

  1. A loads the session. Queue: empty.
  2. B loads the session. Queue: empty.
  3. A's handler returns. A appends response RA to its in-memory queue and saves. Store: [RA].
  4. B's handler returns. B appends RB to its own snapshot, which never saw RA, and saves. Store: [RB]. RA is gone. That is the lost update.
  5. A's transport calls consumeOutgoingMessages(). It loads the store fresh, takes [RB], writes []. A's HTTP response carries B's answer. That is the foreign answer.
  6. B's transport does the same. The queue is empty, so B answers 202 with no body. That is the empty response.

Shift the timing a little and step 4 happens after step 5: B saves [RB] after A emptied the queue, then B's own consume takes it. Both correct, by luck. Shift it the other way and A's consume runs after both saves of a three-worker race: it takes [RB, RC] and the implode branch sends a JSON array, which a spec-compliant client rejects, because the spec requires "a single JSON-RPC" object in a JSON response. The TypeScript client reports the lost ones as MCP error -32001: Request timed out, which is what the n8n and LangChain users in the upstream issues saw.

There is a fourth outcome that is a race on the file rather than on the queue. FileSessionStore::write() in 0.8.1 writes to one temporary file per session, <id>.tmp, and renames it into place. Two workers saving the same session at once share that temporary file, and in the reproduction below some requests died with JsonException: Syntax error thrown from Session::readData(): the worker read a session document that did not parse. That outcome shows up in the server log as a fatal error. The other three do not show up anywhere.

4. Reproducing it

The server is short. One tool, a file session store, the SDK's Streamable HTTP transport over nyholm/psr7:

<?php // server.php, run with: PHP_CLI_SERVER_WORKERS=8 php -S 127.0.0.1:8768 server.php require getenv('SDK_DIR').'/vendor/autoload.php'; use Http\Discovery\Psr17Factory; use Laminas\HttpHandlerRunner\Emitter\SapiEmitter; use Mcp\Server; use Mcp\Server\Session\FileSessionStore; use Mcp\Server\Transport\StreamableHttpTransport; use Psr\Log\NullLogger; final class Tools { public static function listSections(): array { return ['sections' => [['name' => 'blog']]]; } } $server = Server::builder() ->setServerInfo('race-test', '1.0.0') ->setLogger(new NullLogger()) ->addTool([Tools::class, 'listSections'], 'list_sections') ->setSession(new FileSessionStore(getenv('SESSION_DIR'))) ->build(); $result = $server->run(new StreamableHttpTransport( (new Psr17Factory())->createServerRequestFromGlobals(), logger: new NullLogger(), )); (new SapiEmitter())->emit($result); 

setSession() matters. Without it the 0.8.1 builder falls back to InMemorySessionStore, which each worker process keeps for itself, so the second request of a session lands on a worker that has never heard of it and gets 404. That is a different bug, and the reason every production deployment uses a file or cache store, which is exactly what makes the race possible.

The client is a Python script. It sends initialize, keeps the Mcp-Session-Id, sends notifications/initialized, then runs rounds of ten tools/call requests in ten threads, each with its own request id, and sorts the answers into five bins: a single object with the right id, a single object with another id, a JSON array, an empty 202, and anything else.

One round of ten against 0.8.1 looked like this. Request c1 got its own answer. c0 got c7's, c3 and c7 both got c9's, c4, c8 and c9 got 202 with no body, and c2, c5 and c6 got an HTML fatal error page from the torn session file. One right answer in ten.

Over more rounds the numbers move with timing, so here is one run of each configuration rather than an average:

Server, 8 workers, 10 parallel calls per round Rounds Own answer Foreign answer JSON array Empty 202 Fatal
mcp/sdk 0.8.1, FileSessionStore 30 3 280 2 4 11
mcp/sdk 0.8.1, FileSessionStore 100 46 897 9 43 5
mcp/sdk 0.9.0, FileSessionStore 30 300 0 0 0 0
mcp/sdk 0.9.0, FileSessionStore 100 1,000 0 0 0 0
mcp/sdk 0.9.0, FileSessionStore + FileSessionLock 30 300 0 0 0 0
mcp/sdk 0.9.0, FileSessionStore + FileSessionLock 100 1,000 0 0 0 0

The author of the upstream fix measured the same shape with a different tool, chr-hertel/mcp-concurrency-test, on FrankenPHP worker mode: 100 rounds of 10 calls, 0 rounds fully correct, 328 foreign and 185 lost before the fix, 100 rounds correct after. His production figure on 0.8.1 through symfony/mcp-bundle was "1 call in 10 got a 202".

The lock rows are correct and slow. With FileSessionLock the 100-round run took 8.9 seconds against 0.7 seconds without it, because the lock does what it says: the ten calls of a round run one after another. We come back to that trade-off in section 7.

5. What 0.9.0 changed

The fix landed in three pull requests between 6 and 14 October 2026, all in 0.9.0.

PR #535 took responses out of the session. Protocol::sendResponse() now hands every response to TransportInterface::send() with the session id in the context, and createJsonResponse() answers the POST with the responses of the requests that POST carried. The outgoing queue still exists, but only for server-initiated requests and notifications. The release note calls it a BC break for custom transports: send() now receives every response of a handler, and a batch gets several. A POST of only notifications or responses is answered 202 and the queued messages stay where they are. The same PR fixed the JSON array branch for the messages that do still go through the queue: a request whose session has queued notifications is answered as SSE, queued messages first, instead of as an array.

PR #572 made Session::save() write only the keys the request changed, applied onto a fresh read of the store, so two requests that touch different keys of one session no longer overwrite each other. The 0.9.0 save() also refuses to resurrect a session that was deleted while the request ran. A read-modify-write of the same key by two requests, such as a counter kept in the session by a tool handler, is still a race. That is what the lock is for.

PR #584 added the opt-in per-session lock. Builder::setSessionLock() takes a SessionLockInterface. FileSessionLock uses flock() on one file per session next to FileSessionStore, for the workers of one machine. SymfonyLockSessionLock wraps a symfony/lock store, for sessions shared across machines through Redis or a database. Protocol takes the lock before the session is read and releases it after the save, releases it while a handler is suspended waiting for the client, and takes it briefly on each turn of the SSE loop. A request that cannot get the lock within the timeout, 30 seconds by default, is answered 503 with a JSON-RPC error under its own id.

$server = Server::builder() ->setSession(new FileSessionStore(__DIR__.'/sessions')) ->setSessionLock(new FileSessionLock(__DIR__.'/sessions')) ->build(); 

In symfony/mcp-bundle 0.15.0 the same thing is configuration: session.lock.enabled, session.lock.factory for a LockFactory service when the store is not file, session.lock.timeout (30 seconds) and session.lock.ttl (300 seconds). The bundle refuses a lock without a factory on any store but file.

For the production server the upgrade was symfony/mcp-bundle 0.14.1 to 0.15.0 and mcp/sdk 0.8.1 to 0.9.0, nothing else. The same 30 rounds of six parallel calls went from 175 correct, 2 foreign and 3 empty on the last 0.8.1 build to 180 correct. The existing connector session kept working across the deploy. Three BC breaks in 0.9.0 are worth checking before you do the same: OAuthRequestMetaMiddleware is gone and the validated token comes from RequestContext::getAccessToken(), ids of requests the server sends to the client are UUIDs instead of integers, and TransportInterface::send() has the new semantics above if you wrote your own transport. The lock stayed off: with responses out of the session and nothing else written per call, there was nothing left for it to protect.

6. What 0.10.0 changed, and what the spec changed

0.10.0 went a step further and made the no-session case the default. From the release notes: handshake-era servers over Streamable HTTP "run without sessions unless Builder::setSession() is called". initialize is answered without Mcp-Session-Id, later requests run on an ephemeral session that is never stored, and GET and DELETE get 405. The old fallback to InMemorySessionStore, the one that produced 404s under any multi-process server, is gone. A server that wants sessions declares a store, and with it accepts the race surface and, if it needs to, the lock.

Two other 0.10.0 changes bear on this article. JSON-RPC batches are refused with -32600 and HTTP 400 on every protocol revision, including 2025-03-26, which required batch support. And PHP 8.2 is the minimum.

The protocol moved the same way. MCP revision 2026-07-28 removed protocol-level sessions and the Mcp-Session-Id header from the Streamable HTTP transport (SEP-2567), and removed the initialize handshake (SEP-2575). Every request carries its protocol version and client capabilities in _meta, and a server that needs state across calls hands the client an explicit handle as an ordinary tool argument. The SDK's release notes call the two designs the handshake era and the modern era, and 0.8.1 already served both on one endpoint. The design that caused the race is the one the protocol is retiring.

7. When you still want a session

Sessionless is not free. A session is the only place a server can keep things the protocol expects it to keep between HTTP requests on the handshake-era revisions that most clients still speak:

  • Requests from the server to the client. Elicitation and sampling suspend the handler in a fiber, send a request over the stream, and resume when the client's answer arrives in a later POST. The pending request and the fiber's state live in the session.
  • Server-initiated notifications. notifications/resources/updated for a subscription, or notifications/tools/list_changed, need a queue the GET stream can drain.
  • Resumable streams. A client that lost its SSE connection can send Last-Event-ID and expect the server to replay what it missed, which means the server stored it.

If your server does any of that, keep the session, and on 0.9.0 or later turn the lock on. The price is the one in the table: the calls of one session run one at a time, so a client that sends ten calls in parallel waits for the slowest chain of ten. For quick tools that is invisible. For tools that wait on an external API it adds up, and the modern-era design, state in an explicit handle rather than in a session, is the way out.

If your server does none of that, the session is pure liability. It costs a store, it costs a lock or a race, and it buys nothing.

8. A tools-only server with no session

mattleads/agent-publishing-bundle exposes its publishing tools over MCP so an agent can draft, lint and submit articles. The decision in the article that introduced it was to implement the protocol directly rather than depend on mcp/sdk while it was moving. The race is the other half of that decision. The server offers initialize, ping, tools/list and tools/call, acknowledges notifications, and that is the whole surface. No resources, no prompts, no server-initiated requests, so no session.

The transport is one Symfony controller:

// agent-publishing-bundle, src/Mcp/McpController.php public function endpoint(Request $request): Response { // ... $headers = ['MCP-Protocol-Version' => McpServer::negotiate($request->headers->get('MCP-Protocol-Version'))]; if ($request->isMethod('DELETE')) { return new Response('', Response::HTTP_NO_CONTENT, $headers); } if (!$request->isMethod('POST')) { return new JsonResponse(['error' => 'Send JSON-RPC messages with POST. This server does not open server-to-client streams.'], Response::HTTP_METHOD_NOT_ALLOWED, $headers + ['Allow' => 'POST, DELETE']); } // ... decode the body, resolve the API key from the Authorization header $batch = array_is_list($payload); $messages = $batch ? $payload : [$payload]; $responses = []; foreach ($messages as $message) { // ... $response = $this->server->handle($message, $key); if (null !== $response) { $responses[] = $response; } } if ([] === $responses) { return new Response('', Response::HTTP_ACCEPTED, $headers); } return new JsonResponse($batch ? $responses : $responses[0], Response::HTTP_OK, $headers); } 

Every response is computed from the request that carried it and returned in the same HTTP response. There is no queue, no store, no id to look up. initialize answers without Mcp-Session-Id, so the client has nothing to send back and nothing to lose. GET answers 405, which the spec allows for a server "that does not offer an SSE stream". DELETE answers 204, because ending a session that does not exist is a no-op. The identity that a session would otherwise carry, which client this is and what it may do, comes from the API key on every request, and tools/list is filtered by that key's scopes. The server negotiates the three handshake-era revisions, 2025-06-18, 2025-03-26 and 2024-11-05, and accepts a JSON array from a 2025-03-26 client because that revision required it, which is one place it is more lenient than mcp/sdk 0.10.0.

McpServer::handle() returns null for a message without an id, which is how a notification becomes a 202. A batch answers only its requests. The bundle's functional test, tests/Functional/McpTest.php, drives the handshake, the version echo, a notifications/initialized with its empty 202, scope-filtered tool lists for an agent key and an editor key, the full agent loop from list_sections to submit_article, tool errors as results with isError, protocol errors with JSON-RPC codes, a batch, the GET 405 and the DELETE 204.

The same race script, pointed at the demo app on 8 workers with initialize and 10 parallel tools/call list_sections per round:

Server, 8 workers, 10 parallel calls per round Rounds Own answer Foreign Array Empty 202 Fatal Time
agent-publishing-bundle 0.3.1 on Symfony 8.1, php -S 30 300 0 0 0 0 0.8 s
agent-publishing-bundle 0.3.1 on Symfony 8.1, php -S 100 1,000 0 0 0 0 2.6 s

Nothing is shared between the requests of a client, so there is nothing to race. The time is the Symfony kernel booting per request under php -S, not serialization.

The limitation is the one stated in the previous article: agents that need resources, prompts or server-to-client streams need a different server. For a publishing workflow, where the agent's job is to call tools and read their results, that has not come up.

Conclusion

Each pattern here maps to a decision you make once per server.

  • Tools only, no server-initiated messages. Do not keep a session. Answer each POST from its own request, authenticate every request on its own, and send no Mcp-Session-Id. That is what mcp/sdk 0.10.0 does by default, what MCP 2026-07-28 made the only option, and what agent-publishing-bundle does on every revision it serves.
  • Elicitation, sampling, subscriptions or resumable streams. Keep a session, use a store every worker can reach, and on mcp/sdk 0.9.0 or later turn on the per-session lock. Accept that one session's calls run in series.
  • Still on mcp/sdk 0.8.x behind php-fpm or FrankenPHP. Upgrade before anything else. The race is in every multi-process deployment, and the first symptom you will see is an agent reporting a timeout on a call your logs say succeeded.

If you are writing the server, test it the way agents use it: ten calls at once on one session, against several workers, counting whose answer came back.

Source Code: You can find the full implementation and follow the project's progress on GitHub: https://github.com/mattleads/agent-publishing-bundle

Let's Connect!

If you found this helpful or have questions about the implementation, I'd love to hear from you. Let's stay in touch and keep the conversation going across these platforms: