🚀 Performance Fix: Implement Lazy Loading to Resolve MCP Server Timeout Issues #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Performance Fix: Implement Lazy Loading to Resolve MCP Server Timeout Issues
Overview
This PR implements lazy loading for heavy components to resolve widespread MCP server timeout and disconnect issues. Reduces startup time from 10+ seconds to <1 second.
Problem Solved
Multiple users have reported timeout/disconnect issues across different MCP clients:
Root cause: Heavy components (PyTorch CrossEncoder, Neo4j Knowledge Graph, AST parsing) loaded during startup, causing 5-10 second delays that trigger client timeouts.
Solution: Lazy Loading Implementation
Key Changes
Added lazy loading wrapper functions:
get_reranking_model()- Loads CrossEncoder only when neededget_knowledge_validator()- Loads Neo4j only when neededget_repo_extractor()- Loads AST parser only when neededModified lifespan function to only load essential components:
Updated tool functions to use lazy loading:
perform_rag_query()→ usesget_reranking_model()check_ai_script_hallucinations()→ usesget_knowledge_validator()parse_github_repository()→ usesget_repo_extractor()Performance Results
Testing
Impact
This fix resolves the most common issue reported by users - MCP server timeouts during startup. It makes the server much more reliable and responsive across all MCP clients.
Backward Compatibility