Fix TypeError when MCP schema type is a list#4867
Fix TypeError when MCP schema type is a list#4867Soulter merged 3 commits intoAstrBotDevs:masterfrom
Conversation
Fixes crash in Gemini native tools with VRChat MCP.
There was a problem hiding this comment.
Hey - 我在这里给出了一些总体反馈:
- 新增的逻辑会通过重写
schema['type']来修改传入的schema字典;建议在本地变量或浅拷贝上操作,这样复用原始 schema 的调用方就不会被副作用惊到。 - 当
schema['type']是一个仅包含不受支持类型(除了"null")的列表时,next(...)的回退逻辑会把它设置为"string",但是后续的supported_types检查仍有可能跳过它;如果这是有意为之,建议加一段简短的注释,说明对“不受支持的 union 类型”期望的行为,以便后续维护者理解。
给 AI Agents 的提示词
Please address the comments from this code review:
## Overall Comments
- The new logic mutates the incoming `schema` dict by overwriting `schema['type']`; consider working on a local variable or shallow copy so callers that reuse the original schema aren’t surprised by side effects.
- When `schema['type']` is a list containing only unsupported types (other than `"null"`), the `next(...)` fallback will set it to `"string"` but the subsequent `supported_types` check may still skip it; if that’s intentional, a short comment clarifying the desired behavior for unsupported union types would help future maintainers.让我更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've left some high level feedback:
- The new logic mutates the incoming
schemadict by overwritingschema['type']; consider working on a local variable or shallow copy so callers that reuse the original schema aren’t surprised by side effects. - When
schema['type']is a list containing only unsupported types (other than"null"), thenext(...)fallback will set it to"string"but the subsequentsupported_typescheck may still skip it; if that’s intentional, a short comment clarifying the desired behavior for unsupported union types would help future maintainers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new logic mutates the incoming `schema` dict by overwriting `schema['type']`; consider working on a local variable or shallow copy so callers that reuse the original schema aren’t surprised by side effects.
- When `schema['type']` is a list containing only unsupported types (other than `"null"`), the `next(...)` fallback will set it to `"string"` but the subsequent `supported_types` check may still skip it; if that’s intentional, a short comment clarifying the desired behavior for unsupported union types would help future maintainers.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Is this bug due to the MCP Server itself being of a non-standard list type? |
|
Thanks for flagging this. I looked up the official documentation, and it explains exactly why this mismatch happens. According to the Function calling with the Gemini API, the Schema object for function calling represents a "selected subset of the OpenAPI 3.0 schema object." Crucially:
Conclusion: |
* 默认host修改为::,同时新增两个环境变量DASHBOARD_HOST,DASHBOARD_ENABLE,和DASHBOARD_PORT对齐 * feat: systemd support (#4880) * fix: pyright lint (#4874) * feat: 将 MessageSession 的 platform_id 改为 init=False,实例化时无需传入 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 将 isinstance 检查改为元组、将默认模型值设为空字符串、将类型注解改为 Any 并导入 * refactor: 为 _serialize_job 增加返回类型注解 dict * fix: 使用 cast 获取百度 AIP 的 msg 并对 psutil_addr 引入 type: ignore Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 引入 _AddrWithPort 协议并替换 conn.laddr 的 cast Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: 在构建 AstrBotMessage 时对 ctx.channel 可能为 None 进行兜底处理 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> --------- Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * 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 * docs: update watashiwakoseinodesukara Removed duplicate text and added a new image. * 修复/跨平台一致性 * 琐事/类型标注和一些简单错误修正 * 修复/检查端口时候包含ipv6 * 修复/enable变量的赋值逻辑 --------- Co-authored-by: Dt8333 <25431943+Dt8333@users.noreply.github.com> Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> Co-authored-by: boushi1111 <95118141+boushi1111@users.noreply.github.com> Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
* 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
* 默认host修改为::,同时新增两个环境变量DASHBOARD_HOST,DASHBOARD_ENABLE,和DASHBOARD_PORT对齐 * feat: systemd support (AstrBotDevs#4880) * fix: pyright lint (AstrBotDevs#4874) * feat: 将 MessageSession 的 platform_id 改为 init=False,实例化时无需传入 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 将 isinstance 检查改为元组、将默认模型值设为空字符串、将类型注解改为 Any 并导入 * refactor: 为 _serialize_job 增加返回类型注解 dict * fix: 使用 cast 获取百度 AIP 的 msg 并对 psutil_addr 引入 type: ignore Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 引入 _AddrWithPort 协议并替换 conn.laddr 的 cast Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: 在构建 AstrBotMessage 时对 ctx.channel 可能为 None 进行兜底处理 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> --------- Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: TypeError when MCP schema type is a list (AstrBotDevs#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 * docs: update watashiwakoseinodesukara Removed duplicate text and added a new image. * 修复/跨平台一致性 * 琐事/类型标注和一些简单错误修正 * 修复/检查端口时候包含ipv6 * 修复/enable变量的赋值逻辑 --------- Co-authored-by: Dt8333 <25431943+Dt8333@users.noreply.github.com> Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> Co-authored-by: boushi1111 <95118141+boushi1111@users.noreply.github.com> Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
Fixes crash in Gemini native tools with VRChat MCP.
Modifications / 改动点
File Modified: astrbot/core/agent/tool.py
Fix: Added a check in convert_schema. If a parameter type is a list (e.g., ["string", "null"] returned by some MCP servers like vrchat-mcp), it now defaults to the first non-null type (e.g., "string") instead of crashing with TypeError.
Impact: Enables Gemini Native Tools to work with Node.js-based MCP servers.
Screenshots or Test Results / 运行截图或测试结果
Before Fix (Crash Log):
After Fix (Successful VRChat Query): User: 查询一下现在在线的vrc好友
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
Bug Fixes:
convert_schema中可能出现的TypeError:通过将其规范化为列表中第一个非空类型来避免错误。Original summary in English
Summary by Sourcery
Bug Fixes: