Repository navigation
Description
Context & Rationale
ai/mcp/server.py is 3,019 lines. 152 functions carry @mcp.tool, and 2,064 of the lines are their bodies (13.6 lines on average). 147 of them call _run_mcp_cmd([..., "uv", "run", "devops", <group>, <command>, <flags>]); 146 map to a devops subcommand across 23 groups (ai 29, gh 24, k8s 15, pr 12, ...). Only 63 of the 146 tool names equal the dispatched path. Checked at 9c879ae.
InProcessDispatcher._dispatch_typer(ai/mcp/dispatcher.py:213-236) runs the CLI throughtyper.testing.CliRunnerin production and returns scraped console text; 21 tools ask for--format json, the other ~126 return Rich table text.register_handler(dispatcher.py:180) has zero callers; the "functional handler" path is dead.server.py:72branches onhasattr(run_subprocess, "assert_called"): production checks whether it is under a test mock.- Drift is already observable:
k8s_pods(namespace)(:275) validatesnamespaceand then runsdevops k8s statuswithout it. fix(mcp): mcp tools and resources call commands and options that exist #836 fixed 12 tools that called commands or options that did not exist. tests/test_mcp.py: 32 tests, 26 patches ofserver._run_mcp_cmd, 54 assertions on argv lists. The tests pass while the real command rejects the flags.
Deletion test: delete the 2,064 lines and nothing reappears. The knowledge they repeat (names, options, types, help) already lives in Typer's command metadata.
Scope & Deliverables
- Deliverable: one module walks the Typer app and emits FastMCP tools: typed parameters from the options, help from the option help, the domain gate from the group, the timeout class from an annotation, and the command's result model returned as JSON rather than scraped text. Hand-written tools remain only for the 5 with no command counterpart (
hydrate_tool_domain,security_intel_*,scan_uv_audit,k8s_jaeger_info).register_handlerand the mock-attribute branch go. - Tests: delete the ~26 argv-assertion tests. One parametrised test asserts that every exposed command is a tool whose parameter names and types match; the domain-gate and argument-contract tests (fix(mcp): mcp tools refuse coerced arguments before they run, with prescriptive errors that never echo values #862) stay.
- Key questions (open):
- Which commands are exposed: every command, or an allow-list per group?
- How are feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857's
ToolAnnotations(readOnlyHint) derived: from the read-only/mutating classification chore(cli): every argument-taking--dry-runcommand path is recorded as read-only or mutating, one candidate per offender #986 records? - Does every exposed command have a result model to return (feat(cli): output format adoption across the command surface #411), or do some still return text?
- How does fix(ai): mcp command tools return the failing output and never write to the protocol stream #839's contract (failing output returned, nothing written to the protocol stream) carry into the generated tools?
- Constraint: feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857 and fix(ai): mcp command tools return the failing output and never write to the protocol stream #839 are scheduled for v0.2.28 and edit
server.py; land this before or after them, not alongside.
Strategic Alignment
- Milestone: Backlog (no release)
- Design: none
- Depends on: none
- Related: fix(mcp): mcp tools and resources call commands and options that exist #836, feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857, fix(ai): mcp command tools return the failing output and never write to the protocol stream #839, fix(mcp): mcp tools refuse coerced arguments before they run, with prescriptive errors that never echo values #862, feat(mcp): fastmcp in-process execution, in-memory tool dispatch & schema caching acceleration research #318, feat(mcp): lazy domain-gated mcp tool schema hydration #429, feat(cli): output format adoption across the command surface #411, chore(cli): every argument-taking
--dry-runcommand path is recorded as read-only or mutating, one candidate per offender #986 - Source: architecture review of 2026-10-02, AI core
Scope added 2026-10-02: checked at 38517a8; the claims hold with moved lines. ai/mcp/server.py is 3,028 lines (#980 edited it). 152 functions carry @mcp.tool, 147 of them call _run_mcp_cmd, and the tool bodies are 2,065 lines. The five without a command are hydrate_tool_domain, security_intel_package, security_intel_network, scan_uv_audit and k8s_jaeger_info. _dispatch_typer is at ai/mcp/dispatcher.py:229-236, register_handler (:177) has no caller, the mock-attribute branch is at server.py:72, and k8s_pods (:279-286) still validates namespace and drops it; #956 (v0.2.25, in flight) changes it to run devops k8s pods -n <namespace>. tests/test_mcp.py has 32 tests. Of the scheduled items, #857 (ToolAnnotations) and #839 (failing output, nothing on the protocol stream) are in v0.2.28; #986, which records read-only and mutating command paths, and #411 (result models) are in the backlog.
Acceptance criteria
- One module registers a FastMCP tool for each command in an exposure table held as data (command path, timeout class, read-only or mutating). Each tool's parameters come from the command's Typer parameters: name, type, default, required flag and help.
- A parametrised test walks the table. For each tool it asserts that the input schema's properties match the command's parameters, and that the argv built from a full set of arguments parses with the real Click command (
make_contextsucceeds). No test patches_run_mcp_cmdto assert an argv list. At 38517a8, 52 patches in 13 test files do, 26 of them intests/test_mcp.pyand 13 intests/test_fastmcp_contracts.py. - A test fails when a tool accepts a parameter its command does not take, as
k8s_pods(namespace)did at 38517a8. - A test fails when a command is in neither the exposure table nor its exclusion list, so exposing a new command is a recorded decision.
- Only the five tools above stay hand-written.
register_handlerand thehasattr(run_subprocess, "assert_called")branch are deleted. - Domain gating (feat(mcp): lazy domain-gated mcp tool schema hydration #429) still hides a group's tools until
hydrate_tool_domainnames the group. The domain-gate tests and fix(mcp): mcp tools refuse coerced arguments before they run, with prescriptive errors that never echo values #862's coerced-argument tests (tests/test_fastmcp_contracts.py) still pass, changed only for renamed tools and for the argv assertions above. - Every generated tool keeps fix(ai): mcp command tools return the failing output and never write to the protocol stream #839's contract: a failing command returns its output and status, and nothing is written to the protocol stream. One test runs a generated tool whose command fails.
- Every generated tool carries feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857's
readOnlyHintfrom the table's read-only column. A test asserts that each tool sets it. - A tool returns the command's
--format jsonoutput where the command offers one, and its text otherwise. The PR lists which tools return JSON. -
docs/MCP_TOOLS.mdis regenerated. - The tests run offline and dispatch no real command that reaches a network or cluster.
-
changelog.d/997.mdlists renamed tools under### Changed.CHANGELOG.mdis not edited. -
uv run devops cipasses. - (person-run) Claude Code connected to
devops mcp servelists the tools, andreview_findings,k8s_statusandpr_check_readinessreturn the same output as their commands.
Key questions
- Which commands are exposed: every command, or an allow-list per group? (proposed) An allow-list held as data next to the generator, seeded from the 147 commands dispatched today, so exposure does not change in this PR. Some commands are interactive (
ai chat, the TUI dashboard,--watch) or long-running, and feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857 puts mutating tools behind approval, so exposure stays a decision. - How are feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857's
ToolAnnotations(readOnlyHint) derived: from the read-only/mutating classification chore(cli): every argument-taking--dry-runcommand path is recorded as read-only or mutating, one candidate per offender #986 records? (proposed) From the table's read-only column, seeded from feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857's classification. chore(cli): every argument-taking--dry-runcommand path is recorded as read-only or mutating, one candidate per offender #986 records which--dry-runpaths are read-only, a different question, and is unscheduled. This item lands after feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857. - Does every exposed command have a result model to return (feat(cli): output format adoption across the command surface #411), or do some still return text? (proposed) Some still return text. A tool returns JSON where the command has
--format json(21 tools ask for it today) and text otherwise. feat(cli): output format adoption across the command surface #411 changes the commands, and the bridge then returns their JSON without further change. - How does fix(ai): mcp command tools return the failing output and never write to the protocol stream #839's contract carry into the generated tools? (proposed) It lives in the one dispatcher every generated tool calls, so this item lands after fix(ai): mcp command tools return the failing output and never write to the protocol stream #839 and adds the per-tool test above.
- Are tool names taken from the command path? (proposed) Yes, the command path joined with
_. 83 of today's 146 names change; the changelog lists them, with no aliases, under the pre-1.0 policy.
Update 2026-10-08: refinement
The premise holds (157 tools; register_handler uncalled, ai/mcp/dispatcher.py:282). #839 shipped; this still lands after #857. #1330 owns deleting the mock branch (ai/mcp/server.py:88) and the patches; whichever lands second rebases the MCP tests. Generated tools keep #1356's deadline.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Linked: #886. Its dry-run class (makes no external request) differs from #857's
readOnlyHint(changes no state); if each command declares both once, this item's generated tools and #886's test read the same data. Found by the 2026-10-08 backlog review.dan-petty commentedon Oct 17, 2026
Moved to v0.2.37: v0.2.37 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
fix(mcp): normalize absolute path defaults to empty string in generat…
refactor(mcp): generate FastMCP tool bridge from Typer app (#997) (#1619
dan-petty commentedon Oct 18, 2026
What changed
#1619, merged into
release/v0.2.37as a48a5fa.30 file(s) changed.
How it was verified
Check runs at 3ad2a75:
Acceptance Criteria of
docs/agent/tasks/task-997-mcp-tool-bridge-from-typer.md:No Acceptance Criteria section.
feat(release): v0.2.37 (#1720)
fix(security): the agent scan tools run the scanner adapters and repo…