From 25a9949c49194d5a64de54a11bcc5b4724ac9bd5 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Wed, 28 May 2025 17:17:21 -0700 Subject: [PATCH] fix: ensure inputSchema for MCP tool always has "properties" field when talking to OpenAI (#1150) As noted in the comment introduced in this PR, this is analogous to the issue reported in https://github.com/openai/openai-agents-python/issues/449. This seems to work now. --- codex-rs/core/src/client.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index 57534e2f..72ce845f 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -280,12 +280,26 @@ fn mcp_tool_to_openai_tool( fully_qualified_name: String, tool: mcp_types::Tool, ) -> serde_json::Value { + let mcp_types::Tool { + description, + mut input_schema, + .. + } = tool; + + // OpenAI models mandate the "properties" field in the schema. The Agents + // SDK fixed this by inserting an empty object for "properties" if it is not + // already present https://github.com/openai/openai-agents-python/issues/449 + // so here we do the same. + if input_schema.properties.is_none() { + input_schema.properties = Some(serde_json::Value::Object(serde_json::Map::new())); + } + // TODO(mbolin): Change the contract of this function to return // ResponsesApiTool. json!({ "name": fully_qualified_name, - "description": tool.description, - "parameters": tool.input_schema, + "description": description, + "parameters": input_schema, "type": "function", }) }