fix: 修复特殊字段查询导致 MCP 连接关闭 - #121
Open
qijingyu0727 wants to merge 1 commit into
Open
Conversation
✅ PR 自动校验结果状态: 校验通过 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题说明
SQLServer 查询工具在返回 datetime、date、Decimal、UUID 等非 JSON 原生类型时,AI 节点可能长时间停留在“思考中”,最终报错:
McpError: Connection closed
原工具将 default_serializer 定义在入口函数 query_sqlserver 内部。MaxKB 将工具转换为 FastMCP 服务时,会对入口函数中的 return 语句进行 AST 包装,嵌套序列化函数的返回值也会被转换成 Result 对象。
当 json.dumps() 序列化日期等字段时,会不断尝试序列化新生成的 Result 对象,导致工具子进程内存持续增长,最终被系统 OOM Killer 终止。MCP stdio 连接随之关闭,因此前端只显示 McpError: Connection closed。
该问题具有偶发性:只查询字符串、整数等字段时通常正常;查询 create_date 等特殊类型字段时才会触发。