core.server_context

Server Context - Dependency Injection Container Manages all server dependencies and eliminates global state

Classes

ServerContext([config_manager])

Centralized dependency injection container for the MCP server.

class core.server_context.ServerContext(config_manager=None)[source]

Bases: object

Centralized dependency injection container for the MCP server.

This class manages all server dependencies including configuration, pipelines, and session management, eliminating global state.

__init__(config_manager=None)[source]

Initialize the server context with default dependencies.

property config_manager: ConfigManager

Get the configuration manager, creating it if needed.

property document_pipeline: Pipeline | None

Get the document processing pipeline.

property rag_pipeline: RAGPipeline | None

Get the RAG pipeline.

property session_manager: ChatSessionManager

Get the session manager, creating it if needed.

property processors: List[IProcessor]

Get the list of loaded processors.

property is_initialized: bool

Check if the server context has been fully initialized.

initialize()[source]

Initialize all server components in the correct dependency order.

This method implements a multi-phase initialization strategy: 1. Guard check: Prevent duplicate initialization 2. Core pipeline setup: Create document processing pipeline 3. Processor loading: Dynamically load and configure document processors 4. RAG pipeline setup: Initialize retrieval-augmented generation capabilities 5. Validation: Ensure all components are properly initialized

The initialization order is critical: - Document pipeline must exist before processors are loaded - Processors must be loaded before RAG pipeline initialization - RAG pipeline depends on document processing capabilities

This method should be called once during server startup to ensure all dependencies are properly configured and connected.

Raises:

Exception – If any component fails to initialize properly

cleanup()[source]

Clean up resources and reset the context with proper resource management.

get_status()[source]

Get the current status of the server context.