From eb94274eb87e5caa3d8db25ba8de285bb2bacf85 Mon Sep 17 00:00:00 2001 From: Haihua Xiao Date: Fri, 19 Sep 2025 19:53:32 +0800 Subject: [PATCH 1/2] Keep empty properties OpenAI will report error if InputSchema with object type has no properties. openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for function 'getCurrentProfile': In context=(), object schema missing properties.", 'type': 'invalid_request_error', 'param': 'tools[0].function.parameters', 'code': 'invalid_function_parameters'}, 'user': '{"appkey": "egai-prd-strategyoffice-020029831-workflow-1746045106141", "session_id": "b95e59c0-a570-4f82-9905-05eff7b35eba-1758281506244515510", "user": "", "prompt_truncate": "yes"}'} --- mcp/tools.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcp/tools.go b/mcp/tools.go index 493e8c778..72cf653c5 100644 --- a/mcp/tools.go +++ b/mcp/tools.go @@ -620,7 +620,7 @@ func (t Tool) MarshalJSON() ([]byte, error) { type ToolArgumentsSchema struct { Defs map[string]any `json:"$defs,omitempty"` Type string `json:"type"` - Properties map[string]any `json:"properties,omitempty"` + Properties map[string]any `json:"properties"` Required []string `json:"required,omitempty"` } From 051ec943100dc2dcff018ff86102ff2d81de6f50 Mon Sep 17 00:00:00 2001 From: Haihua Xiao Date: Thu, 13 Nov 2025 14:30:38 +0800 Subject: [PATCH 2/2] Update tools.go fix(json): make ToolInputSchema and ToolOutputSchema aliases of ToolArgumentsSchema Previously, ToolInputSchema and ToolOutputSchema were defined as new types, which prevented them from inheriting ToolArgumentsSchema.MarshalJSON. This change converts them into type aliases, ensuring consistent JSON serialization behavior across all schema types. --- mcp/tools.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mcp/tools.go b/mcp/tools.go index 9fc1bd31a..6b0d62b59 100644 --- a/mcp/tools.go +++ b/mcp/tools.go @@ -625,12 +625,12 @@ func (t Tool) MarshalJSON() ([]byte, error) { type ToolArgumentsSchema struct { Defs map[string]any `json:"$defs,omitempty"` Type string `json:"type"` - Properties map[string]any `json:"properties"` + Properties map[string]any `json:"properties,omitempty"` Required []string `json:"required,omitempty"` } -type ToolInputSchema ToolArgumentsSchema // For retro-compatibility -type ToolOutputSchema ToolArgumentsSchema +type ToolInputSchema = ToolArgumentsSchema // For retro-compatibility +type ToolOutputSchema = ToolArgumentsSchema // MarshalJSON implements the json.Marshaler interface for ToolInputSchema. func (tis ToolArgumentsSchema) MarshalJSON() ([]byte, error) {