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.

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

Bases: RuntimeError

Raised when an MCP tool call returns an error result.

MCPToolSpec dataclass

MCPToolSpec(name, description, input_schema)

A tool advertised by an MCP server.

MCPToolAdapter

MCPToolAdapter(session)

Expose a connected mcp.ClientSession's tools to arun_tool.

The caller owns the MCP connection lifecycle (stdio_client / sse_client + ClientSession); 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.

tool

tool(name, arguments=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.