快速结论:当 MCP 工具定义的输入参数(input_schema)包含 pydantic 嵌套模型时,Anthropic agent 调用会崩溃。优先排查是否使用了嵌套的 BaseModel,并尝试将参数扁平化。
适用环境:AnythingLLM Docker 本地部署,使用 Anthropic agent 调用 MCP 服务器,MCP 工具通过 pydantic v2 定义嵌套参数。
最快修复方案:暂无确认的一步修复方案。官方在 Issue 中给出的临时方案是将嵌套的 pydantic 参数展开为扁平参数(使用 Field 直接定义),但此方法可能影响其他 tool calling 行为。
注意事项:该修复方案未经官方完全验证,可能引入新问题(如破坏其他工具的调用)。若参数数量过多,扁平化可读性较差,需谨慎评估。Issue 状态为 blocked,官方尚未合并修复。
问题场景
用户在 AnythingLLM 的 Docker 本地部署中,添加了自定义 MCP 服务器。该 MCP 工具使用 pydantic v2 的嵌套模型定义输入参数(例如 GetCryptocurrenciesParams 中包含嵌套的 PaginationParams)。当 Anthropic agent 尝试调用该工具时,触发崩溃。
报错原文
[BUG]: MCP servers with nested params in input_schema crash an Anthropic agent
实际运行时可能伴随类似 “Tool call failed” 或 “Schema parsing error” 的额外错误,但 Issue 中未记录具体堆栈。
原因分析
可能原因是 Anthropic provider 在解析 MCP 工具的 input_schema 时,无法正确处理 pydantic 嵌套模型的嵌套结构(如嵌套的 JSON Schema),导致解析异常或崩溃。Issue 维护者确认了此问题,并认为扁平化参数可以绕过该解析缺陷,但认为直接修改全局 schema 可能带来副作用。
环境排查
- 确认 AnythingLLM 运行环境为 Docker(本地部署)。
- 确认使用的 agent 类型为 Anthropic(如 Claude 系列)。
- 确认 MCP 服务端框架为使用了 pydantic v2 的 Python SDK(如
mcp包)。 - 确认工具定义中是否包含嵌套的 pydantic BaseModel 作为参数类型。
解决步骤
- 定位 MCP 工具定义代码中使用了 pydantic 嵌套模型的函数,例如:
class PaginationParams(BaseModel): page: int limit: int class GetCryptocurrenciesParams(BaseModel): pagination: PaginationParams # 其他嵌套字段 @server.tool() async def get_cryptocurrencies(params: GetCryptocurrenciesParams): ... - 将嵌套模型展开为扁平参数,使用
Field提供描述:@server.tool() async def get_cryptocurrencies( page: int = Field(..., description="Page number"), limit: int = Field(..., description="Items per page"), # 其他原本在嵌套模型中的字段直接作为参数 ): ... - 重启 AnythingLLM 并重新加载 MCP 服务器。
- 测试调用该工具,确认不再崩溃。
重要提示:此解决方案仅为临时规避手段,官方尚未确认不会引发其他副作用(如影响其他工具的 schema 解析)。如果参数过多,可考虑使用 Annotated 或保持原有结构等待官方修复。
验证方法
在 AnythingLLM 中通过 Anthropic agent 调用该 MCP 工具,观察是否正常返回结果,不再出现崩溃或错误提示。同时测试其他 MCP 工具是否仍能正常调用,以确保扁平化未破坏整体兼容性。
参考来源
Mintplex-Labs/anything-llm #3938
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。
![[BUG]: Can only use TXT files from linked directory [possible bug or unclear documentation]](https://www.chat-gpts.plus/wp-content/uploads/2026/07/6041-94550219-768x403.jpg)
![[bug]: triton not found; flop counting will not work for triton kernels](https://www.chat-gpts.plus/wp-content/uploads/2026/07/9372-401df1af-768x403.jpg)
![[Bug]: Ragflow would NOT create the es index if the document no parsing and throw error: no chunk found](https://www.chat-gpts.plus/wp-content/uploads/2026/07/8221-f99094b8-768x403.jpg)