Repository navigation
Conversation
After an ASK or a DEFER on a tools/call response, the Observed Agent can send the same response again. The Guardian had already closed the call, so the second send got DENY mcp_call_not_open. The call now closes only on a final ALLOW, MODIFY or DENY. Part of GenAI-Security-Project#701 Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
Two cases left a call open for good. A cancelled request usually gets no response, so its call stayed open. And the only bound on the open calls denied new ones: once the calls filled limits.max_policy_state_bytes, every new tools/call in the session was denied. A notifications/cancelled now closes the call it names. It does so only from MCP 2026-07-28 on, where only the client's requests can be cancelled. The version comes from the method, or else from the one MCP version the client declared. Under MCP 2025-11-25 and earlier a cancel closes nothing, because its id can name a request of the MCP server; there only eviction bounds the record. When a new call does not fit in limits.max_policy_state_bytes, the oldest calls close, and an mcp_calls_evicted event names them. This is an event of this Guardian's own audit log, not of the specification. Session.MCPCalls is now MCPCalls, an ordered record saved as a JSON list. A Conclusion names the call it opens (OpenMCPCall) and the calls it closes (CloseMCPCalls), and a store applies both with MCPCalls.Apply. The engine still reads SessionContext.MCPCalls as a map. This changes the store format. A store cannot load the earlier form, a JSON object by id, so end those sessions before the upgrade. The record is per ACS session, so MCP ids in flight must be unique across the session's connections. The cancel is the third place that asks whether a method wraps an MCP message, so method.WrappedMethod now answers it once, case-insensitive as before, for the cancel, the Guardian's tools/call and the bridge. Example: "protocols/mcp/notifications/cancelled" names MCP. Part of GenAI-Security-Project#701 Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
With a manifest that has no result policy, the bridge still denied an MCP result it could not decode. The denial named a policy that does not exist. Decide now allows such a result when no policy governs steps/toolCallResult, and denies it as before when one does. Part of GenAI-Security-Project#701 Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
A server may answer a tools/call with a task instead of the tool's
output. The bridge refused that answer as unreadable. It now accepts a
task in both forms: a task object (MCP 2025-11-25) and resultType "task"
(the MCP Tasks extension). checkResult reports which results acknowledge
a task.
A task acknowledgement with no outputs is allowed without asking the
result policy. The stock AGT policy reads outputs[0], so it would deny
the empty result with runtime_error:path_missing. An acknowledgement
that carries content or _meta is decided like any result.
A server that answers with a task skips the result policy: the tool's
output arrives later, in tasks/result or tasks/get, which no policy
reads. Neither does a task's statusMessage. The docs state this gap.
The result reader no longer carries a branch for an MCP error object it
cannot decode: mcp.Read has already refused such a response, for
example {"error":{"code":1,"message":7}}, so no input reached it.
Part of GenAI-Security-Project#701
Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
The MCP handler read a tools/call with ReadToolCall and refused such a call with -32602 before the Guardian could read it. The handler now checks a tools/call as it checks every MCP message, with Read. The Guardian's own read then refuses it: a signed DENY evaluation_failed, as before GenAI-Security-Project#619. Example: {"jsonrpc":"2.0","id":3,"method":"tools/call", "params":{"name":42}}. The same DENY now covers three neighbours of this case: - a null or missing name ("name":null) reached the policy as the tool ""; - a request without an id (MCP requires one) reached the policy, and its call was not tracked; - arguments that are neither an object nor null ("arguments":[]) reached the engine; the AGT bridge failed to translate them, so the step was denied as an engine failure, and another engine got them. The reasoning of this DENY now names what was refused, such as "the wrapped tools/call has no tool name that is a string". Part of GenAI-Security-Project#701 Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
changesMCPCall read its modifications without a nil check. At d315da3 too, disposition.Check (called from fit in decide) refused a MODIFY without modifications before changesMCPCall, so no panic could occur. The guard only protects a future caller. It reads nil as no change, which its own test covers. An end-to-end test pins the case of item 6: such a MODIFY on a wrapped tools/call gets DENY evaluation_failed, no panic. Part of GenAI-Security-Project#701 Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
RFC 8785 writes every number as a double. Two numeric ids that differ beyond a double's precision, such as 9007199254740992 and 9007199254740993, canonicalize to one id and share one call. A numeric id is now unreadable, and its call a signed DENY evaluation_failed, when it is not an integer or is 2^53 or more in magnitude. I-JSON (RFC 7493 section 2.2), which RFC 8785 builds on, sets the same bound for an exact integer. Reading an id exactly is cheap for an ordinary number, but an exponent such as 1e-999999 makes a huge integer; the 64-character and exponent bounds keep that read cheap. An id beyond the range of a double is not I-JSON and fails envelope parsing first, so its request gets -32700. Part of GenAI-Security-Project#701 Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
The SessionContextStore contract in guardiantest gave every test entry a made-up entry_hash: digest(n) was the number n padded to 64 hex digits, so entry 1 carried 000...0001. A store may check each entry's entry_hash before it keeps it; such a store refused every entry, and the 11 cases that append one could not test it. Steps to reproduce: run guardiantest.TestSessionContextStore against a store whose Append checks chain.EntryHash(a.Entry) == a.Entry.EntryHash. Expected: the contract runs and passes. Actual: every Append fails with "entry 1 carries entry_hash 000...0001, its content gives b253...". entry now seals each entry with chain.Seal, as the Guardian seals it, and digest(n) is the entry_hash of entry n in the chain 1, ..., n. The case that gives entry 2 the step id of entry 1 seals it again after the change. TestTheStoreContractHoldsForAStoreThatChecksEntryHashes runs the contract against the memory store wrapped by such a check: it fails before this change and passes after it. Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
rocklambros
left a comment
There was a problem hiding this comment.
Thanks, Konstantin. Six of the seven items are good, and the store test fix is good too. make test passes in every package at d00fcc7, including TestRecordingIsCurrent and TestRecordedCases, and go vet is clean.
One thing blocks the merge. It's the first point you asked us to check: item 4 lets a tool's output reach the agent without a result check, even when a policy checks tool results.
In agtbridge/bridge.go (lines 148 to 151), the bridge answers ALLOW to a task acknowledgement before it asks whether the result point is governed. The real output then comes back in a tasks/result or tasks/get response, and project() in agtbridge/mcp.go maps neither one to a policy point, so the bridge allows those too. I tested this through the Guardian with the stock AGT policy and a ghp_ token in the tool output:
| Step | integration (905f124) |
This PR (d00fcc7) |
|---|---|---|
| Direct result with the token | MODIFY redaction_applied |
MODIFY redaction_applied |
Task acknowledgement (task object or resultType: "task") |
DENY mcp_result_unreadable |
ALLOW |
tasks/result or tasks/get response with the token |
ALLOW | ALLOW |
The last row is ALLOW on integration too, but today the DENY on the acknowledgement stops the agent before it learns the task ID. This PR removes that DENY, so the token reaches the agent without redaction. ACS says the agent can't get around the control, so the fix has to be part of this PR.
Please make this change:
- When the result point is governed, answer DENY with
mcp_result_unreadableto a task acknowledgement and to everytasks/resultortasks/getresponse. When no result policy exists, keep ALLOW. Use the same check as line 136 inbridge.go. - Add tests for both cases (result policy governed, and no result policy) for the acknowledgement and for the
tasks/resultandtasks/getresponses. - Update
docs/conformance.mdline 29 to say that a task's output is denied while a result policy is set.
The full fix would record which tool each task ID belongs to, and then check the later tasks/result output with that tool's result policy. That's a bigger change, so I'd like to keep it for a separate issue. The change above is enough for this PR.
If you use an AI coding tool, this prompt covers it:
In reference-implementations/agt-go/agtbridge/bridge.go, Engine.Decide currently returns
ALLOW for an MCP task acknowledgement (p.task && len(p.outputs) == 0) before it checks the
result policy. Change it so that, when the steps/toolCallResult point is governed (the same
check as the errMCPResultUnreadable branch: e.mapping.point(acs.StepToolCallResult) and
e.evaluator.Governs(point)), the bridge returns DENY with reason code
mcp_result_unreadable for (a) a task acknowledgement and (b) any MCP response to a
tasks/result or tasks/get request. When the result point is not governed, keep ALLOW. Add
Go tests in agtbridge/bridge_test.go for both cases, with both task forms (a task object and
resultType "task") and both follow-up methods. Update docs/conformance.md line 29 to match.
Then run `make test` and `go vet ./...` in reference-implementations/agt-go.
One optional follow-up that can wait for a later PR: in guardian/step.go (line 714), a response answered ASK or DEFER keeps its call open with no time limit, and only eviction closes it. Eviction goes by age only, so it can close a call that is still waiting for its approver. Closing the call when the ASK or DEFER is answered or times out would fix that.
When the fix is in, this PR can merge into integration in the next batch, together with other PRs for release 0.1.6.
Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
Item 4 let a task's acknowledgement through, but no policy reads the output that follows: the bridge maps tasks/result, tasks/get and notifications/tasks to no policy point. So with a result policy, a secret in a task's output reached the agent unredacted. Before item 4, the Guardian denied the acknowledgement, and the agent never got the output. Steps to reproduce: with the stock AGT policy, send a wrapped tools/call that asks for a task, its acknowledgement, a tasks/result request, and the response, whose content holds a ghp_ token. Expected: the token does not reach the agent. Actual: each step is ALLOW. While the manifest has a result policy, the bridge now answers DENY mcp_result_unreadable to a task's acknowledgement, to every response to tasks/result or tasks/get, and to notifications/tasks, in which the MCP Tasks extension pushes the same task with its output. Without a result policy it allows them, as before. The tasks/result and tasks/get requests carry no output and stay allowed. TestWrappedMCPTaskAcknowledgement and TestWrappedMCPTaskOutput cover both forms of a task, the three messages, the stock policy, which has a result policy, and a policy that checks only tool calls. They fail before this change. Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
|
Thanks, Rock. Fixed in e6d15da. With a result policy set, the bridge now denies the task acknowledgement and the task output: Checking task output with its tool's policy is #766. |
What changed
This pull request fixes the seven Go Guardian items that issue #701 lists. Each item has its own commit. The pull request also includes one test fix.
tools/callrequest, it keeps the call open. The agent can then send the response again. The Guardian closes the call only after a final ALLOW, MODIFY or DENY on the response.notifications/cancelledmessage names. When the list of open calls is full, the Guardian closes the oldest calls. It records this as anmcp_calls_evictedevent in its own audit log. This event is not in the ACS event catalog.taskobject (MCP 2025-11-25) andresultType: "task"(the MCP Tasks extension). No policy checks the task's output, which arrives later in atasks/resultortasks/getresponse or anotifications/tasksmessage. So when a policy checks tool results, the Guardian denies the task and its output. When no policy checks tool results, it allows them. Issue [RefImpl] Go Guardian: check MCP task results and other server content #766 tracks checking a task's output with its tool's policy.tools/callrequest whose tool name is not a string, as it did before Fix the Go Guardian items from the #169 review #619. The same signed DENY now also applies to a request with no tool name, a request with no ID, and a request whoseargumentsis not a JSON object ornull.changesMCPCallnow reports no change when the modification data is missing. This could not cause a crash before, becausedisposition.Checkalready rejects such a MODIFY beforechangesMCPCallruns. The new check protects future callers ofchangesMCPCall.2^53or more. Above that limit, the Guardian could treat two different IDs as the same ID. I-JSON (RFC 7493, section 2.2) sets the same limit.guardianteststore tests gave each entry a placeholderentry_hash. A store that verifies entry hashes rejected those entries, so 11 tests could not run on that store. The tests now use the correct hash for each entry. I can move this fix to a separate pull request if you prefer.Please check these two points:
tools/calland a server request can both be open with ID7. Anotifications/cancelledmessage names the request to cancel by its ID. In MCP 2025-11-25 and earlier, either side may cancel its own request, so the Guardian cannot tell from the ID alone whether "cancel 7" is for the client's call or the server's request. It closes nothing. In MCP 2026-07-28, a cancellation can name only a client request, so the Guardian closes the client's call7. In the older versions, only the size limit closes an old call that never gets a final decision.Session.MCPCalls, the session's list of open calls. Stores saved a JSON object with call IDs as keys. Stores now save a JSON array, oldest call first, because the Guardian closes the oldest calls first and a JSON object has no defined order.Which issue does this implement
Closes #701
meaning, so it needs no issue
Base branch
integration. Every pull request targetsintegration, documentation included.Only a promotion targets
main(see CONTRIBUTING.md)release/0.2, because this changes normative specification text, a schema, or aconformance requirement for 0.2, or carries out such a change in code
Type of change
I tested this
uv run pytest -vpasses on my machineuv run mkdocs build --strictpasses on my machineIn
reference-implementations/agt-go,make checkandmake test-racepass on Linux and on macOS.make loadpasses on macOS.I also sent test events to this Guardian through the Claude Code, Cursor and NAT adapters. The Guardian returned the same answers as on
integration. These adapters do not send MCP messages wrapped in ACS messages, so only the Go tests cover the MCP changes.Checklist
git commit -s(required by the DCO)Security
Items 3 and 4 change some DENY decisions to ALLOW, but only when no policy checks tool results. Item 5 returns a signed DENY in place of an error: before, an agent configured to
proceedcould treat that error as permission to continue. Item 7 stops the Guardian from matching two different IDs to the same call.