Limit turn metadata forwarding to Codex Apps MCP

This commit is contained in:
miaolin
2026-05-22 10:53:23 -07:00
parent 10a6d8c033
commit d2470098d4
2 changed files with 28 additions and 4 deletions
@@ -343,6 +343,7 @@ use codex_login::complete_device_code_login;
use codex_login::login_with_api_key;
use codex_login::request_device_code;
use codex_login::run_login_server;
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_mcp::McpRuntimeContext;
use codex_mcp::McpServerStatusSnapshot;
use codex_mcp::McpSnapshotDetail;
@@ -402,10 +402,14 @@ impl McpRequestProcessor {
let thread_id = params.thread_id.clone();
let (_, thread) = self.load_thread(&thread_id).await?;
let meta = with_mcp_tool_call_thread_id_meta(params.meta, &thread_id);
let meta = with_mcp_tool_call_turn_metadata_meta(
meta,
thread.current_mcp_request_turn_metadata().await,
);
let meta = if should_forward_turn_metadata_to_mcp_server(&params.server) {
with_mcp_tool_call_turn_metadata_meta(
meta,
thread.current_mcp_request_turn_metadata().await,
)
} else {
meta
};
let request_id = request_id.clone();
tokio::spawn(async move {
@@ -420,6 +424,10 @@ impl McpRequestProcessor {
}
}
fn should_forward_turn_metadata_to_mcp_server(server: &str) -> bool {
server == CODEX_APPS_MCP_SERVER_NAME
}
fn with_mcp_tool_call_turn_metadata_meta(
meta: Option<serde_json::Value>,
turn_metadata: Option<serde_json::Value>,
@@ -448,6 +456,21 @@ fn with_mcp_tool_call_turn_metadata_meta(
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn turn_metadata_is_forwarded_only_to_codex_apps_mcp_server() {
assert!(should_forward_turn_metadata_to_mcp_server(
CODEX_APPS_MCP_SERVER_NAME
));
assert!(!should_forward_turn_metadata_to_mcp_server(
"custom_mcp_server"
));
}
}
fn with_mcp_tool_call_thread_id_meta(
meta: Option<serde_json::Value>,
thread_id: &str,