mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Simplify MCP tool handler plumbing (#21595)
## Why The MCP tool path had accumulated a few core-owned special cases: a dedicated payload variant, resolver plumbing, a legacy `AfterToolUse` translation path, and a side channel for parallel-call metadata. That made `ToolRegistry` and the spec builder know more about MCP than they needed to. This change moves MCP-specific execution details back onto `ToolInfo` and `McpHandler` so `codex-core` can treat MCP calls like normal function calls while still preserving MCP-specific dispatch and telemetry behavior where it belongs. ## What changed - removed `resolve_mcp_tool_info`, `ToolPayload::Mcp`, `ToolKind`, and the remaining registry-side MCP resolver path - stored MCP routing metadata directly on `McpHandler` and `ToolInfo`, including `supports_parallel_tool_calls` - deleted the legacy `AfterToolUse` consumer in `core`, which removes the need for handler-specific `after_tool_use_payload` implementations - switched tool-result telemetry to handler-provided tags and kept MCP-specific dispatch payload construction inside the handler - simplified tool spec planning/building by passing `ToolInfo` directly and dropping the direct/deferred MCP wrapper structs and the parallel-server side table ## Testing - `cargo check -p codex-core -p codex-mcp -p codex-otel` - `cargo test -p codex-core mcp_parallel_support_uses_exact_payload_server` - `cargo test -p codex-core direct_mcp_tools_register_namespaced_handlers` - `cargo test -p codex-core search_tool_description_lists_each_mcp_source_once` - `cargo test -p codex-mcp list_all_tools_uses_startup_snapshot_while_client_is_pending` - `just fix -p codex-core -p codex-mcp -p codex-otel`
This commit is contained in:
@@ -93,11 +93,6 @@ pub enum ToolDispatchPayload {
|
||||
additional_permissions: Option<AdditionalPermissionProfile>,
|
||||
justification: Option<String>,
|
||||
},
|
||||
Mcp {
|
||||
server: String,
|
||||
tool: String,
|
||||
raw_arguments: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Result data returned from a dispatch-level tool call.
|
||||
@@ -263,14 +258,7 @@ fn requester_fields(
|
||||
}
|
||||
}
|
||||
|
||||
fn dispatched_tool_kind(tool_name: &str, payload: &ToolDispatchPayload) -> ToolCallKind {
|
||||
if let ToolDispatchPayload::Mcp { server, tool, .. } = payload {
|
||||
return ToolCallKind::Mcp {
|
||||
server: server.clone(),
|
||||
tool: tool.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
fn dispatched_tool_kind(tool_name: &str, _payload: &ToolDispatchPayload) -> ToolCallKind {
|
||||
match tool_name {
|
||||
"exec_command" | "local_shell" | "shell" | "shell_command" => ToolCallKind::ExecCommand,
|
||||
"write_stdin" => ToolCallKind::WriteStdin,
|
||||
@@ -291,12 +279,8 @@ fn dispatched_tool_kind(tool_name: &str, payload: &ToolDispatchPayload) -> ToolC
|
||||
fn dispatched_tool_label(
|
||||
tool_name: &str,
|
||||
tool_namespace: Option<&str>,
|
||||
payload: &ToolDispatchPayload,
|
||||
_payload: &ToolDispatchPayload,
|
||||
) -> String {
|
||||
if let ToolDispatchPayload::Mcp { server, tool, .. } = payload {
|
||||
return format!("mcp:{server}:{tool}");
|
||||
}
|
||||
|
||||
match tool_namespace {
|
||||
Some(namespace) => format!("{namespace}.{tool_name}"),
|
||||
None => tool_name.to_string(),
|
||||
@@ -310,7 +294,6 @@ impl ToolDispatchPayload {
|
||||
ToolDispatchPayload::ToolSearch { arguments } => truncate_preview(&arguments.query),
|
||||
ToolDispatchPayload::Custom { input } => truncate_preview(input),
|
||||
ToolDispatchPayload::LocalShell { command, .. } => truncate_preview(&command.join(" ")),
|
||||
ToolDispatchPayload::Mcp { raw_arguments, .. } => truncate_preview(raw_arguments),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,16 +329,6 @@ impl ToolDispatchPayload {
|
||||
"additional_permissions": additional_permissions,
|
||||
"justification": justification,
|
||||
}),
|
||||
ToolDispatchPayload::Mcp {
|
||||
server,
|
||||
tool,
|
||||
raw_arguments,
|
||||
} => json!({
|
||||
"type": "mcp",
|
||||
"server": server,
|
||||
"tool": tool,
|
||||
"raw_arguments": raw_arguments,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user