Skip to content

Add structured MCP work proof guidance#317

Merged
ramimbo merged 2 commits into
ramimbo:mainfrom
shootingallday:shootingallday/structured-submit-work-proof-315
May 25, 2026
Merged

Add structured MCP work proof guidance#317
ramimbo merged 2 commits into
ramimbo:mainfrom
shootingallday:shootingallday/structured-submit-work-proof-315

Conversation

@shootingallday
Copy link
Copy Markdown
Contributor

@shootingallday shootingallday commented May 25, 2026

Refs #315

What changed:

  • Added an explicit format argument to MCP submit_work_proof.
  • Preserved existing behavior when format is omitted or set to text.
  • Added format: "json" support that returns machine-readable structuredContent plus a JSON text fallback for clients that only inspect text content.
  • Structured bounty guidance uses actual bounty fields: id, issue number, status, awards remaining, award counts, reward, available MRWK, repository, issue URL, title, acceptance text, submission format, and safety rules.
  • Structured generic guidance now works on the no-selector fallback path.
  • Added focused tests for bounty-specific structured guidance, generic structured guidance, invalid format values, and the existing text behavior.

Contributor / agent impact:

  • Agents can request structured work-proof instructions without scraping the existing prose response, while current text callers keep receiving the same text.

Validation:

  • uv run --with pytest pytest tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_bounty_specific_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_keeps_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_bounty_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_reports_unknown_bounty tests/test_api_mcp.py::test_mcp_submit_work_proof_rejects_invalid_bounty_selectors tests/test_api_mcp.py::test_mcp_submit_work_proof_rejects_ambiguous_issue_number -q -> 13 passed.
  • uv run --with ruff ruff check app/main.py tests/test_api_mcp.py -> passed.
  • uv run --with ruff ruff format --check app/main.py tests/test_api_mcp.py -> passed.
  • uv run --with mypy mypy app -> success.
  • git diff --check -> clean.

No private keys, seed material, secrets, deployment credentials, private vulnerability details, payout details, or price claims are included.

Summary by CodeRabbit

  • New Features

    • Work proof submission guidance now available in structured JSON, with bounty-specific and generic guidance including metadata, reward/availability, submission instructions, and safety rules; preserves existing text fallback.
  • Tests

    • Added tests validating structured JSON responses for bounty-specific and generic guidance and asserting invalid format arguments are rejected.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5aab9f34-1f63-43a1-810b-dfa4f634dbe2

📥 Commits

Reviewing files that changed from the base of the PR and between ef8c1a9 and 214a341.

📒 Files selected for processing (1)
  • tests/test_api_mcp.py

📝 Walkthrough

Walkthrough

The PR adds JSON guidance capability to the MCP submit_work_proof tool. The MCP handler now routes dict results to result.structuredContent, and submit_work_proof accepts a format argument to return structured guidance objects for bounty-specific or generic cases, with new tests validating both paths and format validation.

Changes

JSON Structured Guidance for submit_work_proof

