Forward caller metadata on MCP resource reads (#59509)

## What changed

Accept an optional `_meta` object on `mcpServer/resource/read` and forward it to MCP `resources/read`, including reads bound to an originating tool call. Update the protocol schemas and generated TypeScript and Python types.

Reject caller metadata containing host-owned `threadId`, `x-codex-turn-metadata`, or `codex/connectionLease` keys. For `codex_apps`, also reserve `connector_id`, `link_id`, and `_codex_apps.resource_uri` to preserve app and account routing.

## Testing

Add integration coverage for metadata forwarding through stdio, hosted app reads with and without a thread, and origin-bound widget reads. Cover rejection of reserved keys and non-object metadata.

GitOrigin-RevId: 227ee0fb5fe15fa2ff2ec66d4d5ae16de8935a8c
This commit is contained in:
Joe Savona
2026-11-04 22:55:22 +00:00
committed by copyberry
parent ad5e6e57a1
commit aa1399cbcd
22 changed files with 279 additions and 40 deletions
@@ -2173,6 +2173,14 @@
},
"McpResourceReadParams": {
"properties": {
"_meta": {
"additionalProperties": true,
"description": "Additional MCP request metadata. Account and turn routing keys are reserved.",
"type": [
"object",
"null"
]
},
"connectorId": {
"type": [
"string",
@@ -15299,6 +15299,14 @@
"McpResourceReadParams": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"_meta": {
"additionalProperties": true,
"description": "Additional MCP request metadata. Account and turn routing keys are reserved.",
"type": [
"object",
"null"
]
},
"connectorId": {
"type": [
"string",
@@ -11260,6 +11260,14 @@
"McpResourceReadParams": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"_meta": {
"additionalProperties": true,
"description": "Additional MCP request metadata. Account and turn routing keys are reserved.",
"type": [
"object",
"null"
]
},
"connectorId": {
"type": [
"string",
@@ -22,6 +22,14 @@
}
},
"properties": {
"_meta": {
"additionalProperties": true,
"description": "Additional MCP request metadata. Account and turn routing keys are reserved.",
"type": [
"object",
"null"
]
},
"connectorId": {
"type": [
"string",
@@ -1,9 +1,14 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { JsonValue } from "../serde_json/JsonValue";
import type { McpResourceReadTarget } from "./McpResourceReadTarget";
export type McpResourceReadParams = { threadId?: string | null,
export type McpResourceReadParams = {
/**
* Additional MCP request metadata. Account and turn routing keys are reserved.
*/
_meta?: { [key in string]?: JsonValue } | null, threadId?: string | null,
/**
* Originating MCP tool call used to select the resource's app.
*/
@@ -2569,6 +2569,7 @@ mod tests {
let mcp_resource_read = ClientRequest::McpResourceRead {
request_id: request_id(),
params: v2::McpResourceReadParams {
meta: None,
thread_id: Some("thread-1".to_string()),
origin_call_id: None,
server: "server-a".to_string(),
@@ -2763,6 +2764,7 @@ mod tests {
let mcp_resource_read = ClientRequest::McpResourceRead {
request_id: request_id(),
params: v2::McpResourceReadParams {
meta: None,
thread_id: None,
origin_call_id: None,
server: "server-a".to_string(),
@@ -112,6 +112,10 @@ pub struct ListMcpServerStatusResponse {
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct McpResourceReadParams {
/// Additional MCP request metadata. Account and turn routing keys are reserved.
#[serde(rename = "_meta")]
#[ts(rename = "_meta", optional = nullable)]
pub meta: Option<serde_json::Map<String, JsonValue>>,
#[ts(optional = nullable)]
pub thread_id: Option<String>,
/// Originating MCP tool call used to select the resource's app.