mirror of
https://github.com/openai/codex.git
synced 2026-11-03 08:22:30 +00:00
Summary - drop `McpToolOutput` in favor of `CallToolResult`, moving its helpers to keep MCP tooling focused on the final result shape - wire the new schema definitions through code mode, context, handlers, and spec modules so MCP tools serialize the exact output shape expected by the model - extend code mode tests to cover multiple MCP call scenarios and ensure the serialized data matches the new schema - refresh JS runner helpers and protocol models alongside the schema changes Testing - Not run (not requested)
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use async_trait::async_trait;
|
|
use std::sync::Arc;
|
|
|
|
use crate::function_tool::FunctionCallError;
|
|
use crate::mcp_tool_call::handle_mcp_tool_call;
|
|
use crate::tools::context::ToolInvocation;
|
|
use crate::tools::context::ToolPayload;
|
|
use crate::tools::registry::ToolHandler;
|
|
use crate::tools::registry::ToolKind;
|
|
use codex_protocol::mcp::CallToolResult;
|
|
|
|
pub struct McpHandler;
|
|
#[async_trait]
|
|
impl ToolHandler for McpHandler {
|
|
type Output = CallToolResult;
|
|
|
|
fn kind(&self) -> ToolKind {
|
|
ToolKind::Mcp
|
|
}
|
|
|
|
async fn handle(&self, invocation: ToolInvocation) -> Result<Self::Output, FunctionCallError> {
|
|
let ToolInvocation {
|
|
session,
|
|
turn,
|
|
call_id,
|
|
payload,
|
|
..
|
|
} = invocation;
|
|
|
|
let payload = match payload {
|
|
ToolPayload::Mcp {
|
|
server,
|
|
tool,
|
|
raw_arguments,
|
|
} => (server, tool, raw_arguments),
|
|
_ => {
|
|
return Err(FunctionCallError::RespondToModel(
|
|
"mcp handler received unsupported payload".to_string(),
|
|
));
|
|
}
|
|
};
|
|
|
|
let (server, tool, raw_arguments) = payload;
|
|
let arguments_str = raw_arguments;
|
|
|
|
let output = handle_mcp_tool_call(
|
|
Arc::clone(&session),
|
|
&turn,
|
|
call_id.clone(),
|
|
server,
|
|
tool,
|
|
arguments_str,
|
|
)
|
|
.await;
|
|
|
|
Ok(output)
|
|
}
|
|
}
|