Skip to content

Remote MCP toolset never reconnects after server closes idle SSE session cleanly #3063

Closed

Description

@aheritier

Summary

When a remote MCP server (observed with Notion, https://mcp.notion.com/sse) closes an idle SSE connection cleanly, the toolset supervisor marks the toolset Failed and never reconnects. Every later use of the agent fails tool listing with "toolset not started"; the runtime logs "Tool setup partially failed; continuing" and the agent runs without any of its MCP tools, so the LLM improvises useless workarounds.

Observed behavior (debug logs)

17:07:58 DEBUG Started MCP toolset successfully server=https://mcp.notion.com/sse  (14 tools listed)
17:11:47 WARN  supervisor: session lost server=https://mcp.notion.com/sse error=<nil> forced=false
18:09:02 WARN  Toolset listing failed; skipping agent=notion toolset="mcp(remote host=mcp.notion.com transport=sse)" error="toolset not started"
18:09:02 WARN  Tool setup partially failed; continuing agent=notion
18:09:07+ DEBUG Toolset listing still failing; retrying next turn (repeats forever, never recovers)

Notion drops idle SSE connections after ~4–30 minutes; every observed "session lost" event has error= (clean close). 5 occurrences across recent logs, all leading to permanent tool loss for the rest of the process.

Root cause (three compounding issues)

  1. pkg/tools/lifecycle/supervisor.go — shouldRestart(): the default RestartOnFailure policy only restarts when err != nil && !IsPermanent(err). A clean SSE close yields waitErr == nil, so the supervisor transitions to StateFailed and never uses its existing tryRestart backoff machinery.
  2. pkg/tools/startable.go — StartableToolSet: started is set true on first success and never cleared when the underlying session dies. Start() becomes a permanent no-op, so the per-turn retry in pkg/agent/agent.go collectTools() just re-calls Tools() against a dead supervisor and gets ErrNotStarted forever.
  3. Toolset.Restart() in pkg/tools/mcp/mcp.go (the documented recovery path for Failed/Stopped supervisors) is never invoked by the retry path.

Expected behavior

A dropped/cleanly-closed remote MCP session should be re-established automatically (with the existing 1s..32s backoff), or at minimum recovered lazily on the next agent turn instead of failing every turn until process restart.

Proposed fix

  • Treat an unexpected clean close (waitErr == nil, not stopping, not forced) as a restartable disconnect under RestartOnFailure (or use RestartAlways for remote MCP toolsets).
  • Make the ErrNotStarted retry path actually recover: clear StartableToolSet.started / call Toolset.Restart() so Start() re-runs.
  • Add tests for the clean-close restart and the ErrNotStarted recovery path.

Activity

  1. added theissue type on Jun 10, 2026
  2. added
    area/mcp
    area/tools
    area/agent
    on Jun 10, 2026
  3. self-assigned this
    on Jun 10, 2026
  4. added a commit that references this issue on Jun 11, 2026
    c6e690d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/agentarea/mcparea/tools

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions