Skip to content

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 ​

ComponentFileLinesChange Type
Context Interfacemcp-server/src/connection-context.tsNEWCreate
Executor Functionmcp-server/src/executor.ts240-280Update signature & spawn
Tool Handlermcp-server/src/index.ts145, 1325Update schemas & handler
CLI Connectionsutils/connections.js92-110Add env var checks

Data Flow: Single Command Execution ​


Backward Compatibility ​


Security Model ​


Testing Matrix ​

Test CaseBeforeAfterExpected
No context param✓ Works✓ WorksSame behavior
With projectPath✗ Ignored✓ UsedUses project dir
With connectionFile✗ Ignored✓ UsedUses specified file
With direct credentials✗ Ignored✓ UsedDirect connection
Context switching✗ N/A✓ WorksEach cmd gets own DB
Multiple projects✗ Fails✓ WorksIsolated contexts

Benefits Summary ​

PerspectiveBenefit
AI AgentsCan work with multiple projects, switching databases mid-conversation
DevelopersNo manual connection setup per project
TeamsProject-specific DBs for different environments (dev/test/prod)
SecurityEach project isolated to its credentials
Backward CompatExisting integrations work unchanged

Quick Reference: 5-Step Implementation ​

  1. Create interface → connection-context.ts
  2. Update executor → Handle context in executeCommand()
  3. Update MCP tools → Pass context from handler
  4. Update CLI → Check env vars in connections.js
  5. Test & Deploy → Backward compatible, no breaking changes

See Also ​