claude-code - 💡(How to fix) Fix SessionStart hooks with mcp_tool type fire before MCP servers connect [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#57932Fetched 2026-05-11 03:21:35
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Plugin SessionStart hooks that use type: "mcp_tool" always fail because they fire before the MCP server has connected. The hooks execute synchronously during startup, and MCP connection begins ~290ms later. Every mcp_tool hook gets skipped with "MCP server not connected."

Error Message

2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected 2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected 2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected 2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected

Root Cause

Plugin SessionStart hooks that use type: "mcp_tool" always fail because they fire before the MCP server has connected. The hooks execute synchronously during startup, and MCP connection begins ~290ms later. Every mcp_tool hook gets skipped with "MCP server not connected."

Code Example

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup",
        "hooks": [
          {
            "type": "mcp_tool",
            "server": "concurai-ememory",
            "tool": "e_property",
            "input": { "action": "list" },
            "timeout": 30
          }
        ]
      }
    ]
  }
}

---

2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.921Z [DEBUG] MCP server "plugin:concurai-ememory:concurai-ememory": Starting connection...
2026-05-11T01:45:09.197Z [DEBUG] MCP server "plugin:concurai-ememory:concurai-ememory": Successfully connected (transport: http) in 280ms
RAW_BUFFERClick to expand / collapse

Description

Plugin SessionStart hooks that use type: "mcp_tool" always fail because they fire before the MCP server has connected. The hooks execute synchronously during startup, and MCP connection begins ~290ms later. Every mcp_tool hook gets skipped with "MCP server not connected."

Steps to Reproduce

  1. Create a plugin with hooks/hooks.json containing SessionStart hooks that call MCP tools:
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup",
        "hooks": [
          {
            "type": "mcp_tool",
            "server": "concurai-ememory",
            "tool": "e_property",
            "input": { "action": "list" },
            "timeout": 30
          }
        ]
      }
    ]
  }
}
  1. Plugin has .mcp.json configuring an HTTP MCP server
  2. Launch Claude Code with --plugin-dir

Expected Behavior

SessionStart hooks with type: "mcp_tool" should execute after the MCP server they reference has connected, or Claude Code should provide an McpReady hook event that fires after MCP connections are established.

Actual Behavior

All mcp_tool hooks are skipped with warning: Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected

Debug log shows the timing gap clearly:

2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.907Z [WARN] Hooks: mcp_tool hook skipped — MCP server 'concurai-ememory' not connected
2026-05-11T01:45:08.921Z [DEBUG] MCP server "plugin:concurai-ememory:concurai-ememory": Starting connection...
2026-05-11T01:45:09.197Z [DEBUG] MCP server "plugin:concurai-ememory:concurai-ememory": Successfully connected (transport: http) in 280ms

Hooks fire at .907, MCP connection starts at .921 and completes at .197 — hooks never had a chance.

Use Case

Session memory continuity. Our plugin uses SessionStart hooks to restore context from a knowledge store on startup (orient), on context compaction (restore session state), and on resume (cross-session context). These are the primary use cases for mcp_tool hooks — they're useless if they can't call the MCP server they depend on.

Suggested Fix

Either:

  1. Wait for MCP connections before firing SessionStart hooks that reference MCP tools
  2. Add an McpReady hook event that fires after all MCP servers have connected
  3. Retry mcp_tool hooks that fail due to server not connected (with backoff)

Environment

  • Claude Code v2.1.138
  • macOS (Darwin 25.3.0)
  • MCP transport: HTTP (Streamable HTTP)
  • Plugin loaded via --plugin-dir

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING