The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tools): hug lone closers in MCP errors/transport (AST-neutral)
Teknium87c033a3e96f
diff --git a/tools/mcp_tool_errors.py b/tools/mcp_tool_errors.pyindex fe79816d1cf..3a0219be653 100644--- a/tools/mcp_tool_errors.py+++ b/tools/mcp_tool_errors.py@@ -99,8 +99,7 @@ def _classify_mcp_failure(exc: BaseException) -> str:or isinstance(root, (NonMcpEndpointError, InvalidMcpUrlError, FileNotFoundError))or (isinstance(root, OSError) and getattr(root, "errno", None) == errno.ENOENT)# 401/403 HTTPStatusError that _is_auth_error's type-gate missed (auth types not importable here).- or getattr(getattr(root, "response", None), "status_code", None) in (401, 403)- )+ or getattr(getattr(root, "response", None), "status_code", None) in (401, 403))return "permanent" if permanent else "transient"@@ -334,8 +333,7 @@ def _is_auth_error(exc: BaseException) -> bool:_SESSION_EXPIRED_MARKERS: tuple = ("invalid or expired session", "expired session", "session expired", "session not found","unknown session", "session terminated", "closedresourceerror", "closed resource",- "transport is closed", "connection closed", "broken pipe", "end of file",-)+ "transport is closed", "connection closed", "broken pipe", "end of file")# Node budget for ``_is_session_expired_error``. The visited set breaks cycles; the budget# bounds pathological acyclic graphs. Kept well above ``sys.getrecursionlimit()`` so deepdiff --git a/tools/mcp_tool_transport.py b/tools/mcp_tool_transport.pyindex 604bcd73bd9..66e1e8c0f3f 100644--- a/tools/mcp_tool_transport.py+++ b/tools/mcp_tool_transport.py@@ -17,8 +17,7 @@ logger = logging.getLogger("tools.mcp_tool")# JSON-RPC ``initialize`` body used by the content-type preflight POST._PROBE_INITIALIZE_BODY = ('{"jsonrpc":"2.0","id":"_probe","method":"initialize","params":{"protocolVersion":"2025-03-26",'- '"capabilities":{},"clientInfo":{"name":"hermes-probe","version":"0.1"}}}'-)+ '"capabilities":{},"clientInfo":{"name":"hermes-probe","version":"0.1"}}}')def _content_type_base(resp) -> str: