mcp.downloader.config ===================== .. py:module:: mcp.downloader.config .. autoapi-nested-parse:: Configuration models for MCP Downloader. This module defines the configuration models used throughout the MCP downloader system, including templates, server configurations, and installation methods. .. rubric:: Example Creating a server template: .. code-block:: python template = ServerTemplate( name="npm_official", installation_method=InstallationMethod.NPM, command_pattern="@modelcontextprotocol/server-{service}", capabilities=["tools"], category="official" ) Creating a server configuration: .. code-block:: python config = ServerConfig( name="filesystem", template="npm_official", source="npm", variables={"service": "filesystem"}, tags={"official", "file-operations"} ) Classes: InstallationMethod: Enum of supported installation methods ServerTemplate: Template for server installation patterns ServerConfig: Configuration for a specific server DownloaderConfig: Overall downloader configuration Classes ------- .. autoapisummary:: mcp.downloader.config.DiscoveryConfig mcp.downloader.config.DownloaderConfig mcp.downloader.config.InstallationMethod mcp.downloader.config.ServerConfig mcp.downloader.config.ServerTemplate Functions --------- .. autoapisummary:: mcp.downloader.config.load_config mcp.downloader.config.save_config Module Contents --------------- .. py:class:: DiscoveryConfig(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel` Configuration for server discovery. .. attribute:: sources List of discovery source URLs .. attribute:: patterns Package naming patterns by registry .. attribute:: auto_discover Enable automatic discovery .. attribute:: discovery_interval Hours between discovery runs .. attribute:: max_servers Maximum servers to discover per source .. py:attribute:: auto_discover :type: bool :value: None .. py:attribute:: discovery_interval :type: int :value: None .. py:attribute:: max_servers :type: int :value: None .. py:attribute:: patterns :type: dict[str, list[str]] :value: None .. py:attribute:: sources :type: list[str] :value: None .. py:class:: DownloaderConfig(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel` Overall configuration for the MCP downloader. .. attribute:: install_dir Directory for server installations .. attribute:: config_dir Directory for configuration files .. attribute:: log_dir Directory for log files .. attribute:: max_concurrent Maximum concurrent downloads .. attribute:: retry_attempts Number of retry attempts .. attribute:: retry_delay Delay between retries in seconds .. attribute:: health_check_enabled Enable health checks after install .. attribute:: health_check_timeout Health check timeout in seconds .. attribute:: backup_enabled Enable configuration backups .. attribute:: backup_dir Directory for backups .. attribute:: templates List of server templates .. attribute:: servers List of server configurations .. attribute:: discovery Discovery configuration .. rubric:: Example Full configuration: .. code-block:: python config = DownloaderConfig( install_dir="/home/user/.mcp/servers", max_concurrent=5, retry_attempts=3, templates=[template1, template2], servers=[server1, server2] ) .. py:attribute:: backup_dir :type: pathlib.Path :value: None .. py:attribute:: backup_enabled :type: bool :value: None .. py:attribute:: config_dir :type: pathlib.Path :value: None .. py:attribute:: discovery :type: DiscoveryConfig :value: None .. py:attribute:: health_check_enabled :type: bool :value: None .. py:attribute:: health_check_timeout :type: int :value: None .. py:attribute:: install_dir :type: pathlib.Path :value: None .. py:attribute:: log_dir :type: pathlib.Path :value: None .. py:attribute:: max_concurrent :type: int :value: None .. py:attribute:: retry_attempts :type: int :value: None .. py:attribute:: retry_delay :type: int :value: None .. py:attribute:: servers :type: list[ServerConfig] :value: None .. py:attribute:: templates :type: list[ServerTemplate] :value: None .. py:class:: InstallationMethod Bases: :py:obj:`str`, :py:obj:`enum.Enum` Supported installation methods for MCP servers. .. attribute:: NPM Node Package Manager installation .. attribute:: PIP Python Package Index installation .. attribute:: GIT Git repository cloning .. attribute:: DOCKER Docker image pull .. attribute:: BINARY Binary executable download .. attribute:: CURL Direct HTTP download .. attribute:: MANUAL Manual installation process .. attribute:: SCRIPT Custom script execution .. py:attribute:: BINARY :value: 'binary' .. py:attribute:: CURL :value: 'curl' .. py:attribute:: DOCKER :value: 'docker' .. py:attribute:: GIT :value: 'git' .. py:attribute:: MANUAL :value: 'manual' .. py:attribute:: NPM :value: 'npm' .. py:attribute:: PIP :value: 'pip' .. py:attribute:: SCRIPT :value: 'script' .. py:class:: ServerConfig(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel` Configuration for a specific MCP server. Server configurations define individual servers to be installed, referencing a template and providing server-specific variables. .. attribute:: name Server name identifier .. attribute:: template Template name to use .. attribute:: source Source location (npm, git URL, etc.) .. attribute:: variables Variables to substitute in template patterns .. attribute:: enabled Whether the server is enabled for installation .. attribute:: priority Installation priority (lower = higher priority) .. attribute:: tags Set of tags for categorization .. attribute:: env_vars Additional environment variables .. attribute:: version Specific version to install .. rubric:: Example Filesystem server config: .. code-block:: python config = ServerConfig( name="filesystem", template="npm_official", source="npm", variables={"service": "filesystem"}, tags={"official", "file-operations"}, priority=1 ) .. py:attribute:: enabled :type: bool :value: None .. py:attribute:: env_vars :type: dict[str, str] :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:: priority :type: int :value: None .. py:attribute:: source :type: str :value: None .. py:attribute:: tags :type: set[str] :value: None .. py:attribute:: template :type: str :value: None .. py:attribute:: variables :type: dict[str, Any] :value: None .. py:attribute:: version :type: str | None :value: None .. py:class:: ServerTemplate(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel` Template for MCP server installation patterns. Templates define reusable installation patterns that can be applied to multiple servers with similar installation requirements. .. attribute:: name Unique template identifier .. attribute:: installation_method Method to use for installation .. attribute:: command_pattern Pattern for the command to run the server .. attribute:: args_pattern Default arguments for the command .. attribute:: env_vars Environment variables to set .. attribute:: capabilities List of server capabilities .. attribute:: category Server category for organization .. attribute:: health_check Command to verify server health .. attribute:: prerequisites Required system dependencies .. attribute:: post_install Commands to run after installation .. attribute:: timeout Installation timeout in seconds .. rubric:: Example NPM template: .. code-block:: python template = ServerTemplate( name="npm_official", installation_method=InstallationMethod.NPM, command_pattern="@modelcontextprotocol/server-{service}", capabilities=["tools"], category="official", prerequisites=["node", "npm"] ) .. py:attribute:: args_pattern :type: list[str] :value: None .. py:attribute:: capabilities :type: list[str] :value: None .. py:attribute:: category :type: str :value: None .. py:attribute:: command_pattern :type: str :value: None .. py:attribute:: env_vars :type: dict[str, str] :value: None .. py:attribute:: health_check :type: str | None :value: None .. py:attribute:: installation_method :type: InstallationMethod :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:: post_install :type: list[str] :value: None .. py:attribute:: prerequisites :type: list[str] :value: None .. py:attribute:: timeout :type: int :value: None .. py:function:: load_config(config_file: pathlib.Path) -> DownloaderConfig Load configuration from YAML file. :param config_file: Path to YAML configuration file :returns: Loaded configuration :rtype: DownloaderConfig :raises FileNotFoundError: If config file doesn't exist :raises ValueError: If config file is invalid .. rubric:: Example Loading config: .. code-block:: python config = load_config(Path("mcp_config.yaml")) print(f"Loaded {len(config.templates)} templates") .. py:function:: save_config(config: DownloaderConfig, config_file: pathlib.Path) -> None Save configuration to YAML file. :param config: Configuration to save :param config_file: Path to save file .. rubric:: Example Saving config: .. code-block:: python config = DownloaderConfig(max_concurrent=10) save_config(config, Path("my_config.yaml"))