Files
claude-code-action/.github/workflows/test-mcp-servers.yml
Ashwin Bhat ba60ef7ba2 Consolidate CI workflows into a single entry point (#836)
* refactor: consolidate CI workflows with ci-all.yml orchestrator

- Add ci-all.yml to orchestrate all CI workflows on push to main
- Update individual workflows to use workflow_call for reusability
- Remove redundant push triggers from individual test workflows
- Update release.yml to trigger on CI All workflow completion
- Auto-release on version bump commits after CI passes

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Generated-By: Claude Code (cli/claude-opus-4-5=100%)
Claude-Steers: 8
Claude-Permission-Prompts: 1
Claude-Escapes: 0

* address security review comments

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-20 11:58:13 -08:00

159 lines
6.0 KiB
YAML

name: Test MCP Servers
on:
pull_request:
workflow_dispatch:
workflow_call:
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: "List all available tools"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
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"
# Check if test-server is connected
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers[] | select(.name == "test-server" and .status == "connected")' "$OUTPUT_FILE" > /dev/null; then
echo "✓ test-server is connected"
else
echo "✗ test-server not found or not connected"
jq '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE"
exit 1
fi
# Check if mcp tools are available
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .tools[] | select(. == "mcp__test-server__test_tool")' "$OUTPUT_FILE" > /dev/null; then
echo "✓ MCP test tool found"
else
echo "✗ MCP test tool not found"
jq '.[] | select(.type == "system" and .subtype == "init") | .tools' "$OUTPUT_FILE"
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: "List all available tools"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
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"
# Check if test-server is connected
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers[] | select(.name == "test-server" and .status == "connected")' "$OUTPUT_FILE" > /dev/null; then
echo "✓ test-server is connected"
else
echo "✗ test-server not found or not connected"
jq '.[] | select(.type == "system" and .subtype == "init") | .mcp_servers' "$OUTPUT_FILE"
exit 1
fi
# Check if mcp tools are available
if jq -e '.[] | select(.type == "system" and .subtype == "init") | .tools[] | select(. == "mcp__test-server__test_tool")' "$OUTPUT_FILE" > /dev/null; then
echo "✓ MCP test tool found"
else
echo "✗ MCP test tool not found"
jq '.[] | select(.type == "system" and .subtype == "init") | .tools' "$OUTPUT_FILE"
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!"