Layer / File(s) Summary
MCP handler dict response support
app/main.py
MCP /mcp handler routes dict tool results to result.structuredContent, and _call_mcp_tool return type expands to `str
Format argument parsing and validation
app/main.py
submit_work_proof includes output_format_arg helper that parses the optional format argument, defaulting to "text" and restricting to "text" or "json".
JSON guidance generation helpers
app/main.py
work_proof_guidance_json and generic_work_proof_guidance_json functions generate structured JSON guidance with bounty metadata, reward/availability, submission instructions, and safety rules.
submit_work_proof tool format integration
app/main.py
submit_work_proof selects response by format argument: returns JSON guidance for format=="json" in both bounty-specific and generic cases, preserving text guidance for format=="text".
JSON guidance and format validation tests
tests/test_api_mcp.py
Two new tests validate structured bounty-specific and generic JSON guidance; extended invalid-argument parameterization rejects unsupported format values ("xml", non-string types) with JSON-RPC error semantics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • ramimbo/mergework#289: Both PRs modify the MCP tool dispatcher in app/main.py around _call_mcp_tool handling of dict tool results.
  • ramimbo/mergework#287: Both PRs update the MCP submit_work_proof flow in app/main.py; this PR extends support for format: "json" with structuredContent.

Suggested reviewers

  • TateLyman
  • weilixiong
  • Karry2019web
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding structured JSON support to MCP work proof guidance output.
Description check ✅ Passed The description provides comprehensive coverage of changes, evidence, test results, and MRWK reference. All template sections are addressed with substantive content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_api_mcp.py`:
- Around line 1159-1173: Add an assertion for the new structured "title" field
after structured = result["structuredContent"]; verify structured["title"]
equals the expected bounty title (use the existing bounty fixture or literal
expected string used elsewhere in this test suite, e.g., compare to the same
title used when creating the bounty or to result["content"][0]["title"]) so the
test covers the new contract field.
- Around line 1183-1211: Update the test in tests/test_api_mcp.py that posts to
client.post("/mcp",
json={"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"submit_work_proof","arguments":{"format":"json"}}})
so it also asserts the JSON text fallback is present and equal to the same
guidance; after obtaining result = ... .json()["result"]["structuredContent"],
add an assertion that the response's fallback text (e.g.
response.json()["result"]["text"] or whichever top-level key your API uses for
text fallback) matches the expected submission guidance string (the same value
used for structuredContent["submission_format"]) to ensure parity for text-only
MCP clients.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 743546d8-3520-4bd4-adb4-9acb9e2b9ac2

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8baf7 and ef8c1a9.

📒 Files selected for processing (2)
  • app/main.py
  • tests/test_api_mcp.py

Comment thread tests/test_api_mcp.py
Comment thread tests/test_api_mcp.py Outdated
Copy link
Copy Markdown
Contributor

@tolga-tom-nook tolga-tom-nook left a comment

Choose a reason for hiding this comment

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

No blockers from my review.

Evidence checked:

  • Inspected app/main.py and tests/test_api_mcp.py against Bounty #315 acceptance criteria.
  • Confirmed omitted format / default text behavior remains unchanged, while format: "json" returns machine-readable bounty-specific guidance and generic no-selector guidance.
  • Confirmed invalid format values and non-string format values are covered by the existing invalid-argument path.
  • Ran focused MCP tests: ./.venv/bin/python -m pytest tests/test_api_mcp.py -q → 67 passed.
  • Ran static validation: ./.venv/bin/python -m ruff check app/main.py tests/test_api_mcp.py, ./.venv/bin/python -m mypy app, and git diff --check origin/main...HEAD → all passed.

One implementation detail I verified as useful: JSON-mode results are exposed both as structuredContent and as JSON text in the MCP content block, preserving compatibility for text-only MCP clients while giving structured callers actual fields.

@ramimbo ramimbo merged commit d24c887 into ramimbo:main May 25, 2026
2 checks passed
Copy link
Copy Markdown
Contributor

@ayskobtw-lil ayskobtw-lil left a comment

Choose a reason for hiding this comment

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

No blockers from my review.

Evidence checked:

  • Inspected the PR diff for app/main.py and tests/test_api_mcp.py.
  • Verified format parsing preserves the existing default text guidance, accepts case/whitespace-normalized json, and rejects unsupported or non-string format values through the existing JSON-RPC invalid-arguments path.
  • Confirmed JSON-mode bounty-specific guidance includes the expected public bounty fields, including title, reward/capacity/availability values, issue URL, acceptance text, submission instructions, and safety rules.
  • Confirmed JSON-mode generic guidance returns structured guidance when no selector is supplied, while the MCP text content fallback is the same JSON object serialized for text-only clients.
  • Checked the follow-up commit addressed the prior CodeRabbit coverage comments for title and content/structured parity.

Validation run on current PR head 214a341:

  • python -m pytest tests/test_api_mcp.py::test_mcp_submit_work_proof_keeps_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_bounty_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_returns_structured_generic_guidance tests/test_api_mcp.py::test_mcp_submit_work_proof_rejects_invalid_bounty_selectors -q -> 10 passed
  • python -m ruff check app/main.py tests/test_api_mcp.py -> All checks passed!
  • python -m ruff format --check app/main.py tests/test_api_mcp.py -> 2 files already formatted
  • git diff --check HEAD~2..HEAD -> clean

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

Labels

mrwk:accepted Maintainer accepted for payout mrwk:paid Ledger payment recorded

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants