🐛 fix(mcp): 强制查询工具遵守结果上限 - #113
Merged
Merged
Conversation
Owner
Author
|
问题复现:请求 limit=10 时,原实现对已有 LIMIT 1000 的 SQL 不做修改,只在响应阶段切片;数据库工作量和接口上限因此不一致。 |
Owner
Author
|
实现记录:新增顶层 LIMIT 扫描与收紧逻辑,屏蔽字符串字面量,支持数字、ALL 和 offset,count 形式;嵌套查询保持独立。 |
Owner
Author
|
实验结果:LIMIT 1000 -> LIMIT 10,LIMIT 3 保持不变,LIMIT ALL -> LIMIT 10,LIMIT 20, 100 -> LIMIT 20, 10。 |
Owner
Author
|
测试记录:查询安全定向测试 17 项通过,完整单元测试 656 项通过,Ruff 检查与 diff 检查通过。 |
Owner
Author
|
边界说明:复杂方言特有 LIMIT 语法未扩展;本次未建立可比性能基准,性能数据未测量。 |
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.
背景
db_query_execute 接受 limit 参数,但原实现只在 SQL 没有顶层 LIMIT 时追加限制;用户传入更大的 LIMIT 或 LIMIT ALL 时,数据库仍可能执行超出接口上限的查询,服务端最后才截断数组。
变更
验证
实验
请求 limit=10 时,SELECT ... LIMIT 1000 被发送为 LIMIT 10;LIMIT 3 保持不变;LIMIT ALL 被替换为 LIMIT 10;字符串中的 LIMIT 不改变追加逻辑。
风险与边界
仅影响 db_query_execute 的顶层结果上限,不改变查询过滤或排序;复杂方言特有 LIMIT 语法未扩展。未建立可比性能基准,性能数据未测量。
Closes #111