fix(mcp): ensure server.shutdown() on probe iteration failure
Wrap the _tools iteration in _probe_single_server() in try/finally so that server.shutdown() is called even if iterating tool metadata raises. Without this, the MCP server connection leaks until the event loop is torn down by _stop_mcp_loop().
This commit is contained in:
@ -225,13 +225,15 @@ def _probe_single_server(
|
||||
server = await asyncio.wait_for(
|
||||
_connect_server(name, config), timeout=connect_timeout
|
||||
)
|
||||
for t in server._tools:
|
||||
desc = getattr(t, "description", "") or ""
|
||||
# Truncate long descriptions for display
|
||||
if len(desc) > 80:
|
||||
desc = desc[:77] + "..."
|
||||
tools_found.append((t.name, desc))
|
||||
await server.shutdown()
|
||||
try:
|
||||
for t in server._tools:
|
||||
desc = getattr(t, "description", "") or ""
|
||||
# Truncate long descriptions for display
|
||||
if len(desc) > 80:
|
||||
desc = desc[:77] + "..."
|
||||
tools_found.append((t.name, desc))
|
||||
finally:
|
||||
await server.shutdown()
|
||||
|
||||
try:
|
||||
_run_on_mcp_loop(_probe(), timeout=connect_timeout + 10)
|
||||
|
||||
Reference in New Issue
Block a user