mcp.downloader.integration¶

Agent integration for MCP Downloader.

This module provides integration between the MCP downloader system and Haive agents, enabling automatic tool, resource, and prompt discovery from downloaded MCP servers.

Examples

Basic integration:


from haive.mcp.downloader import MCPAgentIntegration

from haive import core

integration = MCPAgentIntegration() agent = await integration.create_agent_with_mcp_servers(

engine=engine, server_names=[“filesystem”, “github”]

)

Auto-discovery integration:

agent = await integration.create_agent_with_auto_discovery(
engine=engine,
limit=10,
categories=["official", "core"]

)

Classes:

MCPAgentIntegration: Main integration class MCPServerConnection: Connection management for MCP servers MCPCapabilityExtractor: Extract tools, resources, and prompts

Attributes¶

Classes¶

MCPAgentIntegration

Integration between MCP downloader and Haive agents.

MCPCapabilityExtractor

Extracts tools, resources, and prompts from MCP servers.

MCPServerConnection

Manages connection to an MCP server.

Module Contents¶

class mcp.downloader.integration.MCPAgentIntegration(config_file: str | None = None, install_dir: str | None = None)¶

Integration between MCP downloader and Haive agents.

This class provides high-level methods to create agents with MCP servers automatically configured and connected.

downloader¶

General MCP downloader instance

extractor¶

Capability extractor

manager¶

MCP manager for agent integration

Examples

Creating integrated agent:

async create_agent_with_auto_discovery(engine: haive.core.engine.aug_llm.AugLLMConfig, limit: int | None = None, categories: list[str] | None = None, tags: set[str] | None = None, agent_class: type = MCPAgent, **agent_kwargs) haive.mcp.agents.MCPAgent¶

Create an agent with auto-discovered MCP servers.

Parameters:
  • engine – Haive engine configuration

  • limit – Maximum servers to discover

  • categories – Server categories to include

  • tags – Server tags to filter by

  • agent_class – Agent class to instantiate

  • **agent_kwargs – Additional agent arguments

Returns:

Configured agent with discovered servers

Examples

Auto-discovery agent:

async create_agent_with_mcp_servers(engine: haive.core.engine.aug_llm.AugLLMConfig, server_names: list[str], agent_class: type = MCPAgent, install_if_missing: bool = True, **agent_kwargs) haive.mcp.agents.MCPAgent¶

Create an agent with specific MCP servers.

Parameters:
  • engine – Haive engine configuration

  • server_names – List of server names to use

  • agent_class – Agent class to instantiate

  • install_if_missing – Install missing servers

  • **agent_kwargs – Additional agent arguments

Returns:

Configured agent with MCP servers

Examples

Creating agent with servers:

async create_transferable_agent_team(engine: haive.core.engine.aug_llm.AugLLMConfig, num_agents: int, server_distribution: str = 'shared', **agent_kwargs) list[haive.mcp.agents.TransferableMCPAgent]¶

Create a team of transferable MCP agents.

Parameters:
  • engine – Haive engine configuration

  • num_agents – Number of agents to create

  • server_distribution – How to distribute servers - “shared”: All agents share all servers - “split”: Divide servers among agents - “specialized”: Each agent gets specific categories

  • **agent_kwargs – Additional agent arguments

Returns:

List of configured transferable agents

Examples

Creating agent team:

get_capability_summary() dict[str, Any]¶

Get a summary of all discovered capabilities.

Returns:

Dict with capability statistics

Examples

Getting summary:

downloader¶
extractor¶
manager¶
class mcp.downloader.integration.MCPCapabilityExtractor¶

Extracts tools, resources, and prompts from MCP servers.

This class provides methods to extract and organize capabilities from multiple MCP servers for use with agents.

connections¶

Active server connections

all_tools¶

Aggregated tools from all servers

all_resources¶

Aggregated resources

all_prompts¶

Aggregated prompts

Examples

Extracting capabilities:

async add_server(name: str, config: dict[str, Any], transport: str = 'stdio') bool¶

Add and connect to an MCP server.

Parameters:
  • name – Server name

  • config – Server configuration

  • transport – Transport type

Returns:

True if server added successfully

Return type:

bool

Examples

Adding a server:

async add_servers_from_config(servers: list[haive.mcp.downloader.config.ServerConfig], config_dir: pathlib.Path) dict[str, bool]¶

Add multiple servers from configuration.

Parameters:
  • servers – List of server configurations

  • config_dir – Directory containing server configs

Returns:

Dict mapping server names to success status

Examples

Adding from config:

get_all_prompts() dict[str, list[dict]]¶

Get all discovered prompts.

Returns:

Dict of server name to prompt list

get_all_resources() dict[str, list[dict]]¶

Get all discovered resources.

Returns:

Dict of server name to resource list

get_all_tools() dict[str, langchain_core.tools.BaseTool]¶

Get all discovered tools.

Returns:

Dict of tool name to tool object

Examples

Getting tools:

get_tools_by_capability(capability: str) dict[str, langchain_core.tools.BaseTool]¶

Get tools that have a specific capability.

Parameters:

capability – Capability to filter by

Returns:

Dict of tools with that capability

get_tools_by_server(server_name: str) dict[str, langchain_core.tools.BaseTool]¶

Get tools from a specific server.

Parameters:

server_name – Name of the server

Returns:

Dict of tools from that server

all_prompts: dict[str, list[dict]]¶
all_resources: dict[str, list[dict]]¶
all_tools: dict[str, langchain_core.tools.BaseTool]¶
connections: dict[str, MCPServerConnection]¶
class mcp.downloader.integration.MCPServerConnection(/, **data: Any)¶

Bases: pydantic.BaseModel

Manages connection to an MCP server.

name¶

Server name identifier

config¶

Server configuration

transport¶

Transport type (stdio, sse, etc.)

connection¶

Active connection object

tools¶

Discovered tools from the server

resources¶

Available resources

prompts¶

Available prompts

connected¶

Connection status

Examples

Creating a connection:

async connect() bool¶

Establish connection to the MCP server.

Returns:

True if connection successful

Return type:

bool

Examples

Connecting to server:

async discover_capabilities() dict[str, Any]¶

Discover tools, resources, and prompts from the server.

Returns:

Dict containing discovered capabilities

Examples

Discovering capabilities:

config: dict[str, Any] = None¶
connected: bool = None¶
connection: Any | None = None¶
model_config¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str = None¶
prompts: list[dict[str, Any]] = None¶
resources: list[dict[str, Any]] = None¶
tools: dict[str, langchain_core.tools.BaseTool] = None¶
transport: str = None¶
mcp.downloader.integration.MCP_ADAPTERS_AVAILABLE = True¶
mcp.downloader.integration.logger¶