Attach verified access context to eligible plugin MCP calls (#41005)

## What changed

- Fetch ChatGPT account access and attach `cyber_trusted_access` under
  `openai/entitlementContext` when an installed or selected plugin explicitly
  requests it from a local, read-only stdio tool with no arguments.
- Reject caller-supplied entitlement context on direct MCP calls, and fall back
  to an `unknown` status when access cannot be verified or the account changes
  during the lookup.
- Count entitlement lookup time against the MCP tool-call timeout.

## Testing

- Cover eligible calls plus unowned, remote, HTTP, mutable, argument-bearing,
  API-key, undeclared, direct, and account-switch cases in core and app-server
  integration tests.

GitOrigin-RevId: 303b61585ef4530276c373d914a2d0ccef1f4ac2
This commit is contained in:
soyeon-oai authored and copyberry committed 2026-08-27 00:02:26 +00:00
1 parent e56e4922eb
commit ae357e7250
16 files changed
+935 -31

No files matched your search

@@ -79,6 +79,28 @@ impl TestToolServer {
Arc::new(sandbox_meta_schema),
);
sandbox_meta_tool.annotations = Some(ToolAnnotations::new().read_only(true));
let entitlement_tools = std::env::var("MCP_TEST_DAYBREAK_READ_ONLY")
.ok()
.into_iter()
.flat_map(|read_only| {
["get_codex_security_daybreak_access", "get_daybreak_access"].map(|name| {
let mut tool = sandbox_meta_tool.clone();
tool.name = Cow::Borrowed(name);
tool.description =
Some(Cow::Borrowed("Return requested account access metadata."));
tool.annotations = Some(ToolAnnotations::new().read_only(read_only == "true"));
if name == "get_codex_security_daybreak_access" {
let mut meta = MetaObject::new();
meta.insert(
"openai/requestedEntitlements".to_string(),
json!(["cyber_trusted_access"]),
);
tool.meta = Some(meta);
}
tool
})
})
.collect::<Vec<_>>();
#[expect(clippy::expect_used)]
let thread_hint_schema: JsonObject = serde_json::from_value(json!({
@@ -124,6 +146,7 @@ impl TestToolServer {
Self::image_scenario_tool(),
sandbox_meta_tool,
];
tools.extend(entitlement_tools);
if std::env::var_os("MCP_TEST_ENABLE_NODE_REPL_JS").is_some() {
#[expect(clippy::expect_used)]
let schema: JsonObject = serde_json::from_value(json!({
@@ -662,9 +685,9 @@ impl ServerHandler for TestToolServer {
.supports_openai_form_elicitation
.load(Ordering::Relaxed),
}))),
"sandbox_meta" => Ok(Self::structured_result(serde_json::Value::Object(
context.meta.0.0,
))),
"sandbox_meta" | "get_codex_security_daybreak_access" | "get_daybreak_access" => Ok(
Self::structured_result(serde_json::Value::Object(context.meta.0.0)),
),
"cwd" => {
let cwd = std::env::current_dir()
.map(|path| path.to_string_lossy().into_owned())