ConfigurationΒΆ

The haive-mcp package provides flexible configuration options for MCP servers, discovery, and agent integration.

Configuration ClassesΒΆ

MCPTransportΒΆ

class haive.mcp.config.MCPTransport(*values)[source]ΒΆ

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'ΒΆ

Supported transport types:

  • stdio: Standard input/output communication (most common)

  • sse: Server-Sent Events for HTTP streaming

  • streamable_http: HTTP streaming for continuous data transfer

MCPServerConfigΒΆ

class haive.mcp.config.MCPServerConfig(*, name: str, enabled: bool = True, transport: ~haive.mcp.config.MCPTransport = MCPTransport.STDIO, command: str | None = None, args: list[str] | None = <factory>, url: str | None = None, env: dict[str, str] = <factory>, api_key: str | None = None, category: str | None = None, description: str | None = None, capabilities: list[str] = <factory>, timeout: int = 30, retry_attempts: int = 3, auto_start: bool = True, health_check_interval: int | None = None, **extra_data: ~typing.Any)[source]ΒΆ

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

Type:

str

enabledΒΆ

Whether this server should be activated

Type:

bool

transportΒΆ

Communication transport type (stdio, sse, streamable_http)

Type:

haive.mcp.config.MCPTransport

commandΒΆ

Executable command for stdio transport

Type:

str | None

argsΒΆ

Command arguments for stdio transport

Type:

list[str] | None

urlΒΆ

Server URL for HTTP-based transports

Type:

str | None

envΒΆ

Environment variables to set when starting server

Type:

dict[str, str]

api_keyΒΆ

Optional API key for authentication

Type:

str | None

categoryΒΆ

Server category for organization (e.g., β€œfilesystem”, β€œdatabase”)

Type:

str | None

descriptionΒΆ

Human-readable description of server functionality

Type:

str | None

capabilitiesΒΆ

List of capabilities provided by the server

Type:

list[str]

timeoutΒΆ

Connection timeout in seconds

Type:

int

retry_attemptsΒΆ

Number of retry attempts on connection failure

Type:

int

auto_startΒΆ

Whether to automatically start the server

Type:

bool

health_check_intervalΒΆ

Interval for health checks in seconds

Type:

int | None

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"
)
api_key: str | NoneΒΆ
args: list[str] | NoneΒΆ
auto_start: boolΒΆ
capabilities: list[str]ΒΆ
category: str | NoneΒΆ
command: str | NoneΒΆ
description: str | NoneΒΆ
enabled: boolΒΆ
env: dict[str, str]ΒΆ
health_check_interval: int | NoneΒΆ
model_config: ClassVar[ConfigDict] = {'extra': 'allow'}ΒΆ

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

name: strΒΆ
retry_attempts: intΒΆ
timeout: intΒΆ
transport: MCPTransportΒΆ
url: str | NoneΒΆ

Key configuration fields:

MCPServerConfig(
    name="server_name",           # Unique identifier
    enabled=True,                 # Whether to activate
    transport="stdio",            # Communication method
    command="npx",                # Executable command
    args=["-y", "package-name"],  # Command arguments
    url="http://localhost:3000",  # For HTTP transports
    env={"KEY": "value"},         # Environment variables
    api_key="secret",             # Authentication key
    category="filesystem",        # Organizational category
    description="Server purpose", # Human-readable description
    capabilities=["read", "write"], # Server capabilities
    timeout=30,                   # Connection timeout (seconds)
    retry_attempts=3,             # Retry count on failure
    auto_start=True,              # Auto-start on init
    health_check_interval=60      # Health check frequency
)

MCPConfigΒΆ

class haive.mcp.config.MCPConfig(*, enabled: bool = False, auto_discover: bool = True, lazy_init: bool = True, servers: dict[str, ~haive.mcp.config.MCPServerConfig] = <factory>, discovery_paths: list[str] = <factory>, categories: list[str] | None = None, required_capabilities: list[str] | None = None, global_timeout: int = 60, max_concurrent_servers: int = 10, enable_health_checks: bool = True, on_server_connected: str | None = None, on_server_failed: str | None = None, on_tool_discovered: str | None = None)[source]ΒΆ

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

Type:

bool

auto_discoverΒΆ

Automatically discover servers from configured paths

