Skip to content

feat(mcp): record per-backend initialization failures in metrics - #2733

Open
sangkyoonnam wants to merge 1 commit into
theagentrouter:mainfrom
sangkyoonnam:fix/2724-mcp-backend-init-failure-metrics
Open

sangkyoonnam wants to merge 1 commit into
theagentrouter:mainfrom
sangkyoonnam:fix/2724-mcp-backend-init-failure-metrics

Conversation

@sangkyoonnam

@sangkyoonnam sangkyoonnam commented Sep 24, 2026 •

Copy link
Copy Markdown

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 TODO at 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 (handleServerDiscover in the modern path, and the request handlers): initializeSession now counts the failure in mcp.method.count with status=error and records its duration in mcp.request.duration with error.type, both with the mcp.backend attribute. The count is keyed by the phase the failure happened in, so a backend that answers initialize but rejects notifications/initialized is distinguishable from one that never initialized, and the error duration is measured from the request's startAt, 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 existing RecordMethodErrorCount and RecordRequestErrorDuration are used.

Tests: TestNewSession_PartialBackendFailure_RecordsMetrics (one backend fails initialize, the other succeeds; the session keeps the surviving backend and the metrics name the failed one), and TestInitializeSession_NotificationsInitializedFailure now asserts the failure is attributed to notifications/initialized with initialize still counted as success. Both fail without the mcpproxy.go change and pass with it. make precommit and make test pass.

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 RecordInitializationErrorDuration on mcp.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.

@sangkyoonnam
sangkyoonnam requested a review from a team as a code owner September 24, 2026 12:43
@netlify

netlify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for theagentrouter ready!

Name Link
🔨 Latest commit 5564754
🔍 Latest deploy log https://app.netlify.com/projects/theagentrouter/deploys/6ab6179f1d6c7600089e7670
😎 Deploy Preview https://deploy-preview-2733--theagentrouter.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@missBerg missBerg added enhancement New feature or request area/mcp MCP proxy, MCPRoute, and MCP spec conformance area/observability Metrics, tracing, logging, GenAI observability labels Sep 24, 2026
Signed-off-by: Sangkyoon Nam <sangkyoon.nam@namsang.co>
@sangkyoonnam
sangkyoonnam force-pushed the fix/2724-mcp-backend-init-failure-metrics branch from cdd178e to 5564754 Compare September 25, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/mcp MCP proxy, MCPRoute, and MCP spec conformance area/observability Metrics, tracing, logging, GenAI observability enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: record per-backend initialization failures in metrics

2 participants