Repository navigation
feat(policy): record an MCP tool's output and read http tool replies - #416
Conversation
|
Assessment: Approve I re-reviewed at 41a7ee4. The two findings from my 8d5d2c6 review are fixed in 67e3cdc and covered by tests (see the thread replies). The merge from New code in 67e3cdc: checks that held
Both fixes are the narrow ones, with a test for each case. |
|
Assessment: Approve I re-reviewed head Assumptions checked in this commit that held
|
|
Assessment: Approve I re-reviewed head Assumptions checked that held
|
# Conflicts: # crates/policy/src/dogwood.rs
|
Assessment: Comment I re-reviewed head Assumptions checked that held
|
|
Assessment: Approve I re-reviewed head Assumptions checked that held
|
…against the upstream Shell The vendored Shell files that #397 changed are deleted here. #397's Shell tests move to crates/shell/tests/main_shell_semantics.rs and the broker tests, and its two Lua stdin tests move to the broker. The tests for #397's Shell fixes fail until the upstream Shell fixes land.
Description
Follow-up to #391.
Problem
#391 records how a tool call ended (
output.reply), but not what the tool answered. A rule like"reset a password only after
verify_identitysaidverified: true" can't be written. And overhttp Box never read the reply, so every http call recorded
indeterminateand a precondition onan http server refused every call.
Solution
Tool output. A tool's
::responsecarriesoutput.structured: the reply'sstructuredContent, keeping only the fields itsoutputSchemadeclares, for aresultonly. Anoptional field that doesn't match its type is left out. Like inputs, outputs have no size cap of
their own; the stdio frame and the gateway's response limit bound both. Example:
http replies. The gateway copies a
tools/callreply after redaction and hands it to a newReplyObserver. The policy adapter records the tool's response once both the reply and therequest outcome are known, and only after
mcp:call::responserecorded. It works for streamedreplies too. The gateway asks the server for an uncompressed tool reply, and a reply id matches
by value (
1.0is1).Not an answer yet. A reply that only accepts an MCP task, or has a
resultTypeother thancomplete(such asinput_required), recordsindeterminate. The task case was raised by@kevin-orellana on fix(policy): record a finished MCP tool call under the tool's own action #391.
Unreadable output schemas. An
outputSchemaCedar can't read drops only that tool'soutput.structured, instead of the server's whole catalog.Limits:
ends. This fails closed.
a full copy per connection. A reply over it records
indeterminateand still reaches the agent.On the topic of Frozen surfaces
Discussed why we marked "frozen interfaces" in the code with Fernando:
The changes to "frozen surfaces" here are:
ReplyObserver;EffectPermit::reply_observerwitha default.
PolicyError::OutcomeKept, returned when the history keeps an outcome to writelater (after fix(policy): refuse history stamped ahead of the clock #410), so callers record the tool's response behind it; new
PolicyEngine::record_tool_reply;McpReply::of_replyreturnsindeterminatefor atask reply.
output.structured; over http,output.replynow recordsresult,tool_error, orprotocol_error.output.structuredand<tool>Outputtypes. A server thatdeclares outputs restages once after upgrade.
Related Issues
Follow-up to #391.
Type of Change
New feature
Testing
Unit tests were added to cover the relevant sections. Not covered: recording the tool only after
mcp:callrecorded, because no test can make that record fail. The box-level http test usesplain HTTP; TLS is covered in the gateway's own tests.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.