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[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, transport='http', timeout=30)[source]
async _close_session()[source]

Placeholder for compatibility; HTTP client calls are scoped per request.

_get_mcp_endpoint(path)[source]

Get the full MCP endpoint URL

async _make_mcp_request(method, params=None)[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.MCPClientTool[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 list_tools()[source]

List available tools from the MCP server

async call_tool(name, arguments)[source]

Call a tool on the MCP server

async list_resources()[source]

List available resources from the MCP server

async read_resource(uri)[source]

Read a resource from the MCP server

async list_prompts()[source]

List available prompts from the MCP server

async get_prompt(name, arguments=None)[source]

Get a prompt from the MCP server

run(arguments)[source]

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

async _run_list_tools()[source]

Run list_tools operation

async _run_call_tool(arguments)[source]

Run call_tool operation

async _run_list_resources()[source]

Run list_resources operation

async _run_read_resource(arguments)[source]

Run read_resource operation

async _run_list_prompts()[source]

Run list_prompts operation

async _run_get_prompt(arguments)[source]

Run get_prompt operation

class tooluniverse.mcp_client_tool.MCPProxyTool[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.

async static discover_server_tools(server_url, transport='http')[source]

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

static create_mcp_tools_config(server_configs)[source]

Create tool configurations for multiple MCP servers.

Parameters:

server_configs (List[Dict[str, str]]) – 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

Return type:

List[Dict[str, Any]]

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

Discover all available tools from the MCP server

async call_tool(tool_name, arguments)[source]

Directly call an MCP tool by name

generate_proxy_tool_configs()[source]

Generate proxy tool configurations for discovered tools

register_tools_in_engine(engine)[source]

Register discovered tools using ToolUniverse public API

async auto_load_and_register(engine)[source]

Automatically discover, load and register all MCP tools

run(arguments)[source]

Main run method for the auto-loader tool

__del__()[source]

Cleanup when object is destroyed