fix(mcp): make tools/list resilient to an empty registry#8371
Open
soyuka wants to merge 2 commits into
Open
Conversation
tools/list reads from the SDK registry, which is populated once, when mcp.server is built. Under a persistent runtime (e.g. FrankenPHP worker mode) that single build can capture an empty registry and stay empty for the whole process, so tools/list returns [] while tools/call keeps working through the request-time Handler. Add a ListHandler (tagged mcp.request_handler, so it precedes the SDK's registry-backed list handlers) that loads API Platform elements into the registry on first use and reads back through the shared registry, so runtime registrations and registry decorators are preserved. Refs api-platform#8370
ffedb71 to
5544a15
Compare
soyuka
commented
Jul 1, 2026
Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reported in #8370: under FrankenPHP worker mode, MCP
tools/listreturns an empty array whiletools/callkeeps working.tools/listreads from the SDK registry, which is populated once, when the sharedmcp.serverservice is built (Builder::build()runs all loaders into the sharedmcp.registry). Under a persistent runtime the kernel boots once, so that build happens once — and if it runs while the API Platform metadata is not yet available (e.g. a cold cache pool during worker warmup), the registry captures an empty state and stays empty for the whole process.tools/callis unaffected because the request-timeHandler(taggedmcp.request_handler) resolves operations from resource metadata directly, independent of the registry.tools/listhad no equivalent request-time path — hence the asymmetry.Fix
Add
ApiPlatform\Mcp\Server\ListHandler, taggedmcp.request_handlerso it precedes the SDK's registry-backed list handlers. On first use it loads the API Platform elements into the registry (idempotent, once per process), then reads back through the sharedmcp.registry— so:Covered by unit tests, including a case asserting runtime-registered tools stay visible and a case asserting the loader runs once.