Skip to main content

Module mcp

Module mcp 

Source
Expand description

Model Context Protocol (MCP) integration for external tool servers.

This module provides integration with MCP-compliant tool servers, allowing external tools to be registered and called through the standard tool registry.

MCP is a protocol for connecting LLM applications with external tool providers. This module supports loading MCP server configurations from JSON files (compatible with Claude Desktop format) and manages connection pooling for efficient server communication.

§Features

  • Load MCP server configurations from JSON files
  • Automatic connection pooling for MCP servers
  • Register MCP tools with the global tool registry
  • Graceful shutdown of all MCP connections

§Example

use modular_agent_core::mcp::{register_tools_from_mcp_json, shutdown_all_mcp_connections};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load and register tools from MCP configuration
    let tools = register_tools_from_mcp_json("mcp.json").await?;
    println!("Registered {} MCP tools", tools.len());

    // ... use tools ...

    // Clean up connections on shutdown
    shutdown_all_mcp_connections().await?;
    Ok(())
}

Structs§

MCPConfig
Root configuration structure for MCP servers.
MCPServerConfig
Configuration for a single MCP server.

Functions§

register_tools_from_mcp_json
Loads MCP configuration from a JSON file and registers all tools
shutdown_all_mcp_connections
Shuts down all MCP server connections.