Преглед изворни кода

feat: enable MCP tools in Claude Code headless mode with environment-specific configuration

- Add --mcp-config flag to claude command in handle-issue.sh to load MCP servers
- Create .mcp-gogs.json.example template for gogs MCP server configuration
- Add GOGS_MCP_PATH environment variable to .env.example for environment-specific paths
- Generate .mcp-gogs.json dynamically at runtime using GOGS_MCP_PATH from .env
- Add .mcp-gogs.json to .gitignore (generated file, not committed)
- Update CLAUDE.md documentation with MCP server configuration section

This allows Claude Code in headless mode to access gogs-mcp tools for issue automation,
while supporting different gogs-mcp installation paths across environments.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh пре 9 месеци
родитељ
комит
482c07b709
5 измењених фајлова са 52 додато и 0 уклоњено
  1. 4 0
      .env.example
  2. 1 0
      .gitignore
  3. 12 0
      .mcp-gogs.json.example
  4. 7 0
      CLAUDE.md
  5. 28 0
      scripts/handle-issue.sh

+ 4 - 0
.env.example

@@ -16,6 +16,10 @@ WEBHOOK_ISSUES_ENABLED=false
 WEBHOOK_ISSUE_COMMENT_ENABLED=false
 WEBHOOK_GLOBAL_ENABLED=false
 
+# MCP Server Configuration
+# Path to gogs-mcp server (used in headless Claude Code mode)
+GOGS_MCP_PATH=/data/gogs-mcp/dist/index.js
+
 # Legacy Command Configuration (deprecated - use commands.json instead)
 # These settings are maintained for backward compatibility
 # WEBHOOK_PUSH_COMMAND=echo "Push to {{branch}} by {{pusher}} in {{repo}}"

+ 1 - 0
.gitignore

@@ -9,3 +9,4 @@ yarn-error.log*
 .DS_Store
 queue.json
 commands.json
+.mcp-gogs.json

+ 12 - 0
.mcp-gogs.json.example

@@ -0,0 +1,12 @@
+{
+  "mcpServers": {
+    "gogs": {
+      "type": "stdio",
+      "command": "node",
+      "args": [
+        "${GOGS_MCP_PATH:-/data/gogs-mcp/dist/index.js}"
+      ],
+      "env": {}
+    }
+  }
+}

+ 7 - 0
CLAUDE.md

@@ -116,6 +116,13 @@ WEBHOOK_{EVENT_TYPE}_ENABLED=true|false
 
 **Supported Event Types:** push, pull_request, create, delete, release, issues, issue_comment, global
 
+**MCP Server Configuration:**
+```env
+GOGS_MCP_PATH=/data/gogs-mcp/dist/index.js  # Path to gogs-mcp server for headless Claude Code
+```
+
+The `GOGS_MCP_PATH` environment variable configures the location of the gogs-mcp server used by Claude Code in headless mode for issue automation. The handle-issue.sh script dynamically generates the MCP configuration file (.mcp-gogs.json) using this path at runtime, making it environment-specific.
+
 ### 2. Command Configuration (`commands.json`)
 
 Copy from `commands.json.example` and configure commands for each event type.

+ 28 - 0
scripts/handle-issue.sh

@@ -73,6 +73,32 @@ fi
 cd "$REPO_PATH" || exit 1
 echo "Working directory: $(pwd)"
 
+# Load .env file to get GOGS_MCP_PATH
+if [ -f "$REPO_PATH/.env" ]; then
+    export $(grep -v '^#' "$REPO_PATH/.env" | grep GOGS_MCP_PATH | xargs)
+fi
+
+# Set default GOGS_MCP_PATH if not set
+GOGS_MCP_PATH="${GOGS_MCP_PATH:-/data/gogs-mcp/dist/index.js}"
+
+# Generate MCP config file dynamically with environment-specific path
+cat > "$REPO_PATH/.mcp-gogs.json" <<EOF
+{
+  "mcpServers": {
+    "gogs": {
+      "type": "stdio",
+      "command": "node",
+      "args": [
+        "$GOGS_MCP_PATH"
+      ],
+      "env": {}
+    }
+  }
+}
+EOF
+
+echo "Generated MCP config with path: $GOGS_MCP_PATH"
+
 # Build the prompt for Claude with instructions to use Gogs MCP tool
 if [ -n "$COMMENT_BODY" ]; then
     # Issue comment event - new comment was added
@@ -217,11 +243,13 @@ echo "---"
 # Call claude with the prompt in non-interactive mode
 # -p / --print: Non-interactive mode, prints output and exits
 # --output-format json: Get structured JSON output for programmatic parsing
+# --mcp-config: Load MCP servers from config file (enables gogs MCP tools)
 # --allowedTools: Enable specific tools (MCP Gogs server and file tools)
 # --dangerously-skip-permissions: Skip all permission prompts (safe in controlled environment)
 # This allows Claude to run unattended without waiting for user input
 OUTPUT=$(claude -p "$PROMPT" \
     --output-format json \
+    --mcp-config "$REPO_PATH/.mcp-gogs.json" \
     --allowedTools "mcp__gogs,Read,Write,Edit,Bash,Grep,Glob,TodoWrite" \
     --dangerously-skip-permissions 2>&1)
 EXIT_CODE=$?