Skip to main content
Glama

ssh_session_exec

Destructive

Executes a command in an existing SSH session, returning stdout, stderr, and the exit code while revalidating signer policy, target access, sudo, and PTY constraints before running it.

Instructions

Execute a command in a session opened with ssh_session_open. Returns stdout, stderr and exit_code. exit_code != 0 means remote command failure, NOT a tool error. The command is preflighted against the current signer policy before execution; target and bastion access, end-user groups, sudo, sudo_user, PTY, and the host's physical route are revalidated, and audit-mode policy warnings are returned in warnings. If a policy is enabled after a shell/pty session was opened, later commands in that session are rejected. Session state (current directory, environment variables) persists across calls when mode=shell or mode=pty. In mode=pty a command is limited to 4000 bytes (tty line limit); longer commands are rejected, so use mode=exec or split them. In mode=pty a command may contain printable text only; control bytes, tab included (the tty line discipline or readline completion would edit the line before the shell runs it), are rejected.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "session_id": "<session_id>",
      "command": "<command>"
    },
    "name": "ssh_session_exec"
  }
}

Input Schema

NameRequiredDescriptionDefault
commandYescommand to execute in the session
session_idYesid returned by ssh_session_open

Output Schema

NameRequiredDescriptionDefault
serialYesaudit identifier; ignore when reasoning about the result
stderrYeserror output of the remote command (empty when pty=true, since stdout and stderr are merged)
stdoutYesstandard output of the remote command
decisionNopresent only on a dry_run: the policy decision (allow/deny/approval) with a machine-readable reason_code, instead of executed output
warningsNoadvisory warnings; command_policy audit-mode warnings mean the command was allowed but would have been blocked or approval-gated in enforce mode
exit_codeYesexit code of the remote command: 0=success, non-zero=command failure (NOT a tool error)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv3.1.2
  2. Removedv3.0.1
  3. Changed1 schema field changedv2.0.0
    • addedOutput schema / properties / decision
      Added value: +{
      +  "additionalProperties": false,
      +  "description": "present only on a dry_run: the policy decision (allow/deny/approval) with a machine-readable reason_code, instead of executed output",
      +  "properties": {
      +    "allowed": {
      +      "description": "whether the command would be authorised",
      +      "type": "boolean"
      +    },
      +    "enforcement": {
      +      "description": "effective command_policy enforcement mode (enforce or audit)",
      +      "type": "string"
      +    },
      +    "force_command": {
      +      "description": "the force-command that would be baked into the certificate",
      +      "type": "string"
      +    },
      +    "matched_rule": {
      +      "description": "the command_policy rule that drove the decision, e.g. 'deny:^rm ' or 'allowlist:no-match'",
      +      "type": "string"
      +    },
      +    "reason": {
      +      "description": "human-readable explanation of a denial (empty when allowed)",
      +      "type": "string"
      +    },
      +    "reason_code": {
      +      "description": "machine-readable outcome: allowed | needs_approval | command_denied | allowlist_no_match | shell_parse_error | denied",
      +      "type": "string"
      +    },
      +    "require_approval": {
      +      "description": "true when the command is allowed but needs out-of-band human approval before it will execute",
      +      "type": "boolean"
      +    },
      +    "ttl_seconds": {
      +      "description": "TTL the issued certificate would carry, in seconds",
      +      "type": "integer"
      +    },
      +    "warning": {
      +      "description": "audit-mode observation: allowed now, but would be blocked or approval-gated in enforce mode",
      +      "type": "string"
      +    },
      +    "would_deny": {
      +      "description": "audit mode only: the command would have been denied in enforce mode",
      +      "type": "boolean"
      +    }
      +  },
      +  "required": [
      +    "allowed",
      +    "reason_code"
      +  ],
      +  "type": [
      +    "null",
      +    "object"
      +  ]
      +}
  4. First observedv1.0.0

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Well beyond the annotations (readOnly=false, destructive=true, idempotent=false), it discloses exit_code != 0 meaning remote failure rather than tool error, the preflight/revalidation of signer policy, target/bastion/group/sudo/PTY/route checks, audit warnings, and post-open policy rejection behavior. It also states session state persistence and the 4000-byte and printable-only pty limits, which are exactly the traps an agent would otherwise hit.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads purpose and return contract, then failure semantics, then policy, then mode-specific limits — a sensible ordering with no filler. The policy sentence is long and packs five revalidated items into one clause, which is dense but each detail is operationally relevant.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive, session-stateful execution tool it covers return semantics, failure interpretation, policy gating, and per-mode limits, and an output schema exists so return shape need not be spelled out. It does not say what happens when session_id is unknown or the session has expired, which is the one operational gap for a stateful tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% and only two flat params exist, so the schema carries the basics (session_id from ssh_session_open, command string). The description nevertheless adds real semantics for the command parameter: the 4000-byte tty cap, the printable-text-only restriction, and that state persists across calls in shell/pty mode.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Execute a command') plus the scope that separates it from siblings: 'in a session opened with ssh_session_open'. It also pins the return contract (stdout, stderr, exit_code), so an agent can tell this apart from ssh_execute or ssh_session_open without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives concrete conditional guidance: long commands should use mode=exec or be split, and pty mode forbids control bytes. It does not explicitly state when to pick this over ssh_execute, but the session-bound framing plus the in-description alternatives make the choice clear for a reader who knows ssh_session_open.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.