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.
This commit is contained in:
@@ -280,12 +280,26 @@ fn mcp_tool_to_openai_tool(
|
|||||||
fully_qualified_name: String,
|
fully_qualified_name: String,
|
||||||
tool: mcp_types::Tool,
|
tool: mcp_types::Tool,
|
||||||
) -> serde_json::Value {
|
) -> 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
|
// TODO(mbolin): Change the contract of this function to return
|
||||||
// ResponsesApiTool.
|
// ResponsesApiTool.
|
||||||
json!({
|
json!({
|
||||||
"name": fully_qualified_name,
|
"name": fully_qualified_name,
|
||||||
"description": tool.description,
|
"description": description,
|
||||||
"parameters": tool.input_schema,
|
"parameters": input_schema,
|
||||||
"type": "function",
|
"type": "function",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user