Repository navigation
Conversation
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
BenchmarksBenchmark execution time: 2026-11-26 08:56:08 Comparing candidate commit 46886f7 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 378 metrics, 9 unstable metrics.
|
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The Anthropic converter dropped mcp_tool_use and mcp_tool_result blocks as unknown types, so the calls and results of MCP servers run by the Anthropic MCP connector (client.beta.messages.create(mcp_servers=...)) were never evaluated, neither in the response nor in the history of later requests. - Convert mcp_tool_use into an assistant tool call and mcp_tool_result into a tool message, split like server tools (tool call, tool result, synthesis). - With DD_AI_GUARD_MCP_ENABLED, reference a managed_by provider mcp_servers entry built from the name and URL origin of the request's mcp_servers entry with that name, or from the name alone when the request does not declare it. authorization_token is never read. - Restore server_name and the mcp_tool_result type in the buffered stream reconstruction, which the shared contrib rebuild drops. - Update the line pinned for _anthropic.py in the constant log message check. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64f6d5a35c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
64f6d5a to
7ac8b8a
Compare
…s and fail open - attach_mcp no longer reassigns a tool call that already references a server, so an MCP connector call named like a client-managed MCP tool keeps its provider entry. - mark_evaluated only counts calls that reference the tool's own server, so such a connector call no longer spares a later call of the client-managed tool its check. - A failure while referencing the connector server drops only the MCP metadata. - The buffered stream reconstruction keeps an mcp_tool_use input sent whole in the content_block_start chunk. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Anthropic buffered stream wrappers keep their own kwargs for the deferred response evaluation, while the before-hook materialized an iterable mcp_servers only in the copy the contrib receives. The deferred evaluation then read an exhausted generator and identified MCP connector calls by name alone. Materialize an iterable mcp_servers in the wrapper kwargs before forwarding the call, so the SDK and the deferred evaluation read the same servers. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Two critical correctness issues stand out: iterator-backed mcp_tool_result content is consumed without being written back to the shared request payload, so the SDK and after-hook both lose the result text; and same-origin connector calls are incorrectly recorded as evaluated client-tool calls, allowing a matching client invocation to bypass its pre-execution AI Guard check entirely.
🤖 Bits Code Review · Commit b26e381
…ient-tool marks - Write a materialized iterable tool result content back into its block, so the SDK still sends the content that the conversion consumed. - Skip the response's mcp_tool_use calls when marking evaluated client-managed MCP tool calls: on a shared URL origin both servers have one ID, so only the call's provenance tells a provider-run call apart. - Emit a client tool_use that follows a server tool result after that result, so the evaluated turn ends with the pending call. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The PR adds Anthropic MCP connector calls and results to AI Guard, and the latest commit fixes same-origin evaluation marks, same-turn call ordering, and exhausted result generators. The new code can drop resumed server results before a pending client call and freeze reusable result content, sending stale history on later requests.
🤖 Bits Code Review · Commit 456d3af
- Emit server tool results when the message has calls before them or pending client calls after them, so a resumed turn whose result's call is in an earlier message keeps that result, before the pending call. - Write back only one-shot iterator tool result content, so a reusable view in the caller's history stays live. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f92bfa6c8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
The most critical issues involve the Anthropic integration's parser incorrectly ordering conversation turns for AI Guard: resumed turns containing MCP tool/connector results do not set the appropriate boundary flag, causing synthesis text to be emitted before the results it describes. A separate issue affects single-use iterable wrappers for mcp_tool_result content, which are silently drained by the before-hook leaving subsequent hooks with empty content.
🤖 Bits Code Review · Commit 1f92bfa
…sage A resumed Anthropic turn can hold a server or MCP connector tool result whose call is in an earlier message. The converter dropped such results, so a result-only response skipped the response evaluation and a result followed by text evaluated only the text. Emit server tool results whenever a message has them, and treat text after a result as synthesis so the evaluated order matches the conversation. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover a resumed Anthropic turn shaped [mcp_tool_result, text, tool_use] in response and history conversion: the text stays after the result and before the pending client call. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
AI Guard now evaluates Anthropic MCP connector calls and results, including buffered streams, with provider-managed server metadata. The previously reported iterable-content loss and resumed-turn ordering defects are fixed; resumed results remain before subsequent synthesis and pending client calls, and no findings remain open.
Was this helpful? React 👍 or 👎
🤖 Bits Code Review · Commit 0ff6dd8
…order - materialize_request reads the iterables of an Anthropic request once, before the SDK and any AI Guard hook: messages and mcp_servers become lists, and a block whose content is an iterable (a generator or any single-use iterable) gets a request-local copy with that content as a list. The caller's objects are not changed, so reusable iterables stay live. The stream wrappers call it too, so the deferred evaluation reads the same values. - Convert content blocks in a single in-order walk instead of pre/post buckets: text and tool calls gather into one message, and each result of a tool Anthropic runs closes it and follows in place, so a new call after a resumed result is evaluated after that result. - Move the line pinned for _anthropic.py in the constant log message check. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Two of the most critical issues are: request normalization running outside the fail-open boundary (causing exceptions to abort application calls), and buffered server-tool results being appended after the assistant's synthesis block (causing AIGuard to misclassify responses as INPUT and skip output-only evaluation). A third distinct issue involves shallow dict() conversion of code-execution result blocks producing malformed JSON arrays instead of objects.
🤖 Bits Code Review · Commit 85e8211
…g requests - Guard materialize_request: an unexpected request shape is logged at debug level and leaves the request as it is, in the before-hook and the stream wrappers. - Materialize only the content of tool_result and mcp_tool_result blocks, the ones the SDK types as an Iterable, and never SDK models, which iterate over their fields. - Ignore generic tool_result blocks in responses: a response holds none, and the stream rebuild gives that type to server tool results, which would otherwise end the evaluated response with a tool message. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
In _anthropic.py, generator-backed or one-shot results (e.g. MCP tool results) can be silently emptied when an exception occurs after the iterator is consumed but before the copied snapshot is published — snapshots must be persisted before any subsequent inspection that could raise.
🤖 Bits Code Review · Commit 256140d
materialize_request published its request-local copy of the messages only at the end, so a failure on a later message, caught to fail open, lost tool result content already read from a single-use iterable. Publish each copy as soon as its content is read. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The PR adds AI Guard evaluation for Anthropic MCP connector calls and results, and earlier results now survive a later history lookup error. A buffered request can still send an empty result if copying the current block fails after its iterator has been consumed.
🤖 Bits Code Review · Commit 3baeba9
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 46886f7 | Docs | View more details | Give us feedback! |
Co-authored-by: datadog-prod-us1-6[bot] <266788760+datadog-prod-us1-6[bot]@users.noreply.github.com>
There was a problem hiding this comment.
More details
AI Guard now evaluates Anthropic MCP connector calls and results, including buffered streams, with provider-managed server metadata. Earlier content-loss, ordering, and exception-propagation defects remain resolved; request copies are now prepared before consuming single-use content, and no findings remain open.
🤖 Bits Code Review · Commit 04087c2
…thropic-evaluate-mcp-connector Resolve the conflicts with #22038: keep the in-order content walk and apply its rule there, so the tool results of a user turn come before that turn's text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1f8370782
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
AI Guard evaluates Anthropic MCP connector calls and results and preserves result snapshots across later lookup failures. Request preparation can still swallow an iterator error and send an empty connector list, and a connector result after a pending client call can cause output-only middleware to skip evaluation.
🤖 Bits Code Review · Commit d1f8370
…thropic test helpers - materialize_request also reads iterable system and tools once, so the deferred stream evaluation keeps the system prompt and the client-managed MCP tools; the separate conversions in the before-hook and _attach_mcp_servers are gone. - Move the SSE, transport, client and payload helpers of the Anthropic AI Guard tests into their conftest, shared by test_mcp and test_mcp_connector. - Shorten the _format_content_blocks and materialize_request docstrings. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The PR adds AI Guard evaluation for Anthropic MCP connector calls and results. Request preparation can now send empty system instructions as well as an empty connector list after iterator errors, and a trailing connector result can still cause output-only middleware to skip evaluation of a pending client call.
🤖 Bits Code Review · Commit 121dd08
…ending client calls - An error raised by a caller iterable while materialize_request reads it now reaches the caller, as it would from the SDK before sending the request; only failures of AI Guard's own inspection stay fail-open. - Client tool_use calls are pending until the next user turn, so they end the assistant turn after any server or connector result, and a response that stops for a client call stays an output evaluation. - _connector_mcp_servers lists mcp_servers only, instead of walking the history again after the before-hook. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
AI Guard evaluates Anthropic MCP connector calls and results, classifies pending client calls as output, and stops requests when their iterators raise. The new re-raise clears the original exception chain, hiding the underlying failure from callers.
🤖 Bits Code Review · Commit 26f8317
Co-authored-by: datadog-prod-us1-6[bot] <266788760+datadog-prod-us1-6[bot]@users.noreply.github.com>
…t iterable - Re-raise a caller iterable's error outside the exception handler, so it keeps its own __cause__ and __context__. - Say in the materialize_request docstring that caller iterator errors reach the caller and only AI Guard's own failures fail open. - Drop the second mcp_servers listing in _connector_mcp_servers: it is already a list by then. - Test caller iterator errors for messages, system, tools, mcp_servers and tool result content, with the caller's own cause. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
AI Guard evaluates Anthropic MCP connector calls and results, including buffered streams, with provider-managed server metadata. The latest change preserves caller exception chains while keeping inspection failures fail-open; earlier content-loss and ordering fixes remain intact, and no findings remain open.
🤖 Bits Code Review · Commit 7b94c94
|
Superseded by #22113: a minimal rewrite of the same fix from main. Closing this one. |
Description
AI Guard's Anthropic integration dropped
mcp_tool_useandmcp_tool_resultcontent blocks as unknown block types. With the Anthropic MCP connector (client.beta.messages.create(mcp_servers=[...])), Anthropic runs the MCP client itself and reports each call and its result with these blocks. So connector tool calls and their results never reached AI Guard: neither in the evaluation of the response nor in the history of later requests. A tool result is model-visible content, so this left an indirect prompt injection path unevaluated.This PR:
mcp_tool_useinto an assistant tool call (id, name, JSON input) andmcp_tool_resultinto a tool message with its text content, whateverDD_AI_GUARD_MCP_ENABLEDsays, like the conversion of OpenAI Responsesmcp_callitems.tool_usecalls end the assistant turn, after any such result, because the application has not run them yet. Calls, results and later text therefore keep the conversation's order, including a resumed turn whose result's call is in an earlier message. The tool results of a user turn come before its text.DD_AI_GUARD_MCP_ENABLED, gives each connector call anmcp.server_idthat resolves to amanaged_by: providerentry ofmcp_servers:nameandurlof the request'smcp_serversentry with thatserver_name, with transportunknown, the URL reduced to its origin and the tools mapped to themselves;authorization_tokenis never read;mcp_servers.anthropic.lib.tools.mcp) with the same name, even on the same URL origin: a connector call keeps its provider reference and never spares a client-managed call its own check.messages,system,tools,mcp_servers, and the content oftool_result/mcp_tool_resultblocks), before the SDK and any AI Guard hook, including the buffered stream wrappers. Tool result content goes into a request-local block copy, so the caller's objects are never changed. An error raised by a caller iterable reaches the caller, as it would from the SDK; failures of AI Guard's own inspection fail open.server_nameofmcp_tool_use, the type ofmcp_tool_resultand an input sent whole incontent_block_startinreconstruct_anthropic, the buffered stream reconstruction. The shared contrib rebuild drops them; the fix stays on the AI Guard side, so the shape that LLM Observability reads is unchanged. Generictool_resultblocks are ignored in responses, where the rebuild also gives that type to server tool results.DD_AI_GUARD_MCP_ENABLEDindocs/configuration.rstand in the AI Guard development rule._anthropic.pyinscripts/check_constant_log_message.pyfrom 67 to 70.Jira: APPSEC-71909
Customer impact
Applications that use the Anthropic MCP connector now get AI Guard evaluations of the connector's tool calls and results, and those evaluations can block. Anthropic has already run a connector call when the response arrives, so a blocking verdict withholds the response from the application but cannot stop the call itself. Server tool results whose call is in an earlier message (resumed turns) are now evaluated too. A
fixesrelease note is included.Testing
tests/aiguard/anthropic/test_mcp_connector.py(33 tests, 9 of them need an SDK with the MCP connector) covers:/evaluatepayload and theai_guardspan meta-struct, where everymcp.server_idresolves to the reportedmcp_servers;authorization_tokenand no URL user information, path, query or fragment in the payload or the meta-struct;DD_AI_GUARD_MCP_ENABLED=false, an undeclared server, two server names on one origin, generatormcp_servers/system, single-use tool result content, structured content, fail-open materialization, and caller iterator errors reaching the caller with their own cause;beta.messages.createsync and async, buffered streams sync and async (inline tool input, single-use history content), and a blocking verdict.tests/aiguard/anthropic/test_mcp.pycovers a connector call named like a client-managed tool, on another origin and on the same origin. The shared HTTP and SSE helpers of both modules live in the anthropicconftest.py.Local runs with
scripts/run-tests:ai_guard_anthropic5316c60f847apy3.13,anthropic==0.84.0,mcp<2ai_guard_anthropic5051ae7c17f6py3.14,anthropic<1,mcp<3ai_guard_anthropic8bc03089e6c5py3.9,anthropic==0.28.0mcp)ai_guard_litellm_guardrail1227021fb1a6py3.10,litellm[proxy]==1.78.5<1): an offline script ranbeta.messages.createsync and async, streamed and not, through the patched SDK; each evaluation had the split turn, a resolvingmanaged_by: providerentry and no token.scripts/lint(format, typing, constant log check) passes.Risks
managed_by.Additional Notes
Follow-ups, not in this PR:
reconstruct_anthropicwould fix them; it is tracked separately.ChatAnthropicunder LangChain, the LangChain integration evaluates instead of the Anthropic hooks, and its converter still drops the connector blocks.🤖 Generated with Claude Code