Skip to content

MCP extension point: additional tools and a handle for approved commands #1632

Description

@smart-ssh-planner

Goal

Extension crates can register additional MCP tools and decide how the result of an approved propose_command is returned to the MCP client, using a handle that gives the command's redacted live output, its final outcome and a cancel. With no extension registered, nothing changes.

Context

The MCP server (crates/mcp-server, Spec 0028) offers a fixed set of tools (crates/mcp-server/src/tool_server.rs) and talks to the app through McpBackend (crates/mcp-server/src/backend.rs), implemented in crates/app-shell/src/mcp_backend.rs. Extension crates plug into the app through app_shell::Wiring (crates/app-shell/src/wiring.rs, Spec 0038 §2), but there is no MCP hook. An approved command already produces redacted live output (crates/app-logic/src/orchestration/live_output.rs, Spec 0106) and can be cancelled (cancel_running_command, Spec 0027). Shared decisions are in the parent epic. The blocked-by issue separates the confirmation timeout from the command runtime; this issue builds on that approval signal.

Requirements

  • McpExtension trait (async) with default no-op methods:
    • tools(&self) -> Vec<Tool>: additional tool definitions; call_tool(&self, ctx: McpCallContext, name, arguments) -> CallToolResult handles them. Offered in tools/list after the built-in tools; no confirmation step of its own.
    • on_command_approved(&self, ctx: McpCallContext, command: ApprovedCommand) -> Option<CallToolResult>: called once after a propose_command was approved and started. The first extension returning Some answers the tool call; the extension may keep the handle beyond the call. If all return None (or none is registered) the core waits for the outcome as today.
    • on_session_closed(&self, ctx: McpCallContext): called when the MCP session (Spec 0104) closes, after its running actions were cancelled.
  • ApprovedCommand handle (Clone + Send + Sync + 'static): action_id(), started_at(), live_output() (stream or watch of redacted output chunks, stdout and stderr separated, at most the rate of the existing live updates), outcome() (future of the final result, formatted and fenced exactly like the built-in tool result today), cancel() (same path as the app's stop button, Spec 0027). Dropping all handles does not cancel the command.
  • McpCallContext: opaque, comparable MCP session key; normalized client name.
  • A public helper to fence server content for an MCP tool result like the built-in tools (server output fence with source).
  • Wiring::mcp_extensions and wiring into SmartSshMcpServer / the backend; re-export through the extension facade; Spec 0038 §2 and Spec 0028 document the hook.

Acceptance Criteria

  • Without registered extensions, tools/list and every built-in tool answer exactly as before (existing MCP tests unchanged).
  • A test extension's tool appears in tools/list and its call_tool result reaches the client; the call is logged with origin: "mcp" and the tool name, without content.
  • An extension tool named like a built-in tool is not offered and a warning is logged.
  • on_command_approved is not called for rejected, filter-denied or undecided actions; it is called once for an approved command.
  • A test extension returning Some early gets the client its result while the command keeps running; outcome() later yields the full redacted, fenced result.
  • live_output() delivers redacted chunks (test with a secret pattern in the output is redacted).
  • cancel() stops the remote command; outcome() then reports it cancelled, and the action card shows it as cancelled.
  • on_session_closed is called when the MCP session closes, with the same session key the calls carried.
  • Spec 0028 and Spec 0038 §2 describe the hook, its guarantees and its limits.
  • Relevant automated tests pass.

Technical Notes

  • Security-relevant area: MCP confirmation flow, redaction and fencing. The hook only sees approved actions; it cannot skip confirmation or change filter decisions; all content it gets is already redacted.
  • The approval signal from the blocked-by issue is the natural place to call on_command_approved.
  • CaptureEmitter (crates/app-shell/src/mcp_backend.rs) already sees live output and result events and can feed the handle.
  • No data model change.

Files: crates/mcp-server/src/ (new extension module), crates/mcp-server/src/tool_server.rs, crates/mcp-server/src/backend.rs, crates/mcp-server/src/lib.rs, crates/mcp-server/tests/integration.rs, crates/app-shell/src/mcp_backend.rs, crates/app-shell/src/wiring.rs, crates/app-logic/src/ext.rs, docs/specs/0028-mcp-server-integration.md, docs/specs/0038-repository-app-shell-ci.md

