diff --git a/config/mcp.json.template b/config/mcp.json.template new file mode 100644 index 000000000..8c56032c3 --- /dev/null +++ b/config/mcp.json.template @@ -0,0 +1,26 @@ +{ + "$schema": "https://modelcontextprotocol.io/schema/mcp.json", + "mcpServers": { + "codegen": { + "command": "python", + "args": ["/tmp/Zeeeepa/codegen/src/codegen/cli/mcp/server.py"], + "env": { + "PYTHONPATH": "/tmp/Zeeeepa/codegen/src" + }, + "disabled": false + }, + "playwright": { + "command": "npx", + "args": ["@playwright/mcp"], + "env": {}, + "disabled": false + }, + "context7": { + "command": "npx", + "args": ["@upstash/context7-mcp"], + "env": {}, + "disabled": false + } + } +} + diff --git a/docs/MCP_SETUP.md b/docs/MCP_SETUP.md new file mode 100644 index 000000000..1b2267dd9 --- /dev/null +++ b/docs/MCP_SETUP.md @@ -0,0 +1,308 @@ +# MCP Setup Guide + +Complete guide for setting up Model Context Protocol (MCP) servers for use with Claude Desktop, Cline, and other MCP-compatible clients. + +## ๐ŸŽฏ What This Sets Up + +This setup installs three MCP servers: + +1. **Codegen MCP** - Advanced code generation and analysis tools +2. **Playwright MCP** - Browser automation and testing capabilities +3. **Context7 MCP** - Up-to-date library documentation access + +## ๐Ÿ“‹ Prerequisites + +- Linux-based system (tested on Ubuntu/Debian) +- Python 3.8+ +- sudo access +- Internet connection + +## ๐Ÿš€ Quick Start + +### Step 1: Run the Setup Script + +```bash +cd /tmp/Zeeeepa/codegen +chmod +x scripts/setup_mcp_fixed.sh +./scripts/setup_mcp_fixed.sh +``` + +This script will: +- โœ… Install system dependencies (Node.js, npm, browser libraries) +- โœ… Install Codegen Python package +- โœ… Install Playwright MCP via npm +- โœ… Install Context7 MCP via npm +- โœ… Download Chromium browser for Playwright +- โœ… Generate configuration templates + +**Expected Output:** +``` +=== Starting MCP Setup === +๐Ÿ“ฆ Installing system dependencies... +โœ“ System dependencies installed +๐Ÿ Installing codegen... +โœ“ Codegen installed +... +Setup Complete! ๐ŸŽ‰ +``` + +### Step 2: Verify Installation + +```bash +chmod +x scripts/verify_mcp_setup.sh +./scripts/verify_mcp_setup.sh +``` + +This will test all MCP servers and report any issues. + +### Step 3: Configure Your MCP Client + +Copy the template configuration to your MCP client's config location: + +#### For Claude Desktop (macOS): +```bash +cp config/mcp.json.template ~/Library/Application\ Support/Claude/mcp.json +``` + +#### For Claude Desktop (Linux): +```bash +cp config/mcp.json.template ~/.config/Claude/mcp.json +``` + +#### For Cline (VS Code Extension): +```bash +cp config/mcp.json.template ~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/mcp.json +``` + +#### For Other Clients: +Consult your MCP client's documentation for the correct config file location. + +### Step 4: Restart Your MCP Client + +After copying the configuration file, restart your MCP client application to load the new servers. + +## ๐Ÿ”ง Configuration Details + +### mcp.json Structure + +```json +{ + "mcpServers": { + "codegen": { + "command": "python", + "args": ["/path/to/codegen/server.py"] + }, + "playwright": { + "command": "npx", + "args": ["@playwright/mcp"] + }, + "context7": { + "command": "npx", + "args": ["@upstash/context7-mcp"] + } + } +} +``` + +### Customizing Paths + +If your Codegen installation is in a different location: + +1. Find your Codegen path: + ```bash + python -c "import codegen; print(codegen.__file__)" + ``` + +2. Update `mcp.json`: + ```json + "codegen": { + "command": "python", + "args": ["/your/custom/path/codegen/cli/mcp/server.py"] + } + ``` + +## ๐Ÿ› Troubleshooting + +### "Terminated" Error During Setup + +**Problem:** Setup script shows "Terminated" after Playwright installation. + +**Cause:** The original script used `which playwright`, but `playwright` isn't a standalone command. + +**Solution:** Use the fixed script `setup_mcp_fixed.sh` which properly verifies npm packages. + +### Playwright MCP Not Found + +**Check installation:** +```bash +npm list -g @playwright/mcp --depth=0 +``` + +**Reinstall if needed:** +```bash +npm install -g @playwright/mcp@latest +npx playwright install chromium --with-deps +``` + +### Context7 MCP Not Working + +**Check installation:** +```bash +npm list -g @upstash/context7-mcp --depth=0 +``` + +**Test invocation:** +```bash +npx @upstash/context7-mcp --help +``` + +### Codegen MCP Server Not Found + +**Verify the server file exists:** +```bash +ls -la /tmp/Zeeeepa/codegen/src/codegen/cli/mcp/server.py +``` + +**Check Python can import codegen:** +```bash +python -c "import codegen; print('OK')" +``` + +### Node.js/npm Not Found + +**Source NVM:** +```bash +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +``` + +**Set as default:** +```bash +nvm alias default node +``` + +### Permission Errors + +**Make scripts executable:** +```bash +chmod +x scripts/*.sh +``` + +**NPM global permission issues:** +```bash +mkdir -p ~/.npm-global +npm config set prefix '~/.npm-global' +export PATH=~/.npm-global/bin:$PATH +``` + +## ๐Ÿงช Testing MCP Servers + +### Test Playwright MCP + +```bash +npx @playwright/mcp --help +``` + +Expected: Help text or version information. + +### Test Context7 MCP + +```bash +npx @upstash/context7-mcp --help +``` + +Expected: Command output (may vary). + +### Test Codegen MCP + +```bash +python /tmp/Zeeeepa/codegen/src/codegen/cli/mcp/server.py +``` + +Expected: MCP server startup or help message. + +## ๐Ÿ“š What Each MCP Server Does + +### Codegen MCP +- **Purpose:** Advanced code generation and codebase analysis +- **Tools:** Code search, refactoring, pattern detection +- **Use Cases:** Large-scale code transformations, architecture analysis + +### Playwright MCP +- **Purpose:** Browser automation and web testing +- **Tools:** Navigate, click, type, screenshot, console messages +- **Use Cases:** Web scraping, E2E testing, UI verification + +### Context7 MCP +- **Purpose:** Real-time library documentation access +- **Tools:** Library search, API documentation retrieval +- **Use Cases:** Finding current API patterns, checking deprecations + +## ๐Ÿ”„ Updating MCP Servers + +### Update Playwright MCP +```bash +npm update -g @playwright/mcp +npx playwright install chromium --with-deps +``` + +### Update Context7 MCP +```bash +npm update -g @upstash/context7-mcp +``` + +### Update Codegen +```bash +cd /tmp/Zeeeepa/codegen +git pull +pip install -e . --upgrade +``` + +## ๐Ÿ“– Additional Resources + +- [MCP Official Documentation](https://modelcontextprotocol.io/) +- [Playwright MCP GitHub](https://github.com/playwright-community/playwright-mcp) +- [Context7 Documentation](https://github.com/upstash/context7-mcp) +- [Codegen Documentation](https://docs.codegen.com/) + +## ๐Ÿ’ก Tips + +### Using MCP Servers Effectively + +1. **Playwright:** Use for visual testing and screenshots + ``` + "Take a screenshot of the login page in mobile view" + ``` + +2. **Context7:** Check library docs before coding + ``` + "Show me the latest FastAPI routing patterns" + ``` + +3. **Codegen:** Large refactoring tasks + ``` + "Rename this function across the entire codebase" + ``` + +### Performance Optimization + +- **Disable unused servers:** Set `"disabled": true` in `mcp.json` +- **Use specific tools:** Reference servers by name for faster response +- **Cache browser state:** Playwright reuses browser instances + +## ๐Ÿ†˜ Getting Help + +If you encounter issues not covered here: + +1. **Run the verification script:** `./scripts/verify_mcp_setup.sh` +2. **Check logs:** Look in your MCP client's logs directory +3. **Test manually:** Try invoking each MCP server directly +4. **Review paths:** Ensure all paths in `mcp.json` are correct +5. **File an issue:** Provide verification script output + +--- + +**Last Updated:** 2025-01-15 +**Script Version:** 1.0 +**Tested On:** Ubuntu 22.04, Node.js 20.x, Python 3.10 + diff --git a/scripts/setup_mcp_fixed.sh b/scripts/setup_mcp_fixed.sh new file mode 100755 index 000000000..56ca29f6a --- /dev/null +++ b/scripts/setup_mcp_fixed.sh @@ -0,0 +1,171 @@ +#!/bin/bash + +set -e # Exit on error + +echo "=== Starting MCP Setup ===" +echo "" + +# Color codes for output +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Success/failure tracking +ERRORS=0 + +# Update system and install base dependencies +echo "๐Ÿ“ฆ Installing system dependencies..." +sudo apt update > /dev/null 2>&1 +sudo apt install -y nodejs npm git curl libnss3 libx11-6 libx11-xcb1 libxcb1 \ + libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 \ + libxrandr2 libxrender1 libxss1 libxtst6 libgtk-3-0 libasound2 \ + libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libgbm1 libpango-1.0-0 \ + libpangocairo-1.0-0 libatspi2.0-0 libxkbcommon0 libwayland-client0 \ + fonts-liberation xdg-utils wget ca-certificates > /dev/null 2>&1 +echo -e "${GREEN}โœ“${NC} System dependencies installed" +echo "" + +# Install codegen dependencies +echo "๐Ÿ Installing codegen..." +pip install -e . > /dev/null 2>&1 +pip install codegen-api-client > /dev/null 2>&1 +echo -e "${GREEN}โœ“${NC} Codegen installed" +echo "" + +# Install nvm and Node.js LTS +echo "๐Ÿ“ฆ Installing nvm and Node.js..." +if [ ! -d "$HOME/.nvm" ]; then + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh 2>/dev/null | bash > /dev/null 2>&1 +fi + +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + +nvm install --lts > /dev/null 2>&1 +nvm use --lts > /dev/null 2>&1 + +# Get Node.js path for later +NODE_PATH=$(which node) +NPX_PATH=$(which npx) + +echo -e "${GREEN}โœ“${NC} Node.js installed at: $NODE_PATH" +echo -e "${GREEN}โœ“${NC} npx installed at: $NPX_PATH" +echo "" + +# Create MCP directory +echo "๐Ÿ“ Creating MCP directory..." +mkdir -p /home/l/mcp +echo -e "${GREEN}โœ“${NC} MCP directory created: /home/l/mcp" +echo "" + +# Install Playwright MCP via NPM +echo "๐ŸŽญ Installing Playwright MCP..." +npm install -g @playwright/mcp@latest > /dev/null 2>&1 +npx playwright install chromium --with-deps + +# Verify Playwright MCP installation +echo " Verifying Playwright MCP..." +if npm list -g @playwright/mcp --depth=0 > /dev/null 2>&1; then + echo -e "${GREEN}โœ“${NC} Playwright MCP installed successfully" +else + echo -e "${RED}โœ—${NC} Playwright MCP installation verification failed" + ERRORS=$((ERRORS + 1)) +fi +echo "" + +# Install Context7 MCP via NPM +echo "๐Ÿ“š Installing Context7 MCP..." +npm install -g @upstash/context7-mcp@latest > /dev/null 2>&1 + +# Verify Context7 MCP installation +echo " Verifying Context7 MCP..." +if npm list -g @upstash/context7-mcp --depth=0 > /dev/null 2>&1; then + echo -e "${GREEN}โœ“${NC} Context7 MCP installed successfully" +else + echo -e "${RED}โœ—${NC} Context7 MCP installation verification failed" + ERRORS=$((ERRORS + 1)) +fi +echo "" + +# Verify codegen MCP server +echo "๐Ÿ”ง Verifying Codegen MCP server..." +CODEGEN_MCP_PATH="/tmp/Zeeeepa/codegen/src/codegen/cli/mcp" +if [ -d "$CODEGEN_MCP_PATH" ]; then + echo -e "${GREEN}โœ“${NC} Codegen MCP server found at: $CODEGEN_MCP_PATH" +else + echo -e "${YELLOW}โš ${NC} Codegen MCP server not found at expected path" + echo " Expected: $CODEGEN_MCP_PATH" + echo " You may need to adjust the path in mcp.json" +fi +echo "" + +# Save Node paths to a file for reference +echo "๐Ÿ’พ Saving configuration..." +cat > /home/l/mcp/node_paths.txt << EOF +NODE_PATH=$NODE_PATH +NPX_PATH=$NPX_PATH +NVM_DIR=$NVM_DIR +PLAYWRIGHT_MCP=npx @playwright/mcp +CONTEXT7_MCP=npx @upstash/context7-mcp +CODEGEN_MCP=$CODEGEN_MCP_PATH +EOF +echo -e "${GREEN}โœ“${NC} Configuration saved to: /home/l/mcp/node_paths.txt" +echo "" + +# Generate mcp.json template +echo "๐Ÿ“ Generating mcp.json template..." +cat > /home/l/mcp/mcp.json.template << 'EOF' +{ + "mcpServers": { + "codegen": { + "command": "python", + "args": ["/tmp/Zeeeepa/codegen/src/codegen/cli/mcp/server.py"] + }, + "playwright": { + "command": "npx", + "args": ["@playwright/mcp"] + }, + "context7": { + "command": "npx", + "args": ["@upstash/context7-mcp"] + } + } +} +EOF +echo -e "${GREEN}โœ“${NC} Template saved to: /home/l/mcp/mcp.json.template" +echo "" + +# Summary +echo "=========================================" +echo " Setup Complete! ๐ŸŽ‰" +echo "=========================================" +echo "" + +if [ $ERRORS -eq 0 ]; then + echo -e "${GREEN}โœ“${NC} All MCP servers installed successfully!" +else + echo -e "${YELLOW}โš ${NC} Setup completed with $ERRORS warning(s)" + echo " Review the output above for details" +fi + +echo "" +echo "๐Ÿ“ฆ Installed MCP Servers:" +echo " 1. Codegen: $CODEGEN_MCP_PATH" +echo " 2. Playwright: npx @playwright/mcp" +echo " 3. Context7: npx @upstash/context7-mcp" +echo "" +echo "๐Ÿ“„ Configuration files:" +echo " โ€ข Node paths: /home/l/mcp/node_paths.txt" +echo " โ€ข MCP template: /home/l/mcp/mcp.json.template" +echo "" +echo "๐Ÿ”ง Next Steps:" +echo " 1. Run: ./scripts/verify_mcp_setup.sh (to test installations)" +echo " 2. Copy mcp.json.template to your MCP client config location" +echo " 3. Read: docs/MCP_SETUP.md for detailed instructions" +echo "" +echo "Test commands:" +echo " npx @playwright/mcp --help" +echo " npx @upstash/context7-mcp --help" +echo "" + diff --git a/scripts/verify_mcp_setup.sh b/scripts/verify_mcp_setup.sh new file mode 100755 index 000000000..a061870a0 --- /dev/null +++ b/scripts/verify_mcp_setup.sh @@ -0,0 +1,180 @@ +#!/bin/bash + +# MCP Setup Verification Script +# Tests all MCP servers to ensure they're properly installed and functional + +echo "=== MCP Setup Verification ===" +echo "" + +# Color codes for output +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Track results +PASSED=0 +FAILED=0 +WARNINGS=0 + +# Helper function for test results +print_result() { + local test_name=$1 + local result=$2 + local message=$3 + + if [ "$result" = "pass" ]; then + echo -e "${GREEN}โœ“${NC} $test_name" + PASSED=$((PASSED + 1)) + elif [ "$result" = "fail" ]; then + echo -e "${RED}โœ—${NC} $test_name" + [ -n "$message" ] && echo -e " ${RED}Error:${NC} $message" + FAILED=$((FAILED + 1)) + elif [ "$result" = "warn" ]; then + echo -e "${YELLOW}โš ${NC} $test_name" + [ -n "$message" ] && echo -e " ${YELLOW}Warning:${NC} $message" + WARNINGS=$((WARNINGS + 1)) + fi +} + +# Test 1: Node.js and npm +echo -e "${BLUE}Testing Node.js Environment${NC}" +echo "----------------------------" +if command -v node > /dev/null 2>&1; then + NODE_VERSION=$(node --version) + print_result "Node.js installed ($NODE_VERSION)" "pass" +else + print_result "Node.js installed" "fail" "Node.js not found in PATH" +fi + +if command -v npm > /dev/null 2>&1; then + NPM_VERSION=$(npm --version) + print_result "npm installed ($NPM_VERSION)" "pass" +else + print_result "npm installed" "fail" "npm not found in PATH" +fi + +if command -v npx > /dev/null 2>&1; then + print_result "npx available" "pass" +else + print_result "npx available" "fail" "npx not found in PATH" +fi +echo "" + +# Test 2: Playwright MCP +echo -e "${BLUE}Testing Playwright MCP${NC}" +echo "----------------------" +if npm list -g @playwright/mcp --depth=0 > /dev/null 2>&1; then + PLAYWRIGHT_VERSION=$(npm list -g @playwright/mcp --depth=0 2>/dev/null | grep @playwright/mcp | awk '{print $2}') + print_result "Playwright MCP package installed ($PLAYWRIGHT_VERSION)" "pass" + + # Test actual invocation + if timeout 5 npx @playwright/mcp --help > /dev/null 2>&1; then + print_result "Playwright MCP executable works" "pass" + else + print_result "Playwright MCP executable works" "warn" "Command timed out or returned error" + fi + + # Check Chromium installation + if [ -d "$HOME/.cache/ms-playwright/chromium"* ] 2>/dev/null || [ -d "/root/.cache/ms-playwright/chromium"* ] 2>/dev/null; then + print_result "Chromium browser installed" "pass" + else + print_result "Chromium browser installed" "warn" "Chromium not found in cache directory" + fi +else + print_result "Playwright MCP package installed" "fail" "Package not found in global npm packages" +fi +echo "" + +# Test 3: Context7 MCP +echo -e "${BLUE}Testing Context7 MCP${NC}" +echo "--------------------" +if npm list -g @upstash/context7-mcp --depth=0 > /dev/null 2>&1; then + CONTEXT7_VERSION=$(npm list -g @upstash/context7-mcp --depth=0 2>/dev/null | grep @upstash/context7-mcp | awk '{print $2}') + print_result "Context7 MCP package installed ($CONTEXT7_VERSION)" "pass" + + # Test actual invocation + if timeout 5 npx @upstash/context7-mcp --help > /dev/null 2>&1; then + print_result "Context7 MCP executable works" "pass" + else + print_result "Context7 MCP executable works" "warn" "Command timed out or returned error (may be normal)" + fi +else + print_result "Context7 MCP package installed" "fail" "Package not found in global npm packages" +fi +echo "" + +# Test 4: Codegen MCP +echo -e "${BLUE}Testing Codegen MCP${NC}" +echo "-------------------" +CODEGEN_MCP_PATH="/tmp/Zeeeepa/codegen/src/codegen/cli/mcp" +if [ -d "$CODEGEN_MCP_PATH" ]; then + print_result "Codegen MCP directory exists" "pass" + + # Check for server.py + if [ -f "$CODEGEN_MCP_PATH/server.py" ]; then + print_result "Codegen MCP server.py found" "pass" + + # Test if it's valid Python + if python3 -m py_compile "$CODEGEN_MCP_PATH/server.py" 2>/dev/null; then + print_result "Codegen MCP server.py is valid Python" "pass" + else + print_result "Codegen MCP server.py is valid Python" "fail" "Syntax errors in server.py" + fi + else + print_result "Codegen MCP server.py found" "fail" "server.py not found at $CODEGEN_MCP_PATH/server.py" + fi +else + print_result "Codegen MCP directory exists" "fail" "Directory not found: $CODEGEN_MCP_PATH" +fi +echo "" + +# Test 5: Configuration Files +echo -e "${BLUE}Testing Configuration Files${NC}" +echo "---------------------------" +if [ -f "/home/l/mcp/node_paths.txt" ]; then + print_result "Node paths configuration exists" "pass" +else + print_result "Node paths configuration exists" "warn" "File not found: /home/l/mcp/node_paths.txt" +fi + +if [ -f "/home/l/mcp/mcp.json.template" ]; then + print_result "MCP JSON template exists" "pass" +else + print_result "MCP JSON template exists" "warn" "File not found: /home/l/mcp/mcp.json.template" +fi +echo "" + +# Summary +echo "=========================================" +echo " Verification Summary" +echo "=========================================" +echo "" +echo -e "${GREEN}Passed:${NC} $PASSED" +echo -e "${YELLOW}Warnings:${NC} $WARNINGS" +echo -e "${RED}Failed:${NC} $FAILED" +echo "" + +if [ $FAILED -eq 0 ]; then + if [ $WARNINGS -eq 0 ]; then + echo -e "${GREEN}โœ“ All tests passed!${NC} Your MCP setup is ready to use." + else + echo -e "${YELLOW}โš  Setup complete with warnings.${NC} Review warnings above." + fi + echo "" + echo "Next steps:" + echo " 1. Copy /home/l/mcp/mcp.json.template to your MCP client config" + echo " 2. Adjust paths if necessary" + echo " 3. Restart your MCP client (Claude Desktop, Cline, etc.)" + exit 0 +else + echo -e "${RED}โœ— Some tests failed.${NC} Please review the errors above." + echo "" + echo "Troubleshooting:" + echo " 1. Re-run: ./scripts/setup_mcp_fixed.sh" + echo " 2. Check: docs/MCP_SETUP.md for detailed help" + echo " 3. Verify npm globals: npm list -g --depth=0" + exit 1 +fi +