From d69592aaa8cecf23e86be6c291de2d443d0c45b0 Mon Sep 17 00:00:00 2001 From: boushi1111 <95118141+boushi1111@users.noreply.github.com> Date: Thu, 5 Feb 2026 23:51:29 +0900 Subject: [PATCH] fix: TypeError when MCP schema type is a list (#4867) * Fix TypeError when MCP schema type is a list Fixes crash in Gemini native tools with VRChat MCP. * Refactor: avoid modifying schema in place per feedback * Fix formatting and cleanup comments --- astrbot/core/agent/tool.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/astrbot/core/agent/tool.py b/astrbot/core/agent/tool.py index 2ffbd40ca..50899ff80 100644 --- a/astrbot/core/agent/tool.py +++ b/astrbot/core/agent/tool.py @@ -246,8 +246,18 @@ class ToolSet: result = {} - if "type" in schema and schema["type"] in supported_types: - result["type"] = schema["type"] + # Avoid side effects by not modifying the original schema + origin_type = schema.get("type") + target_type = origin_type + + # Compatibility fix: Gemini API expects 'type' to be a string (enum), + # but standard JSON Schema (MCP) allows lists (e.g. ["string", "null"]). + # We fallback to the first non-null type. + if isinstance(origin_type, list): + target_type = next((t for t in origin_type if t != "null"), "string") + + if target_type in supported_types: + result["type"] = target_type if "format" in schema and schema["format"] in supported_formats.get( result["type"], set(),