tooluniverse.mcp_client_tool moduleΒΆ

MCP Client Tool for ToolUniverse

This module provides a tool that acts as a client to connect to an existing MCP server, supporting all MCP functionality including tools, resources, and prompts.

class tooluniverse.mcp_client_tool.BaseMCPClient(server_url: str, transport: str = 'http', timeout: int = 30)[source]ΒΆ

Bases: object

Base MCP client with common functionality shared between MCPClientTool and MCPAutoLoaderTool. Provides session management, request handling, and async cleanup patterns.

__init__(server_url: str, transport: str = 'http', timeout: int = 30)[source]ΒΆ
async _close_session()[source]ΒΆ

Close HTTP session if exists

async _ensure_session()[source]ΒΆ

Ensure HTTP session is available for HTTP transport

_get_mcp_endpoint(path: str) str[source]ΒΆ

Get the full MCP endpoint URL

async _initialize_mcp_session()[source]ΒΆ

Initialize MCP session if needed (for compatibility with different MCP servers)

async _make_mcp_request(method: str, params: Dict | None = None) Dict[str, Any][source]ΒΆ

Make an MCP JSON-RPC request

_run_with_cleanup(async_func)[source]ΒΆ

Common async execution pattern with proper cleanup

class tooluniverse.mcp_client_tool.MCPAutoLoaderTool(tool_config)[source]ΒΆ

Bases: BaseTool, BaseMCPClient

An advanced MCP tool that automatically discovers and loads all tools from an MCP server. It can register discovered tools as individual ToolUniverse tools for seamless usage.

__del__()[source]ΒΆ

Cleanup when object is destroyed

__init__(tool_config)[source]ΒΆ
async auto_load_and_register(engine) Dict[str, Any][source]ΒΆ

Automatically discover, load and register all MCP tools

async call_tool(tool_name: str, arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Directly call an MCP tool by name

async discover_tools() Dict[str, Any][source]ΒΆ

Discover all available tools from the MCP server

generate_proxy_tool_configs() List[Dict[str, Any]][source]ΒΆ

Generate proxy tool configurations for discovered tools

register_tools_in_engine(engine)[source]ΒΆ

Register discovered tools directly in the ToolUniverse engine

run(arguments)[source]ΒΆ

Main run method for the auto-loader tool

class tooluniverse.mcp_client_tool.MCPClientTool(tool_config)[source]ΒΆ

Bases: BaseTool, BaseMCPClient

A tool that acts as an MCP client to connect to existing MCP servers. Supports both HTTP and WebSocket transports.

__init__(tool_config)[source]ΒΆ
async _run_call_tool(arguments)[source]ΒΆ

Run call_tool operation

async _run_get_prompt(arguments)[source]ΒΆ

Run get_prompt operation

async _run_list_prompts()[source]ΒΆ

Run list_prompts operation

async _run_list_resources()[source]ΒΆ

Run list_resources operation

async _run_list_tools()[source]ΒΆ

Run list_tools operation

async _run_read_resource(arguments)[source]ΒΆ

Run read_resource operation

async call_tool(name: str, arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Call a tool on the MCP server

async get_prompt(name: str, arguments: Dict[str, Any] | None = None) Dict[str, Any][source]ΒΆ

Get a prompt from the MCP server

async list_prompts() List[Dict[str, Any]][source]ΒΆ

List available prompts from the MCP server

async list_resources() List[Dict[str, Any]][source]ΒΆ

List available resources from the MCP server

async list_tools() List[Dict[str, Any]][source]ΒΆ

List available tools from the MCP server

async read_resource(uri: str) Dict[str, Any][source]ΒΆ

Read a resource from the MCP server

run(arguments)[source]ΒΆ

Main run method for the tool. Supports different operations based on the β€˜operation’ argument.

class tooluniverse.mcp_client_tool.MCPProxyTool(tool_config)[source]ΒΆ

Bases: MCPClientTool

A proxy tool that automatically forwards tool calls to an MCP server. This creates individual tools for each tool available on the MCP server.

__init__(tool_config)[source]ΒΆ
run(arguments)[source]ΒΆ

Forward the call directly to the target tool on the MCP server

class tooluniverse.mcp_client_tool.MCPServerDiscovery[source]ΒΆ

Bases: object

Helper class to discover and create tool configurations for MCP servers.

static create_mcp_tools_config(server_configs: List[Dict[str, str]]) List[Dict[str, Any]][source]ΒΆ

Create tool configurations for multiple MCP servers.

Parameters:

server_configs – List of server configurations, each containing: - server_url: URL of the MCP server - transport: β€˜http’ or β€˜websocket’ (optional, defaults to β€˜http’) - server_name: Name prefix for tools (optional)

Returns:

List of tool configurations that can be loaded into ToolUniverse

async static discover_server_tools(server_url: str, transport: str = 'http') List[Dict[str, Any]][source]ΒΆ

Discover all tools available on an MCP server and return tool configurations.