Skip to content

feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857

Closed

Description

@dan-petty

Context & Rationale

All 155 tools in src/devops_cli/ai/mcp/server.py use a bare @mcp.tool() with no annotations=. A client therefore cannot tell these tools from read-only ones:

  • tf_apply (:670), which defaults to auto_approve=True;
  • k8s_teardown_stack (:302), which defaults to the infra stack;
  • valkey_flush (:2502);
  • vault_set (:2060);
  • pr_close (:2303).

DomainGateMiddleware filters only the listing (:3006).

devops ai pipeline hands every stage get_default_tools(). The agent loop already turns ApprovalRequired into DeferredToolRequests, but no production tool sets requires_approval, and require_approval_toolset (ai/toolsets/__init__.py:429) has no caller.

docs/ROADMAP.md:1082 (P1, no issue) designs the fix.

Scope & Deliverables

  • Deliverable:
    • PR1:
      • Annotate every tool through FastMCP's annotations=.
      • Add a test beside test_fastmcp_tool_docstrings_and_parameters that iterates mcp._list_tools() and fails when readOnlyHint is unset.
      • Carry the hints into export-schemas, MCPToolInfo and MCP_TOOLS.md.
      • Change tf_apply to default to auto_approve=False.
    • PR2:
      • The bridge builds agent tools only from FunctionTool components, and sets requires_approval unless readOnlyHint is true.
      • devops ai pipeline gets a HandleDeferredToolCalls capability that prompts on a TTY and denies otherwise.
      • ToolSlot reads the annotation.
      • Delete require_approval_toolset and its re-exports.
  • Acceptance criteria:
    • Every registered tool has readOnlyHint set (registry test).
    • Each argument-dependent tool is annotated for its most dangerous arguments.
    • A non-interactive pipeline run denies an unannotated or mutating tool.
    • devops docs check passes, and the new tests take at most 1 s.
  • Key questions:
    • Do external clients such as Claude Code also need a confirm argument? (proposed) No. They have their own permission prompts, and the spec says clients must not trust annotations from untrusted servers. This protects devops-cli's own loop.
  • Constraint:

Strategic Alignment

  • Milestone: Backlog
  • Depends on: none

Update 2026-10-08: refinement

No tool sets annotations=; tf_apply defaults to auto_approve=True (ai/mcp/server.py:930). As the 2026-10-01 placement asked, this item keeps PR1 (annotations, registry test, hints, tf_apply default False); PR2 (agent approval, deleting require_approval_toolset) becomes its own item depending on this one.

  • Tools that write for some arguments carry readOnlyHint: false, including roadmap_render, gh_project_reconcile, docker_sign, argo_rollout_analyze and rag_drift; the test holds the list as a floor.

Proposed design

Problem statement

All 155 MCP tools in src/devops_cli/ai/mcp/server.py are registered with a bare @mcp.tool() and no annotations= parameter, so no client can distinguish read-only tools from mutating ones such as tf_apply (which defaults to auto_approve=True), k8s_teardown_stack, valkey_flush, vault_set and pr_close. This issue (PR1 of a two-PR split) adds a readOnlyHint annotation to every tool via FastMCP's annotations= parameter, enforces it with a registry test, carries the hints into export-schemas / MCPToolInfo / MCP_TOOLS.md, and changes tf_apply to default to auto_approve=False. PR2 (agent-loop approval and deletion of require_approval_toolset) is a separate item that depends on this one.

