🐛 fix(mcp): 统一跨工具驱动值 JSON 序列化 - #162
Merged
Merged
Conversation
Owner
Author
阶段回帖 1/2:实现完成(2026-09-09)当前结论提交 变更与设计取舍
兼容性边界
|
Owner
Author
阶段回帖 2/2:验证完成(2026-09-09)当前结论共享编码和原子上下文回归已在本地通过;完整 unit 与 SQLite 查询/代码生成合同没有回归。结果只证明受控 fixture 的 JSON 合同,不代表 CI 或真实 MySQL/PostgreSQL 服务器已验证。 环境、输入与原始结果
验收映射
未执行与回滚
|
This was referenced Sep 8, 2026
ZhaoXingPeng
force-pushed
the
fix/161-shared-json-serialization
branch
from
September 9, 2026 01:55
5199d51 to
6ebb683
Compare
ZhaoXingPeng
force-pushed
the
fix/161-shared-json-serialization
branch
from
September 9, 2026 02:12
6ebb683 to
7356eb6
Compare
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 #161
背景(Situation)
MCP 响应序列化规则分散在多个模块。查询结果已有 Decimal、日期时间、UUID、bytes/memoryview 的驱动值编码,但原子
codegen_build_context、代码生成渲染和部分数据库/项目 handler 仍直接调用json.dumps。真实 MySQL/PostgreSQL metadata 嵌入模板上下文或响应时,非原生值会触发TypeError,客户端得到不可解析的错误。任务(Task)
建立无数据库依赖的共享 JSON 编码边界,统一驱动值规则并迁移
mcp_tools.py与原子 codegen 的成功/错误响应;保持现有ensure_ascii=False、缩进、字段和错误 envelope,不改变 SQL、事务、权限或 MCP 输入合同。行动(Action)
src/dbjavagenix/utils/json_serialization.py,集中处理 Decimal 保精度字符串、date/datetime/time ISO 文本、UUID 字符串、bytes/bytearray/memoryview 的 base64 对象和 timedelta 稳定文本;未知对象继续抛TypeError。mcp_tools.py的_query_result_json_default保留为兼容别名并委托共享default;所有 Raw Responsejson.dumps入口改用共享dumps。atomic_codegen_tools.py的 build context、render、错误响应统一使用共享dumps,保留缩进和 JSON 字段结构。验证(Verification)
环境:Windows,Python
3.10.1、pytest9.0.3、pytest-asyncio1.3.0;项目声明 Python>=3.11。来源提交:5199d51,唯一实现提交。实验与证据(Evidence)
12.30、UTC datetime、date/time、UUID、bytes、bytearray、memoryview 和 timedelta;json.loads(dumps(...))结果保留精度、ISO 文本和 base64 身份。codegen_build_context的嵌套 context 使用 Decimal、datetime、UUID、memoryview mock 值,Raw Response 可被json.loads解析;原子 render 工具的files、language、note字段保持可解析。rg -n "json\\.dumps"在受影响的mcp_tools.py与atomic_codegen_tools.py无直接调用;真实 MySQL/PostgreSQL 容器值类型未在本地宣称验证。兼容性、风险与回滚
mcp_tools._query_result_json_default继续可供既有测试/调用方使用。5199d51,不涉及数据迁移或数据库 schema 变化。