fabricatio_tool.mcp

MCP (Model Context Protocol) management utilities.

Functions

get_global_mcp_manager(→ fabricatio_tool.rust.MCPManager)

Get the global MCP manager instance.

mcp_tool_to_function(→ Callable[Ellipsis, ...)

Converts a registered MCP tool into a callable async function.

mcp_to_toolbox(→ fabricatio_tool.models.tool.ToolBox)

Converts all tools from a specified MCP client into a ToolBox.

Module Contents

async fabricatio_tool.mcp.get_global_mcp_manager(conf: Dict[str, fabricatio_tool.config.ServiceConfig] = tool_config.mcp_servers) fabricatio_tool.rust.MCPManager

Get the global MCP manager instance.

async fabricatio_tool.mcp.mcp_tool_to_function(client_id: str, tool_name: str) Callable[Ellipsis, Coroutine[Any, Any, List[str]]]

Converts a registered MCP tool into a callable async function.

This function dynamically generates and returns an async function that wraps the specified tool’s execution. The generated function will have: - A signature derived from the tool’s input schema - A docstring containing the tool description and parameter documentation - Execution that delegates to the MCP manager’s call_tool method

Parameters:
  • client_id – Identifier for the client/service hosting the tool

  • tool_name – Name of the tool to convert to a function

Returns:

Coroutine-enabled function that accepts keyword arguments matching the tool’s input schema and returns a list of execution result strings

Raises:

ValueError – If the specified tool cannot be found

Notes

The generated function uses functools.wraps to preserve metadata and will raise if called with invalid arguments based on the tool’s schema

async fabricatio_tool.mcp.mcp_to_toolbox(client_id: str) fabricatio_tool.models.tool.ToolBox

Converts all tools from a specified MCP client into a ToolBox.

This function retrieves all available tools from the given MCP client, converts each tool into a callable async function, and adds them to a ToolBox instance.

Parameters:

client_id – Identifier for the client/service hosting the tools

Returns:

A toolbox containing all tools from the specified client

Return type:

ToolBox

Raises:

ValueError – If the specified client cannot be found