MCP Connection Context Documentation Index โ
Quick Answer to Your Question โ
Q: How is the MCP server getting its connection context and how do I fix it to use project-specific connections instead of install path?
A: Currently, the MCP server always uses connection files from the install path (~/.hana-cli/default.json) or user home directory. The solution is to pass project-specific context through MCP tool parameters, which the executor then applies as the working directory and environment variables when spawning the CLI.
Documentation Guide โ
This directory contains comprehensive documentation for implementing project-specific connection context in the MCP server. Choose your starting point based on your role:
๐ฏ Quick Start (5-10 minutes) โ
visual-summary.md - Problem visualization and architecture flows
- Before/after diagrams
- Data flow examples
- Quick reference diagrams
Best for: Getting a mental model quickly
๐จโ๐ป Implementation (2-3 hours) โ
implementation-guide.md - Step-by-step checklist
- Exact code changes with line numbers
- Before/after code snippets
- Testing checklist
- Validation steps
Best for: Developers ready to implement the solution
๐ Understanding (30-60 minutes) โ
connection-context-solution.md - Detailed walkthrough
- Current flow explanation with code
- Key code locations
- Step-by-step implementation walkthrough
- Real usage examples
- Files to modify summary
Best for: Understanding the complete solution approach
๐๏ธ Architecture (1 hour) โ
connection-context-analysis.md - Deep architectural analysis
- Multiple implementation options
- Pros/cons of each approach
- Architecture diagrams
- Security considerations
- Future enhancements
- Migration strategies
Best for: Architects and decision makers
๐ Historical Reference โ
implementation-complete.md - Implementation status snapshot (Feb 2026)
- Historical snapshot of what was implemented
- Specific code changes made
- Build status from Feb 2026
- Usage examples from initial implementation
Note: This is a historical document. For current implementation, use the guides above.
Related Documentation โ
MCP Server Core:
- Architecture - Overall MCP technical architecture
- Server Usage - Running and configuring the MCP server
- Connection Guide - General connection configuration
Other Features:
- MCP Index - Main MCP documentation hub
- Server Updates - Recent MCP server enhancements
How to Use These Documents โ
For Quick Understanding (15 minutes) โ
- Read visual-summary.md - Get mental model
- Skim implementation-guide.md - See what needs to change
For Implementation (2-3 hours) โ
- Read implementation-guide.md - Follow step-by-step
- Reference connection-context-solution.md - For detailed explanations
- Reference visual-summary.md - If confused about flow
For Design Review (1 hour) โ
- Read connection-context-analysis.md - Understand all options
- Review visual-summary.md - Verify architecture
- Check implementation-guide.md - Assess effort
The Problem in One Diagram โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AI Agent working on Project A โ
โ โ Asks: "List tables in my database" โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
MCP Server gets request
โ
Spawns CLI with:
โข cwd = /install/path (WRONG!)
โข env = parent environment (NO PROJECT CONTEXT)
โ
CLI looks for connection file
โข Searches from /install/path upward
โข Finds ~/.hana-cli/default.json
โข Connects to DEFAULT DATABASE
โ
โ WRONG! Should connect to Project A's database
โ Agent gets data from wrong database
โ All projects use same default connectionThe Solution in One Diagram โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AI Agent working on Project A โ
โ โ Asks: "List tables in my database" โ
โ + Provides: __projectContext.projectPath=/proj/a โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
MCP Server extracts context & spawns CLI with:
โข cwd = /proj/a (โ PROJECT DIRECTORY!)
โข env.HANA_CLI_PROJECT_PATH = /proj/a
โข env.HANA_CLI_CONN_FILE = ".env"
โ
CLI looks for connection file
โข Searches from /proj/a upward
โข Finds /proj/a/.env
โข Connects to PROJECT A'S DATABASE
โ
โ CORRECT! Connects to Project A's database
โ Agent gets data from correct database
โ Each project uses its own connectionCurrent System Flow โ
MCP Tool Call
โ
Tool Handler (index.ts line 1325)
โ
executeCommand(commandName, args) โ No project context!
โ
spawn('node', [cli.js], {
cwd: /install/path โ HARDCODED!
env: process.env โ Parent env, no project context
})
โ
CLI Process
โ
Connection Resolution (connections.js)
โข Starts from cwd = /install/path
โข Finds ~/.hana-cli/default.json
โข Uses default database โNew System Flow โ
MCP Tool Call with __projectContext
โ
Tool Handler (index.ts) โ UPDATED
โโ Extract: context = args.__projectContext
โโ Clean args (remove context key)
โโ Pass: executeCommand(cmd, args, context) โ NEW!
โ
executeCommand(commandName, args, context) โ UPDATED
โโ Build env with: HANA_CLI_PROJECT_PATH, etc.
โโ Set cwd = context.projectPath โ DYNAMIC!
โโ spawn('node', [cli.js], {env, cwd})
โ
CLI Process
โ
Connection Resolution โ UPDATED
โข Checks: process.env.HANA_CLI_PROJECT_PATH
โข Starts from cwd = /project/path
โข Finds /project/path/.env
โข Uses project database โStep-by-Step Implementation Priority โ
Phase 1: Core Implementation (HIGH PRIORITY) โ
Time: ~4 hours | Complexity: Medium
- โ๏ธ Create
connection-context.tsinterface - โ๏ธ Update
executor.ts- add context param, build env, set cwd - โ๏ธ Update
index.ts- extract context, update schemas - โ๏ธ Update
connections.js- check env vars - โ Test basic functionality
Phase 2: Enhancement (MEDIUM PRIORITY) โ
Time: ~2-3 hours | Complexity: Low-Medium
- ๐ Add connection management tools
- ๐ Add project auto-detection
- ๐ Add connection switching within conversation
Phase 3: Polish (LOW PRIORITY) โ
Time: ~2 hours | Complexity: Low
- ๐ Add security validations
- ๐ Update documentation
- ๐งช Add comprehensive tests
Key Technical Insights โ
Why It Currently Doesn't Work โ
- Hardcoded CWD:
executor.tsline 270 hascwd: join(__dirname, '..', '..') - No Context Passing: Connection context never flows from MCP to CLI
- Parent Environment Only: Spawned process inherits parent env, no project override
- Search Order:
connections.jssearches up from cwd, which is always install path
Why The Solution Works โ
- Dynamic CWD: Pass
context.projectPathas cwd to spawn - Environment Signaling: Use env vars (HANA_CLI_PROJECT_PATH, etc.) to signal project context
- CLI Auto-Detection: CLI looks for these env vars first, changes directory if set
- Correct Search Order: Connection resolution now starts from project directory
Technical Debt & Future Work โ
Potential Enhancements โ
- Connection Registry: Store project connections for reuse
- Session Context: Set context once, use for multiple commands
- Auto-Detection: Automatically detect project from CLI context
- Secure Vault: Encrypted credential storage
- Connection Profiles: Named connection sets for different environments
Security Improvements โ
- Path validation/normalization
- Credential encryption
- Audit logging for connections
- Access control per project
Questions Answered โ
Q: Where does the MCP server currently get credentials?
- From
~/.hana-cli/default.jsonordefault-env.jsonin install path
Q: Why doesn't it use project's .env?
- Because the CLI is spawned with
cwd = /install/path, not project path
Q: How do I send project context to MCP?
- Add
__projectContextobject to any tool parameter
Q: Will existing integrations break?
- No!
__projectContextis optional, backward compatible
Q: What's the simplest way to implement this?
- Follow implementation-guide.md step 1-5
Q: How do I test if it works?
- See validation checklist in implementation-guide.md
Document Recommendation by Role โ
๐จโ๐ผ Project Manager / Decision Maker โ
โ Start with: visual-summary.md โ Decision: 15 minutes, understand scope and benefits
๐จโ๐ป Developer / Implementation โ
โ Start with: implementation-guide.md โ Implement: 2-3 hours, line-by-line code changes
๐๏ธ Architect / Technical Lead โ
โ Start with: connection-context-analysis.md โ Design: 1 hour, evaluate options and approach
๐ Code Reviewer โ
โ Check against: implementation-guide.md checklist โ Review: Cross-verify all modified files
๐ค Understanding Decision โ
โ Read in order:
- visual-summary.md (5 min)
- connection-context-solution.md (15 min)
- implementation-guide.md (10 min)
โ Total: 30 minutes for complete understanding
Success Criteria โ
After implementation, you should be able to:
- โ
Pass project path to MCP tools via
__projectContext.projectPath - โ Have CLI execute from that project directory
- โ Connection files found in project directory first
- โ Multiple projects use different databases in one conversation
- โ Backward compatible with existing integrations
- โ No breaking changes to any APIs
Support Matrix โ
| Issue | Solution | Document |
|---|---|---|
| "What's the problem?" | Start here | visual-summary.md |
| "How do I fix it?" | Code changes | implementation-guide.md |
| "Walk me through it" | Detailed explanation | connection-context-solution.md |
| "What about X?" | Design considerations | connection-context-analysis.md |
| "Show me diagrams" | Visual explanations | visual-summary.md |
| "I need the code" | Exact changes | implementation-guide.md |
Next Steps โ
- Choose your starting document based on your role above
- Understand the problem using diagrams and flows
- Plan implementation using the guide
- Execute changes following the step-by-step process
- Test thoroughly using provided test matrix
- Deploy with confidence - fully backward compatible!
Quick Links to Documents โ
| Document | Purpose | Time |
|---|---|---|
| ๐ visual-summary.md | Diagrams & quick overview | 15 min |
| ๐ ๏ธ implementation-guide.md | Code changes & checklist | 2-3 hrs |
| ๐ connection-context-solution.md | Detailed walkthrough | 30 min |
| ๐ฏ connection-context-analysis.md | Full analysis & options | 1 hour |
Questions? โ
If you have questions about:
- The problem: Check visual-summary.md diagrams
- The implementation: Check implementation-guide.md code sections
- The design choices: Check connection-context-analysis.md options
- The flow: Check connection-context-solution.md walkthrough
All documents include examples, diagrams, and detailed explanations for different learning styles.