axio-tools-mcp

Explicit MCP server connections and conversion of discovered MCP tools into Axio Tool definitions.

class axio_tools_mcp.MCPServerConfig(name: str, command: str | None = None, args: list[str] = <factory>, env: dict[str, str] | None=None, url: str | None = None, headers: dict[str, str]=<factory>, timeout: float = 30.0, scope: str = 'global', protocol_version: str | None = None)[source]

Configuration for connecting to an MCP server.

Exactly one of command (stdio transport) or url (HTTP transport) must be set.

classmethod from_dict(name: str, data: dict[str, str]) → MCPServerConfig[source]

Deserialize from flat string dict.

to_dict() → dict[str, str][source]

Serialize to flat string dict for config DB persistence.

class axio_tools_mcp.MCPSession(config: MCPServerConfig)[source]

Manages connection lifecycle for a single MCP server.

async call_tool(name: str, arguments: dict[str, Any]) → CallToolResult[source]

Call a tool on the connected MCP server.

async close() → None[source]

Close the session and release resources.

async connect() → None[source]

Connect to the MCP server and complete the handshake.

connect_http(adapter: Adapter) → Client[source]

Open an HTTP session for the Streamable HTTP transport.

async connect_stdio(adapter: Adapter) → StdioClient[source]

Start the server process and talk to its standard streams.

environment() → dict[str, str][source]

Return the child environment: this process’s, plus the configured extras.

exclusive() → AbstractAsyncContextManager[Any][source]

Serialize requests on stdio; HTTP requests are independent.

async handshake() → None[source]

Initialize, then follow the server to the revision it answered with.

async list_tools() → list[ToolDef][source]

List available tools from the connected MCP server.

async log_stderr(stream: StreamReader) → None[source]

Forward the server’s standard error to the logger as warnings.

async open(protocol_version: str) → None[source]

Start the transport and complete the handshake on one revision.

property protocol_version: str | None

Return the revision in use, or None while disconnected.

async axio_tools_mcp.load_mcp_tools(servers: list[MCPServerConfig]) → tuple[list[Tool[Any]], list[MCPSession]][source]

Connect to MCP servers and discover their tools.

Returns (tools, sessions). The caller is responsible for closing sessions. Failed servers are logged and skipped.

class axio_tools_mcp.MCPRegistry(_configs: dict[str, ~axio_tools_mcp.config.MCPServerConfig]=<factory>, _sessions: dict[str, ~axio_tools_mcp.session.MCPSession]=<factory>, _tools: dict[str, list[~axio.tool.Tool[~typing.Any]]]=<factory>, _errors: dict[str, str]=<factory>, _config_db: Any = None, _global_config_db: Any = None, _server_scope: dict[str, ~typing.Any]=<factory>)[source]

Manages MCP server instances, discovers tools, persists to config DB.

async add_server(config: MCPServerConfig, scope: Any = None) → list[Tool[Any]][source]

Add new server, connect, load tools, persist config.

property all_tools: list[Tool[Any]]

Flat list of all MCP tools across all servers.

async close() → None[source]

Close all sessions.

get_server_scope(name: str) → Any[source]

Return the config DB instance a server is persisted to.

async init(config: Any = None, global_config: Any = None) → None[source]

Load saved MCP server configs from both DBs, connect, discover tools.

async remove_server(name: str) → None[source]

Disconnect and remove server, delete from config DB.

server_config(name: str) → MCPServerConfig[source]

Return the config for a given server.

property server_names: list[str]

Names of all configured servers.

server_status(name: str) → str[source]

Return ‘connected’, ‘error’, or ‘disconnected’.

server_tool_count(name: str) → int[source]

Return the number of tools for a given server.

async update_server(name: str, config: MCPServerConfig, scope: Any = None) → list[Tool[Any]][source]

Reconnect server with new config.

Plugin

MCPPlugin is what the axio.tools.settings entry point resolves to, so a host application can offer MCP server configuration without importing this package.

class axio_tools_mcp.MCPPlugin[source]

Dynamic tool provider that bridges MCP servers into Axio.

Discovered via the axio.tools.settings entry point group. The TUI interacts with this class through the ToolsPlugin protocol.