Acceptance criteria

  • Criterion 1: Every registered tool in src/devops_cli/ai/mcp/server.py has readOnlyHint set via FastMCP's annotations= parameter.
    Verification: A test beside test_fastmcp_tool_docstrings_and_parameters iterates mcp._list_tools() and fails when any tool's readOnlyHint is unset; run pytest on that test and confirm it passes.
  • Criterion 2: Tools that write for some arguments carry readOnlyHint: false, including roadmap_render, gh_project_reconcile, docker_sign, argo_rollout_analyze and rag_drift; the test holds the list as a floor.
    Verification: The registry test asserts each named tool has readOnlyHint set to false; run pytest on that test and confirm it passes.
  • Criterion 3: tf_apply defaults to auto_approve=False.
    Verification: Inspect the tf_apply function signature in src/devops_cli/ai/mcp/server.py and confirm the default value is False; run a test that calls tf_apply without auto_approve and verifies the command does not include --auto-approve.
  • Criterion 4: The readOnlyHint values are carried into export-schemas output, the MCPToolInfo model, and docs/MCP_TOOLS.md.
    Verification: Run devops ai mcp export-schemas and confirm the JSON output includes annotation data; verify MCPToolInfo in src/devops_cli/models/ai.py has a field for the hint; confirm docs/MCP_TOOLS.md renders the hints.
  • Criterion 5: devops docs check passes and the new tests complete in at most 1 second.
    Verification: Run devops docs check and confirm exit code 0; run pytest -x --timeout=1 on the new registry test and confirm it passes within the budget.

Key questions

  • Do external clients such as Claude Code also need a confirm argument?: No. External clients have their own permission prompts, and the MCP spec says clients must not trust annotations from untrusted servers. The annotations protect devops-cli's own agent loop, not third-party clients. (proposed)
  • Which tools must carry readOnlyHint: false as a floor in the registry test?: roadmap_render, gh_project_reconcile, docker_sign, argo_rollout_analyze and rag_drift are named as the floor; the test holds this list and any tool that writes for some arguments must also be annotated false. [sources: src/devops_cli/ai/mcp/server.py]
  • Should tools be wrapped with pydantic-ai's approval_required?: No. extract_tools_from_toolset drops every tool behind approval_required, so wrapping would silently remove tools from the agent's toolset. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/security
    scope/mcp
    priority/p1-high
    on Oct 1, 2026
  2. added this to the v0.2.28 milestone on Oct 1, 2026
  3. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Placement (2026-10-01): v0.2.28. Value High, Effort High. Not Ready yet.

    Checked against release/v0.2.24 at d38251e. What stops it being Ready:

    • The scope is explicitly two PRs (PR1 annotations + tf_apply default; PR2 approval in the agent loop), but an item must be delivered by exactly one PR. Split it into two issues.
    • Stale refs: 154 tools, not 155. tf_apply is at :686 (cited 670), k8s_teardown_stack :318 (302), valkey_flush :2479 (2502), vault_set :2054 (2060), pr_close :2280 (2303), DomainGateMiddleware :2976 (3006), ROADMAP :1078 (1082).
    • The acceptance criteria do not say how 'argument-dependent tools annotated for their most dangerous arguments' is checked (no list of such tools).
  4. removed this from the v0.2.28 milestone on Oct 6, 2026
  5. dan-petty-bot commented on Oct 6, 2026

    @dan-petty-bot
    Collaborator

    Moved to the backlog: it was New, not Ready, when v0.2.28 started. (devops roadmap reprioritize)

  6. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #997 takes readOnlyHint from this item and lands after it. #886's dry-run class (makes no external request) differs from readOnlyHint (changes no state); one declaration per command can serve both. Found by the 2026-10-08 backlog review.

  7. dan-petty-bot commented on Oct 10, 2026

    @dan-petty-bot
    Collaborator

    Status set to Ready at 69c99cf (see proposed design in issue body).

  8. added this to the v0.2.36 milestone on Oct 11, 2026
  9. added
    status/in-progress
    on Oct 16, 2026
  10. removed
    status/in-progress
    on Oct 16, 2026
  11. dan-petty commented on Oct 16, 2026

    @dan-petty
    OwnerAuthor

    Delivered in #1600 (dd1b896) on release/v0.2.36.

  12. added a commit that references this issue on Oct 17, 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/p1-highscope/mcptype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions