Skip to content

fix(mcp-agent): surface initialization failures - #1960

Open
dvd233 wants to merge 1 commit into
bytedance:mainfrom
dvd233:fix/surface-mcp-init-errors
Open

fix(mcp-agent): surface initialization failures#1960
dvd233 wants to merge 1 commit into
bytedance:mainfrom
dvd233:fix/surface-mcp-init-errors

Conversation

@dvd233

@dvd233 dvd233 commented Aug 31, 2026

Copy link
Copy Markdown

Summary

  • emit a structured system error event when an MCP server cannot be constructed or initialized
  • continue initializing the remaining MCP servers so one unavailable integration does not abort the session
  • clean up partially initialized MCP clients and keep close() idempotent
  • add package-level Vitest coverage and test scripts for the failure path

Why

MCPAgent.initialize() previously logged an MCP connection failure and immediately rethrew it. That stopped the server loop, prevented later MCP servers from becoming available, and left the Web UI without an initialization event it could render.

The agent server already subscribes to the agent event stream before calling initialize(), persists non-streaming events, returns initialization events from session creation, and the Web UI already renders system events. Emitting the failure through that existing path therefore surfaces a clear error without adding a parallel UI-only error channel.

The regression test was red on main: initialization rejected on the first failed server instead of reaching the healthy server. It now verifies that:

  • the failed server produces a system event with level: "error"
  • later servers still initialize and register their tools
  • constructor failures follow the same visible degradation path
  • a partially initialized client is cleaned up exactly once, even if close() is called again

Related work

#1834 addresses a lower-level case where MCP tool-list errors can be swallowed. This PR handles the next layer: any propagated construction or initialization failure is surfaced to the event stream and isolated to that server. The changes are independent and merge cleanly.

Validation

Closes #1338

Checklist

  • Added or updated necessary tests.
  • Updated documentation (not needed; no public API surface changed).
  • Verified no breaking API changes; the behavior change is intentionally limited to per-server initialization failure handling.

@netlify

netlify Bot commented Aug 31, 2026

Copy link
Copy Markdown

Deploy Preview for tarko ready!

Name Link
🔨 Latest commit 3606d80
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/6a95a38750981e000863459d
😎 Deploy Preview https://deploy-preview-1960--tarko.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.

@netlify

netlify Bot commented Aug 31, 2026

Copy link
Copy Markdown

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit 3606d80
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/6a95a3871f8f380008fb725d
😎 Deploy Preview https://deploy-preview-1960--agent-tars-docs.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report]: MCP initialization errors not surfaced in Web UI

1 participant