Table of Contents
Module spoon_ai.agents.mcp_client_mixin
MCPClientMixin Objects​
class MCPClientMixin()
get_session​
@asynccontextmanager
async def get_session()
Get a session with robust resource management and cleanup.
Features:
- Automatic session reuse per task
- Resource limits to prevent exhaustion
- Proper cleanup on cancellation/failure
- Periodic cleanup of stale sessions
list_mcp_tools​
async def list_mcp_tools()
Get the list of available tools from the MCP server
call_mcp_tool​
async def call_mcp_tool(tool_name: str, **kwargs)
Call a tool on the MCP server
send_mcp_message​
async def send_mcp_message(recipient: str,
message: Union[str, Dict[str, Any]],
topic: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None) -> bool
Send a message to the MCP system
Arguments:
recipient- Recipient IDmessage- Message content (string or dictionary)topic- Message topicmetadata- Additional metadata
Returns:
bool- Whether the message was sent successfully
cleanup​
async def cleanup()
Enhanced cleanup method with comprehensive resource cleanup.
get_session_stats​
def get_session_stats() -> Dict[str, Any]
Get session statistics for monitoring.