mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Let extensions attach metadata to MCP tool requests (#62435)
## What changed Add `ToolLifecycleContributor::mcp_tool_request_meta` so an extension can use thread and turn data and the captured tool registration to attach an entry to the outgoing request's `_meta`. Codex rejects duplicate keys. Expose the registering plugin's package ID in `McpToolContext` so contributors can scope metadata to that plugin. Export `PERSISTED_MCP_RESULT_MAX_BYTES`, the existing 64 KiB limit for untruncated MCP results in durable history. ## Testing Extend the multi-environment MCP scenario to check that only the call for the selected plugin receives the metadata and that the result callback sees the same plugin context. GitOrigin-RevId: 25a2afc5402a5c9323de184313d614aede3692fb
This commit is contained in:
@@ -468,6 +468,17 @@ pub trait ToolLifecycleContributor: Send + Sync {
|
||||
Box::pin(std::future::ready(()))
|
||||
}
|
||||
|
||||
/// Provides one private request metadata entry for an MCP call. Use the captured
|
||||
/// registration to scope data to its intended recipient. Keys must be unique.
|
||||
fn mcp_tool_request_meta(
|
||||
&self,
|
||||
_thread_store: &ExtensionData,
|
||||
_turn_store: &ExtensionData,
|
||||
_mcp_tool: &McpToolContext,
|
||||
) -> Option<(&'static str, serde_json::Value)> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Runs before the MCP result is sent to the client and model.
|
||||
fn on_mcp_tool_result<'a>(&'a self, _input: McpToolResultInput<'a>) -> ToolLifecycleFuture<'a> {
|
||||
Box::pin(std::future::ready(()))
|
||||
|
||||
@@ -65,6 +65,8 @@ pub enum McpToolSource {
|
||||
pub struct McpToolContext {
|
||||
tool: crate::McpToolInfo,
|
||||
source: McpToolSource,
|
||||
/// Package ID of the plugin that registered this call's MCP server.
|
||||
pub plugin_id: Option<String>,
|
||||
}
|
||||
|
||||
impl McpToolContext {
|
||||
@@ -100,7 +102,11 @@ impl McpToolContext {
|
||||
McpToolSource::Other
|
||||
};
|
||||
|
||||
Self { tool, source }
|
||||
Self {
|
||||
tool,
|
||||
source,
|
||||
plugin_id: call.plugin_id().map(str::to_owned),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns frozen metadata for the exact model-visible MCP tool being executed.
|
||||
|
||||
Reference in New Issue
Block a user