MCP Connection Context - Visual Summary
The Problem: Connection Mismatch
The Solution: Project Context Passing
Current Architecture
Proposed Architecture
Message Flow Comparison
Before (All commands use install path)
After (Each command uses project context)
Implementation Timeline
Key Code Sections to Modify
| Component | File | Lines | Change Type |
|---|---|---|---|
| Context Interface | mcp-server/src/connection-context.ts | NEW | Create |
| Executor Function | mcp-server/src/executor.ts | 240-280 | Update signature & spawn |
| Tool Handler | mcp-server/src/index.ts | 145, 1325 | Update schemas & handler |
| CLI Connections | utils/connections.js | 92-110 | Add env var checks |
Data Flow: Single Command Execution
Backward Compatibility
Security Model
Testing Matrix
Benefits Summary
| Perspective | Benefit |
|---|---|
| AI Agents | Can work with multiple projects, switching databases mid-conversation |
| Developers | No manual connection setup per project |
| Teams | Project-specific DBs for different environments (dev/test/prod) |
| Security | Each project isolated to its credentials |
| Backward Compat | Existing integrations work unchanged |
Quick Reference: 5-Step Implementation
- Create interface →
connection-context.ts - Update executor → Handle context in
executeCommand() - Update MCP tools → Pass context from handler
- Update CLI → Check env vars in
connections.js - Test & Deploy → Backward compatible, no breaking changes
