mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Honor explicit account selectors for Apps tool calls (#42054)
## What changed - Resolve `link_id` from tool-call arguments when Apps metadata sets `requires_explicit_link_id` to `true`. - Reject the call before approval or execution when the required selector is missing, empty, or not a string. - Preserve catalog-provided account metadata for legacy Apps tools and leave non-Apps MCP tools unchanged. ## Testing - Add unit coverage for required selectors, malformed values, legacy fallbacks, and non-Apps tools. - Add end-to-end coverage for execution, approval prompts, and rejection when an Apps call omits `link_id`. GitOrigin-RevId: 667fd04102a3934d53ded020da6d1bf68a1ca3e5
This commit is contained in:
1 parent
0ec375eb70
commit
0e37d834d4
4 files changed
+365
-16
No files matched your search
@@ -0,0 +1,39 @@
|
||||
//! Resolves account identity before native Apps approvals. Required selectors
|
||||
//! must be valid; optional catalog identities never block legacy calls.
|
||||
|
||||
use super::MCP_TOOL_LINK_ID_META_KEY;
|
||||
use codex_mcp::MCP_TOOL_CODEX_APPS_META_KEY;
|
||||
use codex_mcp::ToolInfo;
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
|
||||
pub(super) enum McpToolAccountError {
|
||||
#[error("This app tool requires a non-empty string link_id argument")]
|
||||
InvalidSelector,
|
||||
}
|
||||
|
||||
pub(super) fn resolve_account(
|
||||
tool_info: &ToolInfo,
|
||||
arguments: Option<&JsonValue>,
|
||||
) -> Result<Option<String>, McpToolAccountError> {
|
||||
let tool_meta = tool_info.tool.meta.as_deref();
|
||||
let requires_explicit_link_id = tool_meta
|
||||
.and_then(|meta| meta.get(MCP_TOOL_CODEX_APPS_META_KEY))
|
||||
.and_then(|meta| meta.get("requires_explicit_link_id"))
|
||||
.and_then(JsonValue::as_bool)
|
||||
== Some(true);
|
||||
let link_id = if requires_explicit_link_id {
|
||||
arguments.and_then(|arguments| arguments.get(MCP_TOOL_LINK_ID_META_KEY))
|
||||
} else {
|
||||
tool_meta.and_then(|meta| meta.get(MCP_TOOL_LINK_ID_META_KEY))
|
||||
}
|
||||
.and_then(JsonValue::as_str)
|
||||
.filter(|link_id| !link_id.trim().is_empty())
|
||||
.map(str::to_owned);
|
||||
|
||||
if requires_explicit_link_id && link_id.is_none() {
|
||||
Err(McpToolAccountError::InvalidSelector)
|
||||
} else {
|
||||
Ok(link_id)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user