Skip to content
Changelog

Check whether MCPTools connected and leave no stray MCP servers

ContributorsNickSannya Singal

November 17, 20261 min read

Agno's MCPTools.connect() now returns True once the toolkit has the server's tools and False when it doesn't, so your code can tell whether the MCP server is usable. Before, the method logged any error and returned None in every case.

mcp_tools = MCPTools("npx -y @openbnb/mcp-server-airbnb")
if not await mcp_tools.connect():
    raise RuntimeError("Airbnb MCP server is unavailable")

A stdio server that answered the handshake and then failed tool discovery also kept running on earlier releases, and close() skipped it because the toolkit never finished initializing. A connect cancelled while tools were loading left the server behind the same way. connect() now closes the session and the server process in both cases.

Earlier releases: connect() returned None; server processes alive after connect(): ['badtools_server.py']; after close(): ['badtools_server.py']
This release:     connect() returned False; server processes alive after connect(): []; after close(): []

We ran each case on both releases against small stdio servers written for the test, one that errors on tools/list and one that never answers it, and listed child processes with psutil.

See the cookbook, and learn more about the stdio transport in the documentation.

Frequently asked questions

It closes the session and the server it started, then lets the cancellation through, so asyncio.wait_for still raises TimeoutError. With a test server that never answered tools/list, earlier releases left it running: server processes alive after connect(): ['slowtools_server.py']. This release printed [].

No. With a missing deno binary and with a server that never answered the handshake, both releases cleaned up and left no child process. The only difference there is the return value, None on earlier releases and False now.

Not on a toolkit that already holds its tools. A second call returns True straight away, and connect(force=True) drops the session and opens a new one.

Shipped around the same time