Skip to content

fix(mcp): mcp tools refuse coerced arguments before they run, with prescriptive errors that never echo values #862

Closed

Description

@dan-petty

Context & Rationale

Filed from the unchecked P0 entry at docs/ROADMAP.md:962 (at 308a71f), which had no issue, after re-checking it as decision D9 of the 2026-10-01 agentic quality assessment asked.

Reproduced on release/v0.2.24. The real tool registry was called through fastmcp.Client(mcp) with _run_mcp_cmd patched to record the argv, so nothing ran:

Arguments argv the tool builds
{"number": true, "post": true} devops review pr 1 --persona devsecops --post
{"number": "1"} devops review pr 1 --persona devsecops
{"number": 1.0} devops review pr 1 --persona devsecops

A malformed or hallucinated call would review PR #1 and post a comment on it. _validate_mcp_int_bound("number", ..., min_val=1) (src/devops_cli/ai/mcp/server.py:158) passes, because True == 1 after pydantic's lax coercion.

AGENTS.md:75-77 requires FastMCP tools to forbid undeclared parameters and to answer bad calls with prescriptive errors listing allowable arguments. The first half holds only through FastMCP 3.4.7 defaults; no test asserts it or sends a bad argument. The second half is false: an unknown key returns pydantic's raw Unexpected keyword argument text, and the body helpers (src/devops_cli/ai/mcp/server.py:79-114) raise on the first breach only. Types are coerced (server.py:35 omits strict_input_validation): review_pr runs, and with post comments on PR 1, for number=true. The SDK's strict check covers only listed tools (mcp/server/lowlevel/server.py:531-534) and names the value, not the field, while DomainGateMiddleware (server.py:3017) withholds sandbox_stop, tf_apply and pr_close. Principle 2 fails too: FastMCP logs rejected inputs (fastmcp/server/server.py:1313-1325), so a malformed vault_set writes key_values to the log and the result.

Scope & Deliverables

  • Deliverable: Port nothing from vibes verifier.py or app_factory.py. (1) One on_call_tool middleware beside DomainGateMiddleware resolves the registered tool, listed or withheld, runs jsonschema Draft202012Validator.iter_errors against its published tool.parameters and refuses before the handler, and catches fastmcp.exceptions.ValidationError via __cause__.errors(include_url=False). Both feed one renderer, shared with 'Lossless Structured Error Reflection for Schema Retries': a numbered envelope (parameter, kind such as HALLUCINATED_PARAM or TYPE_MISMATCH, expected, fix), the sorted allowed parameters, and 're-issue the call'. Declare jsonschema in pyproject.toml. (2) An Annotated[int, Field(ge=1, strict=True)] alias for PR and issue numbers. (3) A logging.Filter on fastmcp.server.server redacting input, caplog-tested like test_no_dispatch_argument_reaches_a_log_record. (4) In tests/test_fastmcp_contracts.py, via fastmcp.Client(mcp): every schema keeps additionalProperties: false; strict_input_validation stays off; bool-for-int, string-for-int and string-for-bool are refused on an advertised tool and on sandbox_stop, with _run_mcp_cmd failing if reached; a sweep runs the validator, never a handler, over every integer, boolean or number schema; bound coverage is reported, not enforced. Follow-up: per-argument-class Annotated bounds, the hyphen check in an AfterValidator, then delete the three helpers and tests/test_mcp.py:471.
  • Acceptance criteria:
    • Through fastmcp.Client(mcp) with _run_mcp_cmd patched, review_pr refuses {"number": true}, {"number": "1"} and {"number": 1.0} before the handler runs, and the patched runner records no call.
    • The same holds for a withheld tool such as sandbox_stop.
    • The refusal names the parameter, the expected type and the allowed parameters, and never echoes the value.
    • Tests never touch the network. uv run devops ci passes.
  • Constraint: Echoing values is the leak: render from json_path, validator and expected type, never jsonschema's message, which quotes the value; never echo key_values, oidc_token or reply body, other values only as a short prefix. Validate against FastMCP's published schema, never a hand-written copy. Caps are per argument class: verifier.py's blanket 256-character cap would break pr_thread_reply(body) (server.py:2195) and the LogQL and AST query arguments (:314, :973). strict_input_validation=True alone is worse: withheld tools still coerce, and its single error precedes middleware. Faithful coercions such as "5" become errors; pre-1.0 policy accepts that.
  • Measured (roadmap entry): uv run python merge_probe.py (real registry, fastmcp.Client(mcp), _run_mcp_cmd patched): all 156 registered tools emit additionalProperties: false; 51 of the 67 tools with an integer, boolean or number parameter are withheld from the default listing; review_pr ran for {"number": true} and {"number": "1"}; an invalid vault_set echoed a sentinel in the result and a fastmcp.server.server warning. uv run python strict_probe.py (toy server, strict_input_validation=True, listing filter): the listed tool refused true; the withheld tool's handler ran.

Strategic Alignment

Activity

  1. added
    type/bug
    scope/mcp
    priority/p0-critical
    on Oct 1, 2026
  2. added this to the v0.2.24 milestone on Oct 1, 2026
  3. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Admitted to v0.2.24 as a critical fix, by the owner's decision (2026-10-01): a P0 security defect fix, delivered before the cut.

  4. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Closed by #903, merged into release/v0.2.24.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  5. added a commit that references this issue on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p0-criticalscope/mcptype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions