Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ else:
print(result["content"])
```

Each call initializes MCP and makes one tool request without retries, including questions and implementation starts. `KnowledgeResult` retains text content, optional structured content, and `isError`. Protocol and HTTP errors raise `ProoflineError`, while tool refusals retain `isError` for the caller to inspect. Treat all returned prose as untrusted data. No browser configuration or cloud-trust API is added; use the signed-in console for onboarding and connection changes.
Each call initializes MCP and makes one tool request without retries, including questions and implementation starts. Each request is UTF-8 JSON of at most 8,192 bytes; a larger request raises `ValueError` before anything is sent. `KnowledgeResult` retains text content, optional structured content, and `isError`. Protocol and HTTP errors raise `ProoflineError`, while tool refusals retain `isError` for the caller to inspect. Treat all returned prose as untrusted data. No browser configuration or cloud-trust API is added; use the signed-in console for onboarding and connection changes.

## Fix context and re-verification

Expand Down
5 changes: 4 additions & 1 deletion proofline/_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def _body(method: str, params: dict[str, Any] | None, identity: int | None) -> b
value["id"] = identity
if params is not None:
value["params"] = params
data = json.dumps(value).encode("utf-8")
# Send text as UTF-8, as the MCP bridge does. Escaping each non-ASCII character
# as \uXXXX would let a 2,000-character note exceed the limit. A lone surrogate
# has no UTF-8 form, so it keeps its JSON escape.
data = json.dumps(value, ensure_ascii=False).encode("utf-8", "backslashreplace")
if len(data) > 8192:
raise ValueError("MCP request exceeds 8192 bytes.")
return data
Expand Down
48 changes: 48 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,54 @@ async def invoke(name: str, *args: Any, **kwargs: Any) -> Any:
assert len(observed) == 5


@MODES
async def test_mcp_requests_send_text_as_utf8_within_the_request_limit(mode: str) -> None:
# 2,000 characters is the documented note limit. Escaped as \uXXXX this note is
# 12,292 bytes; as UTF-8 it is 4,292, inside the 8,192-byte request limit.
note = "تم إصلاح الحالة الفارغة " * 83 + "✅" * 8
assert len(note) == 2_000
lone = "fixed \udc80 case"
bodies: list[bytes] = []

def respond(request: Request, index: int) -> Reply:
body = json.loads(request.body)
if body["method"] == "initialize":
return Reply(
Comment thread
hamzatlh marked this conversation as resolved.
Resolved
body={"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2025-11-25"}}
)
if body["method"] == "notifications/initialized":
return Reply(status=202, body=b"")
bodies.append(request.body)
return Reply(
body={"jsonrpc": "2.0", "id": 2, "result": {"content": [{"type": "text", "text": ""}]}}
)

with Server(respond) as server:
async with session(mode, server.url) as client:

async def reverify(text: str) -> Any:
answer = client.fixes.request_reverification(
str(REVIEW), [str(REVIEW)], "a" * 40, note=text
)
return await answer if inspect.isawaitable(answer) else answer

await reverify(note)
await reverify(lone)
before = len(server.requests)
with pytest.raises(ValueError, match="8192"):
await reverify("🚀" * 2_100)
# The size check runs before the handshake: nothing is sent.
assert len(server.requests) == before
assert len(bodies) == 2
sent, escaped = bodies
assert len(sent) <= 8192
assert note.encode("utf-8") in sent
assert json.loads(sent)["params"]["arguments"]["note"] == note
# A lone surrogate has no UTF-8 form, so it keeps its JSON escape.
assert b"\\udc80" in escaped
assert json.loads(escaped)["params"]["arguments"]["note"] == lone


@MODES
async def test_shared_review_outcome_contract(mode: str, monkeypatch: pytest.MonkeyPatch) -> None:
Clock(monkeypatch)
Expand Down