Repository navigation
Conversation
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. - Keep a connector call named like a client-managed MCP tool apart from that tool: it keeps its provider reference and never spares the tool its check. - Share the Anthropic AI Guard test helpers through the tests' conftest. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dependency direction analysis
|
Codeowners resolved asResolved from the full PR diff against |
|
@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. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
BenchmarksBenchmark execution time: 2026-11-26 18:12:46 Comparing candidate commit 684e6f7 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 387 metrics, 9 unstable metrics.
|
…er intact - List iterable messages, system, tools and mcp_servers once in the before-hook, in the kwargs the SDK gets, replacing three inline copies; an error raised by a caller iterable reaches the caller, as it would from the SDK. - Evaluate buffered streams with the contrib stream handler's request kwargs, the dict the before-hook listed, instead of the wrapper's own kwargs. - Emit a client tool_use that follows a server or connector result after that result, so a response that stops for a client call stays an output. - Emit server and connector results even when their call is in an earlier message, before any text that follows them. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ra_body servers - Replace the pre/post buckets with one conversion in block order: each result of a tool Anthropic ran (server tools, mcp_tool_result) ends the assistant message before it and follows as a tool message, so several connector rounds in one message keep their order. User turns keep their tool results before their text; responses ignore generic tool_result blocks, which the stream rebuild also gives to server tool results. - Read the connector servers from extra_body when it carries mcp_servers: the SDK merges extra_body over the params, and older SDKs can only send them that way. - Move the line pinned for _anthropic.py in the constant log message check to 70. APPSEC-71909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The before-hook no longer lists the top-level mcp_servers when extra_body replaces it, since that param is never sent. Tool result content that is a one-shot iterator is not read, so the SDK still sends it intact; AI Guard does not evaluate it and reports the skip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK sends extra_body mcp_servers given as a one-pass iterable, but AI Guard only read lists and tuples, so connector calls lost their declared server URL. The before-hook now lists them once into a new extra_body dict, leaving the caller's dict unchanged, and both evaluations read that list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ends The SDK merges extra_body over the request params, but AI Guard read the top-level messages, system and tools, so it evaluated values that were never sent and missed the ones that were. Every read now goes through _sent_param, which prefers extra_body. A param that extra_body replaces is left unread, and extra_body values are listed once into a new dict, leaving the caller's dict unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t unread The converter consumed one-shot iterators in document source content and web search result content without writing them back, so the SDK sent empty lists. Like tool result content, they are now left unread (_is_one_shot): the SDK still sends them, AI Guard does not evaluate them, and the skip is reported. The anthropic tests share one recording client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Two points from the latest review: Performance note in the description (P3). This is already addressed: since 826af3e, the description no longer says the added work is a dictionary lookup limited to connector requests. It says the changed code runs for every Anthropic request AI Guard evaluates, including buffered streams, and that the overhead was not measured because no benchmark scenario covers the AI Guard listeners. Single-use nested content (known gap). Nested content that may only be read once (tool result content, document |
…ep pending client calls last Nested content is read only when it is a string, list or tuple: any other iterable may only be read once (an iterator, or an iterable that hands out the same iterator), so it is left for the SDK and the skip is reported. Web search error results are not reported. Client tool_use calls go in the last assistant message of a turn, so a client call before a connector result no longer ends the response on a tool message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.The design is: read the connector servers of the request once, then attach them while converting the messages.
_connector_mcp_servers): each hook maps thenameof every entry of the request'smcp_serversto amanaged_by: providerserver entry, with transportunknownand the URL reduced to its origin. Onlynameandurlare read;authorization_tokennever is.mcp_tool_usebecomes an assistant tool call whosemcp.server_idreferences its server (tools map to themselves), andmcp_tool_resultbecomes a tool message. Content blocks are converted in block order: each result of a tool Anthropic ran (server tools,mcp_tool_result) ends the assistant message before it and follows as a tool message, so several connector rounds in one message keep their order. Servers are read fromextra_bodywhen it carriesmcp_servers(the only way on older SDKs). A server that the request does not declare is identified by its name alone, and only servers referenced by a tool call are sent. The conversion happens whateverDD_AI_GUARD_MCP_ENABLEDsays; only the MCP metadata depends on it.server_nameand renamesmcp_tool_resulttotool_result.reconstruct_anthropicrestores both from thecontent_block_startchunks, on AI Guard's side, so the shape LLM Observability reads is unchanged.tool_usecalls wait for the next user turn, so they go in the last assistant message of a turn, after any server or connector result, whatever their position among the blocks. A response that stops for a client call therefore stays an output evaluation. dd-trace-js still puts a client call that comes before a connector result in the same message as the connector call; aligning it is tracked in APPSEC-72055.tool_result/mcp_tool_resultcontent, documentsource.content,web_search_tool_resultcontent) is evaluated only when it is a string, a list or a tuple. Any other iterable may only be read once (an iterator, or an iterable that hands out the same iterator), so AI Guard leaves it unread and the SDK still sends it intact; AI Guard does not evaluate it and reports the skip to telemetry.extra_bodysends: the SDK mergesextra_bodyover the params, so every read ofmessages,system,toolsandmcp_servers(before and after the call, and buffered streams) uses theextra_bodyvalue when there is one (_sent_param). AI Guard leaves a param thatextra_bodyreplaces unread (the SDK and LLM Observability may still read it), and iterableextra_bodyvalues are listed once into a newextra_bodydict, so the caller's is unchanged. Before, AI Guard evaluated the top-level values even when they were not sent.messages,system,toolsandmcp_serversonce, in the kwargs the SDK gets, so the SDK, LLM Observability and AI Guard read the same lists; an error raised by a caller iterable reaches the caller, as it would from the SDK. Buffered streams evaluate with the contrib stream handler's kwargs, that same dict.attach_mcpno longer reassigns a call that already references a server, andmark_evaluatedskips the response's connector calls, so a connector call never spares a client-managed tool call its own check.Also: docs for
DD_AI_GUARD_MCP_ENABLED, the AI Guard development rule, afixesrelease note, the shared test helpers moved into the anthropic tests'conftest.py, and the line pinned for_anthropic.pyinscripts/check_constant_log_message.py(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.
Testing
tests/aiguard/anthropic/test_mcp_connector.py: conversion; the/evaluatepayload and theai_guardspan meta-struct, where everymcp.server_idresolves; noauthorization_tokenor URL user information, path, query or fragment in either; flag off; undeclared server; two names on one origin; generatormcp_servers(also in buffered streams, sync and async); caller iterator errors; resumed results, pending client calls and several connector rounds in one message, in responses and in history;extra_bodyservers as a list or an iterator, and an overriddenmcp_serversiterator left unread; single-use result content (an iterator and an iterable wrapper) reaching Anthropic intact through the SDK; a pending client call before or after a connector result; and through the SDK,beta.messages.createsync, async and buffered streams (sync and async), and a blocking verdict.tests/aiguard/anthropic/test_anthropic.py: the before-hook withmessages,systemandtoolsfromextra_body, the replaced iterators left unread and the caller'sextra_bodyunchanged; through the SDK,extra_bodymessages (list) and system (string) in the sent request and both evaluations; one-shot document source and web search result content left unread, in top-level andextra_bodymessages; a web search error result converted without a report.tests/aiguard/anthropic/test_mcp.py: a connector call named like a client-managed tool, on another origin and on the same origin.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_guardrail1227021fb1a6/0c22a699084f,litellm[proxy]==1.78.5/1.82.6scripts/lint(format, typing, constant log check) passes. Not run: a live call through the connector. No benchmark scenario covers the AI Guard listeners, and the overhead was not measured. The changed code runs for every Anthropic request AI Guard evaluates, including buffered streams; it adds a few type checks and dictionary lookups per request and per content block.Risks
managed_by.Additional Notes
This replaces #22068, which grew beyond the ticket. Follow-ups, not in this PR:
ChatAnthropicunder LangChain, the LangChain integration evaluates instead of the Anthropic hooks, and its converter drops the connector blocks.🤖 Generated with Claude Code