Skip to content

🐛 fix(mcp): 统一成功响应 JSON 序列化 - #110

Merged
ZhaoXingPeng merged 1 commit into
mainfrom
fix/107-mcp-success-json
Sep 7, 2026
Merged

🐛 fix(mcp): 统一成功响应 JSON 序列化#110
ZhaoXingPeng merged 1 commit into
mainfrom
fix/107-mcp-success-json

Conversation

@ZhaoXingPeng

@ZhaoXingPeng ZhaoXingPeng commented Sep 7, 2026

Copy link
Copy Markdown
Owner

关联 Issue

Closes #107

背景(Situation)

多个 MCP 成功路径仍以 Python repr 拼接 Raw Response,使用单引号、NoneTrue 等非 JSON 语法;失败路径已使用 json.dumps,同一 public handler 因此存在两套响应协议,调用方无法稳定执行 json.loads

任务(Task)

把成功路径的结构化 Raw Response 统一序列化为 UTF-8 JSON,保持用户可读摘要和字段名不变,并覆盖查询、表存在性及 metadata 成功响应。

行动(Action)

  • 将连接、表存在性、查询、表描述、列、主键、外键和索引成功分支改用 json.dumps
  • 增加成功查询与表存在性响应的 JSON 回归测试。
  • 保留错误 envelope、SQL 校验、limit 和文本摘要语义。
  • 没有做什么:不重写所有历史 handler、不改变 SQL 或数据库权限、不建立性能收益结论。

验证(Verification)

环境:Windows 11,Python 3.12.12。

  • MCP 定向测试:30 passed。
  • PYTHONPATH=src python -m pytest tests/unit/ -q:651 passed。
  • ruff check src tests scripts、变更文件格式检查和 git diff --check:通过。

实验与证据(Evidence)

对查询和表存在性成功响应的 Raw Response 片段执行 json.loads:修复前因 Python repr 失败,修复后成功解析,布尔值、空值和列表保持 JSON 语义。用户可读文本未改变。

兼容性、风险与回滚

@ZhaoXingPeng

Copy link
Copy Markdown
Owner Author

问题复现:成功响应的 Raw Response 在多个工具中使用 Python repr,布尔值、空值和字符串格式不符合 JSON;失败响应却使用 json.dumps,造成同一 MCP 边界两套协议。

@ZhaoXingPeng

Copy link
Copy Markdown
Owner Author

实现记录:统一连接、表存在性、查询、表描述、列、主键、外键和索引成功路径的 JSON 序列化,保留用户可读摘要和既有字段名。

@ZhaoXingPeng

Copy link
Copy Markdown
Owner Author

实验结果:对 Raw Response 片段执行 json.loads,查询和表存在性路径由失败变为成功,True/None/list 等值保持 JSON 语义。

@ZhaoXingPeng

Copy link
Copy Markdown
Owner Author

测试记录:定向 MCP 回归 30 项通过,完整单元测试 651 项通过,Ruff 检查与 diff 检查通过。

@ZhaoXingPeng

Copy link
Copy Markdown
Owner Author

兼容性边界:客户端应按 JSON 解析,不再依赖 Python repr;本次未建立可比性能基准,性能数据未测量。

@ZhaoXingPeng
ZhaoXingPeng merged commit 93d0894 into main Sep 7, 2026
9 checks passed
@ZhaoXingPeng
ZhaoXingPeng deleted the fix/107-mcp-success-json branch September 9, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 fix(mcp): 统一成功响应 JSON 序列化

1 participant