mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Bound MCP namespace descriptions (#35941)
## What changed - Limit model-facing MCP namespace descriptions to 1,000 bytes without splitting UTF-8 characters or mutating the stored server metadata. - Cap the aggregate source-description list in `tool_search` at 4 KiB while retaining source names and discovery instructions. - Cover direct and deferred MCP tool exposure, including multibyte descriptions and tool visibility. GitOrigin-RevId: 92736ec39475a1d6b3b03f5e3063e28225d8a5f6
This commit is contained in:
1 parent
fbf666fa98
commit
ddf33ea802
5 files changed
+235
-15
No files matched your search
@@ -23,11 +23,13 @@ use codex_tools::ToolSearchInfo;
|
||||
use codex_tools::ToolSearchSourceInfo;
|
||||
use codex_tools::ToolSpec;
|
||||
use codex_tools::mcp_tool_to_responses_api_tool;
|
||||
use codex_utils_string::take_bytes_at_char_boundary;
|
||||
use serde_json::Map;
|
||||
use serde_json::Value;
|
||||
|
||||
const LEGACY_MCP_TOOL_NAME_PREFIX: &str = "mcp__";
|
||||
const MCP_TOOL_NAME_DELIMITER: &str = "__";
|
||||
const MAX_MCP_NAMESPACE_DESCRIPTION_BYTES: usize = 1_000;
|
||||
|
||||
pub struct McpHandler {
|
||||
tool_info: ToolInfo,
|
||||
@@ -102,6 +104,7 @@ impl ToolExecutor<ToolInvocation> for McpHandler {
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|description| !description.is_empty())
|
||||
.map(bounded_mcp_namespace_description)
|
||||
.map(str::to_string),
|
||||
});
|
||||
|
||||
@@ -254,11 +257,15 @@ fn create_tool_spec(tool_info: &ToolInfo) -> Result<ToolSpec, serde_json::Error>
|
||||
|
||||
Ok(ToolSpec::Namespace(ResponsesApiNamespace {
|
||||
name: tool_info.callable_namespace.clone(),
|
||||
description,
|
||||
description: bounded_mcp_namespace_description(&description).to_string(),
|
||||
tools: vec![ResponsesApiNamespaceTool::Function(tool)],
|
||||
}))
|
||||
}
|
||||
|
||||
fn bounded_mcp_namespace_description(description: &str) -> &str {
|
||||
take_bytes_at_char_boundary(description, MAX_MCP_NAMESPACE_DESCRIPTION_BYTES)
|
||||
}
|
||||
|
||||
fn mcp_hook_tool_input(raw_arguments: &str) -> Value {
|
||||
if raw_arguments.trim().is_empty() {
|
||||
return Value::Object(Map::new());
|
||||
|
||||
Reference in new issue
Block a user