Skip to content

MCP Config Manager

dnallm.mcp.config_manager

Configuration Manager for MCP Server.

This module provides configuration management functionality for the MCP server, including loading, validating, and managing both main server configurations and individual model configurations.

Classes

MCPConfigManager

MCPConfigManager(
    config_dir, server_config_file="mcp_server_config.yaml"
)

Manages MCP server configurations and model configurations.

Initialize the configuration manager.

Parameters:

Name Type Description Default
config_dir str

Path to the configuration directory

required
server_config_file str

Name of the server configuration file

'mcp_server_config.yaml'
Source code in dnallm/mcp/config_manager.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def __init__(
    self,
    config_dir: str,
    server_config_file: str = "mcp_server_config.yaml",
):
    """Initialize the configuration manager.

    Args:
        config_dir: Path to the configuration directory
        server_config_file: Name of the server configuration file
    """
    self.config_dir = Path(config_dir)
    self.server_config_path = self.config_dir / server_config_file
    self.server_config: MCPServerConfig | None = None
    self.model_configs: dict[str, InferenceModelConfig] = {}
    self._load_configurations()
Functions
get_enabled_models
get_enabled_models()

Get list of enabled model names.

Returns:

Type Description
list[str]

List of enabled model names

Source code in dnallm/mcp/config_manager.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def get_enabled_models(self) -> list[str]:
    """Get list of enabled model names.

    Returns:
        List of enabled model names
    """
    if not self.server_config:
        return []

    return [
        name
        for name, entry in self.server_config.models.items()
        if entry.enabled
    ]
get_logging_config
get_logging_config()

Get logging configuration.

Returns:

Type Description
dict[str, Any]

Dictionary of logging configuration parameters

Source code in dnallm/mcp/config_manager.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def get_logging_config(self) -> dict[str, Any]:
    """Get logging configuration.

    Returns:
        Dictionary of logging configuration parameters
    """
    if not self.server_config:
        return {}

    logging_config = self.server_config.logging
    return {
        "level": logging_config.level,
        "format": logging_config.format,
        "file": logging_config.file,
        "max_size": logging_config.max_size,
        "backup_count": logging_config.backup_count,
    }
get_model_config
get_model_config(model_name)

Get configuration for a specific model.

Parameters:

Name Type Description Default
model_name str

Name of the model

required

Returns:

Type Description
InferenceModelConfig | None

InferenceModelConfig object or None if not found

Source code in dnallm/mcp/config_manager.py
103
104
105
106
107
108
109
110
111
112
def get_model_config(self, model_name: str) -> InferenceModelConfig | None:
    """Get configuration for a specific model.

    Args:
        model_name: Name of the model

    Returns:
        InferenceModelConfig object or None if not found
    """
    return self.model_configs.get(model_name)
get_model_configs
get_model_configs()

Get all loaded model configurations.

Returns:

Type Description
dict[str, InferenceModelConfig]

Dictionary of model configurations

Source code in dnallm/mcp/config_manager.py
114
115
116
117
118
119
120
def get_model_configs(self) -> dict[str, InferenceModelConfig]:
    """Get all loaded model configurations.

    Returns:
        Dictionary of model configurations
    """
    return self.model_configs.copy()
get_model_info_summary
get_model_info_summary()

Get summary information about all loaded models.

Returns:

Type Description
dict[str, Any]

Dictionary containing model information summary

Source code in dnallm/mcp/config_manager.py
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
def get_model_info_summary(self) -> dict[str, Any]:
    """Get summary information about all loaded models.

    Returns:
        Dictionary containing model information summary
    """
    summary = {
        "total_models": len(self.model_configs),
        "enabled_models": len(self.get_enabled_models()),
        "models": {},
    }

    for model_name, model_config in self.model_configs.items():
        summary["models"][model_name] = {
            "task_type": model_config.task.task_type,
            "num_labels": model_config.task.num_labels,
            "label_names": model_config.task.label_names,
            "model_path": model_config.model.path,
            "model_source": model_config.model.source,
            "architecture": model_config.model.task_info.architecture,
            "tokenizer": model_config.model.task_info.tokenizer,
            "species": model_config.model.task_info.species,
            "task_category": model_config.model.task_info.task_category,
        }

    return summary
