Skip to content

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

Draft
avara1986 wants to merge 2 commits into
mainfrom
alberto.vara/APPSEC-71867-ai-guard-sdk-mcp
Draft

avara1986 wants to merge 2 commits into
mainfrom
alberto.vara/APPSEC-71867-ai-guard-sdk-mcp

Conversation

@avara1986

@avara1986 avara1986 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

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:

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 feat(aiguard): accept MCP server metadata in the SDK evaluate call 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)

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

🛟 #apm-shared-testing 🛟

🤖 Generated with Claude Code

The /ai_guard/evaluate weblog endpoint also accepts an object body with
the messages and the MCP servers they reference, passed to the SDK
(mcp_servers in Python, mcpServers in Node.js). Test_MCP_ToolCalls sends a
tool call with mcp.server_id and its server list, and checks that the
evaluation matches its body-hashed cassette and that the ai_guard span
reports mcp_servers and the mcp reference. The cassette was recorded and
scrubbed.

Enabled for Python from v4.18.0-rc1; missing_feature for Node.js until
DataDog/dd-trace-js#11384 ships.

APPSEC-71867

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

CODEOWNERS have been resolved as:

utils/build/docker/vcr/cassettes/aiguard/aiguard_evaluate_post_812be9b8.json  @DataDog/k9-ai-guard @DataDog/system-tests-core
docs/understand/weblogs/end-to-end_weblog.md                            @DataDog/system-tests-core
manifests/cpp_httpd.yml                                                 @DataDog/system-tests-reviewers
manifests/cpp_nginx.yml                                                 @DataDog/system-tests-reviewers
manifests/dotnet.yml                                                    @DataDog/system-tests-reviewers
manifests/golang.yml                                                    @DataDog/system-tests-reviewers
manifests/java.yml                                                      @DataDog/system-tests-reviewers
manifests/nodejs.yml                                                    @DataDog/system-tests-reviewers
manifests/php.yml                                                       @DataDog/system-tests-reviewers
manifests/python.yml                                                    @DataDog/system-tests-reviewers
manifests/ruby.yml                                                      @DataDog/system-tests-reviewers
tests/ai_guard/test_ai_guard_sdk.py                                     @DataDog/k9-ai-guard
utils/build/docker/nodejs/express/app.js                                @DataDog/system-tests-reviewers
utils/build/docker/python/flask/app.py                                  @DataDog/system-tests-reviewers

@datadog-official

datadog-official Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 2 Pipeline jobs failed

DataDog/system-tests | build_base_images — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

Testing the test | all-jobs-are-green

View more details · View in GitHub Actions

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e5bad10 | Docs | View more details | Give us feedback!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant