Skip to content

Conversation

@prosdev
Copy link
Collaborator

@prosdev prosdev commented Nov 26, 2025

🎯 Overview

Adds --cursor flag to MCP commands to support Cursor IDE alongside Claude Code. Users can now seamlessly install and manage dev-agent MCP server in Cursor with automatic workspace detection and proper process cleanup.

✨ Features

  • ✅ Cursor config utilities (read/write ~/.cursor/mcp.json)
  • --cursor flag on install, uninstall, and list commands
  • ✅ Smart server name generation with conflict resolution
  • ✅ Duplicate detection - prevents installing twice for same repository
  • ✅ Shows ALL MCP servers in list (not just dev-agent)
  • ✅ Idempotent operations - safe to run multiple times
  • Dynamic workspace detection - single server adapts to open workspace
  • Zombie process prevention - properly cleans up when window closes

🚀 Usage

# Install for Cursor
dev mcp install --cursor
# Output: Creates 'dev-agent-{reponame}' server in ~/.cursor/mcp.json

# List all MCP servers in Cursor
dev mcp list --cursor
# Shows: Figma, dev-agent, and any other configured servers

# Uninstall from Cursor
dev mcp uninstall --cursor
# Removes dev-agent server for current repository

# Default behavior (Claude Code) unchanged
dev mcp install

🏗️ Implementation

New Cursor Config Module

Created packages/cli/src/utils/cursor-config.ts with:

  • readCursorConfig() - Read Cursor MCP config (creates if missing)
  • writeCursorConfig() - Write config with atomic operations
  • generateServerName() - Generate unique names (dev-agent-{repo})
  • addCursorServer() - Add server with duplicate detection
  • removeCursorServer() - Remove server by repository path
  • findServerByRepository() - Find existing server
  • listCursorServers() - List all MCP servers (not just dev-agent)

Updated MCP Commands

All commands now support --cursor flag:

  • Default behavior: Uses Claude Code (claude CLI)
  • With --cursor: Directly manipulates ~/.cursor/mcp.json

Dynamic Workspace Detection

Problem: Original implementation used static REPOSITORY_PATH, causing MCP server to stay locked to one workspace even when switching windows.

Solution: Prioritize WORKSPACE_FOLDER_PATHS environment variable (Cursor's dynamic workspace indicator):

// MCP server entry point now detects workspace dynamically
const repositoryPath = 
  process.env.WORKSPACE_FOLDER_PATHS ||  // Cursor's dynamic workspace
  process.env.REPOSITORY_PATH ||         // Static fallback
  process.cwd();                         // Final fallback

Impact: Single dev-agent MCP server now adapts to whatever workspace is open in Cursor!

Zombie Process Prevention

Problem: MCP server processes weren't terminating when Cursor closed windows, leading to zombie process accumulation.

Solution: Added stdin closure handlers in StdioTransport:

// Handle stdin closure (when IDE closes)
this.readline.on('close', () => {
  process.exit(0);
});

process.stdin.on('end', () => {
  process.exit(0);
});

Testing: Verified with real Cursor windows - process count correctly decreases when windows close.

🧪 Testing

  • ✅ 20 tests for Cursor config utilities, all passing
  • ✅ Comprehensive coverage of all operations
  • ✅ Tests for duplicate detection
  • ✅ Tests for HTTP vs stdio server types
  • ✅ All existing tests still passing
  • ✅ Manually tested dynamic workspace switching
  • ✅ Manually tested zombie process cleanup

📊 Test Coverage

Test Files  1 passed (1)
     Tests  20 passed (20)

Tests include:

  • Config file read/write with missing files
  • Server name generation with conflicts
  • Add server with duplicate detection
  • Remove server by repository path
  • List all servers (HTTP and stdio types)
  • JSON formatting validation

🎨 User Experience

Install - Already Exists

$ dev mcp install --cursor
ℹ MCP server already installed in Cursor!

Server name: dev-agent-my-repo
Repository: /Users/user/workspace/my-repo

Run dev mcp list --cursor to see all servers

Install - Success

$ dev mcp install --cursor
✔ MCP server installed in Cursor!

Integration complete! 🎉

Server name: dev-agent-my-repo
Available tools in Cursor:
  dev_search  - Semantic code search
  dev_status  - Repository status
  dev_plan    - Generate development plans
  dev_explore - Explore code patterns
  dev_gh      - Search GitHub issues/PRs

Repository: /Users/user/workspace/my-repo
Storage: ~/.dev-agent/indexes/a1b2c3d4

⚠️  Please restart Cursor to apply changes

List - Multiple Servers

$ dev mcp list --cursor

MCP Servers in Cursor:

  Figma
    Command: HTTP: https://mcp.figma.com/mcp

  dev-agent
    Command: dev mcp start
    Repository: /Users/user/workspace/dev-agent

Total: 2 server(s)

Dynamic Workspace Switching (NEW!)

# Open dev-agent repo in Cursor → Use dev_status
Repository: /Users/user/workspace/dev-agent (128 files)

# Open lytics-lab repo in new window → Use dev_status
Repository: /Users/user/workspace/lytics-lab (456 files)

# Close lytics-lab window
# Process properly terminates, no zombies! ✅

🔗 Related

Closes #58
Related: #61 (CLI improvements for future)

📝 Follow-up

Created #61 for additional CLI improvements:

  • --yes flag for non-interactive mode
  • --format json for machine-readable output
  • --dry-run for preview mode
  • Standardized exit codes

Add --cursor flag to MCP commands to support Cursor IDE alongside Claude Code.

Features:
- Add Cursor config utilities (read/write ~/.cursor/mcp.json)
- Support --cursor flag on install, uninstall, and list commands
- Generate unique server names per repository
- Handle Cursor config creation and updates
- Preserve existing Claude Code integration
- Duplicate detection - prevents installing twice for same repo
- Shows ALL MCP servers in list (not just dev-agent)
- Fix: Use REPOSITORY_PATH env var in 'dev mcp start'

Implementation:
- New cursor-config.ts module with config manipulation functions
- Updated mcp.ts commands to handle both Claude Code and Cursor
- Smart server name generation with conflict resolution
- Idempotent operations - safe to run multiple times
- Respects REPOSITORY_PATH environment variable for IDE integration

Testing:
- 20 tests for Cursor config utilities, all passing
- Comprehensive coverage of config read/write operations
- Tests for add, remove, and list functionality
- Tests for duplicate detection and conflict resolution
- All existing tests still passing
- Verified working with actual Cursor IDE

Usage:
```bash
# Install for Cursor (creates new or detects existing)
dev mcp install --cursor

# List ALL Cursor MCP servers
dev mcp list --cursor

# Uninstall from Cursor
dev mcp uninstall --cursor

# Default behavior (Claude Code) unchanged
dev mcp install
```

Closes #58
- Add stdin close and end event handlers in StdioTransport
- Gracefully exit process when Cursor closes window
- Prevents accumulation of zombie MCP server processes
- Tested: Process count correctly decreases when window closes
- Add isGracefulShutdown flag to differentiate between graceful stop() and unexpected stdin closure
- Only call process.exit(0) when IDE closes connection unexpectedly
- Fixes test failures in server.integration.test.ts
- All 994 tests now passing
@prosdev prosdev merged commit a3c6434 into main Nov 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add Cursor MCP integration commands

1 participant