MCP Integration

Requires pip install 'techrevati-runtime[mcp]'.

MCPToolAdapter wraps a connected mcp.ClientSession and exposes its tools as coroutine factories for AsyncOrchestrationSession.arun_tool. See the MCP pattern for a worked example.

techrevati.runtime.mcp

MCP — Model Context Protocol tool integration (optional [mcp] extra).

Bridges tools exposed by an MCP server into the runtime's tool-execution lifecycle. The runtime has no tool registry — run_tool / arun_tool execute caller-supplied callables — so :class:MCPToolAdapter does not register anything; it wraps a connected mcp.ClientSession and hands back coroutine factories that slot straight into AsyncOrchestrationSession.arun_tool:

from mcp import ClientSession
from mcp.client.stdio import stdio_client, StdioServerParameters
from techrevati.runtime import AgentSession
from techrevati.runtime.mcp import MCPToolAdapter

async with stdio_client(StdioServerParameters(command="my-mcp-server")) as (r, w):
    async with ClientSession(r, w) as mcp_session:
        await mcp_session.initialize()
        adapter = MCPToolAdapter(mcp_session)

        agent = AgentSession(role="researcher", phase="gather")
        async with agent.asession() as session:
            result = await session.arun_tool(
                "search", adapter.tool("search", {"q": "EU AI Act"})
            )

Because the tool flows through arun_tool, the call still passes the permission, guardrail, governance, and hook checks unchanged. run_tool / arun_tool signatures are not modified.

Works with both SDK lines: a 1.x or 2.x ClientSession, and the 2.x high-level mcp.Client, which also handles servers that ask the client for more input.

Zero-dependency invariant: the mcp package is imported behind a guard and is only needed when this module is used (install techrevati-runtime[mcp]).

MCPToolError

MCPToolError(message, *, tool_name=None, code=None)

Bases: RuntimeError

Raised when an MCP tool call fails.

Covers error results, protocol errors (including request timeouts), and results that cannot be used as a tool's outcome. tool_name names the tool; code carries the protocol error code when the failure was a protocol error.

MCPToolSpec dataclass

MCPToolSpec(name, description, input_schema)

A tool advertised by an MCP server.

MCPToolAdapter

MCPToolAdapter(session)

Expose a connected MCP client's tools to arun_tool.

session is a connected mcp.ClientSession or, on SDK 2.x, an entered mcp.Client. It is typed loosely because the two SDK lines share no class. The caller owns the connection lifecycle; the adapter only bridges call_tool into a coroutine factory and normalizes the result.

list_tools async

list_tools()

List every tool the MCP server advertises, following pagination.

The MCP tools/list response is paginated; this walks nextCursor until the server stops returning one, so tools beyond the first page are not silently dropped. A seen-cursor guard avoids an infinite loop if a misbehaving server repeats a cursor, and tools are keyed by name so that a repeated page does not yield duplicates. An empty cursor ends the walk.

tool

tool(name, arguments=None, *, timeout=None)

Return a coroutine factory for arun_tool(name, factory).

Each call to the returned factory invokes the MCP tool once and returns its normalized result. timeout is a per-call limit in seconds, enforced by the SDK; exceeding it raises :class:MCPToolError.