Connecting MCP to IDEs & Desktop Clients
Configuring mcp.json in Claude Desktop, Cursor, and Antigravity, and debugging stdio socket connection failures.
Core Conceptual Brief
Learn how to register custom and community MCP servers in Claude Desktop and Cursor, manage environment variables, and debug socket handshake failures.
Theoretical & Empirical Architecture
Once an MCP server is written, it is activated by registering its launch command inside the client's configuration file:
- Claude Desktop:
~/Library/Application Support/Claude/claude_desktop_config.json(macOS) or%APPDATA%\Claude\claude_desktop_config.json(Windows) - Cursor: Settings > Features > MCP > Add New MCP Server
- Antigravity:
.gemini/mcp.jsonor workspace configuration.
Under the Hood: Key Engineering Mechanics
1Configuring Environment Variables Securely
Never hardcode API keys inside the server source code. The MCP configuration file allows injecting environment variables dynamically at child process spawn time.
2Path Resolution Issues on Windows and macOS
When Claude Desktop or Cursor launches a child process, it may not inherit your user's interactive shell PATH. Always use absolute paths to Node (/usr/local/bin/node or node.exe) or Python interpreters.
3Troubleshooting Connection Hangs
If the MCP hammer icon does not turn green: (1) Run the server command directly in your terminal to check for missing dependencies, (2) Inspect the client's mcp.log file, (3) Ensure no background process is holding a lock on the required socket or SQLite database.
Production claude_desktop_config.json Configuration
{
"mcpServers": {
"postgres-analytics": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://readonly_user:secret_pw@db.internal.net:5432/analytics"
]
},
"custom-filesystem-guardian": {
"command": "node",
"args": ["d:/Spark/DataBench/scripts/mcp-guardian.js"],
"env": {
"ALLOWED_WORKSPACE_ROOT": "d:/Spark/DataBench",
"NODE_ENV": "production"
}
}
}
}Production Guardrails & Takeaways
- Always specify absolute executable paths or use npx -y for reliable launching.
- Inject secrets via the "env" dictionary in the configuration file, never in code.
- Always check mcp.log when servers fail to appear in the tool picker.
Real Staff AI Systems Interview Question
Q: Why might an MCP server work perfectly in the terminal but fail to start when launched by Claude Desktop or Cursor?
Desktop applications launched from the OS GUI do not source .bashrc or .zshrc, so environment variables (like PATH, NVM_DIR, or custom PYTHONPATH) are missing. The child process fails because it cannot find the node or python binary. Supplying absolute paths resolves this.