|
| 1 | +name: MCP CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, feat/mcp-*] |
| 6 | + paths: |
| 7 | + - 'causal_copilot/mcp/**' |
| 8 | + - 'causal_discovery/**' |
| 9 | + - 'tests/test_mcp*.py' |
| 10 | + - 'Dockerfile.mcp-*' |
| 11 | + - 'requirements_mcp_core.txt' |
| 12 | + - '.github/workflows/mcp-ci.yml' |
| 13 | + pull_request: |
| 14 | + branches: [main] |
| 15 | + paths: |
| 16 | + - 'causal_copilot/mcp/**' |
| 17 | + - 'causal_discovery/**' |
| 18 | + - 'tests/test_mcp*.py' |
| 19 | + - 'Dockerfile.mcp-*' |
| 20 | + - 'requirements_mcp_core.txt' |
| 21 | + |
| 22 | +jobs: |
| 23 | + test: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + submodules: recursive |
| 29 | + |
| 30 | + - uses: actions/setup-python@v5 |
| 31 | + with: |
| 32 | + python-version: '3.12' |
| 33 | + cache: pip |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + pip install -r requirements_mcp_core.txt |
| 38 | + pip install pytest |
| 39 | +
|
| 40 | + - name: Run MCP unit tests |
| 41 | + env: |
| 42 | + PYTHONPATH: ${{ github.workspace }}:${{ github.workspace }}/externals:${{ github.workspace }}/externals/causal-learn |
| 43 | + run: | |
| 44 | + pytest tests/test_mcp.py tests/test_mcp_golden.py tests/test_mcp_integration.py tests/test_mcp_resources.py -x -q |
| 45 | +
|
| 46 | + docker: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + needs: test |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + submodules: recursive |
| 53 | + |
| 54 | + - name: Build mcp-core image |
| 55 | + run: docker build -f Dockerfile.mcp-core -t causal-copilot-mcp:core . |
| 56 | + |
| 57 | + - name: Verify image starts |
| 58 | + run: | |
| 59 | + docker run -d --name mcp-test -p 8000:8000 causal-copilot-mcp:core |
| 60 | + # Poll until MCP server responds (up to 60s) |
| 61 | + for i in $(seq 1 12); do |
| 62 | + SESSION_ID=$(curl -sf -D /dev/stderr \ |
| 63 | + -X POST http://localhost:8000/mcp \ |
| 64 | + -H 'Content-Type: application/json' \ |
| 65 | + -H 'Accept: application/json, text/event-stream' \ |
| 66 | + -d '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"ci","version":"0.1"}}}' \ |
| 67 | + 2>&1 | grep -oP 'mcp-session-id: \K\S+') && break || sleep 5 |
| 68 | + done |
| 69 | + echo "Session: $SESSION_ID" |
| 70 | + test -n "$SESSION_ID" || (docker logs mcp-test && exit 1) |
| 71 | +
|
| 72 | + - name: Smoke test discover tool |
| 73 | + run: | |
| 74 | + SESSION_ID=$(curl -sf -D /dev/stderr \ |
| 75 | + -X POST http://localhost:8000/mcp \ |
| 76 | + -H 'Content-Type: application/json' \ |
| 77 | + -H 'Accept: application/json, text/event-stream' \ |
| 78 | + -d '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"ci","version":"0.1"}}}' \ |
| 79 | + 2>&1 | grep -oP 'mcp-session-id: \K\S+') |
| 80 | + RESP=$(curl -sf -X POST http://localhost:8000/mcp \ |
| 81 | + -H 'Content-Type: application/json' \ |
| 82 | + -H 'Accept: application/json, text/event-stream' \ |
| 83 | + -H "Mcp-Session-Id: $SESSION_ID" \ |
| 84 | + -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"discover","arguments":{"csv_data":"A,B,C\n1,2,3\n2,4,5\n3,6,8\n4,8,10\n5,10,13\n6,12,15\n7,14,18\n8,16,20\n9,18,23\n10,20,25\n11,22,27\n12,24,30","algorithm":"PC","seed":42}}}') |
| 85 | + echo "$RESP" |
| 86 | + echo "$RESP" | grep -q '"ok"' || (echo "FAIL: discover did not return ok" && exit 1) |
| 87 | +
|
| 88 | + - name: Cleanup |
| 89 | + if: always() |
| 90 | + run: docker rm -f mcp-test 2>/dev/null || true |
0 commit comments