mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Enforce Agent Plugin runtime boundaries (#37027)
## What changed - Track Agent Plugin manifests through plugin, skill, and MCP loading so their capabilities use format-specific behavior without changing legacy plugins. - Discover only direct-child skills, exclude app and hook capabilities, isolate MCP data, and reject MCP configuration files that are non-regular or resolve outside the plugin root. - Bound model-visible skill instructions, plugin instructions, MCP descriptions, schemas, individual tools, and the aggregate Agent Plugin MCP tool set. - Stop MCP and OAuth redirects when Agent Plugins send configured or authorization headers, while retaining existing redirect behavior for legacy MCP servers. ## Testing - Add coverage for capability filtering, skill discovery, isolated MCP data and reserved-path expansion, unsafe MCP configuration files, context limits, and redirect handling. GitOrigin-RevId: c9af66b051269f3226628ca280a58d32c808c38f
This commit is contained in:
1 parent
f21dc46388
commit
56b82e676c
63 files changed
+1830
-106
No files matched your search
@@ -23,6 +23,7 @@ use codex_tools::ToolName;
|
||||
use codex_tools::ToolSearchInfo;
|
||||
use codex_tools::ToolSearchSourceInfo;
|
||||
use codex_tools::ToolSpec;
|
||||
use codex_tools::agent_plugin_mcp_tool_to_responses_api_tool;
|
||||
use codex_tools::mcp_tool_to_responses_api_tool;
|
||||
use codex_utils_string::take_bytes_at_char_boundary;
|
||||
use futures::future::BoxFuture;
|
||||
@@ -31,6 +32,7 @@ use serde_json::Value;
|
||||
|
||||
const LEGACY_MCP_TOOL_NAME_PREFIX: &str = "mcp__";
|
||||
const MCP_TOOL_NAME_DELIMITER: &str = "__";
|
||||
const MAX_AGENT_PLUGIN_MCP_NAMESPACE_DESCRIPTION_BYTES: usize = 1_000;
|
||||
const MAX_MCP_NAMESPACE_DESCRIPTION_BYTES: usize = 512 * 1024;
|
||||
|
||||
pub struct McpHandler {
|
||||
@@ -40,10 +42,38 @@ pub struct McpHandler {
|
||||
|
||||
impl McpHandler {
|
||||
pub fn new(tool_info: ToolInfo) -> Result<Self, serde_json::Error> {
|
||||
let spec = create_tool_spec(&tool_info)?;
|
||||
Self::with_agent_plugin(tool_info, /*agent_plugin*/ false)
|
||||
}
|
||||
|
||||
pub fn new_agent_plugin(tool_info: ToolInfo) -> Result<Self, serde_json::Error> {
|
||||
Self::with_agent_plugin(tool_info, /*agent_plugin*/ true)
|
||||
}
|
||||
|
||||
fn with_agent_plugin(
|
||||
mut tool_info: ToolInfo,
|
||||
agent_plugin: bool,
|
||||
) -> Result<Self, serde_json::Error> {
|
||||
if agent_plugin {
|
||||
tool_info.namespace_description =
|
||||
tool_info
|
||||
.namespace_description
|
||||
.as_deref()
|
||||
.map(|description| {
|
||||
take_bytes_at_char_boundary(
|
||||
description,
|
||||
MAX_AGENT_PLUGIN_MCP_NAMESPACE_DESCRIPTION_BYTES,
|
||||
)
|
||||
.to_string()
|
||||
});
|
||||
}
|
||||
let spec = create_tool_spec(&tool_info, agent_plugin)?;
|
||||
Ok(Self { tool_info, spec })
|
||||
}
|
||||
|
||||
pub(crate) fn model_spec_bytes(&self) -> Result<usize, serde_json::Error> {
|
||||
serde_json::to_vec(&self.spec).map(|spec| spec.len())
|
||||
}
|
||||
|
||||
fn hook_tool_name(&self) -> HookToolName {
|
||||
HookToolName::new(ensure_mcp_prefix(&join_tool_name(&self.tool_name())))
|
||||
}
|
||||
@@ -236,9 +266,16 @@ impl CoreToolRuntime for McpHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_tool_spec(tool_info: &ToolInfo) -> Result<ToolSpec, serde_json::Error> {
|
||||
fn create_tool_spec(
|
||||
tool_info: &ToolInfo,
|
||||
agent_plugin: bool,
|
||||
) -> Result<ToolSpec, serde_json::Error> {
|
||||
let tool_name = tool_info.canonical_tool_name();
|
||||
let tool = mcp_tool_to_responses_api_tool(&tool_name, &tool_info.tool)?;
|
||||
let tool = if agent_plugin {
|
||||
agent_plugin_mcp_tool_to_responses_api_tool(&tool_name, &tool_info.tool)?
|
||||
} else {
|
||||
mcp_tool_to_responses_api_tool(&tool_name, &tool_info.tool)?
|
||||
};
|
||||
let description = tool_info
|
||||
.namespace_description
|
||||
.as_deref()
|
||||
|
||||
Reference in new issue
Block a user