Problem
MCP server performs eager initialization causing 2-5s delays in AI tools. Every AI interaction is blocked by full indexer startup, creating poor UX.
Current behavior:
- Server initializes
RepositoryIndexer on startup
- Location:
packages/mcp-server/bin/dev-agent-mcp.ts:117
- TODO comment exists: "Make this truly lazy (only initialize on first tool call)"
Impact
- User Experience: 2-5s delay before every AI tool interaction
- Adoption: Makes dev-agent feel sluggish compared to competitors
- Success Criteria: <500ms MCP server startup (currently 2-5s)
Solution
Initialize indexer only on first tool call, not server start:
- Move initialization from server startup to first adapter call
- Add mutex to prevent concurrent initialization
- Cache initialized indexer for subsequent calls
- Keep centralized storage pattern
Implementation approach:
// In dev-agent-mcp.ts
let indexer: RepositoryIndexer | null = null;
let initPromise: Promise<RepositoryIndexer> | null = null;
async function ensureIndexer() {
if (indexer) return indexer;
if (initPromise) return initPromise;
initPromise = (async () => {
// Initialize indexer
indexer = new RepositoryIndexer({...});
await indexer.initialize();
return indexer;
})();
return initPromise;
}
Acceptance Criteria
Files to Modify
packages/mcp-server/bin/dev-agent-mcp.ts - Main initialization logic
- Tests for lazy loading behavior
Priority: P0 - Blocking user experience
Part of: #104 - Performance & Reliability Critical Path
Problem
MCP server performs eager initialization causing 2-5s delays in AI tools. Every AI interaction is blocked by full indexer startup, creating poor UX.
Current behavior:
RepositoryIndexeron startuppackages/mcp-server/bin/dev-agent-mcp.ts:117Impact
Solution
Initialize indexer only on first tool call, not server start:
Implementation approach:
Acceptance Criteria
Files to Modify
packages/mcp-server/bin/dev-agent-mcp.ts- Main initialization logicPriority: P0 - Blocking user experience
Part of: #104 - Performance & Reliability Critical Path