stop • AI Agent SDK

stop: Best-effort teardown for the runner thread.

stop

Method

</div>

This is a method of the MCPToolRunner class in the mcp module.

Best-effort teardown for the runner thread.

Queues the shutdown sentinel and joins the thread so the request loop exits and its stdio subprocess is terminated instead of leaking a background thread (and its child) across the process lifetime. The request loop polls the queue between async operations, so once any in-flight call unwinds the sentinel is consumed promptly.

Signature

python
def stop(timeout: Any) -> Any

Parameters

ParamField Any

Seconds to wait for the thread to exit. Defaults to the runner’s own operation `timeout` so an in-flight call has a chance to finish before we give up. The thread is a daemon, so this never blocks interpreter exit even if the join times out.

Returns

ResponseField Any

The result of the operation.

Uses

  • put
  • is_set
  • call_soon_threadsafe
  • is_alive

Source

View on GitHub

praisonaiagents/mcp/mcp.py at line 388