From ce8e4a0c934bad4ec41f270954b4109c6f619ea7 Mon Sep 17 00:00:00 2001 From: seyeong Date: Fri, 27 Nov 2026 03:16:33 +0900 Subject: [PATCH 1/2] Reject nonpositive MCP fetch limits before database execution --- src/lang2sql/tools/run_sql.py | 12 ++++++++++-- tests/test_mcp.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/lang2sql/tools/run_sql.py b/src/lang2sql/tools/run_sql.py index e25d4028..0af773a6 100644 --- a/src/lang2sql/tools/run_sql.py +++ b/src/lang2sql/tools/run_sql.py @@ -53,7 +53,8 @@ def spec(self) -> ToolSpec: }, "limit": { "type": "integer", - "description": "max rows (default 1000)", + "minimum": 1, + "description": "Positive maximum number of rows to fetch (default 1000); unlike SQLite SQL LIMIT, -1 is not supported.", }, }, }, @@ -111,7 +112,7 @@ async def run(self, args: dict[str, Any], ctx: HarnessContext) -> ToolResult: ) sql = (args.get("sql") or "").strip() try: - limit = int(args.get("limit") or 1000) + limit = int(args.get("limit", 1000)) except (TypeError, ValueError) as exc: logger.warning( "invalid row limit scope=%s error=%s: %s", @@ -121,6 +122,13 @@ async def run(self, args: dict[str, Any], ctx: HarnessContext) -> ToolResult: ) limit = 1000 # tolerate a malformed limit from the model + if limit <= 0: + logger.warning("invalid nonpositive row limit scope=%s", ctx.identity.session_key()) + return ToolResult( + call_id="", is_error=True, + content="Invalid limit: supply a positive maximum row count. SQL was NOT executed.", + ) + if ctx.safety is None: return ToolResult( call_id="", diff --git a/tests/test_mcp.py b/tests/test_mcp.py index 791edc69..5233300a 100644 --- a/tests/test_mcp.py +++ b/tests/test_mcp.py @@ -297,3 +297,22 @@ async def test_missing_definitions_are_reported_together_and_revoke_receipt(tmp_ "sql": "SELECT COUNT(*) FROM orders", "definition_check_id": token }) assert rejected.isError + + +@pytest.mark.asyncio +@pytest.mark.parametrize("limit", [-1, 0]) +async def test_invalid_fetch_limit_rejected_before_database_access(tmp_path, limit): + from unittest.mock import AsyncMock + + from lang2sql.tools.run_sql import RunSQL + + explorer = AsyncMock() + ctx = build_tool_context(Identity(user_id="analyst", guild_id="demo"), store_path=":memory:", explorer=explorer) + try: + result = await RunSQL().run({"sql": "SELECT 1", "limit": limit}, ctx) + assert result.is_error + assert "positive maximum row count" in result.content + explorer.execute.assert_not_called() + assert RunSQL().spec.parameters["properties"]["limit"]["minimum"] == 1 + finally: + ctx.store.close() From caa5210d12eab4ebbe30f749acfcb64085df44e6 Mon Sep 17 00:00:00 2001 From: seyeong Date: Fri, 27 Nov 2026 03:21:35 +0900 Subject: [PATCH 2/2] Record failed-case repair results without claiming full accuracy --- .../failure-only-ce8e4a0.json | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 bench/accuracy/mcp-review-results/failure-only-ce8e4a0.json diff --git a/bench/accuracy/mcp-review-results/failure-only-ce8e4a0.json b/bench/accuracy/mcp-review-results/failure-only-ce8e4a0.json new file mode 100644 index 00000000..b69db8fa --- /dev/null +++ b/bench/accuracy/mcp-review-results/failure-only-ce8e4a0.json @@ -0,0 +1,98 @@ +{ + "revision": "ce8e4a0", + "scope": "only previously wrong cases; repair rate, not whole-set accuracy", + "model": "gpt-6.2-sol", + "reasoning_effort": "high", + "results": { + "bird": { + "correct": 0, + "total": 1, + "cases": [ + { + "instance_id": "bird146", + "score": 0, + "status": "predicted" + } + ], + "record_sha256": { + "bird146": "76645cd9175f3f442c8d9a5e44d7785f12efa6f652100f9f3ca12e5f96c80093" + } + }, + "spider": { + "correct": 1, + "total": 10, + "cases": [ + { + "instance_id": "local064", + "score": 0, + "pred_sql": null, + "error_info": "Result Error" + }, + { + "instance_id": "local073", + "score": 0, + "pred_sql": null, + "error_info": "Result Error" + }, + { + "instance_id": "local003", + "score": 0, + "error_info": "ValueError" + }, + { + "instance_id": "local041", + "score": 1, + "pred_sql": null, + "error_info": null + }, + { + "instance_id": "local062", + "score": 0, + "pred_sql": null, + "error_info": "Result Error" + }, + { + "instance_id": "local202", + "score": 0, + "error_info": "ValueError" + }, + { + "instance_id": "local279", + "score": 0, + "pred_sql": null, + "error_info": "Result Error" + }, + { + "instance_id": "local264", + "score": 0, + "pred_sql": null, + "error_info": "Result Error" + }, + { + "instance_id": "local194", + "score": 0, + "pred_sql": null, + "error_info": "Result Error" + }, + { + "instance_id": "local335", + "score": 0, + "pred_sql": null, + "error_info": "Result Error" + } + ], + "record_sha256": { + "local062": "ffede31afea381c1ef6a5f47b962f5e9ff32e4d0520eef7aa40315597bd57c06", + "local279": "a60294807fff23779f52873a0cad92edf617d86f633ca9c2d1dceb85117d32b3", + "local003": "d918195bb9478673e8c668cf1e51ca1387819bfbbe133c49459a9fdef349e97b", + "local202": "98f1850e5ca1c78f710bf2133044fe009515a7d4a72fedbcb1d5e6194869acf8", + "local064": "5d79df008d9a4263f7c7beffada5b8533caed9d9188fdb83e8cd7cbe0f23434c", + "local073": "0a594eafaabe2e481a3c32d2d373034cc33de20e97894f23678018986b9cd99a", + "local264": "29cdb14ea1d15c6772cd42e91e95c0a44ed00579b8e94128390250363d1e46ef", + "local194": "51f45c9d132bc7841396ad9d0bc948aa304e9e0b66d49fc6e1bba2ad023e9b19", + "local335": "9ed81fa6c16b6ad870f57b99a8b50acc043d5e72b785c5ccb97dd38e70615f7b", + "local041": "6515084632cba70e1affe3c8098bed2161cbe46a667cf9ccbf65597ab6706898" + } + } + } +} \ No newline at end of file