mcp.config ========== .. py:module:: mcp.config .. autoapi-nested-parse:: 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 .. rubric:: Examples Creating an MCP server configuration: .. code-block:: python 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 ------- .. autoapisummary:: mcp.config.MCPConfig mcp.config.MCPServerConfig mcp.config.MCPTransport Module Contents --------------- .. py:class:: MCPConfig(/, **data: Any) Bases: :py:obj:`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. .. attribute:: enabled Whether MCP functionality is enabled .. attribute:: auto_discover Automatically discover servers from configured paths .. attribute:: lazy_init Initialize servers on-demand rather than at startup .. attribute:: servers Dictionary mapping server names to their configurations .. attribute:: discovery_paths List of paths to search for MCP server configurations .. attribute:: categories Optional filter for server categories .. attribute:: required_capabilities Optional list of required server capabilities .. attribute:: global_timeout Timeout for all MCP operations in seconds .. attribute:: max_concurrent_servers Maximum number of concurrent server connections .. attribute:: enable_health_checks Whether to enable periodic server health checks .. attribute:: on_server_connected Optional callback name when server connects .. attribute:: on_server_failed Optional callback name when server fails .. attribute:: on_tool_discovered Optional callback name when tool is discovered .. rubric:: Examples Creating a comprehensive MCP configuration: .. code-block:: python config = MCPConfig( enabled=True, servers={ "filesystem": MCPServerConfig(...), "github": MCPServerConfig(...), }, categories=["development", "filesystem"], required_capabilities=["file_read"], global_timeout=120, max_concurrent_servers=5 ) .. py:attribute:: auto_discover :type: bool :value: None .. py:attribute:: categories :type: list[str] | None :value: None .. py:attribute:: discovery_paths :type: list[str] :value: None .. py:attribute:: enable_health_checks :type: bool :value: None .. py:attribute:: enabled :type: bool :value: None .. py:attribute:: global_timeout :type: int :value: None .. py:attribute:: lazy_init :type: bool :value: None .. py:attribute:: max_concurrent_servers :type: int :value: None .. py:attribute:: on_server_connected :type: str | None :value: None .. py:attribute:: on_server_failed :type: str | None :value: None .. py:attribute:: on_tool_discovered :type: str | None :value: None .. py:attribute:: required_capabilities :type: list[str] | None :value: None .. py:attribute:: servers :type: dict[str, MCPServerConfig] :value: None .. py:class:: MCPServerConfig(/, **data: Any) Bases: :py:obj:`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. .. attribute:: name Unique identifier for the server .. attribute:: enabled Whether this server should be activated .. attribute:: transport Communication transport type (stdio, sse, streamable_http) .. attribute:: command Executable command for stdio transport .. attribute:: args Command arguments for stdio transport .. attribute:: url Server URL for HTTP-based transports .. attribute:: env Environment variables to set when starting server .. attribute:: api_key Optional API key for authentication .. attribute:: category Server category for organization (e.g., "filesystem", "database") .. attribute:: description Human-readable description of server functionality .. attribute:: capabilities List of capabilities provided by the server .. attribute:: timeout Connection timeout in seconds .. attribute:: retry_attempts Number of retry attempts on connection failure .. attribute:: auto_start Whether to automatically start the server .. attribute:: health_check_interval Interval for health checks in seconds .. rubric:: Examples Creating a GitHub MCP server config: .. code-block:: python 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" ) .. py:attribute:: api_key :type: str | None :value: None .. py:attribute:: args :type: list[str] | None :value: None .. py:attribute:: auto_start :type: bool :value: None .. py:attribute:: capabilities :type: list[str] :value: None .. py:attribute:: category :type: str | None :value: None .. py:attribute:: command :type: str | None :value: None .. py:attribute:: description :type: str | None :value: None .. py:attribute:: enabled :type: bool :value: None .. py:attribute:: env :type: dict[str, str] :value: None .. py:attribute:: health_check_interval :type: int | None :value: None .. py:attribute:: model_config Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict]. .. py:attribute:: name :type: str :value: None .. py:attribute:: retry_attempts :type: int :value: None .. py:attribute:: timeout :type: int :value: None .. py:attribute:: transport :type: MCPTransport :value: None .. py:attribute:: url :type: str | None :value: None .. py:class:: MCPTransport Bases: :py:obj:`str`, :py:obj:`enum.Enum` MCP transport types. Defines the communication transport mechanisms supported by MCP servers. .. attribute:: STDIO Standard input/output communication (default for CLI-based servers) .. attribute:: SSE Server-Sent Events for HTTP-based streaming .. attribute:: STREAMABLE_HTTP HTTP streaming for continuous data transfer .. py:attribute:: SSE :value: 'sse' .. py:attribute:: STDIO :value: 'stdio' .. py:attribute:: STREAMABLE_HTTP :value: 'streamable_http'