refactor(tools): hug lone closers in MCP errors/transport (AST-neutral)

This commit is contained in:
Teknium
2026-09-02 22:22:55 -07:00
parent 1ad360b3aa
commit 87c033a3e9
2 changed files with 3 additions and 6 deletions
+2 -4
View File
@@ -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 deep
+1 -2
View File
@@ -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: