mcp.configΒΆ
MCP configuration types for flexible server management.
This module provides Pydantic models for configuring Model Context Protocol (MCP) servers and their integration with Haive agents. It includes comprehensive validation and type safety for all MCP-related configurations.
- The configuration system supports:
Multiple transport types (stdio, SSE, HTTP streaming)
Server-specific settings and capabilities
Environment variables and authentication
Discovery and filtering options
Health monitoring and retry logic
- Classes:
MCPTransport: Enumeration of supported MCP transport types MCPServerConfig: Configuration for individual MCP servers MCPConfig: Complete MCP configuration for agents
Examples
Creating an MCP server configuration:
from haive.mcp.config import MCPConfig, MCPServerConfig, MCPTransport
# Configure a filesystem MCP server
fs_server = MCPServerConfig(
name="filesystem",
transport=MCPTransport.STDIO,
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem"],
capabilities=["file_read", "file_write", "directory_list"],
category="filesystem",
description="Local filesystem operations"
)
# Create complete MCP config
config = MCPConfig(
enabled=True,
servers={"filesystem": fs_server},
auto_discover=True,
lazy_init=True
)
Note
All configuration models use Pydantic v2 for validation and serialization.
ClassesΒΆ
Complete MCP configuration for an agent. |
|
Configuration for a single MCP server. |
|
MCP transport types. |
Module ContentsΒΆ
- class mcp.config.MCPConfig(/, **data: Any)ΒΆ
Bases:
pydantic.BaseModel
Complete MCP configuration for an agent.
This class provides the main configuration structure for MCP integration with Haive agents. It controls server discovery, filtering, initialization, and runtime behavior.
- enabledΒΆ
Whether MCP functionality is enabled
- auto_discoverΒΆ
Automatically discover servers from configured paths
- lazy_initΒΆ
Initialize servers on-demand rather than at startup
- serversΒΆ
Dictionary mapping server names to their configurations
- discovery_pathsΒΆ
List of paths to search for MCP server configurations
- categoriesΒΆ
Optional filter for server categories
- required_capabilitiesΒΆ
Optional list of required server capabilities
- global_timeoutΒΆ
Timeout for all MCP operations in seconds
- max_concurrent_serversΒΆ
Maximum number of concurrent server connections
- enable_health_checksΒΆ
Whether to enable periodic server health checks
- on_server_connectedΒΆ
Optional callback name when server connects
- on_server_failedΒΆ
Optional callback name when server fails
- on_tool_discoveredΒΆ
Optional callback name when tool is discovered
Examples
Creating a comprehensive MCP configuration:
config = MCPConfig( enabled=True, servers={ "filesystem": MCPServerConfig(...), "github": MCPServerConfig(...), }, categories=["development", "filesystem"], required_capabilities=["file_read"], global_timeout=120, max_concurrent_servers=5 )
- servers: dict[str, MCPServerConfig] = NoneΒΆ
- class mcp.config.MCPServerConfig(/, **data: Any)ΒΆ
Bases:
pydantic.BaseModel
Configuration for a single MCP server.
Represents the complete configuration needed to connect to and use an MCP server. Supports multiple transport types and provides extensive customization options.
- nameΒΆ
Unique identifier for the server
- enabledΒΆ
Whether this server should be activated
- transportΒΆ
Communication transport type (stdio, sse, streamable_http)
- commandΒΆ
Executable command for stdio transport
- argsΒΆ
Command arguments for stdio transport
- urlΒΆ
Server URL for HTTP-based transports
- envΒΆ
Environment variables to set when starting server
- api_keyΒΆ
Optional API key for authentication
- categoryΒΆ
Server category for organization (e.g., βfilesystemβ, βdatabaseβ)
- descriptionΒΆ
Human-readable description of server functionality
- capabilitiesΒΆ
List of capabilities provided by the server
- timeoutΒΆ
Connection timeout in seconds
- retry_attemptsΒΆ
Number of retry attempts on connection failure
- auto_startΒΆ
Whether to automatically start the server
- health_check_intervalΒΆ
Interval for health checks in seconds
Examples
Creating a GitHub MCP server config:
config = MCPServerConfig( name="github", transport="stdio", command="npx", args=["-y", "@modelcontextprotocol/server-github"], env={"GITHUB_TOKEN": "your_token"}, capabilities=["repo_access", "issue_management"], category="development", description="GitHub repository operations" )
- model_configΒΆ
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- transport: MCPTransport = NoneΒΆ
- class mcp.config.MCPTransportΒΆ
-
MCP transport types.
Defines the communication transport mechanisms supported by MCP servers.
- STDIOΒΆ
Standard input/output communication (default for CLI-based servers)
- SSEΒΆ
Server-Sent Events for HTTP-based streaming
- STREAMABLE_HTTPΒΆ
HTTP streaming for continuous data transfer
- SSE = 'sse'ΒΆ
- STDIO = 'stdio'ΒΆ
- STREAMABLE_HTTP = 'streamable_http'ΒΆ