Skip to main content
Mole running management commands

Management Commands WebSocket API

Run management commands on remote agents through the mesh. The CLI handles this automatically - this reference is for building custom integrations.

Using the CLI (recommended):

muti-metroo shell abc123 whoami
muti-metroo shell --tty abc123 bash

WebSocket endpoint for custom clients:

ws://localhost:8080/agents/{agent-id}/shell?mode=tty

WebSocket Endpoint​

GET /agents/{agent-id}/shell?mode=tty|stream

Query Parameters​

ParameterValuesDescription
modettyInteractive mode with PTY (default)
streamStreaming mode without PTY

Subprotocol​

The WebSocket uses the muti-metroo-shell subprotocol.

Message Protocol​

The WebSocket uses a binary message protocol. All messages have a 1-byte type prefix followed by the payload. The CLI handles this protocol automatically - you only need to understand it if building custom integrations.

Message Types​

NameDirectionDescription
METAClient → ServerJSON metadata to start session
ACKServer → ClientJSON acknowledgment
STDINClient → ServerKeyboard input (raw bytes)
STDIN_CLOSEClient → ServerStdin EOF; server closes the child's stdin so EOF-sensitive commands (cat, wc, sort, sha256sum) can terminate. No payload.
STDOUTServer → ClientCommand output (raw bytes)
STDERRServer → ClientError output (raw bytes, normal mode only)
RESIZEClient → ServerTerminal resize notification
SIGNALClient → ServerSignal to send (e.g., SIGINT)
EXITServer → ClientProcess exit code
ERRORServer → ClientJSON error message

Session Flow​

1. Connect​

WebSocket: ws://localhost:8080/agents/abc123/shell?mode=tty
Subprotocol: muti-metroo-shell

2. Send Metadata (META)​

First message must be META with session configuration:

{
"command": "bash",
"args": ["-l"],
"env": { "TERM": "xterm-256color" },
"work_dir": "/home/user",
"tty": {
"rows": 24,
"cols": 80,
"term": "xterm-256color"
},
"timeout": 3600,
"auth": {
"origin_agent": "...",
"target_agent": "...",
"timestamp": 1745193600,
"signature": "..."
}
}
FieldTypeDescription
commandstringCommand to execute (required)
argsstring[]Command arguments
envobjectAdditional environment variables
work_dirstringWorking directory
ttyobjectTTY settings (for interactive mode)
tty.rowsnumberTerminal rows
tty.colsnumberTerminal columns
tty.termstringTERM value (default: xterm-256color)
timeoutnumberSession timeout in seconds
authobjectManagement-key signature (normally filled in by the gateway agent on the client's behalf -- see Authentication)

3. Receive Acknowledgment (ACK)​

{
"success": true
}

If success is false, the session failed to start.

4. Data Exchange​

After ACK, send and receive data:

  • STDIN: Send keyboard input as raw bytes
  • STDIN_CLOSE: Signal stdin EOF when piping data from a finite source (cat file | muti-metroo shell ... wc -l). The server closes the child process's stdin so the command can exit.
  • STDOUT: Receive command output
  • STDERR: Receive error output (normal mode only)
  • RESIZE: Send terminal size changes
  • SIGNAL: Send signals (e.g., SIGINT = 2)

5. Session End​

The server sends EXIT with the exit code, then closes the WebSocket.

Error Handling​

ERROR Message​

{
"message": "command not allowed"
}

Sent when:

  • Command not in whitelist
  • Authentication failed
  • Session limit reached
  • Other server errors

WebSocket Close Codes​

CodeReason
1000Normal closure
1002Protocol error
1011Internal error

Custom Client Integration​

For custom integrations, refer to the binary protocol implementation. The message format uses a 1-byte type prefix:

Type ByteMessage
0x01META
0x02ACK
0x03STDIN
0x04STDOUT
0x05STDERR
0x06RESIZE (4 bytes: rows, cols as uint16 BE)
0x07SIGNAL (1 byte: signal number)
0x08EXIT (4 bytes: exit code as int32 BE)
0x09ERROR
0x0aSTDIN_CLOSE (no payload)

For a complete implementation example, see the CLI source code in the project repository.

See Also​