← Back to Pull requests

AI Guard: test MCP server metadata in SDK evaluations #8646

Open
unknown opened this pull request with 400 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 23, 2026 13:33 UTC
Author

Motivation

Jira: APPSEC-71867

Customers call AI Guard directly from their code with the SDK. The SDK can now send MCP server metadata with an evaluation: tool calls carry mcp.server_id, and the call passes the referenced servers as mcp_servers (dd-trace-py, AIGuardClient.evaluate(..., mcp_servers=...)) or mcpServers (dd-trace-js, DataDog/dd-trace-js#11384). No AI Guard SDK test covered it: the weblog endpoint only accepted a bare list of messages, so mcp_servers could not be passed.

Changes

  • POST /ai_guard/evaluate (Flask and Express) also accepts an object body, {"messages": [...], "mcp_servers": [...]}, and passes the servers to the SDK. A bare list of messages keeps working. Flask passes mcp_servers= only when it is sent, so older tracers are unaffected.

  • docs/understand/weblogs/end-to-end_weblog.md documents the new body, with an example.

  • Test_MCP_ToolCalls sends a tool call with mcp.server_id and its server list. It asserts:

  • - an ALLOW response, which only a match of the body-hashed evaluate cassette returns, so a tracer that drops mcp_servers or mcp.server_id fails;
    - the ai_guard span meta-struct reports the sent mcp_servers and keeps the tool call's mcp reference.
  • Cassette aiguard_evaluate_post_812be9b8.json, recorded with utils/scripts/generate-ai-guard-cassettes.sh against the real API and scrubbed (datadog-entity-id removed, the evaluation ID replaced with a synthetic one). Every weblog sends the same meta in this scenario, so the cassette is shared by all tracers.

  • Manifests:

  • - Python flask-poc: v4.18.0-rc1. The SDK mcp_servers argument is not in 4.17.x.
    - Node.js express5: missing_feature until DataDog/dd-trace-js#11384 ships.
    - Java and Ruby: incomplete_test_app, because their weblog does not accept the new body.
    - Go, .NET, PHP and C++: missing_feature, like the other SDK tests there.

    Validation, run locally:

  • Python flask-poc (python@4.18.0-rc1, dd-trace-py main): PASSED. Before the cassette existed, the same test failed with an AIGuardClientError (500). The VCR log showed that the tracer sent exactly the expected body hash.

  • Node.js express5 with the DataDog/dd-trace-js#11384 commit: XPASS, with the same cassette, so both tracers send the identical body.

  • ./format.sh passes.
  • Workflow

    1. ⚠️ Create your PR as draft ⚠️
    2. Work on you PR until the CI passes
    3. Mark it as ready for review
    Tests, manifest, weblog are modified -> you'll need a review from system-tests-reviewers: ask to one of youre co-worker familiar with the tested feature.
    Framework is modified, or non obvious usage of it -> get a review from system-tests-core (slack)

    :rocket: Once your PR is reviewed and the CI green, you can merge it!

    🛟 #apm-shared-testing 🛟

    🤖 Generated with Claude Code

    [APPSEC-71867]: https://datadoghq.atlassian.net/browse/APPSEC-71867?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

    Diff: 400 lines (+300 / -100) across 5 files Reviewer: avara1986 Review duration: 11140m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 400 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.359
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #8646"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.7% (MEDIUM) · Higher = larger blast radius
    44.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.8% · Safe to merge
    23.8%