Skip to main content
Glama

Run a command in a session

terminal_exec

Execute commands in an existing persistent shell session, wait for completion, and return output plus exit code. Use it for multi-step work while preserving working directory and environment.

Instructions

Type a command into an existing session, wait for it to finish and return its output and exit code. The session keeps its working directory and environment, so use this for multi-step work. Waits up to 2 minutes by default. Set waitForCompletion to false for interactive programs or long-running servers.

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": {
      "id": "<id>",
      "command": "<command>"
    },
    "name": "terminal_exec"
  }
}

Input Schema

NameRequiredDescriptionDefault
idYesSession id (for example "term_1a2b3c4d") or the friendly name given at spawn time.
rawNoReturn raw output with ANSI escapes. Default false.
idleMsNoConsider the command finished after this many ms without new output. Default 400.
commandYesCommand line to execute in the session shell.
timeoutMsNoMaximum time to wait in milliseconds. Default 120000 for terminal_exec, 15000 for terminal_write, 30000 for terminal_run.
waitForCompletionNoWait for the command to finish and report its exit code. Default true. Set false for REPLs, prompts or servers that keep running.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.2.0

TDQS

A4/5.0
Behavior4/5

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

Annotations already cover mutability, open-world reach and idempotency, so the description adds value with state persistence (working directory and environment survive across calls) and the default 2-minute wait. It does not discuss failure modes (timeouts, non-zero exits) in depth, which keeps it short of a 5.

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

Conciseness5/5

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

Three sentences, front-loaded with the core action, then the persistence rationale, then the escape hatch for interactive programs. No redundant wording.

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?

With 6 parameters at full schema coverage and no output schema, the description supplies what an agent needs: return values are named (output and exit code), timeouts are stated, and the interactive-program escape hatch is flagged. Only edge behavior on timeout or failure is left unaddressed.

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

Parameters3/5

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

Schema coverage is 100%, so the baseline is 3. The description reinforces waitForCompletion semantics and the default timeout, but the schema descriptions already say those things, so little meaning is added beyond structured data.

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

Purpose4/5

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

States a specific verb and resource: types a command into an EXISTING session, waits, and returns output and exit code. The word 'existing' implicitly separates it from spawn-style siblings, though no sibling is named explicitly.

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 usage context ('use this for multi-step work' because cwd/env persist) and a clear when-not via 'Set waitForCompletion to false for interactive programs or long-running servers.' No sibling is named, but the conditions that select this tool versus a spawn/run path are stated.

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