Tutorial 5: MCP Server and AI Agent Lab¶
Goal: Run the read-only JSON-RPC 2.0 MCP server in
/tmp/cis-mcp-lab, call tools over stdio, and verify SHA-256 digests.
Warning
Isolated Lab Only: Store files under /tmp/cis-mcp-lab.
The server enforces read-only execution with zero live edits.
flowchart LR
CHK["--check & --print-client-config"] --> RPC["initialize & tools/list"]
RPC --> INV["cis_list_targets & cis_verify_specs"]
INV --> DRY["cis_remediate_dry_run -> output_sha256"]
Prerequisites¶
- Python
3.8+checkout ofcis_benchmarks_tools - Completed Tutorial 2: SARIF & Dry-Run Lab
Step 1: Verify Health and Export Client Config¶
rm -rf /tmp/cis-mcp-lab && mkdir -p /tmp/cis-mcp-lab
python3 mcp_server.py --check
python3 mcp_server.py --print-client-config > /tmp/cis-mcp-lab/mcp.json
cat /tmp/cis-mcp-lab/mcp.json
Expected output: --check prints a JSON health summary (18 targets, 5 tools)
and --print-client-config prints a mcpServers block with CIS_DB_PASSWORD.
Step 2: Send Handshake, Discovery, and Offline Tool Calls¶
python3 mcp_server.py << 'EOF'
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"lab","version":"1.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
{"jsonrpc":"2.0","id":3,"method":"resources/list","params":{}}
{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"cis_list_targets","arguments":{}}}
{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"cis_verify_specs","arguments":{}}}
EOF
Expected output prints five JSON lines: initialize (2024-11-05), 5
read-only tools (readOnlyHint: true), 3 resources (cis://targets,
cis://presets, cis://contract), 18 targets (887 controls), and spec status.
Step 3: Call cis_remediate_dry_run and Check SHA-256¶
python3 -c 'import json; json.dump({"target":"postgresql16","overall_score":50.0,"results":[{"id":"3.1.2","name":"log_destination","category":"3. Logging","type":"Automated","status":"FAIL","output":"syslog"}]}, open("/tmp/cis-mcp-lab/pg16.json","w"))'
printf '%s\n' '{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"cis_remediate_dry_run","arguments":{"report_path":"/tmp/cis-mcp-lab/pg16.json","remediation_format":"diff","output_path":"/tmp/cis-mcp-lab/fix.diff"}}}' | python3 mcp_server.py > /tmp/cis-mcp-lab/resp.json
cat /tmp/cis-mcp-lab/resp.json
python3 -c "import hashlib, pathlib; print(hashlib.sha256(pathlib.Path('/tmp/cis-mcp-lab/fix.diff').read_bytes()).hexdigest())"
Expected output: output_sha256 in resp.json matches the SHA-256 digest of
/tmp/cis-mcp-lab/fix.diff.