73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
"""
|
|
Server Configuration
|
|
"""
|
|
from typing import Dict, Any, Optional
|
|
from dataclasses import dataclass
|
|
|
|
from ..core.types import TransportType
|
|
|
|
|
|
@dataclass
|
|
class ServerConfig:
|
|
"""Configuration class for MCP servers"""
|
|
|
|
name: str = "MCP Server"
|
|
version: str = "1.0.0"
|
|
transport: TransportType = TransportType.STDIO
|
|
host: str = "0.0.0.0"
|
|
port: int = 8050
|
|
stateless_http: bool = True
|
|
|
|
# Tool configurations
|
|
enable_default_tools: bool = True
|
|
custom_tools: Optional[Dict[str, Any]] = None
|
|
|
|
# Resource configurations
|
|
enable_file_resources: bool = False
|
|
resource_paths: Optional[list[str]] = None
|
|
|
|
# Prompt configurations
|
|
enable_default_prompts: bool = False
|
|
custom_prompts: Optional[Dict[str, Any]] = None
|
|
|
|
# Performance settings
|
|
max_concurrent_requests: int = 10
|
|
request_timeout: int = 30
|
|
|
|
def __post_init__(self):
|
|
"""Initialize optional fields"""
|
|
if self.custom_tools is None:
|
|
self.custom_tools = {}
|
|
if self.resource_paths is None:
|
|
self.resource_paths = []
|
|
if self.custom_prompts is None:
|
|
self.custom_prompts = {}
|
|
|
|
@classmethod
|
|
def from_dict(cls, config_dict: Dict[str, Any]) -> 'ServerConfig':
|
|
"""Create ServerConfig from dictionary"""
|
|
# Convert transport string to enum
|
|
if 'transport' in config_dict and isinstance(config_dict['transport'], str):
|
|
config_dict['transport'] = TransportType(config_dict['transport'].lower())
|
|
|
|
return cls(**config_dict)
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
"""Convert to dictionary"""
|
|
result = self.__dict__.copy()
|
|
result['transport'] = self.transport.value
|
|
return result
|
|
|
|
def get_transport_config(self) -> Dict[str, Any]:
|
|
"""Get transport-specific configuration"""
|
|
if self.transport == TransportType.SSE:
|
|
return {
|
|
"host": self.host,
|
|
"port": self.port,
|
|
"endpoint": "/sse",
|
|
}
|
|
elif self.transport == TransportType.STDIO:
|
|
return {}
|
|
else:
|
|
return {}
|