Checking Support
Before attempting to use terminal methods, Agents MUST verify that the Client supports this capability by checking the Client Capabilities field in theinitialize
response:
terminal
is false
or not present, the Agent MUST NOT attempt to call any terminal methods.
Executing Commands
Theterminal/create
method starts a command in a new terminal:
The Session ID for this request
The command to execute
Array of command arguments
Environment variables for the command.Each variable has:
name
: The environment variable namevalue
: The environment variable value
Working directory for the command (absolute path)
Maximum number of output bytes to retain. Once exceeded, earlier output is
truncated to stay within this limit.When the limit is exceeded, the Client truncates from the beginning of the output
to stay within the limit.The Client MUST ensure truncation happens at a character boundary to maintain valid
string output, even if this means the retained output is slightly less than the
specified limit.
terminal/wait_for_exit
method to wait for the command to complete.
The Agent MUST release the terminal using
terminal/release
when it’s no
longer needed.Embedding in Tool Calls
Terminals can be embedded directly in tool calls to provide real-time output to users:Getting Output
Theterminal/output
method retrieves the current terminal output without waiting for the command to complete:
The terminal output captured so far
Whether the output was truncated due to byte limits
Present only if the command has exited. Contains:
exitCode
: The process exit code (may be null)signal
: The signal that terminated the process (may be null)
Waiting for Exit
Theterminal/wait_for_exit
method returns once the command completes:
The process exit code (may be null if terminated by signal)
The signal that terminated the process (may be null if exited normally)
Killing Commands
Theterminal/kill
method terminates a command without releasing the terminal:
terminal/output
to get the final outputterminal/wait_for_exit
to get the exit status
terminal/release
when it’s done using it.
Building a Timeout
Agents can implement command timeouts by combining terminal methods:- Create a terminal with
terminal/create
- Start a timer for the desired timeout duration
- Concurrently wait for either the timer to expire or
terminal/wait_for_exit
to return - If the timer expires first:
- Call
terminal/kill
to terminate the command - Call
terminal/output
to retrieve any final output - Include the output in the response to the model
- Call
- Call
terminal/release
when done
Releasing Terminals
Theterminal/release
kills the command if still running and releases all resources:
terminal/*
methods.
If the terminal was added to a tool call, the client SHOULD continue to display its output after release.