Use MCP owner permissions for Guardian reviews and score reuse (#59489)

## Why

An MCP server can belong to a different environment from the turn's primary environment. An early Guardian score based on the issuing context must not bypass review when the server owner's permissions differ.

## What changed

- Capture the owning environment's permissions when preparing an MCP call and retain them for server-initiated approvals tied to that still-running call.
- Use the captured permissions consistently in Guardian review prompts and permission context.
- Require a fresh synchronous review when the captured owner permissions do not match the early score's authorization.

## Testing

Extend regression coverage for MCP score reuse across environments and for follow-up approvals from a local MCP server during a remote-primary turn. Assert that reviews use the owner's denied paths and require a fresh review when permissions differ.

GitOrigin-RevId: eb5eeb1259732c57f39765c38e34148fa0787dae
This commit is contained in:
sayan-oai
2026-11-04 20:37:39 +00:00
committed by copyberry
parent d78f68f8d1
commit 9fcaeb7335
10 changed files with 167 additions and 54 deletions
+9
View File
@@ -1187,6 +1187,15 @@ async fn review_guardian_mcp_elicitation(
}
};
guardian_request.category = guardian_scope;
// Keep the action the server asked about, but use its owner's rules from the original call.
if let Ok(crate::guardian::GuardianApprovalRequest::McpToolCall {
prompt_permissions, ..
}) = &mut guardian_request.request
&& let Some(permissions) =
approval_context.and_then(|context| context.environment_permissions)
{
*prompt_permissions = Some(permissions);
}
let declined_reason = guardian_request.request.as_ref().err().cloned();
let decision = crate::guardian::decide_approval(
session,