mirror of
https://github.com/markwylde/claude-code-gitea-action.git
synced 2026-06-21 23:09:01 +08:00
- Drop anthropic_api_key from repo workflows: only CLAUDE_CODE_OAUTH_TOKEN is configured as a secret, and upstream docs say to pick one auth path - Replace the undeclared allowed_tools input in test workflows with claude_args --allowedTools (base-action only declares claude_args) - Remove dead ClaudeOptions fields and INPUT_* reads that prepareRunConfig never consumed (mcp_config, allowed_tools, max_turns, system prompts, etc.) - Update base-action README to document the actual inputs, with former dedicated inputs expressed as Claude CLI flags via claude_args
180 lines
7.2 KiB
YAML
180 lines
7.2 KiB
YAML
name: Test MCP Servers
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
test-mcp-integration:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4
|
|
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 #v2
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
bun install
|
|
cd base-action/test/mcp-test
|
|
bun install
|
|
|
|
- name: Run Claude Code with MCP test
|
|
uses: ./base-action
|
|
id: claude-test
|
|
with:
|
|
prompt: "Call the test_tool tool and report its response."
|
|
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
|
claude_args: --allowedTools mcp__test-server__test_tool
|
|
env:
|
|
# Change to test directory so it finds .mcp.json
|
|
CLAUDE_WORKING_DIR: ${{ github.workspace }}/base-action/test/mcp-test
|
|
|
|
- name: Check MCP server output
|
|
run: |
|
|
echo "Checking Claude output for MCP servers..."
|
|
|
|
# Parse the JSON output
|
|
OUTPUT_FILE="${RUNNER_TEMP}/claude-execution-output.json"
|
|
|
|
if [ ! -f "$OUTPUT_FILE" ]; then
|
|
echo "Error: Output file not found!"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Output file contents:"
|
|
cat $OUTPUT_FILE
|
|
|
|
# Check if mcp_servers field exists in the init event
|
|
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ Found mcp_servers in output"
|
|
|
|
# MCP servers can connect asynchronously, so the init event may
|
|
# report the server as pending. Check registration there, then
|
|
# verify the tool actually ran.
|
|
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers[] | select(.name == "test-server")' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ test-server is registered"
|
|
else
|
|
echo "✗ test-server not found"
|
|
jq '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if jq -e '.[] | select(.type == "assistant") | .message.content[]? | select(.type == "tool_use" and .name == "mcp__test-server__test_tool")' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ MCP test tool was called"
|
|
else
|
|
echo "✗ MCP test tool was not called"
|
|
jq '[.[] | select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name]' "$OUTPUT_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if jq -e '.[] | select(.type == "user") | .message.content[]? | select(.type == "tool_result") | select(.content | tostring | contains("Test tool response"))' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ MCP test tool returned its response"
|
|
else
|
|
echo "✗ MCP test tool response not found"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "✗ No mcp_servers field found in init event"
|
|
jq '.[] | select(.type == "system" and .subtype == "init")' "$OUTPUT_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✓ All MCP server checks passed!"
|
|
|
|
test-mcp-config-flag:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4
|
|
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 #v2
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
bun install
|
|
cd base-action/test/mcp-test
|
|
bun install
|
|
|
|
- name: Debug environment paths (--mcp-config test)
|
|
run: |
|
|
echo "=== Environment Variables (--mcp-config test) ==="
|
|
echo "HOME: $HOME"
|
|
echo ""
|
|
echo "=== Expected Config Paths ==="
|
|
echo "GitHub action writes to: $HOME/.claude/settings.json"
|
|
echo "Claude should read from: $HOME/.claude/settings.json"
|
|
echo ""
|
|
echo "=== Actual File System ==="
|
|
ls -la $HOME/.claude/ || echo "No $HOME/.claude directory"
|
|
|
|
- name: Run Claude Code with --mcp-config flag
|
|
uses: ./base-action
|
|
id: claude-config-test
|
|
with:
|
|
prompt: "Call the test_tool tool and report its response."
|
|
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
|
claude_args: |
|
|
--allowedTools mcp__test-server__test_tool
|
|
--mcp-config '{"mcpServers":{"test-server":{"type":"stdio","command":"bun","args":["simple-mcp-server.ts"],"env":{}}}}'
|
|
env:
|
|
# Change to test directory so bun can find the MCP server script
|
|
CLAUDE_WORKING_DIR: ${{ github.workspace }}/base-action/test/mcp-test
|
|
|
|
- name: Check MCP server output with --mcp-config
|
|
run: |
|
|
echo "Checking Claude output for MCP servers with --mcp-config flag..."
|
|
|
|
# Parse the JSON output
|
|
OUTPUT_FILE="${RUNNER_TEMP}/claude-execution-output.json"
|
|
|
|
if [ ! -f "$OUTPUT_FILE" ]; then
|
|
echo "Error: Output file not found!"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Output file contents:"
|
|
cat $OUTPUT_FILE
|
|
|
|
# Check if mcp_servers field exists in the init event
|
|
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ Found mcp_servers in output"
|
|
|
|
# MCP servers can connect asynchronously, so the init event may
|
|
# report the server as pending. Check registration there, then
|
|
# verify the tool actually ran.
|
|
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers[] | select(.name == "test-server")' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ test-server is registered"
|
|
else
|
|
echo "✗ test-server not found"
|
|
jq '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if jq -e '.[] | select(.type == "assistant") | .message.content[]? | select(.type == "tool_use" and .name == "mcp__test-server__test_tool")' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ MCP test tool was called"
|
|
else
|
|
echo "✗ MCP test tool was not called"
|
|
jq '[.[] | select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name]' "$OUTPUT_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
if jq -e '.[] | select(.type == "user") | .message.content[]? | select(.type == "tool_result") | select(.content | tostring | contains("Test tool response"))' "$OUTPUT_FILE" > /dev/null; then
|
|
echo "✓ MCP test tool returned its response"
|
|
else
|
|
echo "✗ MCP test tool response not found"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "✗ No mcp_servers field found in init event"
|
|
jq '.[] | select(.type == "system" and .subtype == "init")' "$OUTPUT_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✓ All MCP server checks passed with --mcp-config flag!"
|