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.

tooluniverse.mcp_client_tool.urljoin(base, url, allow_fragments=True)[source][source]

Join a base URL and a possibly relative URL to form an absolute interpretation of the latter.

class tooluniverse.mcp_client_tool.BaseTool(tool_config)[source][source]

Bases: object

__init__(tool_config)[source][source]
classmethod get_default_config_file()[source][source]

Get the path to the default configuration file for this tool type.

This method uses a robust path resolution strategy that works across different installation scenarios:

  1. Installed packages: Uses importlib.resources for proper package resource access

  2. Development mode: Falls back to file-based path resolution

  3. Legacy Python: Handles importlib.resources and importlib_resources

Override this method in subclasses to specify a custom defaults file.

Returns:

Path or resource object pointing to the defaults file

classmethod load_defaults_from_file()[source][source]

Load defaults from the configuration file

run(arguments=None)[source][source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

check_function_call(function_call_json)[source][source]
get_required_parameters()[source][source]

Retrieve required parameters from the endpoint definition. Returns: list: List of required parameters for the given endpoint.

tooluniverse.mcp_client_tool.register_tool(tool_type_name=None, config=None)[source][source]

Decorator to automatically register tool classes and their configs.

Usage:

@register_tool(‘CustomToolName’, config={…}) class MyTool:

pass

class tooluniverse.mcp_client_tool.BaseMCPClient(server_url: str, transport: str = 'http', timeout: int = 30)[source][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][source]
class tooluniverse.mcp_client_tool.MCPClientTool(tool_config)[source][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][source]
async list_tools() List[Dict[str, Any]][source][source]

List available tools from the MCP server

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

Call a tool on the MCP server

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

List available resources from the MCP server

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

Read a resource from the MCP server

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

List available prompts from the MCP server

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

Get a prompt from the MCP server

run(arguments)[source][source]

Main run method for the tool. Supports different operations based on the ‘operation’ argument.

class tooluniverse.mcp_client_tool.MCPProxyTool(tool_config)[source][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][source]
run(arguments)[source][source]

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

class tooluniverse.mcp_client_tool.MCPServerDiscovery[source][source]

Bases: object

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

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

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

static create_mcp_tools_config(server_configs: List[Dict[str, str]]) List[Dict[str, Any]][source][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

class tooluniverse.mcp_client_tool.MCPAutoLoaderTool(tool_config)[source][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.

__init__(tool_config)[source][source]
async discover_tools() Dict[str, Any][source][source]

Discover all available tools from the MCP server

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

Directly call an MCP tool by name

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

Generate proxy tool configurations for discovered tools

register_tools_in_engine(engine)[source][source]

Register discovered tools directly in the ToolUniverse engine

async auto_load_and_register(engine) Dict[str, Any][source][source]

Automatically discover, load and register all MCP tools

run(arguments)[source][source]

Main run method for the auto-loader tool

__del__()[source][source]

Cleanup when object is destroyed