🐛 fix(mcp): 统一成功响应 JSON 序列化 - #110
Merged
Merged
Conversation
Owner
Author
|
问题复现:成功响应的 Raw Response 在多个工具中使用 Python repr,布尔值、空值和字符串格式不符合 JSON;失败响应却使用 json.dumps,造成同一 MCP 边界两套协议。 |
Owner
Author
|
实现记录:统一连接、表存在性、查询、表描述、列、主键、外键和索引成功路径的 JSON 序列化,保留用户可读摘要和既有字段名。 |
Owner
Author
|
实验结果:对 Raw Response 片段执行 json.loads,查询和表存在性路径由失败变为成功,True/None/list 等值保持 JSON 语义。 |
Owner
Author
|
测试记录:定向 MCP 回归 30 项通过,完整单元测试 651 项通过,Ruff 检查与 diff 检查通过。 |
Owner
Author
|
兼容性边界:客户端应按 JSON 解析,不再依赖 Python repr;本次未建立可比性能基准,性能数据未测量。 |
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.
关联 Issue
Closes #107
背景(Situation)
多个 MCP 成功路径仍以 Python
repr拼接 Raw Response,使用单引号、None和True等非 JSON 语法;失败路径已使用json.dumps,同一 public handler 因此存在两套响应协议,调用方无法稳定执行json.loads。任务(Task)
把成功路径的结构化 Raw Response 统一序列化为 UTF-8 JSON,保持用户可读摘要和字段名不变,并覆盖查询、表存在性及 metadata 成功响应。
行动(Action)
json.dumps。验证(Verification)
环境:Windows 11,Python 3.12.12。
PYTHONPATH=src python -m pytest tests/unit/ -q:651 passed。ruff check src tests scripts、变更文件格式检查和git diff --check:通过。实验与证据(Evidence)
对查询和表存在性成功响应的 Raw Response 片段执行
json.loads:修复前因 Pythonrepr失败,修复后成功解析,布尔值、空值和列表保持 JSON 语义。用户可读文本未改变。兼容性、风险与回滚