Skip to content

AI and MCP: offer only the tools the server allows and say so in the prompt #1667

Backlog

Description

@smart-ssh-planner

Goal

The AI knows what the server allows: on a server without command execution it is told it can only read and write files and gets no command tool; on a server without SFTP it gets no file tools. MCP clients get a clear refusal instead of a hang.

Context

  • Tool list per session: system_prompt::session_action_schemas (crates/app-logic/src/system_prompt.rs:355), called at session_builder.rs:264, stored in SessionContext.available_actions (:431). Unknown tool calls are already rejected (crates/app-logic/src/orchestration/chat_turn.rs:640-645).
  • base_prompt (system_prompt.rs:313-350) is static per language (prompt cache) and tells the AI to use suggest_command. The session system context is built in build_session_system_context (session_builder.rs:96-162): base, allow-rules section, notes, extension section.
  • MCP: McpBackend::propose_action (crates/app-shell/src/mcp_backend.rs:165) and the read/write handlers; tools are static in crates/mcp-server/src/tool_server.rs.
  • WriteRemoteFile falls back to sudo over exec (remote_files.rs:386-451).
  • Capabilities come from the blocking issue (SessionCapabilities).

Requirements

  • exec = false → suggest_command is removed from the session's tool list; a section after the allow-rules section says (all prompt languages): "This server does not allow running commands. You can only read and write files with read_remote_file and write_remote_file." The static base prompt stays unchanged.
  • sftp = false → read_remote_file and write_remote_file are removed; the section says: "This server offers no file access (SFTP). You can only propose commands."
  • Both capabilities available → tool list and prompt byte-identical to today.
  • exec = false → the sudo fallback of WriteRemoteFile is not attempted; the write fails with the original SFTP error.
  • A proposed action of a removed kind (chat or MCP) ends as ActionOutcome::Failed with a message naming the missing capability, before filter evaluation and before any confirmation dialog.
  • MCP propose_command on such a session returns that failure; read_remote_file/write_remote_file likewise when sftp = false.

Acceptance Criteria

  • Session with exec=false: tool list without suggest_command, prompt contains the files-only section (test per prompt language).
  • Session with sftp=false: tool list without the file tools, prompt contains the commands-only section.
  • Session with all capabilities: tool list and system context identical to before (snapshot test).
  • Chat: a suggest_command on an exec=false session fails with the capability message; no confirmation dialog, no filter call (test).
  • MCP: propose_command on an exec=false session returns the failure (test); file tools on sftp=false likewise.
  • WriteRemoteFile with exec=false and a permission error does not try sudo (test).
  • Relevant automated tests pass

Technical Notes

  • Security-critical: the action path (handle_action_proposed, evaluate_action, crates/app-logic/src/orchestration/action_exec/propose.rs:42,922) – the capability check is an early refusal before the filter; it never changes the result of FilterEngine::evaluate() and never lets an action skip approval. MCP actions still always need confirmation (invariant test(app-logic): descriptive event-wait assertions in chat_turn tests #3).
  • Keep the static base prompt unchanged (cache).

Files: crates/app-logic/src/system_prompt.rs, crates/app-logic/src/connect/session_builder.rs, crates/app-logic/src/orchestration/action_exec/propose.rs, crates/app-logic/src/orchestration/remote_files.rs, crates/app-shell/src/mcp_backend.rs, docs/specs/0020-sftp-file-transfer.md, docs/specs/0028-mcp-server-integration.md, changelog.d/

Spec impact: update 0020

Open questions

  • Capability message text for refused actions: reuse an existing error code family (ACTION_*) or a new ACTION_CAPABILITY_MISSING. Recommendation: new code, documented in spec 0028.

Related Work

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