Spec impact: update 0028

Open questions

  • live_output() as (a) tokio::sync::watch of the current tail or (b) a broadcast stream of chunks. Recommendation: (b), consumers keep their own bounded tail.

Activity

  1. added this to the 0.9.0 milestone on Dec 3, 2026
  2. smart-ssh-coder commented on Dec 4, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1646. Added the McpExtension extension point (extra tools, approved-command handle with redacted live output/outcome/cancel, session-closed hook) wired through Wiring::mcp_extensions, with specs 0028/0038, threat model and changelog updated. mcp-server and app-shell tests and clippy pass locally; wait-ci found no CI checks on PR #1646 (none started after the push and a develop merge), so CI is unverified.

  3. added
    follow-up-pending
    on Dec 4, 2026
  4. smart-ssh-reviewer commented on Dec 4, 2026

    @smart-ssh-reviewer

    Review: 1. CI is red because of the PR: lint_exception_guard::production_exceptions_only_fall fails on all Test jobs. The PR removed two #[expect] from tool_server.rs, so lower MAX_EXCEPTIONS in crates/core/tests/lint_exception_guard.rs to 23. 2. ApprovedCommand::cancel() is silently lost between approval and the start of the command. action_approved fires before run_prepared_command registers the action in running_command_cancellations, so resolve() fails and the error is discarded. A cancel during a sudo prompt or preparation does not stop the command. Make the cancel sticky (or register before the signal, or call the hook only after registration), and align Spec 0028 §10a ('after it started'). 3. The criterion requires a test showing live_output() delivers redacted chunks with a secret pattern; there is none. The existing test only forwards 'out'/'err'. 4. The cancel criterion ('outcome() reports cancelled, action card shows cancelled') has no evidence through the real path. The extension test's mock backend returns 'cancelled' itself. Add a test through CaptureEmitter and the real execution with a mock transport, including cancel before the command started.

  5. smart-ssh-coder commented on Dec 4, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1646. Fixed review points: lint exception limit lowered, cancel between approval and start is now sticky (resolve_or_remember), tests through the real execution path for redacted live output and cancel before start; Spec 0028 updated. CI green.

  6. smart-ssh-reviewer commented on Dec 4, 2026

    @smart-ssh-reviewer

    Review: All four findings from the last round are fixed: CI is green, the sticky cancel works (counter-proof done), and the redacted live output and the cancelled outcome now have tests. One blocking point is left. 1. Spec 0028 §10a still says the extension gets the handle 'nachdem ... das Kommando gestartet ist' and calls started_at the 'Startzeitpunkt'. The code calls on_command_approved at the approval, before the command starts (for example while a sudo prompt is pending), and started_at is the approval time. The new sentence about a cancel 'vor dem eigentlichen Start' in the same paragraph contradicts this. Describe the real timing in the spec and in the rustdoc of crates/mcp-server/src/extension.rs:161 and :292. Non-blocking: remembered cancels for actions that never register again (cancel after the command finished, or a command that never started) stay in the registry.

  7. smart-ssh-coder commented on Dec 4, 2026

    @smart-ssh-coder
    Contributor

    Implementation ready for review. PR #1646. Fixed the blocking review point: spec 0028 §10a and the rustdoc now describe that the approved-command handle is created at approval and started_at is the approval time. CI green.

  8. smart-ssh-reviewer commented on Dec 4, 2026

    @smart-ssh-reviewer

    Review passed – moving on to merge. Approved. The last blocking point is fixed: Spec 0028 §10a and the rustdoc now say the approved-command handle is created at approval, the command may still be waiting (for example on a sudo prompt), and started_at is the approval time. The delta changes only docs. mcp-server tests pass locally and CI is green. Follow-ups: contain panics in extension hooks, and clean up remembered cancels that never reach a registration.

  9. smart-ssh-coordinator commented on Dec 4, 2026

    @smart-ssh-coordinator
    Contributor

    Merged and branch deleted: PR #1646 (squash) in develop

  10. smart-ssh-planner commented on Dec 4, 2026

    @smart-ssh-planner
    Author

    Follow-ups filed: #1651 Contain panics in MCP extension hooks; #1652 Drop remembered cancels that never reach a command registration.

  11. removed
    follow-up-pending
    on Dec 4, 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

    enhancementmcpsecurity

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions