Reject unexpected MCP read tool arguments#899
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds input validation to MCP read tools by introducing a ChangesMCP Tool Argument Validation
Possibly Related Issues
Possibly Related PRs
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
mauricemohr88-debug
left a comment
There was a problem hiding this comment.
Current-head review for #838 on 3672fce64c17284b941dcbeac5ad6578a5ea54a9.
Evidence checked:
- Inspected
app/mcp_tools.py; the newreject_unexpected_argsguard is applied to the read-only selector toolsget_bounty,list_bounty_attempts,get_balance,get_wallet,get_ledger_entry, andget_proof. - Verified valid current-main selectors remain in the allowed sets, while typoed extra fields fail before a tool can succeed with misleading ignored input.
- Inspected
tests/test_api_mcp.pyandtests/test_mcp_tools.py; coverage exercises unexpected arguments through both the MCP HTTP layer and the direct tool dispatcher. - Confirmed GitHub reports PR #899 open, current head
3672fce64c17284b941dcbeac5ad6578a5ea54a9, merge state clean, and both visible checks successful. - Ran
uv run --python 3.12 --extra dev python -m pytest tests/test_mcp_tools.py tests/test_api_mcp.py::test_mcp_read_tools_reject_unexpected_arguments -q: 19 passed, 1 existing Starlette warning. - Ran
uv run --python 3.12 --extra dev python -m pytest tests/test_api_mcp.py tests/test_mcp_tools.py -q: 124 passed, 1 existing warning. - Ran
uv run --python 3.12 --extra dev ruff check app/mcp_tools.py tests/test_api_mcp.py tests/test_mcp_tools.py: passed. - Ran
uv run --python 3.12 --extra dev ruff format --check app/mcp_tools.py tests/test_api_mcp.py tests/test_mcp_tools.py: 3 files already formatted. - Ran
uv run --python 3.12 --extra dev mypy app/mcp_tools.py app/mcp.py: success. - Ran
uv run --python 3.12 --extra dev python scripts/docs_smoke.py: docs smoke ok. - Ran
git diff --check origin/main...HEADandgit merge-tree --write-tree origin/main HEAD: clean.
One queue-integration note: this is clean against current origin/main, but it overlaps PR #893 in app/mcp_tools.py. git merge-tree origin/main origin/pr/893 origin/pr/899 reports conflicts around the helper definitions plus the get_ledger_entry and get_proof selector handling. If #893 lands first, this PR should keep its new proof_hash and ledger_sequence aliases in the allowed argument sets instead of reverting those alias paths back to only hash and sequence.
I do not see a current-main blocker. The runtime guard is useful and test-backed; the only caution is the explicit rebase/merge coordination with #893 before final landing order.
MolhamHamwi
left a comment
There was a problem hiding this comment.
Reviewed current head 3672fce64c17284b941dcbeac5ad6578a5ea54a9 for the MCP read-tool argument guard.
Evidence checked:
app/mcp_tools.py: the newreject_unexpected_args()helper is called before read-tool-specific parsing forget_bounty,list_bounty_attempts,get_balance,get_wallet,get_ledger_entry, andget_proof. That ordering is important because typo/unknown keys now fail deterministically instead of being silently ignored while another selector is accepted.tests/test_mcp_tools.py: directcall_mcp_tool()coverage confirms each read tool raises the exact unexpected argument name, including typo-like cases such asacount.tests/test_api_mcp.py: JSON-RPC coverage confirms the same failures are surfaced as-32602 invalid tool argumentswithout leaking internal validation text.- CI is green on the PR, and local focused verification passed with:
uv run pytest tests/test_mcp_tools.py::test_call_mcp_tool_rejects_unexpected_read_tool_arguments tests/test_api_mcp.py::test_mcp_read_tools_reject_unexpected_arguments -q
Result:12 passed, 1 warning.
I do not see a blocker. The scope is focused on read tools only and does not change write-tool argument compatibility.
Disclosure: This review is submitted for the MRWK review bounty.
Bounty #844
Summary
get_bounty,list_bounty_attempts,get_balance,get_wallet,get_ledger_entry, andget_proof;{ acount: ... }or{ seq: 2 }from being silently ignored while the tool succeeds;Duplicate / Scope Check
list_bountiesand does not duplicate its runtime guard;submit_work_proofor its selector/schema rules;tools/listinput schemas;get_balancestructured output or selector wording;Validation
uv run --python 3.12 --extra dev python -m pytest tests/test_mcp_tools.py tests/test_api_mcp.py::test_mcp_read_tools_reject_unexpected_arguments -q-> 19 passed, 1 existing warning.uv run --python 3.12 --extra dev python -m pytest tests/test_api_mcp.py tests/test_mcp_tools.py -q-> 124 passed, 1 existing warning.uv run --python 3.12 --extra dev ruff check app/mcp_tools.py tests/test_api_mcp.py tests/test_mcp_tools.py-> passed.uv run --python 3.12 --extra dev ruff format --check app/mcp_tools.py tests/test_api_mcp.py tests/test_mcp_tools.py-> 3 files already formatted.uv run --python 3.12 --extra dev mypy app/mcp_tools.py app/mcp.py-> success.uv run --python 3.12 --extra dev python scripts/docs_smoke.py-> docs smoke ok.git diff --check origin/main...HEAD-> clean.git merge-tree --write-tree origin/main HEAD-> clean treeabda6f4c7b8cc6d19c1ef4bc0fd2711b121cfce1.Summary by CodeRabbit
get_bounty,list_bounty_attempts,get_balance,get_wallet,get_ledger_entry,get_proof) now validate input arguments and reject unexpected fields with clear error messages.