mirror of
https://github.com/hanzoai/dev.git
synced 2026-11-21 14:22:49 +00:00
Wholesale-adopt latest upstream codex-rs (97 crates, new architecture: model-provider-info crate, app-server-daemon/transport, code-mode-host, thread-store, file-watcher, etc.). Hanzo-only crates (browser, debug-client, instructions, tui2) preserved on disk (not yet re-added to workspace). Builds clean as upstream (codex bin). Hanzo overlay (dev bin, api.hanzo.ai default, hanzo.id/Claude login, branding) re-applied in following commits. Co-authored-by: Hanzo Dev <[email protected]>
65 lines
2.1 KiB
Rust
65 lines
2.1 KiB
Rust
use crate::ToolDefinition;
|
|
use crate::parse_tool_input_schema;
|
|
use serde_json::Value as JsonValue;
|
|
use serde_json::json;
|
|
|
|
pub fn parse_mcp_tool(tool: &rmcp::model::Tool) -> Result<ToolDefinition, serde_json::Error> {
|
|
let mut serialized_input_schema = serde_json::Value::Object(tool.input_schema.as_ref().clone());
|
|
|
|
// OpenAI models mandate the "properties" field in the schema. Some MCP
|
|
// servers omit it (or set it to null), so we insert an empty object to
|
|
// match the behavior of the Agents SDK.
|
|
if let serde_json::Value::Object(obj) = &mut serialized_input_schema
|
|
&& obj.get("properties").is_none_or(serde_json::Value::is_null)
|
|
{
|
|
obj.insert(
|
|
"properties".to_string(),
|
|
serde_json::Value::Object(serde_json::Map::new()),
|
|
);
|
|
}
|
|
|
|
let input_schema = parse_tool_input_schema(&serialized_input_schema)?;
|
|
let structured_content_schema = tool
|
|
.output_schema
|
|
.as_ref()
|
|
.map(|output_schema| serde_json::Value::Object(output_schema.as_ref().clone()))
|
|
.unwrap_or_else(|| JsonValue::Object(serde_json::Map::new()));
|
|
|
|
Ok(ToolDefinition {
|
|
name: tool.name.to_string(),
|
|
description: tool.description.clone().map(Into::into).unwrap_or_default(),
|
|
input_schema,
|
|
output_schema: Some(mcp_call_tool_result_output_schema(
|
|
structured_content_schema,
|
|
)),
|
|
defer_loading: false,
|
|
})
|
|
}
|
|
|
|
pub fn mcp_call_tool_result_output_schema(structured_content_schema: JsonValue) -> JsonValue {
|
|
json!({
|
|
"type": "object",
|
|
"properties": {
|
|
"content": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "object"
|
|
}
|
|
},
|
|
"structuredContent": structured_content_schema,
|
|
"isError": {
|
|
"type": "boolean"
|
|
},
|
|
"_meta": {
|
|
"type": "object"
|
|
}
|
|
},
|
|
"required": ["content"],
|
|
"additionalProperties": false
|
|
})
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "mcp_tool_tests.rs"]
|
|
mod tests;
|