Type:

bool

lazy_initΒΆ

Initialize servers on-demand rather than at startup

Type:

bool

serversΒΆ

Dictionary mapping server names to their configurations

Type:

dict[str, haive.mcp.config.MCPServerConfig]

discovery_pathsΒΆ

List of paths to search for MCP server configurations

Type:

list[str]

categoriesΒΆ

Optional filter for server categories

Type:

list[str] | None

required_capabilitiesΒΆ

Optional list of required server capabilities

Type:

list[str] | None

global_timeoutΒΆ

Timeout for all MCP operations in seconds

Type:

int

max_concurrent_serversΒΆ

Maximum number of concurrent server connections

Type:

int

enable_health_checksΒΆ

Whether to enable periodic server health checks

Type:

bool

on_server_connectedΒΆ

Optional callback name when server connects

Type:

str | None

on_server_failedΒΆ

Optional callback name when server fails

Type:

str | None

on_tool_discoveredΒΆ

Optional callback name when tool is discovered

Type:

str | None

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
)
auto_discover: boolΒΆ
categories: list[str] | NoneΒΆ
discovery_paths: list[str]ΒΆ
enable_health_checks: boolΒΆ
enabled: boolΒΆ
global_timeout: intΒΆ
lazy_init: boolΒΆ
max_concurrent_servers: intΒΆ
model_config: ClassVar[ConfigDict] = {}ΒΆ

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

on_server_connected: str | NoneΒΆ
on_server_failed: str | NoneΒΆ
on_tool_discovered: str | NoneΒΆ
required_capabilities: list[str] | NoneΒΆ
servers: dict[str, MCPServerConfig]ΒΆ

Main configuration options:

MCPConfig(
    enabled=True,                 # Enable MCP functionality
    auto_discover=True,           # Auto-discover servers
    lazy_init=False,              # Initialize immediately
    servers={},                   # Server configurations
    discovery_paths=[],           # Paths to search for configs
    categories=["dev", "data"],   # Filter by categories
    required_capabilities=[],     # Required server capabilities
    global_timeout=60,            # Global operation timeout
    max_concurrent_servers=10,    # Max concurrent connections
    enable_health_checks=True,    # Enable health monitoring
    on_server_connected="callback", # Connection callback
    on_server_failed="callback",   # Failure callback
    on_tool_discovered="callback"  # Tool discovery callback
)

Configuration ExamplesΒΆ

Basic Filesystem ServerΒΆ

from haive.mcp.config import MCPConfig, MCPServerConfig

config = MCPConfig(
    enabled=True,
    servers={
        "filesystem": MCPServerConfig(
            name="filesystem",
            transport="stdio",
            command="npx",
            args=["-y", "@modelcontextprotocol/server-filesystem"],
            env={"ALLOWED_PATHS": "/home/user/documents"},
            capabilities=["file_read", "file_write", "directory_list"],
            timeout=30
        )
    }
)

Multi-Server Development EnvironmentΒΆ

config = MCPConfig(
    enabled=True,
    servers={
        "filesystem": MCPServerConfig(
            name="filesystem",
            transport="stdio",
            command="npx",
            args=["-y", "@modelcontextprotocol/server-filesystem"],
            category="storage"
        ),
        "github": MCPServerConfig(
            name="github",
            transport="stdio",
            command="npx",
            args=["-y", "@modelcontextprotocol/server-github"],
            env={"GITHUB_TOKEN": os.getenv("GITHUB_TOKEN")},
            category="development"
        ),
        "postgres": MCPServerConfig(
            name="postgres",
            transport="stdio",
            command="npx",
            args=["-y", "@modelcontextprotocol/server-postgres"],
            env={"DATABASE_URL": "postgresql://localhost/dev"},
            category="database"
        )
    },
    categories=["development", "database"],  # Only load these categories
    required_capabilities=["database_query"], # Must have DB access
    max_concurrent_servers=5,
    enable_health_checks=True
)

HTTP-Based ServerΒΆ

config = MCPConfig(
    enabled=True,
    servers={
        "api_server": MCPServerConfig(
            name="api_server",
            transport="sse",  # Server-Sent Events
            url="http://localhost:3000/mcp",
            api_key="your-api-key",
            timeout=60,
            health_check_interval=30
        )
    }
)

