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
- 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:
Installed packages: Uses importlib.resources for proper package resource access
Development mode: Falls back to file-based path resolution
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
- 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.
- 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.
- 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 list_prompts() List[Dict[str, Any]] [source][source]¶
List available prompts from the MCP server
- 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.
- 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.
- 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