From bf46d7bc9269c4d61f49997bf84d5cb6cdfd90fd Mon Sep 17 00:00:00 2001 From: Jack Amadeo Date: Tue, 30 Sep 2025 22:51:44 -0400 Subject: [PATCH] Add type field to empty schemas for anthropic (#4911) --- crates/goose/src/providers/formats/anthropic.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/goose/src/providers/formats/anthropic.rs b/crates/goose/src/providers/formats/anthropic.rs index e3767d8e..2bbc0dac 100644 --- a/crates/goose/src/providers/formats/anthropic.rs +++ b/crates/goose/src/providers/formats/anthropic.rs @@ -3,9 +3,11 @@ use crate::model::ModelConfig; use crate::providers::base::Usage; use crate::providers::errors::ProviderError; use anyhow::{anyhow, Result}; -use rmcp::model::{object, CallToolRequestParam, ErrorCode, ErrorData, Role, Tool}; +use rmcp::model::{object, CallToolRequestParam, ErrorCode, ErrorData, JsonObject, Role, Tool}; +use rmcp::object as json_object; use serde_json::{json, Value}; use std::collections::HashSet; +use std::sync::Arc; // Constants for frequently used strings in Anthropic API format const TYPE_FIELD: &str = "type"; @@ -168,6 +170,15 @@ pub fn format_messages(messages: &[Message]) -> Vec { anthropic_messages } +fn anthropic_flavored_input_schema(input_schema: Arc) -> Arc { + if input_schema.is_empty() { + return Arc::new(json_object!({ + "type": "object", + })); + } + input_schema +} + /// Convert internal Tool format to Anthropic's API tool specification pub fn format_tools(tools: &[Tool]) -> Vec { let mut unique_tools = HashSet::new(); @@ -178,7 +189,7 @@ pub fn format_tools(tools: &[Tool]) -> Vec { tool_specs.push(json!({ NAME_FIELD: tool.name, "description": tool.description, - "input_schema": tool.input_schema + "input_schema": anthropic_flavored_input_schema(tool.input_schema.clone()) })); } }