Custom Server ConfigurationΒΆ

config = MCPConfig(
    enabled=True,
    servers={
        "custom_server": MCPServerConfig(
            name="custom_server",
            transport="stdio",
            command="python",
            args=["/path/to/my_server.py", "--port", "8080"],
            env={
                "SERVER_MODE": "production",
                "LOG_LEVEL": "INFO",
                "API_KEY": os.getenv("CUSTOM_API_KEY")
            },
            capabilities=["custom_tool", "data_analysis"],
            category="custom",
            description="My custom MCP server implementation",
            timeout=45,
            retry_attempts=5,
            health_check_interval=120
        )
    }
)

Discovery ConfigurationΒΆ

Automatic Server DiscoveryΒΆ

config = MCPConfig(
    enabled=True,
    auto_discover=True,
    discovery_paths=[
        "~/.mcp/servers",      # User config directory
        ".mcp/servers",        # Project-local configs
        "mcp_servers",         # Custom directory
        "/etc/mcp/servers"     # System-wide configs
    ],
    categories=["filesystem", "development"],  # Filter discovered servers
    required_capabilities=["file_read"]        # Capability requirements
)

Manual Server ConfigurationΒΆ

config = MCPConfig(
    enabled=True,
    auto_discover=False,  # Disable auto-discovery
    servers={
        # Explicitly configured servers only
        "filesystem": MCPServerConfig(...),
        "github": MCPServerConfig(...)
    }
)

Environment VariablesΒΆ

You can also configure MCP servers using environment variables:

# Enable MCP
export MCP_ENABLED=true

# Set global timeout
export MCP_GLOBAL_TIMEOUT=120

# Configure filesystem server
export MCP_FILESYSTEM_ENABLED=true
export MCP_FILESYSTEM_COMMAND=npx
export MCP_FILESYSTEM_ARGS="-y,@modelcontextprotocol/server-filesystem"
export MCP_FILESYSTEM_ALLOWED_PATHS="/home/user"

# Configure GitHub server
export MCP_GITHUB_ENABLED=true
export MCP_GITHUB_TOKEN="your_github_token"

Configuration FilesΒΆ

JSON ConfigurationΒΆ

Create a mcp_config.json file:

{
    "enabled": true,
    "auto_discover": true,
    "servers": {
        "filesystem": {
            "name": "filesystem",
            "transport": "stdio",
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-filesystem"],
            "capabilities": ["file_read", "file_write"],
            "timeout": 30
        },
        "github": {
            "name": "github",
            "transport": "stdio",
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-github"],
            "env": {"GITHUB_TOKEN": "${GITHUB_TOKEN}"},
            "capabilities": ["repo_access"]
        }
    }
}

YAML ConfigurationΒΆ

Create a mcp_config.yaml file:

enabled: true
auto_discover: true
global_timeout: 60
max_concurrent_servers: 10

servers:
  filesystem:
    name: filesystem
    transport: stdio
    command: npx
    args:
      - "-y"
      - "@modelcontextprotocol/server-filesystem"
    env:
      ALLOWED_PATHS: "/home/user/documents"
    capabilities:
      - file_read
      - file_write
      - directory_list
    timeout: 30

  github:
    name: github
    transport: stdio
    command: npx
    args:
      - "-y"
      - "@modelcontextprotocol/server-github"
    env:
      GITHUB_TOKEN: "${GITHUB_TOKEN}"
    capabilities:
      - repo_access
      - issue_management

Loading ConfigurationsΒΆ

import json
import yaml
from haive.mcp.config import MCPConfig

# From JSON
with open("mcp_config.json") as f:
    config_data = json.load(f)
config = MCPConfig(**config_data)

# From YAML
with open("mcp_config.yaml") as f:
    config_data = yaml.safe_load(f)
config = MCPConfig(**config_data)

# From environment (using a helper function)
config = MCPConfig.from_env()

Best PracticesΒΆ

  1. Use categories to organize servers by purpose

  2. Set appropriate timeouts based on server complexity

  3. Enable health checks for production environments

  4. Use environment variables for sensitive data like API keys

  5. Start with lazy_init=True for faster startup times

  6. Monitor server health and implement failure callbacks

  7. Test configurations in development before production deployment