Scope MCP app resource reads to their originating call (#39187)

## Why

App widgets need to read resources using the app and account context of the
tool call that produced them, including after a thread is restored.

## What changed

- Add an optional `originCallId` to `mcpServer/resource/read` requests and
  return it on successful scoped reads.
- Track bounded provenance for successful app tool calls in thread history and
  use the current tool binding, account link, and app policy when reading the
  associated widget resource.
- Reject missing, mismatched, failed, or ambiguous origins, while keeping
  app-only tools available for widget reads without exposing them to the model.

## Testing

Add app-server coverage for scoped widget reads across both history modes,
ephemeral and persistent threads, server restarts, app-only visibility, and
invalid origin cases.

GitOrigin-RevId: 11eaefc066b2a3b639599e4cbdef680233d150a2
This commit is contained in:
jif authored and copyberry committed 2026-08-18 11:51:21 +00:00
1 parent 711a5f8b3a
commit 880f1135ea
26 files changed
+779 -22

No files matched your search

@@ -2328,6 +2328,7 @@ mod tests {
request_id: request_id(),
params: v2::McpResourceReadParams {
thread_id: Some("thread-1".to_string()),
origin_call_id: None,
server: "server-a".to_string(),
uri: "file:///tmp/resource".to_string(),
},
@@ -2515,6 +2516,7 @@ mod tests {
request_id: request_id(),
params: v2::McpResourceReadParams {
thread_id: None,
origin_call_id: None,
server: "server-a".to_string(),
uri: "file:///tmp/resource".to_string(),
},
@@ -85,6 +85,9 @@ pub struct ListMcpServerStatusResponse {
pub struct McpResourceReadParams {
#[ts(optional = nullable)]
pub thread_id: Option<String>,
/// Originating MCP tool call used to select the resource's app.
#[ts(optional = nullable)]
pub origin_call_id: Option<String>,
pub server: String,
pub uri: String,
}
@@ -94,6 +97,8 @@ pub struct McpResourceReadParams {
#[ts(export_to = "v2/")]
pub struct McpResourceReadResponse {
pub contents: Vec<McpResourceContent>,
/// Originating call when the server applied app-specific resource scoping.
pub origin_call_id: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]