Skip to content

fix(mcp): support UUID serialization in fixes and knowledge subclients - #115

Open
nitinkoberoii wants to merge 2 commits into
prooflinedev:mainfrom
My-Org-Nitin:nitinkoberoii/fix/mcp-uuid-serialization
Open

nitinkoberoii wants to merge 2 commits into
prooflinedev:mainfrom
My-Org-Nitin:nitinkoberoii/fix/mcp-uuid-serialization

Conversation

@nitinkoberoii

Copy link
Copy Markdown

Problem

Core ProoflineClient and AsyncProoflineClient methods accept and return uuid.UUID objects for identifiers (organization_id, review_id, finding_id, etc.). However, the MCP subclients (client.fixes and client.knowledge) serialized JSON-RPC payloads with standard json.dumps(value) in proofline/_mcp.py.

Passing a UUID directly from a core SDK model into an MCP method crashed at runtime before any HTTP request was sent:

review = client.get_review(org_id, review_id)
client.fixes.get_fix_context(finding_id, organization_id=org_id)
# TypeError: Object of type UUID is not JSON serializable

Approach

  • proofline/_mcp.py: Replaced json.dumps(value) with json.dumps(value, default=_json_default), where _json_default explicitly converts uuid.UUID instances to str and raises TypeError for all other unserializable types.

  • proofline/fixes.py & proofline/knowledge.py: Updated ID parameter annotations across both sync and async clients to accept UUID | str (or UUID | str | None where optional), and typed finding_ids in request_reverification as Sequence[UUID | str] so list[UUID], list[str], and tuple[UUID, ...] all type-check cleanly.

Verification

Added sync and async regression tests in tests/test_http.py covering:

  • Passing UUID objects to client.fixes and client.knowledge methods and verifying the serialized JSON-RPC arguments payload.

  • Passing list[UUID] and tuple[UUID, ...] to request_reverification.

  • Confirming that passing a set or other unserializable object still raises TypeError.

  • Confirming that cyclic containers still raise ValueError.

Reproducible local checks run:

pytest
python -m ruff check .
python -m ruff format --check .
python -m mypy proofline scripts
python scripts/contracts.py

All tests, linting, formatting, type checks, and contract checks pass.

Proofline Review Evaluation

I installed Proofline on my GitHub organization (My-Org-Nitin/sdk-python) and ran a review on my initial PR before opening this upstream PR.

What Proofline caught (and what I changed):

  • Container cycles (Serious · Error handling): My first implementation used a recursive _serialize_mcp_value walker, which would hit RecursionError on cyclic containers before json.dumps could raise ValueError.
  • Shared container copying (Warning · Performance): The recursive walker copied shared references on every visit ($O(2^d)$ allocations).
  • Invariant list[UUID | str] (Warning · Logic): Annotating finding_ids as list[UUID | str] breaks mypy for callers passing list[UUID] or list[str].
  • Silent set coercion (Warning · Edge case): Using a list comprehension over finding_ids silently converted a set into a list instead of letting json.dumps reject it with TypeError.

Replacing the manual walker and list comprehension with a strict json.dumps(..., default=_json_default) hook and Sequence[UUID | str] resolved all four issues cleanly.

Product feedback:
Proofline flagged the list[UUID | str] invariance issue twice on the exact same lines—once under Logic and once under Api contract. Deduplicating overlapping findings across categories would make the review signal even sharper.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 11:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants