feat(mcp): record per-backend initialization failures in metrics - #2733
Open
sangkyoonnam wants to merge 1 commit into
Open
sangkyoonnam wants to merge 1 commit into
sangkyoonnam wants to merge 1 commit into
Conversation
✅ Deploy Preview for theagentrouter ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Signed-off-by: Sangkyoon Nam <sangkyoon.nam@namsang.co>
sangkyoonnam
force-pushed
the
fix/2724-mcp-backend-init-failure-metrics
branch
from
September 25, 2026 06:41
cdd178e to
5564754
Compare
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.
Description
When a composite MCP session initializes its backends in parallel and one of them fails, the client session still succeeds through the others. No metric recorded the failure; it was only logged. The backend-scoped initialization duration, method count and capabilities are only written on the success path, and the code carried a
TODOat the failure branch. A dashboard could show a healthy initialization while one backend's tools had silently dropped out of the catalog.This records the failure against the backend that dropped, the same way a failed request is recorded elsewhere (
handleServerDiscoverin the modern path, and the request handlers):initializeSessionnow counts the failure inmcp.method.countwithstatus=errorand records its duration inmcp.request.durationwitherror.type, both with themcp.backendattribute. The count is keyed by the phase the failure happened in, so a backend that answersinitializebut rejectsnotifications/initializedis distinguishable from one that never initialized, and the error duration is measured from the request'sstartAt, the same boundary the request handlers use, not from the start of this backend's initialization; the modern discover and list fan-out paths time each backend separately. No new metric or interface method; the existingRecordMethodErrorCountandRecordRequestErrorDurationare used.Tests:
TestNewSession_PartialBackendFailure_RecordsMetrics(one backend failsinitialize, the other succeeds; the session keeps the surviving backend and the metrics name the failed one), andTestInitializeSession_NotificationsInitializedFailurenow asserts the failure is attributed tonotifications/initializedwithinitializestill counted as success. Both fail without themcpproxy.gochange and pass with it.make precommitandmake testpass.Per the generative AI policy: this change was developed with AI assistance (Claude Code). I have reviewed it, understand it, and take full ownership of the code, tests, and this description.
Related Issues/PRs (if applicable)
Fixes #2724
Special notes for reviewers (if applicable)
I first added a separate
RecordInitializationErrorDurationonmcp.initialization.duration, then dropped it: the modern discover path and the request handlers already record failures as method count plus request error duration, so this follows that. #2725 (notification stream lifecycle metrics) is left for a separate change.