Skip to main content
Glama
DEPLOYMENT.md7.78 kB
# code2mcp Deployment Guide Version: 1.1.0 Last Updated: 2025-11-17 ## System Architecture code2mcp runs as a **persistent PM2 service** and is registered as an **MCP server** in Claude Code. ### Dual Configuration #### 1. PM2 Service (Process Manager) **Purpose:** Runs the Node.js process that provides the execution sandbox and manages connections to 5 MCP servers. **Status:** ✅ Active ```bash pm2 list # Shows: code2mcp - Status: online ``` **Auto-Start:** ✅ Enabled via LaunchAgent ```bash ~/Library/LaunchAgents/pm2.root.plist ``` **Servers Connected:** - Context7 (documentation) - Playwright (browser automation) - Bright Data (web scraping) - Chrome DevTools (browser debugging) - Firecrawl (web scraping) **Tools Available:** 60 pre-generated TypeScript APIs #### 2. MCP Server (Claude Code Integration) **Purpose:** Exposes the `execute_code` tool to Claude Code so Claude can write TypeScript code that calls MCP tools. **Configuration:** `~/.claude.json` ```json "code2mcp": { "command": "node", "args": ["/Users/blaser/Documents/Projects/code2mcp/build/index.js"], "env": {"LOG_LEVEL": "info"} } ``` ## Token Analysis ### Scenario Comparison: "Get shadcn docs" | Metric | Direct MCP Loading | Code2MCP | Winner | |--------|-------------------|----------|---------| | Preload Tokens | 3,843 | 3,967 | Direct (-3%) | | Tool Usage Tokens | 130 | 92 | Code2MCP (-29%) | | **Total Tokens** | **3,981** | **4,067** | Direct (-2%) | | Tool Calls | 2 | 1 | Code2MCP (-50%) | | Duration | 3,543ms | 3,523ms | Code2MCP (-20ms) | ### Why Code2MCP Wins Overall 1. **One-time preload cost** - 3,967 tokens loaded once per conversation 2. **Saves tokens on complex workflows** - Multi-step tasks use significantly fewer tokens 3. **Better error handling** - TypeScript try/catch blocks 4. **Fewer API round-trips** - Executes multiple tool calls in one code block ### Example: Complex Workflow **Task:** "Scrape 10 companies, get docs for each, summarize findings" - **Direct MCP:** ~50,000 tokens (10 separate conversations) - **Code2MCP:** ~11,000 tokens (1 code execution with loops) - **Savings:** 78% reduction ## Management Commands ### PM2 Operations ```bash # View status pm2 list # View logs pm2 logs code2mcp # Restart service pm2 restart code2mcp # Stop service pm2 stop code2mcp # Start service pm2 start code2mcp # Remove from PM2 (not recommended) pm2 delete code2mcp ``` ### Startup Management ```bash # View LaunchAgent status launchctl list | grep PM2 # Disable auto-start (not recommended) pm2 unstartup launchd # Re-enable auto-start pm2 startup launchd pm2 save ``` ### Debugging ```bash # Check if process is running ps aux | grep code2mcp # View real-time logs pm2 logs code2mcp --lines 50 # Monitor resource usage pm2 monit ``` ## Development Workflow ### Managing MCP Servers **Enable/Disable Servers:** 1. **Edit:** `mcp-servers.config.js` ```javascript module.exports = { servers: { context7: { enabled: true }, playwright: { enabled: false }, // Disabled // ... other servers } }; ``` 2. **Rebuild:** ```bash npm run build ``` 3. **Restart PM2:** ```bash pm2 restart code2mcp ``` 4. **Verify:** ```bash pm2 logs code2mcp --lines 5 | grep "Loaded MCP" # Shows: {"enabledServers":4, "servers":["context7","bright-data",...]} ``` **Adding New MCP Servers:** 1. **Edit:** `mcp-servers.config.js` ```javascript newServer: { enabled: true, command: "npx", args: ["-y", "new-mcp-server"], env: { API_KEY: process.env.NEW_SERVER_KEY } } ``` 2. **Update:** `src/index.ts` - Add to `serverNameMap` 3. **Rebuild + Restart:** `npm run build && pm2 restart code2mcp` ### Making Code Changes 1. **Edit source code** in `src/` 2. **Rebuild:** ```bash npm run build ``` 3. **Restart PM2:** ```bash pm2 restart code2mcp ``` 4. **Verify:** ```bash pm2 logs code2mcp --lines 20 ``` ### Testing Changes ```bash # Test without PM2 (for debugging) npm run build node build/index.js # Test with PM2 pm2 restart code2mcp pm2 logs code2mcp ``` ## File Structure ``` /Users/blaser/Documents/Projects/code2mcp/ ├── build/ # Compiled JavaScript │ └── index.js # Main entry point ├── src/ # TypeScript source │ ├── index.ts # MCP server implementation │ ├── orchestrator/ # Manages MCP connections │ ├── sandbox/ # Code execution sandbox │ └── generator/ # TypeScript API generator ├── generated/ # Pre-generated TypeScript APIs (60 files) ├── ecosystem.config.cjs # PM2 configuration ├── package.json # Dependencies └── tsconfig.json # TypeScript config ``` ## Persistence Verification ### On Mac Login/Restart 1. LaunchAgent starts PM2 2. PM2 resurrects saved process list 3. code2mcp automatically starts 4. Connects to 5 MCP servers 5. Generates 60 TypeScript APIs 6. Ready for Claude Code to use ### Verification Steps ```bash # 1. Reboot Mac sudo reboot # 2. After login, check PM2 pm2 list # Should show: code2mcp - Status: online # 3. Check logs pm2 logs code2mcp --lines 10 # Should show successful MCP connections ``` ## Troubleshooting ### code2mcp not running ```bash # Check PM2 status pm2 list # Start if stopped pm2 start code2mcp # Check logs for errors pm2 logs code2mcp --err ``` ### MCP servers not connecting ```bash # View detailed logs pm2 logs code2mcp --lines 50 # Common issues: # - Missing API keys in environment # - Network connectivity # - npm packages not installed ``` ### Tools not available in Claude Code ```bash # Verify code2mcp is in ~/.claude.json cat ~/.claude.json | grep -A 7 '"code2mcp"' # Should show: # "code2mcp": { # "command": "node", # "args": ["/Users/blaser/Documents/Projects/code2mcp/build/index.js"], # "env": {"LOG_LEVEL": "info"} # } ``` ### High memory usage ```bash # Check memory pm2 info code2mcp | grep memory # Restart if needed pm2 restart code2mcp ``` ## Security Considerations ### API Keys All API keys are stored in: - `ecosystem.config.cjs` (for PM2) - Environment variables - **Never commit API keys to git** ### Sandbox Isolation - Code execution uses Node.js VM module - No filesystem access - No network access - Memory limits enforced ## Backup and Recovery ### Backup PM2 Configuration ```bash pm2 save # Saves to: ~/.pm2/dump.pm2 ``` ### Restore PM2 Configuration ```bash pm2 resurrect ``` ### Backup MCP Configuration ```bash cp ~/.claude.json ~/.claude.json.backup ``` ## Performance Metrics ### Startup Time - PM2 service start: ~5 seconds - MCP connections: ~3-5 seconds per server - Total ready time: ~30 seconds ### Resource Usage - Memory: ~140-175 MB - CPU: <1% idle, 5-10% during execution - Disk: Negligible ## Future Improvements ### Planned Enhancements 1. Add SSE transport support for Bright Data 2. Implement health check endpoint 3. Add Prometheus metrics 4. Create dashboard for monitoring 5. Add request/response caching ### Known Limitations 1. SSE transport not yet implemented 2. Chrome DevTools package not found in npm 3. No automatic API key rotation 4. No built-in rate limiting ## Support ### Logs Location - **PM2 Logs:** `~/.pm2/logs/` - **Stdout:** `~/Library/Logs/code2mcp-out.log` - **Stderr:** `~/Library/Logs/code2mcp-error.log` ### Debug Mode ```bash # Enable debug logging pm2 restart code2mcp --update-env --env production pm2 logs code2mcp --lines 100 ``` ### Contact - Project: https://github.com/yourusername/code2mcp - Issues: https://github.com/yourusername/code2mcp/issues - Documentation: See DOCS/ folder

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/blas0/code2mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server