fix: Configure MCP server per-project via claude mcp add

Claude Code stores MCP configs in ~/.claude.json per-project, NOT in
~/.claude/settings.json. The previous approach of writing to settings.json
didn't work - projects showed "No MCP servers configured".

Changes:
- Remove broken MCP setup from setup-claude-os.sh (was writing to wrong file)
- Add Step 2.5 to /claude-os-init that runs `claude mcp add` for each project
- Update final summary to remind users to restart Claude Code after init

Now the workflow is:
1. ./setup-claude-os.sh - Install Claude OS once
2. /claude-os-init - Run in each project (creates KBs + configures MCP)
3. Restart Claude Code - MCP connects
4. mcp__code-forge__* tools available!

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Bob Roberts 2025-12-17 18:16:19 -06:00
parent c45c2e87a5
commit 753d427896
2 changed files with 45 additions and 39 deletions

View file

@ -971,42 +971,11 @@ setup_claude_integration() {
done
success "Linked ${skill_count} skills"
# Configure MCP server in settings.json
local settings_file="${USER_CLAUDE_DIR}/settings.json"
# NOTE: MCP server is configured per-project when running /claude-os-init
# Claude Code stores MCP configs in ~/.claude.json per-project, not in settings.json
# The /claude-os-init command runs: claude mcp add --transport stdio code-forge ...
if [[ ! -f "$settings_file" ]]; then
echo "{}" > "$settings_file"
fi
python3 << EOF
import json
import os
settings_file = "$settings_file"
claude_os_dir = "$CLAUDE_OS_DIR"
try:
with open(settings_file, 'r') as f:
settings = json.load(f)
except:
settings = {}
if 'mcpServers' not in settings:
settings['mcpServers'] = {}
settings['mcpServers']['code-forge'] = {
"command": os.path.join(claude_os_dir, "venv", "bin", "python3"),
"args": [os.path.join(claude_os_dir, "mcp_server", "claude_code_mcp.py")],
"env": {
"CLAUDE_OS_API": "http://localhost:8051"
}
}
with open(settings_file, 'w') as f:
json.dump(settings, f, indent=2)
EOF
success "Configured MCP server"
info "MCP server will be configured per-project via /claude-os-init"
}
# ═══════════════════════════════════════════════════════════════════════════

View file

@ -133,6 +133,42 @@ Show success message:
- {project_name}-knowledge_docs
```
### Step 2.5: Configure MCP Server for This Project
**IMPORTANT**: Claude Code stores MCP configs per-project in `~/.claude.json`. We need to add the `code-forge` MCP server for this project so Claude can access the knowledge bases.
Run the following command:
```bash
claude mcp add --transport stdio code-forge \
--env CLAUDE_OS_API={claude_os_url} \
-- {claude_os_dir}/venv/bin/python3 {claude_os_dir}/mcp_server/claude_code_mcp.py
```
**Expected output:**
```
Added stdio MCP server code-forge with command: .../python3 .../claude_code_mcp.py to local config
File modified: /Users/.../.claude.json [project: {project_path}]
```
Show success:
```
🔌 Configuring MCP server...
✅ MCP server 'code-forge' added for this project
- Tools available: mcp__code-forge__search_knowledge_base, etc.
- Note: Restart Claude Code to connect
```
**If the command fails** (e.g., `claude` CLI not found):
- Show warning but continue:
```
⚠️ Could not auto-configure MCP server
Run this manually after setup:
claude mcp add --transport stdio code-forge \
--env CLAUDE_OS_API={claude_os_url} \
-- {claude_os_dir}/venv/bin/python3 {claude_os_dir}/mcp_server/claude_code_mcp.py
```
### Step 3: Set Up Project Directory Structure
Create the following structure in the project directory:
@ -474,10 +510,11 @@ Your project is now connected to Claude OS.
./.claude-os/ - Config and state files
📖 Next Steps:
1. Review and customize CLAUDE.md for your team
2. Add more docs anytime via UI: {claude_os_url}
3. Start a session: /claude-os-session start "feature name"
4. Let's build something amazing!
1. **Restart Claude Code** to connect the MCP server (exit and run `claude` again)
2. Review and customize CLAUDE.md for your team
3. Add more docs anytime via UI: {claude_os_url}
4. Start a session: /claude-os-session start "feature name"
5. Let's build something amazing!
💡 Tip: With hybrid indexing, I instantly know your entire codebase structure!
- Structural search is INSTANT (tree-sitter)