setup_mcp.sh 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #!/bin/bash
  2. # Skill Seeker MCP Server - Quick Setup Script
  3. # This script automates the MCP server setup for Claude Code
  4. set -e # Exit on error
  5. echo "=================================================="
  6. echo "Skill Seeker MCP Server - Quick Setup"
  7. echo "=================================================="
  8. echo ""
  9. # Colors for output
  10. GREEN='\033[0;32m'
  11. YELLOW='\033[1;33m'
  12. RED='\033[0;31m'
  13. NC='\033[0m' # No Color
  14. # Step 1: Check Python version
  15. echo "Step 1: Checking Python version..."
  16. if ! command -v python3 &> /dev/null; then
  17. echo -e "${RED}❌ Error: python3 not found${NC}"
  18. echo "Please install Python 3.7 or higher"
  19. exit 1
  20. fi
  21. PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
  22. echo -e "${GREEN}✓${NC} Python $PYTHON_VERSION found"
  23. echo ""
  24. # Step 2: Get repository path
  25. REPO_PATH=$(pwd)
  26. echo "Step 2: Repository location"
  27. echo "Path: $REPO_PATH"
  28. echo ""
  29. # Step 3: Install dependencies
  30. echo "Step 3: Installing Python dependencies..."
  31. # Check if we're in a virtual environment
  32. if [[ -n "$VIRTUAL_ENV" ]]; then
  33. echo -e "${GREEN}✓${NC} Virtual environment detected: $VIRTUAL_ENV"
  34. PIP_INSTALL_CMD="pip install"
  35. elif [[ -d "venv" ]]; then
  36. echo -e "${YELLOW}⚠${NC} Virtual environment found but not activated"
  37. echo "Activating venv..."
  38. source venv/bin/activate
  39. PIP_INSTALL_CMD="pip install"
  40. else
  41. echo -e "${YELLOW}⚠${NC} No virtual environment found"
  42. echo "It's recommended to use a virtual environment to avoid conflicts."
  43. echo ""
  44. read -p "Would you like to create one now? (y/n) " -n 1 -r
  45. echo ""
  46. if [[ $REPLY =~ ^[Yy]$ ]]; then
  47. echo "Creating virtual environment..."
  48. python3 -m venv venv || {
  49. echo -e "${RED}❌ Failed to create virtual environment${NC}"
  50. echo "Falling back to system install..."
  51. PIP_INSTALL_CMD="pip3 install --user --break-system-packages"
  52. }
  53. if [[ -d "venv" ]]; then
  54. source venv/bin/activate
  55. PIP_INSTALL_CMD="pip install"
  56. echo -e "${GREEN}✓${NC} Virtual environment created and activated"
  57. fi
  58. else
  59. echo "Proceeding with system install (using --user --break-system-packages)..."
  60. echo -e "${YELLOW}Note:${NC} This may override system-managed packages"
  61. PIP_INSTALL_CMD="pip3 install --user --break-system-packages"
  62. fi
  63. fi
  64. echo "This will install: mcp, requests, beautifulsoup4"
  65. read -p "Continue? (y/n) " -n 1 -r
  66. echo ""
  67. if [[ $REPLY =~ ^[Yy]$ ]]; then
  68. echo "Installing package in editable mode..."
  69. $PIP_INSTALL_CMD -e . || {
  70. echo -e "${RED}❌ Failed to install package${NC}"
  71. exit 1
  72. }
  73. echo -e "${GREEN}✓${NC} Dependencies installed successfully"
  74. else
  75. echo "Skipping dependency installation"
  76. fi
  77. echo ""
  78. # Step 4: Test MCP server
  79. echo "Step 4: Testing MCP server..."
  80. timeout 3 python3 src/skill_seekers/mcp/server.py 2>/dev/null || {
  81. if [ $? -eq 124 ]; then
  82. echo -e "${GREEN}✓${NC} MCP server starts correctly (timeout expected)"
  83. else
  84. echo -e "${YELLOW}⚠${NC} MCP server test inconclusive, but may still work"
  85. fi
  86. }
  87. echo ""
  88. # Step 5: Optional - Run tests
  89. echo "Step 5: Run test suite? (optional)"
  90. read -p "Run MCP tests to verify everything works? (y/n) " -n 1 -r
  91. echo ""
  92. if [[ $REPLY =~ ^[Yy]$ ]]; then
  93. # Check if pytest is installed
  94. if ! command -v pytest &> /dev/null; then
  95. echo "Installing pytest..."
  96. $PIP_INSTALL_CMD pytest || {
  97. echo -e "${YELLOW}⚠${NC} Could not install pytest, skipping tests"
  98. }
  99. fi
  100. if command -v pytest &> /dev/null; then
  101. echo "Running MCP server tests..."
  102. python3 -m pytest tests/test_mcp_server.py -v --tb=short || {
  103. echo -e "${RED}❌ Some tests failed${NC}"
  104. echo "The server may still work, but please check the errors above"
  105. }
  106. fi
  107. else
  108. echo "Skipping tests"
  109. fi
  110. echo ""
  111. # Step 6: Configure Claude Code
  112. echo "Step 6: Configure Claude Code"
  113. echo "=================================================="
  114. echo ""
  115. echo "You need to add this configuration to Claude Code:"
  116. echo ""
  117. echo -e "${YELLOW}Configuration file:${NC} ~/.config/claude-code/mcp.json"
  118. echo ""
  119. echo "Add this JSON configuration (paths are auto-detected for YOUR system):"
  120. echo ""
  121. echo -e "${GREEN}{"
  122. echo " \"mcpServers\": {"
  123. echo " \"skill-seeker\": {"
  124. echo " \"command\": \"python3\","
  125. echo " \"args\": ["
  126. echo " \"$REPO_PATH/src/skill_seekers/mcp/server.py\""
  127. echo " ],"
  128. echo " \"cwd\": \"$REPO_PATH\""
  129. echo " }"
  130. echo " }"
  131. echo -e "}${NC}"
  132. echo ""
  133. echo -e "${YELLOW}Note:${NC} The paths above are YOUR actual paths (not placeholders!)"
  134. echo ""
  135. # Ask if user wants auto-configure
  136. echo ""
  137. read -p "Auto-configure Claude Code now? (y/n) " -n 1 -r
  138. echo ""
  139. if [[ $REPLY =~ ^[Yy]$ ]]; then
  140. # Check if config already exists
  141. if [ -f ~/.config/claude-code/mcp.json ]; then
  142. echo -e "${YELLOW}⚠ Warning: ~/.config/claude-code/mcp.json already exists${NC}"
  143. echo "Current contents:"
  144. cat ~/.config/claude-code/mcp.json
  145. echo ""
  146. read -p "Overwrite? (y/n) " -n 1 -r
  147. echo ""
  148. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  149. echo "Skipping auto-configuration"
  150. echo "Please manually add the skill-seeker server to your config"
  151. exit 0
  152. fi
  153. fi
  154. # Create config directory
  155. mkdir -p ~/.config/claude-code
  156. # Write configuration with actual expanded path
  157. cat > ~/.config/claude-code/mcp.json << EOF
  158. {
  159. "mcpServers": {
  160. "skill-seeker": {
  161. "command": "python3",
  162. "args": [
  163. "$REPO_PATH/src/skill_seekers/mcp/server.py"
  164. ],
  165. "cwd": "$REPO_PATH"
  166. }
  167. }
  168. }
  169. EOF
  170. echo -e "${GREEN}✓${NC} Configuration written to ~/.config/claude-code/mcp.json"
  171. echo ""
  172. echo "Configuration contents:"
  173. cat ~/.config/claude-code/mcp.json
  174. echo ""
  175. # Verify the path exists
  176. if [ -f "$REPO_PATH/src/skill_seekers/mcp/server.py" ]; then
  177. echo -e "${GREEN}✓${NC} Verified: MCP server file exists at $REPO_PATH/src/skill_seekers/mcp/server.py"
  178. else
  179. echo -e "${RED}❌ Warning: MCP server not found at $REPO_PATH/src/skill_seekers/mcp/server.py${NC}"
  180. echo "Please check the path!"
  181. fi
  182. else
  183. echo "Skipping auto-configuration"
  184. echo "Please manually configure Claude Code using the JSON above"
  185. echo ""
  186. echo "IMPORTANT: Replace \$REPO_PATH with the actual path: $REPO_PATH"
  187. fi
  188. echo ""
  189. # Step 7: Test the configuration
  190. if [ -f ~/.config/claude-code/mcp.json ]; then
  191. echo "Step 7: Testing MCP configuration..."
  192. echo "Checking if paths are correct..."
  193. # Extract the configured path
  194. if command -v jq &> /dev/null; then
  195. CONFIGURED_PATH=$(jq -r '.mcpServers["skill-seeker"].args[0]' ~/.config/claude-code/mcp.json 2>/dev/null || echo "")
  196. if [ -n "$CONFIGURED_PATH" ] && [ -f "$CONFIGURED_PATH" ]; then
  197. echo -e "${GREEN}✓${NC} MCP server path is valid: $CONFIGURED_PATH"
  198. elif [ -n "$CONFIGURED_PATH" ]; then
  199. echo -e "${YELLOW}⚠${NC} Warning: Configured path doesn't exist: $CONFIGURED_PATH"
  200. fi
  201. else
  202. echo "Install 'jq' for config validation: brew install jq (macOS) or apt install jq (Linux)"
  203. fi
  204. fi
  205. echo ""
  206. # Step 8: Final instructions
  207. echo "=================================================="
  208. echo "Setup Complete!"
  209. echo "=================================================="
  210. echo ""
  211. echo "Next steps:"
  212. echo ""
  213. echo " 1. ${YELLOW}Restart Claude Code${NC} (quit and reopen, don't just close window)"
  214. echo " 2. In Claude Code, test with: ${GREEN}\"List all available configs\"${NC}"
  215. echo " 3. You should see 9 Skill Seeker tools available"
  216. echo ""
  217. echo "Available MCP Tools:"
  218. echo " • generate_config - Create new config files"
  219. echo " • estimate_pages - Estimate scraping time"
  220. echo " • scrape_docs - Scrape documentation"
  221. echo " • package_skill - Create .zip files"
  222. echo " • list_configs - Show available configs"
  223. echo " • validate_config - Validate config files"
  224. echo ""
  225. echo "Example commands to try in Claude Code:"
  226. echo " • ${GREEN}List all available configs${NC}"
  227. echo " • ${GREEN}Validate configs/react.json${NC}"
  228. echo " • ${GREEN}Generate config for Tailwind at https://tailwindcss.com/docs${NC}"
  229. echo ""
  230. echo "Documentation:"
  231. echo " • MCP Setup Guide: ${YELLOW}docs/MCP_SETUP.md${NC}"
  232. echo " • Full docs: ${YELLOW}README.md${NC}"
  233. echo ""
  234. echo "Troubleshooting:"
  235. echo " • Check logs: ~/Library/Logs/Claude Code/ (macOS)"
  236. echo " • Test server: python3 src/skill_seekers/mcp/server.py"
  237. echo " • Run tests: python3 -m pytest tests/test_mcp_server.py -v"
  238. echo ""
  239. echo "Happy skill creating! 🚀"