tooluniverse.mcp_tool_registry module¶
MCP Tool Registration System for ToolUniverse
This module provides functionality to register local tools as MCP tools and enables automatic loading of these tools on remote servers via ToolUniverse integration.
Usage:¶
Server Side (Tool Provider): ```python from tooluniverse.mcp_tool_registry import register_mcp_tool, start_mcp_server
- @register_mcp_tool(
tool_type_name=âmy_analysis_toolâ, config={
âdescriptionâ: âPerforms custom data analysisâ
}, mcp_config={
âserver_nameâ: âCustom Analysis Serverâ, âhostâ: â0.0.0.0â, âportâ: 8001
}
) class MyAnalysisTool:
- def run(self, arguments):
return {âresultâ: âanalysis completeâ}
# Start MCP server with registered tools start_mcp_server() ```
Client Side (Tool Consumer): ```python from tooluniverse import ToolUniverse
# Auto-discover and load MCP tools from remote servers tu = ToolUniverse() tu.load_mcp_tools(server_urls=[âhttp://localhost:8001â])
# Use the remote tool result = tu.run_tool(âmy_analysis_toolâ, {âdataâ: âinputâ}) ```
- tooluniverse.mcp_tool_registry.register_mcp_tool(tool_type_name=None, config=None, mcp_config=None)[source]¶
Decorator to register a tool class exactly like register_tool, but also expose it as an MCP server.
This decorator does everything that register_tool does, PLUS exposes the tool via SMCP protocol for remote access. The parameters and behavior are identical to register_tool, with an optional mcp_config parameter for server configuration.
Parameters:¶
- tool_type_namestr, optional
Custom name for the tool type. Same as register_tool.
- configdict, optional
Tool configuration dictionary. Same as register_tool.
- mcp_configdict, optional
Additional MCP server configuration. Can include: - server_name: Name of the MCP server - host: Server host (default: âlocalhostâ) - port: Server port (default: 8000) - transport: âhttpâ or âstdioâ (default: âhttpâ) - auto_start: Whether to auto-start server when tool is registered
Returns:¶
- function
Decorator function that registers the tool class both locally and as MCP server.
Examples:¶
Same as register_tool, just with MCP exposure: ```python @register_mcp_tool(âCustomToolNameâ, config={âŠ}, mcp_config={âportâ: 8001}) class MyTool:
pass
@register_mcp_tool() # Uses class name, default MCP config class AnotherTool:
pass
- tooluniverse.mcp_tool_registry.register_mcp_tool_from_config(tool_class, config)[source]¶
Register an existing tool class as MCP tool using configuration.
This function provides a programmatic way to register tools as MCP tools without using decorators, useful for dynamic tool registration. Just like register_mcp_tool decorator, this does everything register_tool would do PLUS exposes the tool via MCP.
Parameters:¶
- tool_classtype
The tool class to register
- configdict
Configuration containing: - name: Tool name (required) - description: Tool description - parameter_schema: JSON schema for parameters - mcp_config: MCP server configuration
Examples:¶
- def run(self, arguments):
return {âstatusâ: âprocessedâ}
- register_mcp_tool_from_config(ExistingTool, {
ânameâ: âexisting_toolâ, âdescriptionâ: âAn existing tool exposed via MCPâ, âmcp_configâ: {âportâ: 8002}
})¶
- tooluniverse.mcp_tool_registry.get_registered_tools()[source]¶
Get a list of all registered MCP tools with their information.
- tooluniverse.mcp_tool_registry.get_mcp_server_configs()[source]¶
Get the current MCP server configurations grouped by port.
- tooluniverse.mcp_tool_registry.start_mcp_server(port=None, **kwargs)[source]¶
Start MCP server(s) for registered tools.
Parameters:¶
- portint, optional
Specific port to start server for. If None, starts servers for all registered tools.
- **kwargs
Additional arguments passed to SMCP server
Examples:¶
```python # Start server for specific port start_mcp_server(port=8001)
# Start all servers start_mcp_server()
# Start with custom configuration start_mcp_server(max_workers=20, debug=True) ```
- tooluniverse.mcp_tool_registry.start_mcp_server_for_tool(tool_name)[source]¶
Start MCP server for a specific tool.
- tooluniverse.mcp_tool_registry.stop_mcp_server(port=None)[source]¶
Stop MCP server(s).
Parameters:¶
- portint, optional
Specific port to stop server for. If None, stops all servers.
- tooluniverse.mcp_tool_registry.list_mcp_tools()[source]¶
List all registered MCP tools with their configurations.
- tooluniverse.mcp_tool_registry.get_mcp_tool_urls()[source]¶
Get list of MCP server URLs for all registered tools.
- tooluniverse.mcp_tool_registry.load_mcp_tools_to_tooluniverse(tu, server_urls=None)[source]¶
Load MCP tools from servers into a ToolUniverse instance.
Parameters:¶
- tuToolUniverse
ToolUniverse instance to load tools into
- server_urlslist of str, optional
List of MCP server URLs. If None, uses all registered local servers.
Examples:¶
```python from tooluniverse import ToolUniverse from tooluniverse.mcp_tool_registry import load_mcp_tools_to_tooluniverse
tu = ToolUniverse()
# Load from specific servers load_mcp_tools_to_tooluniverse(tu, [
âhttp://localhost:8001â, âhttp://analysis-server:8002â
])
# Load from all local registered servers load_mcp_tools_to_tooluniverse(tu) ```