calute.mcp.integration#
Integration helpers for MCP with Calute agents.
This module provides utilities for integrating Model Context Protocol (MCP) tools with Calute agents, enabling seamless use of external MCP servers and their tools within the Calute framework.
Key features: - Convert MCP tools to Calute-compatible functions - Add MCP tools to existing agents dynamically - Create MCP-enabled agents with automatic tool integration - Handle synchronous/asynchronous execution transparently
The integration preserves the MCP tool’s input schema, allowing Calute’s function introspection to properly extract parameter signatures for LLM function calling.
- async calute.mcp.integration.add_mcp_tools_to_agent(agent: Any, manager: MCPManager, server_names: list[str] | None = None) None[source]#
Add MCP tools to a Calute agent.
Dynamically extends an agent’s function list with tools from MCP servers. Supports both direct Agent instances and CortexAgent wrappers that use an internal agent.
The function converts each MCP tool to a Calute-compatible function and appends it to the agent’s functions list.
- Parameters
agent – A CortexAgent or Calute Agent instance. Must have either a ‘functions’ attribute or an ‘_internal_agent’ with ‘functions’.
manager – The MCP manager instance containing connected servers and their available tools.
server_names – Optional list of server names to filter tools from. If None, adds tools from all connected servers.
- Returns
None. The agent is modified in-place.
Note
If the agent does not support adding functions (missing expected attributes), a warning is logged and no tools are added.
- calute.mcp.integration.create_mcp_enabled_agent(agent_class: type, manager: MCPManager, server_names: list[str] | None = None, **agent_kwargs) Any[source]#
Create an agent with MCP tools automatically added.
Factory function that instantiates an agent and automatically adds MCP tools from the specified servers. This provides a convenient one-step method for creating MCP-enabled agents.
- Parameters
agent_class – The agent class to instantiate. Should be either CortexAgent or Agent, or any compatible class.
manager – The MCP manager instance containing connected servers and their available tools.
server_names – Optional list of server names to filter tools from. If None, adds tools from all connected servers.
**agent_kwargs – Additional keyword arguments passed directly to the agent class constructor.
- Returns
An instantiated agent with MCP tools added to its functions list.
Example
>>> manager = MCPManager() >>> await manager.connect_server("my-server", server_config) >>> agent = create_mcp_enabled_agent( ... Agent, ... manager, ... server_names=["my-server"], ... name="MyAgent", ... model="gpt-4", ... )
- calute.mcp.integration.mcp_tool_to_calute_function(tool: MCPTool, manager: MCPManager) Callable[source]#
Convert an MCP tool to a Calute-compatible function.
Creates a synchronous wrapper function with explicit parameters based on the MCP tool’s input schema, enabling Calute’s function_to_json to properly extract the signature for LLM function calling.
The generated function: - Has a dynamic signature matching the MCP tool’s input schema - Includes proper type annotations for all parameters - Contains a docstring with parameter descriptions and server info - Handles async-to-sync conversion transparently
- Parameters
tool – The MCP tool to convert, containing name, description, and input schema.
manager – The MCP manager instance responsible for executing the tool on its server.
- Returns
A callable function compatible with Calute agents that wraps the MCP tool execution.
- Raises
Exception – Re-raised from MCP tool execution failures after logging.