hermes - 💡(How to fix) Fix MCP server TaskGroup crashes gateway when any single server fails to initialize [1 pull requests]

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…

Error Message

Before (crashes gateway on any single MCP failure):

async with asyncio.TaskGroup() as tg: for server in servers: tg.create_task(_discover_and_register_server(server))

After (isolates failures):

results = await asyncio.gather( *[_discover_and_register_server(s) for s in servers], return_exceptions=True ) for r in results: if isinstance(r, BaseException): logger.warning(f"MCP server failed: {r}")

Root Cause

This is particularly impactful because MCP servers are third-party dependencies with their own Python environments — they frequently fail due to missing packages, version conflicts, or network issues.

Fix Action

Fixed

Code Example

# Before (crashes gateway on any single MCP failure):
async with asyncio.TaskGroup() as tg:
    for server in servers:
        tg.create_task(_discover_and_register_server(server))

# After (isolates failures):
results = await asyncio.gather(
    *[_discover_and_register_server(s) for s in servers],
    return_exceptions=True
)
for r in results:
    if isinstance(r, BaseException):
        logger.warning(f"MCP server failed: {r}")

---

except Exception as e:  # before
except BaseException as e:  # after
RAW_BUFFERClick to expand / collapse

Bug: MCP TaskGroup Crashes Gateway on Single Server Failure

Severity: HIGH
File: mcp_tool.py:3116
Affected versions: v0.14.0

Problem

register_mcp_servers() uses asyncio.TaskGroup to initialize MCP servers in parallel. If any single MCP server fails to connect, the ExceptionGroup cancels all other servers and crashes the entire gateway process.

This is particularly impactful because MCP servers are third-party dependencies with their own Python environments — they frequently fail due to missing packages, version conflicts, or network issues.

Observed Impact

Three MCP servers (akshare, vibe-trading, tradingagents) fail on startup due to Python dependency issues. With TaskGroup, this crashes the gateway. The current try/except Exception in _discover_and_register_server partially mitigates, but TaskGroup's ExceptionGroup can escape if the inner catch doesn't cover BaseException.

The gateway ends up in a crash loop: systemd Restart=on-failure restarts it, MCP servers fail again, gateway crashes again. One profile was observed restarting 385 times/day.

Suggested Fix

Replace TaskGroup with asyncio.gather(return_exceptions=True) and widen inner catch from except Exception to except BaseException in _discover_and_register_server:

# Before (crashes gateway on any single MCP failure):
async with asyncio.TaskGroup() as tg:
    for server in servers:
        tg.create_task(_discover_and_register_server(server))

# After (isolates failures):
results = await asyncio.gather(
    *[_discover_and_register_server(s) for s in servers],
    return_exceptions=True
)
for r in results:
    if isinstance(r, BaseException):
        logger.warning(f"MCP server failed: {r}")

And in _discover_and_register_server, change:

except Exception as e:  # before
except BaseException as e:  # after

Environment

  • Hermes Agent v0.14.0
  • 10 profiles, 3 failing MCP servers
  • Feishu/Weixin platforms

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

hermes - 💡(How to fix) Fix MCP server TaskGroup crashes gateway when any single server fails to initialize [1 pull requests]