We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Sudip-Pandit/mcp-healthcare-project'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
#!/usr/bin/env python3
"""
Configuration Module for Clinical MCP System
Centralized settings for server, client, and deployment.
"""
import os
from dataclasses import dataclass
from typing import Optional, Dict, Any
from enum import Enum
# ============================================================================
# ENVIRONMENT CONFIGURATION
# ============================================================================
class Environment(str, Enum):
"""Application environment"""
LOCAL = "local"
DEVELOPMENT = "development"
STAGING = "staging"
PRODUCTION = "production"
CURRENT_ENV = Environment(os.getenv("ENVIRONMENT", "local"))
# ============================================================================
# SERVER CONFIGURATION
# ============================================================================
@dataclass
class ServerConfig:
"""MCP Server configuration"""
# Server basics
name: str = "clinical-mcp"
version: str = "1.0.0"
host: str = "0.0.0.0"
port: int = 3000
# Timeouts (seconds)
ehr_api_timeout: float = 5.0
tool_execution_timeout: float = 30.0
# Caching
enable_caching: bool = True
cache_ttl_seconds: int = 3600 # 1 hour
cache_max_size: int = 1000
# Rate limiting
enable_rate_limiting: bool = True
rate_limit_requests_per_minute: int = 100
# Logging
log_level: str = "INFO"
log_format: str = "json"
log_to_stdout: bool = True
log_to_file: Optional[str] = None
# Security
require_https: bool = (CURRENT_ENV != Environment.LOCAL)
require_authentication: bool = (CURRENT_ENV in [Environment.STAGING, Environment.PRODUCTION])
# HIPAA Compliance
enable_audit_logging: bool = True
audit_log_retention_days: int = 2555 # 7 years
enable_pii_redaction: bool = True
def __post_init__(self):
"""Apply environment-specific overrides"""
if CURRENT_ENV == Environment.PRODUCTION:
self.log_level = "WARNING"
self.require_https = True
self.require_authentication = True
self.cache_ttl_seconds = 300 # 5 minutes in prod
self.ehr_api_timeout = 3.0
elif CURRENT_ENV == Environment.STAGING:
self.log_level = "INFO"
self.cache_ttl_seconds = 600
# Local and dev use defaults
server_config = ServerConfig()
# ============================================================================
# CLIENT CONFIGURATION
# ============================================================================
@dataclass
class ClientConfig:
"""Claude Client configuration"""
# API
api_key: Optional[str] = None
api_base_url: str = "https://api.anthropic.com"
api_timeout: float = 30.0
# Model selection
model: str = "claude-3-5-sonnet-20241022"
max_tokens: int = 2048
temperature: float = 0.7
# Tool use
enable_tool_use: bool = True
max_tool_iterations: int = 10
# Prompt templates
system_prompt_file: Optional[str] = "./prompts/clinical_system.txt"
use_builtin_prompts: bool = True
# Error handling
retry_attempts: int = 3
retry_delay_seconds: float = 1.0
# Logging
log_tool_calls: bool = True
log_responses: bool = (CURRENT_ENV == Environment.LOCAL)
def __post_init__(self):
"""Load API key from environment"""
if not self.api_key:
self.api_key = os.getenv("ANTHROPIC_API_KEY")
if CURRENT_ENV == Environment.PRODUCTION:
self.log_responses = False
client_config = ClientConfig()
# ============================================================================
# EHR/BACKEND CONFIGURATION
# ============================================================================
@dataclass
class EHRConfig:
"""EHR Backend configuration"""
# Connection
api_url: str = os.getenv("EHR_API_URL", "http://localhost:8080")
api_key: Optional[str] = os.getenv("EHR_API_KEY")
api_version: str = "v2"
# Authentication
auth_type: str = "bearer" # bearer, basic, oauth
# Timeouts
connection_timeout: float = 5.0
read_timeout: float = 10.0
# Retry policy
max_retries: int = 3
retry_delay_base: float = 1.0
retry_backoff_multiplier: float = 2.0
# Data formats
use_fhir: bool = True
fhir_version: str = "R4"
# Security
verify_ssl: bool = (CURRENT_ENV in [Environment.STAGING, Environment.PRODUCTION])
cert_path: Optional[str] = None
ehr_config = EHRConfig()
# ============================================================================
# DATABASE CONFIGURATION
# ============================================================================
@dataclass
class DatabaseConfig:
"""Database configuration for audit logs, cache, etc"""
# Connection
db_type: str = "postgresql" # postgresql, mysql, sqlite
db_host: str = os.getenv("DB_HOST", "localhost")
db_port: int = int(os.getenv("DB_PORT", "5432"))
db_name: str = os.getenv("DB_NAME", "clinical_mcp")
db_user: str = os.getenv("DB_USER", "postgres")
db_password: str = os.getenv("DB_PASSWORD", "")
# Pool settings
pool_size: int = 10
max_overflow: int = 20
pool_timeout: float = 30.0
# Encryption
encrypt_sensitive_data: bool = True
encryption_key_id: Optional[str] = os.getenv("ENCRYPTION_KEY_ID")
# Logging
echo_sql: bool = (CURRENT_ENV == Environment.LOCAL)
def get_connection_string(self) -> str:
"""Get database connection string"""
if self.db_type == "sqlite":
return f"sqlite:///{self.db_name}.db"
elif self.db_type == "postgresql":
return f"postgresql://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
elif self.db_type == "mysql":
return f"mysql+pymysql://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
else:
raise ValueError(f"Unknown database type: {self.db_type}")
database_config = DatabaseConfig()
# ============================================================================
# SECURITY CONFIGURATION
# ============================================================================
@dataclass
class SecurityConfig:
"""Security and compliance configuration"""
# HIPAA
enable_hipaa_audit: bool = True
hipaa_audit_retention_years: int = 7
pii_patterns_to_mask: Dict[str, str] = None
# Data protection
encrypt_at_rest: bool = True
encrypt_in_transit: bool = True
tls_min_version: str = "1.3"
# PII handling
mask_mrn: bool = True
mask_ssn: bool = True
mask_dob: bool = False # Keep for age calculation
mask_phone: bool = True
mask_email: bool = True
# RBAC
enable_rbac: bool = True
role_definitions_file: Optional[str] = "./config/roles.yaml"
# API keys
api_key_rotation_days: int = 90
# Audit log
immutable_audit_log: bool = True
audit_log_location: str = "database" # database, s3, file
def __post_init__(self):
"""Initialize PII patterns"""
if self.pii_patterns_to_mask is None:
self.pii_patterns_to_mask = {
"ssn": r"\d{3}-\d{2}-\d{4}",
"phone": r"\d{3}-\d{3}-\d{4}",
"email": r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}",
"mrn": r"MRN\d{3,10}",
"credit_card": r"\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}"
}
security_config = SecurityConfig()
# ============================================================================
# OBSERVABILITY CONFIGURATION
# ============================================================================
@dataclass
class ObservabilityConfig:
"""Logging, metrics, tracing configuration"""
# Logging
log_level: str = "INFO"
log_format: str = "json" # json, text
log_to_stdout: bool = True
log_to_file: Optional[str] = None
# Metrics
enable_metrics: bool = True
metrics_port: int = 9090
metrics_prefix: str = "clinical_mcp"
# Tracing
enable_tracing: bool = (CURRENT_ENV != Environment.LOCAL)
tracing_backend: str = "jaeger" # jaeger, datadog, aws_xray
tracing_sample_rate: float = 0.1 if CURRENT_ENV == Environment.PRODUCTION else 1.0
# Health checks
enable_health_check: bool = True
health_check_port: int = 8000
health_check_interval_seconds: int = 30
# Alerting
enable_alerting: bool = (CURRENT_ENV in [Environment.STAGING, Environment.PRODUCTION])
alert_thresholds: Dict[str, Any] = None
def __post_init__(self):
"""Initialize alert thresholds"""
if self.alert_thresholds is None:
self.alert_thresholds = {
"error_rate_percent": 5.0,
"latency_p95_ms": 5000,
"tool_timeout_rate": 10.0,
"auth_failure_rate": 1.0
}
observability_config = ObservabilityConfig()
# ============================================================================
# DEPLOYMENT CONFIGURATION
# ============================================================================
@dataclass
class DeploymentConfig:
"""Deployment and infrastructure configuration"""
# Container
container_image: str = "clinical-mcp:latest"
container_registry: str = os.getenv("CONTAINER_REGISTRY", "")
# Kubernetes
k8s_namespace: str = "healthcare"
k8s_replicas: int = 3 if CURRENT_ENV == Environment.PRODUCTION else 1
k8s_resource_requests: Dict[str, str] = None
k8s_resource_limits: Dict[str, str] = None
# Scaling
enable_autoscaling: bool = (CURRENT_ENV == Environment.PRODUCTION)
min_replicas: int = 2
max_replicas: int = 10
target_cpu_percent: int = 70
# Backup & Disaster Recovery
enable_backup: bool = True
backup_retention_days: int = 30
backup_location: str = "s3"
# Regional deployment
region: str = os.getenv("AWS_REGION", "us-east-1")
multi_region: bool = (CURRENT_ENV == Environment.PRODUCTION)
def __post_init__(self):
"""Initialize K8s resource configs"""
if self.k8s_resource_requests is None:
self.k8s_resource_requests = {
"memory": "256Mi",
"cpu": "100m"
}
if self.k8s_resource_limits is None:
self.k8s_resource_limits = {
"memory": "512Mi",
"cpu": "500m"
}
deployment_config = DeploymentConfig()
# ============================================================================
# CONSOLIDATED CONFIG
# ============================================================================
@dataclass
class Config:
"""All configuration in one place"""
environment: Environment = CURRENT_ENV
server: ServerConfig = None
client: ClientConfig = None
ehr: EHRConfig = None
database: DatabaseConfig = None
security: SecurityConfig = None
observability: ObservabilityConfig = None
deployment: DeploymentConfig = None
def __post_init__(self):
"""Initialize all sub-configs"""
if self.server is None:
self.server = server_config
if self.client is None:
self.client = client_config
if self.ehr is None:
self.ehr = ehr_config
if self.database is None:
self.database = database_config
if self.security is None:
self.security = security_config
if self.observability is None:
self.observability = observability_config
if self.deployment is None:
self.deployment = deployment_config
def to_dict(self) -> Dict[str, Any]:
"""Convert config to dictionary"""
return {
"environment": self.environment.value,
"server": self.server.__dict__,
"client": self.client.__dict__,
"ehr": self.ehr.__dict__,
"database": self.database.__dict__,
"security": self.security.__dict__,
"observability": self.observability.__dict__,
"deployment": self.deployment.__dict__
}
# Global config instance
config = Config()
# ============================================================================
# UTILITY FUNCTIONS
# ============================================================================
def get_config() -> Config:
"""Get global configuration"""
return config
def print_config(verbose: bool = False):
"""Print current configuration"""
print(f"Environment: {config.environment.value}")
if verbose:
import json
print(json.dumps(config.to_dict(), indent=2, default=str))
if __name__ == "__main__":
print_config(verbose=True)