get_model_priority
get_model_priority(model_name)

Get priority of a specific model.

Parameters:

Name Type Description Default
model_name str

Name of the model

required

Returns:

Type Description
int

Priority value (1-10, higher is more important)

Source code in dnallm/mcp/config_manager.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def get_model_priority(self, model_name: str) -> int:
    """Get priority of a specific model.

    Args:
        model_name: Name of the model

    Returns:
        Priority value (1-10, higher is more important)
    """
    if (
        not self.server_config
        or model_name not in self.server_config.models
    ):
        return 1

    return self.server_config.models[model_name].priority
get_multi_model_configs
get_multi_model_configs()

Get multi-model parallel prediction configurations.

Returns:

Type Description
dict[str, Any]

Dictionary of multi-model configurations

Source code in dnallm/mcp/config_manager.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def get_multi_model_configs(self) -> dict[str, Any]:
    """Get multi-model parallel prediction configurations.

    Returns:
        Dictionary of multi-model configurations
    """
    if not self.server_config:
        return {}

    return {
        name: {
            "name": config.name,
            "description": config.description,
            "models": config.models,
            "enabled": config.enabled,
        }
        for name, config in self.server_config.multi_model.items()
    }
get_server_config
get_server_config()

Get the main server configuration.

Returns:

Type Description
MCPServerConfig | None

MCPServerConfig object or None if not loaded

Source code in dnallm/mcp/config_manager.py
 95
 96
 97
 98
 99
100
101
def get_server_config(self) -> MCPServerConfig | None:
    """Get the main server configuration.

    Returns:
        MCPServerConfig object or None if not loaded
    """
    return self.server_config
get_sse_config
get_sse_config()

Get SSE configuration.

Returns:

Type Description
dict[str, Any]

Dictionary of SSE configuration parameters

Source code in dnallm/mcp/config_manager.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
def get_sse_config(self) -> dict[str, Any]:
    """Get SSE configuration.

    Returns:
        Dictionary of SSE configuration parameters
    """
    if not self.server_config:
        return {}

    sse_config = self.server_config.sse
    return {
        "heartbeat_interval": sse_config.heartbeat_interval,
        "max_connections": sse_config.max_connections,
        "connection_timeout": sse_config.connection_timeout,
        "enable_compression": sse_config.enable_compression,
    }
reload_configurations
reload_configurations()

Reload all configurations from files.

Source code in dnallm/mcp/config_manager.py
208
209
210
211
212
213
def reload_configurations(self) -> None:
    """Reload all configurations from files."""
    logger.info("Reloading configurations...")
    self.model_configs.clear()
    self._load_configurations()
    logger.info("Configurations reloaded successfully")
validate_model_references
validate_model_references()

Validate that all model references are valid.

Returns:

Type Description
list[str]

List of validation error messages

Source code in dnallm/mcp/config_manager.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
def validate_model_references(self) -> list[str]:
    """Validate that all model references are valid.

    Returns:
        List of validation error messages
    """
    errors = []

    if not self.server_config:
        errors.append("Server configuration not loaded")
        return errors

    # Check that all multi-model configurations reference existing models
    available_models = set(self.server_config.models.keys())

    for multi_name, multi_config in self.server_config.multi_model.items():
        for model_name in multi_config.models:
            if model_name not in available_models:
                errors.append(
                    f"Multi-model config '{multi_name}' references "
                    f"non-existent model '{model_name}'"
                )

    # Check that all model config files exist and are valid
    for model_name, _model_entry in self.server_config.models.items():
        if model_name not in self.model_configs:
            errors.append(
                f"Model configuration not loaded for '{model_name}'"
            )

    return errors

Functions