# Task ID: 20

**Title:** Implement MCP Project Management with Claude Code Integration

**Status:** cancelled

**Dependencies:** None

**Priority:** high

**Description:** Build the `mcpctl claude add-mcp-project <project-name>` command that configures Claude Code sessions to use specific MCP server profiles, generating and managing .mcp.json files automatically.

**Details:**

Extend src/cli/src/commands/ with Claude Code integration:

**New Commands:**

1. **mcpctl claude add-mcp-project <name>** (claude/add-mcp-project.ts):
   - Fetches project definition from mcpd API
   - Generates .mcp.json file pointing to local-proxy
   - Configures local-proxy to route to the project's MCP profiles
   - Example output:
   ```json
   {
     "mcpServers": {
       "weekly_reports": {
         "command": "npx",
         "args": ["-y", "@mcpctl/local-proxy", "--project", "weekly_reports", "--mcpd", "http://mcpd.local:3000"],
         "env": {}
       }
     }
   }
   ```

2. **mcpctl claude remove-mcp-project <name>** (claude/remove-mcp-project.ts):
   - Removes project from .mcp.json
   - Cleans up local-proxy config

3. **mcpctl claude list-projects** (claude/list-projects.ts):
   - Shows configured projects in current directory's .mcp.json
   - Shows available projects from mcpd

4. **mcpctl project create <name>** (project/create.ts):
   - Creates new project on mcpd
   - Interactive profile selection

5. **mcpctl project add-profile <project> <profile>** (project/add-profile.ts):
   - Links existing profile to project

**MCP.json Management** (lib/mcp-json.ts):
```typescript
interface McpJsonManager {
  findMcpJson(startDir: string): string | null;  // Search up directory tree
  readMcpJson(path: string): McpJsonConfig;
  writeMcpJson(path: string, config: McpJsonConfig): void;
  addProject(config: McpJsonConfig, project: ProjectConfig): McpJsonConfig;
  removeProject(config: McpJsonConfig, projectName: string): McpJsonConfig;
}
```

**mcpd API Extensions** (src/mcpd/src/routes/projects.ts):
- GET /projects - List all projects
- GET /projects/:name - Get project details with profiles
- POST /projects - Create project
- PUT /projects/:name/profiles - Update project profiles
- GET /projects/:name/claude-config - Get Claude-ready config

**Workflow Example:**
```bash
# On mcpd server (admin sets up projects)
mcpctl project create weekly_reports
mcpctl project add-profile weekly_reports slack-readonly
mcpctl project add-profile weekly_reports jira-readonly

# On developer machine
cd ~/my-workspace
mcpctl claude add-mcp-project weekly_reports
# Creates/updates .mcp.json with weekly_reports config
# Now Claude Code in this directory can use slack and jira MCPs
```

**Test Strategy:**

Unit test MCP.json parsing and manipulation with various file states (missing, empty, existing projects). Test findMcpJson directory traversal. Integration test with mcpd API: create project, add profiles, fetch Claude config. E2E test: run `mcpctl claude add-mcp-project`, verify .mcp.json created, start Claude Code (mock), verify MCP connection works. Test error handling: project not found, profile not found, conflicting project names. Test update behavior when project already exists in .mcp.json.
