From 5fe0ed3a637fcd2924902edd99c981371e08c47f Mon Sep 17 00:00:00 2001 From: "Nicholas.FS" <145198426+NicholasDAS@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:51:17 -0500 Subject: [PATCH 1/2] Change exception type for MCP request size limit --- proofline/_mcp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proofline/_mcp.py b/proofline/_mcp.py index f80c5e00..96719736 100644 --- a/proofline/_mcp.py +++ b/proofline/_mcp.py @@ -35,7 +35,7 @@ def _body(method: str, params: dict[str, Any] | None, identity: int | None) -> b value["params"] = params data = json.dumps(value).encode("utf-8") if len(data) > 8192: - raise ValueError("MCP request exceeds 8192 bytes.") + raise ProoflineError(0, "urn:proofline:sdk:mcp", "MCP request exceeds 8192 bytes.") return data From d0d61556139fb5672c4d116d5380e6adfcd18f01 Mon Sep 17 00:00:00 2001 From: "Nicholas.FS" <145198426+NicholasDAS@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:57:26 -0500 Subject: [PATCH 2/2] Add tests for MCP request size limits --- tests/test_mcp.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_mcp.py diff --git a/tests/test_mcp.py b/tests/test_mcp.py new file mode 100644 index 00000000..34a2736c --- /dev/null +++ b/tests/test_mcp.py @@ -0,0 +1,40 @@ +"""The MCP request size limit fails with the SDK's typed error.""" + +import httpx2 +import pytest + +from proofline._mcp import _body +from proofline._transport import ProoflineError +from proofline.knowledge import AsyncKnowledgeClient, KnowledgeClient + + +def test_oversized_body_raises_proofline_error() -> None: + with pytest.raises(ProoflineError) as caught: + _body("tools/call", {"name": "ask_codebase", "arguments": {"question": "q" * 9000}}, 2) + + assert caught.value.status == 0 + assert caught.value.type == "urn:proofline:sdk:mcp" + + +def test_normal_body_is_within_the_limit() -> None: + data = _body("tools/call", {"name": "ask_codebase", "arguments": {"question": "why?"}}, 2) + + assert len(data) <= 8192 + + +def test_long_question_raises_before_any_request() -> None: + client = KnowledgeClient(httpx2.Client(base_url="https://proofline.invalid")) + + with pytest.raises(ProoflineError) as caught: + client.ask_codebase("owner/name", "q" * 9000) + + assert caught.value.type == "urn:proofline:sdk:mcp" + + +async def test_long_question_raises_before_any_request_async() -> None: + client = AsyncKnowledgeClient(httpx2.AsyncClient(base_url="https://proofline.invalid")) + + with pytest.raises(ProoflineError) as caught: + await client.ask_codebase("owner/name", "q" * 9000) + + assert caught.value.type == "urn:proofline:sdk:mcp"