This commit updates MCP TAP query-rules tests to always include `target_id` in tool call payloads where query execution is expected.
Details:
- Added explicit `target_id` arguments to MCP `/mcp/query` tool invocations in rule evaluation tests.
- Removed implicit dependence on server-selected defaults during test execution.
Why this change is important:
- Query-rules behavior is now route-aware and can depend on logical target selection.
- Explicit routing in tests prevents non-determinism and ensures assertions are tied to the intended backend target.
Result:
- More deterministic TAP behavior and clearer validation of rule evaluation under target-based routing.
# Test 4.12: Execute MCP query matching rule 100 and verify hit counter increments
log_info "Executing query matching rule 100..."
PAYLOAD_100='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM test_table"}},"id":1}'
PAYLOAD_100='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM test_table","target_id":"'"${MCP_TARGET_ID}"'"}},"id":1}'
mcp_request "query""${PAYLOAD_100}" >/dev/null
sleep 1
HITS_AFTER_100=$(get_hits 100)
@ -169,7 +169,7 @@ main() {
# Test 4.13: Execute MCP query matching rule 101 and verify hit counter increments
log_info "Executing query matching rule 101..."
PAYLOAD_101='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"DROP TABLE IF EXISTS dummy_table"}},"id":2}'
PAYLOAD_101='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"DROP TABLE IF EXISTS dummy_table","target_id":"'"${MCP_TARGET_ID}"'"}},"id":2}'
mcp_request "query""${PAYLOAD_101}" >/dev/null
sleep 1
HITS_AFTER_101=$(get_hits 101)
@ -192,7 +192,7 @@ main() {
# Test 4.15: Execute query NOT matching any rule and verify no test rule counter increments
log_info "Executing query NOT matching any test rule..."
PAYLOAD_NO_MATCH='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM other_table"}},"id":3}'
PAYLOAD_NO_MATCH='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM other_table","target_id":"'"${MCP_TARGET_ID}"'"}},"id":3}'
# Test 5.16: Execute a query and verify it appears in digest
log_info "Executing unique query: SELECT COUNT(*) FROM test_phase5_table"
PAYLOAD_1='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT COUNT(*) FROM test_phase5_table"}},"id":1}'
PAYLOAD_1='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT COUNT(*) FROM test_phase5_table","target_id":"'"${MCP_TARGET_ID}"'"}},"id":1}'
mcp_request "query""${PAYLOAD_1}" >/dev/null
sleep 1
DIGEST_COUNT_AFTER_1=$(exec_admin_silent "SELECT COUNT(*) FROM stats_mcp_query_digest WHERE tool_name = 'run_sql_readonly';")
@ -233,7 +233,7 @@ main() {
# Test 5.18: Execute different query and verify new digest entry
log_info "Executing different query: SELECT * FROM another_phase5_table LIMIT 10"
PAYLOAD_2='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM another_phase5_table LIMIT 10"}},"id":2}'
PAYLOAD_2='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM another_phase5_table LIMIT 10","target_id":"'"${MCP_TARGET_ID}"'"}},"id":2}'
DIGEST_COUNT_BEFORE_2=$(exec_admin_silent "SELECT COUNT(*) FROM stats_mcp_query_digest WHERE tool_name = 'run_sql_readonly';")
log_verbose "Digest count before query 2: ${DIGEST_COUNT_BEFORE_2}"
log_test "T9.2: Verify health_check queries are not tracked"
TOTAL_TESTS=$((TOTAL_TESTS +1))
payload='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM health_check;"}},"id":1}'
payload='{"jsonrpc":"2.0","method":"tools/call","params":{"name":"run_sql_readonly","arguments":{"sql":"SELECT * FROM health_check;","target_id":"'"${MCP_TARGET_ID}"'"}},"id":1}'