NuttX NSH MCP Server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
NuttX NSH MCP Server
An MCP (Model Context Protocol) server that allows AI agents to interact with a NuttX NSH (NuttShell) over a serial connection. The server exposes NSH as a set of MCP tools, providing clean text output free of escape sequences — ideal for LLM consumption.
Features
Serial connection to NuttX boards via
/dev/ttyUSBx,/dev/ttyACMx, or any serial portVT100/ANSI escape sequence handling via the pyte terminal emulator — raw escape codes are processed internally and never leak to the AI agent
Clean text output for AI agents — no escape characters, no garbled control sequences
Virtual TTY for human monitoring — a pseudo-terminal (
/dev/pts/X) is created so a human can connect withpicocom,screen, orminicomand observe (or interact with) the session in real timeTerminal control signals — Ctrl+C, Ctrl+D, Ctrl+Z, and more
Comprehensive key mapping — arrow keys, function keys (F1–F12), Home, End, Page Up/Down, Delete, Tab, Escape, and all Ctrl+letter combinations
Concurrent access — the AI agent and a human can interact with the NuttX board simultaneously
Related MCP server: coserial
Installation
cd nuttx-nsh-mcp
pip install -e .This installs the package in editable (development) mode along with its dependencies:
Dependency | Purpose |
| Model Context Protocol SDK |
| Serial port communication |
| VT100/ANSI terminal emulator |
Requirements: Python ≥ 3.10
MCP Configuration
Claude Desktop / Cline / Generic MCP Client
Add the following to your MCP client configuration (e.g. claude_desktop_config.json or Cline MCP settings).
Using uv (recommended — handles virtualenv and dependencies automatically):
{
"mcpServers": {
"nuttx-nsh": {
"command": "uv",
"args": ["run", "--directory", "/path/to/nuttx-nsh-mcp", "nuttx-nsh-mcp"],
"env": {
"NUTTX_NSH_LOG_LEVEL": "INFO"
}
}
}
}Replace
/path/to/nuttx-nsh-mcpwith the actual absolute path to thenuttx-nsh-mcpdirectory on your system.uvwill automatically create an isolated virtualenv, install dependencies, and run the server.
Alternative — using full path to Python (explicit virtualenv):
{
"mcpServers": {
"nuttx-nsh": {
"command": "/path/to/nuttx-nsh-mcp/.venv/bin/python",
"args": ["-m", "nuttx_nsh_mcp"],
"env": {
"NUTTX_NSH_LOG_LEVEL": "INFO"
}
}
}
}Available Tools
list_serial_ports
List available serial ports on the system.
Parameters: None
Returns: JSON array of port objects with device, description, and hwid fields.
Example:
list_serial_ports()
→ [
{"device": "/dev/ttyACM0", "description": "STM32 STLink", "hwid": "USB VID:PID=0483:374B"},
{"device": "/dev/ttyUSB0", "description": "CP2102 USB to UART", "hwid": "USB VID:PID=10C4:EA60"}
]connect
Connect to a NuttX board via serial port. After opening the port, the server automatically sends Enter keystrokes until the NSH prompt appears (auto-probe). This handles the common NuttX USB-NSH behaviour where the shell requires a few Enter presses before it shows the prompt.
Parameter | Type | Default | Description |
|
| (required) | Serial port path, e.g. |
|
|
| Baud rate |
|
|
| Send Enter keystrokes until the prompt appears |
|
|
| Timeout in seconds for the auto-probe phase |
Returns: JSON object with connected, port, baudrate, virtual_tty, and prompt_ready fields.
Example:
connect("/dev/ttyACM0", 115200)
→ {"connected": true, "port": "/dev/ttyACM0", "baudrate": 115200,
"virtual_tty": "/dev/pts/5", "prompt_ready": true}
connect("/dev/ttyUSB0", 115200, auto_probe=false)
→ {"connected": true, "port": "/dev/ttyUSB0", "baudrate": 115200,
"virtual_tty": "/dev/pts/6", "prompt_ready": false}disconnect
Disconnect from the current serial port and release all resources.
Parameters: None
Returns: JSON object with disconnected and port fields.
send_command
Send a command to NSH and return the clean output.
The command is sent followed by a carriage return. The tool waits for the NSH prompt to reappear, then returns the output with escape sequences stripped, command echo removed, and trailing prompt removed.
Parameter | Type | Default | Description |
|
| (required) | The shell command to execute |
|
|
| Timeout in seconds to wait for the prompt |
Returns: Clean command output as a string. If the prompt is not detected within the timeout, the partial output is returned with a [TIMEOUT] annotation.
Example:
send_command("free")
→ total used free largest npieces
Umem: 262144 15632 246512 246000 3send_key
Send one or more named keystrokes to the terminal. Supports single keys, space-separated key sequences, and a repeat parameter — so the AI agent can press UP four times in a single MCP call instead of making four separate calls.
Parameter | Type | Default | Description |
|
| (required) | Key name or space-separated sequence of key names (case-insensitive) |
|
|
| Number of times to send the key/sequence |
|
|
| Delay in milliseconds between each individual keystroke |
Supported keys:
Category | Keys |
Control |
|
Navigation |
|
Editing |
|
Function |
|
Examples:
send_key("up") → Sent key: up
send_key("up", repeat=4) → Sent keys: up (×4, 4 keystrokes)
send_key("up up up up") → Sent keys: up up up up (4 keystrokes)
send_key("ctrl_a backspace enter") → Sent keys: ctrl_a backspace enter (3 keystrokes)
send_key("down", repeat=3, delay_ms=50) → Sent keys: down (×3, 3 keystrokes)send_ctrl_c
Send Ctrl+C to interrupt the currently running command.
Parameters: None
Example:
send_ctrl_c()
→ Sent key: ctrl_csend_ctrl_d
Send Ctrl+D (EOF) to the terminal.
Parameters: None
send_raw
Send raw data to the serial port. Supports Python escape sequences like \x1b, \r, \n.
Parameter | Type | Default | Description |
|
| (required) | Raw data string (escape sequences are interpreted) |
Returns: Confirmation with byte count.
get_screen
Get the current terminal screen content as clean text (no escape sequences).
Parameters: None
Returns: The full terminal screen content as a multi-line string.
get_status
Get the current connection status and virtual TTY path.
Parameters: None
Returns: JSON object with connected, port, baudrate, virtual_tty, and prompt_pattern fields.
Example:
get_status()
→ {
"connected": true,
"port": "/dev/ttyACM0",
"baudrate": 115200,
"virtual_tty": "/dev/pts/5",
"prompt_pattern": "nsh>\\s*$"
}set_prompt_pattern
Set the regex pattern used to detect the NSH prompt. The default pattern is nsh>\s*$.
Parameter | Type | Default | Description |
|
| (required) | Regex pattern, e.g. |
Example:
set_prompt_pattern("myboard>\\s*$")
→ Prompt pattern set to: myboard>\\s*$Virtual TTY Monitoring
When a connection is established, the server creates a virtual TTY (pseudo-terminal) that mirrors all serial I/O. This allows a human to observe and interact with the NuttX board in real time alongside the AI agent.
# 1. Connect via the MCP tool — note the virtual_tty path in the response
# e.g. "virtual_tty": "/dev/pts/5"
# 2. Open the virtual TTY with your preferred terminal emulator:
picocom /dev/pts/5
# or
screen /dev/pts/5
# or
minicom -D /dev/pts/5How it works:
Everything the NuttX board sends over serial is mirrored to the virtual TTY
Anything the human types into the virtual TTY is forwarded to the serial port
The AI agent and human can interact simultaneously — both see the same output
Environment Variables
Variable | Default | Description |
|
| Logging level ( |
|
| Terminal columns for the pyte emulator |
|
| Terminal rows for the pyte emulator |
|
| Default regex pattern for prompt detection |
Architecture
┌─────────────┐ ┌──────────────────────────────────────┐
│ │ MCP │ NuttX NSH MCP Server │
│ AI Agent │◄────────►│ │
│ (Claude, │ JSON-RPC│ ┌────────────┐ ┌──────────────┐ │ ┌───────────┐
│ Cline, │ stdio │ │ Terminal │ │ Serial I/O │──┼──────►│ NuttX │
│ etc.) │ │ │ Emulator │ │ (pyserial) │◄─┼──────┤ Board │
│ │ │ │ (pyte) │ └──────────────┘ │ RS232│ (NSH) │
└─────────────┘ │ └────────────┘ │ │ └───────────┘
│ │ ┌─────┴────────┐ │
│ │ │ Virtual TTY │ │
│ │ │ (/dev/pts/X) │ │
│ │ └─────┬────────┘ │
└────────┼──────────────────┼──────────┘
│ │
│ ┌─────┴────────┐
│ │ Human │
│ │ (picocom / │
│ │ screen / │
│ │ minicom) │
│ └──────────────┘
│
Clean text output
(no escape codes)Data flow:
AI → NuttX: AI agent calls MCP tools → server sends bytes over serial → NuttX receives commands
NuttX → AI: NuttX sends output over serial → pyte terminal emulator processes escape sequences → clean text returned to AI
NuttX → Human: Serial data is mirrored to the virtual TTY → human sees raw terminal output
Human → NuttX: Human types in virtual TTY → input forwarded to serial port → NuttX receives it
For a detailed design document covering threading model, data flow, error handling, and design decisions, see ARCHITECTURE.md.
Typical Workflow
A typical AI agent interaction looks like this:
1. list_serial_ports()
→ find /dev/ttyACM0
2. connect("/dev/ttyACM0", 115200)
→ connected, virtual TTY at /dev/pts/5
3. send_command("help")
→ list of NSH built-in commands
4. send_command("ls /dev")
→ directory listing of device nodes
5. send_command("free")
→ memory usage statistics
6. send_command("ps")
→ running tasks/threads
7. send_ctrl_c()
→ interrupt if something hangs
8. disconnect()
→ clean disconnect, resources releasedTroubleshooting
Permission denied on serial port
Error: [Errno 13] Permission denied: '/dev/ttyACM0'Solution: Add your user to the dialout group:
sudo usermod -a -G dialout $USER
# Log out and back in for the change to take effectNo serial ports found
list_serial_ports() returns an empty list.
Possible causes:
USB cable not connected or faulty (try a different cable — some are charge-only)
NuttX board not powered on
Missing USB-to-serial driver (check
dmesg | tailafter plugging in)On WSL: USB devices need to be attached via
usbipdfirst
Command timeout
send_command() returns output with [TIMEOUT after 10s — output may be incomplete].
Possible causes:
The command produces a lot of output — increase the
timeoutparameterThe prompt pattern doesn't match your NuttX configuration — use
set_prompt_pattern()to adjustThe board is unresponsive — try
send_ctrl_c()thenget_screen()to see the current state
Garbled output
Output contains unexpected characters or looks corrupted.
Possible causes:
Baud rate mismatch — ensure the
baudrateparameter matches your NuttX serial configuration (checkCONFIG_UART0_BAUDor equivalent in your NuttX.config)Wrong serial port — you may be connected to a debug port instead of the NSH console
Terminal size mismatch — if output wraps oddly, adjust
NUTTX_NSH_SCREEN_COLSandNUTTX_NSH_SCREEN_ROWS
Virtual TTY not created
The virtual_tty field is null in the connection response.
Possible causes:
The system doesn't support pseudo-terminals (unlikely on modern Linux)
Permission issues with
/dev/ptmx— check permissionsThe server logs (set
NUTTX_NSH_LOG_LEVEL=DEBUG) will show the specific error
License
Licensed under the Apache License 2.0, consistent with the Apache NuttX project.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Remote MCP access to user-authorized Linux, Windows and Intel Mac devices for AI assistants.
Remote MCP server exposing your Node Command fleet (files, shell, processes, browser) to AI hosts.
Remote desktop MCP: let AI see, click, type and run terminal commands on your own Windows or Mac.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI agents to control serial port devices (modems, instruments, embedded boards) via MCP tools for listing ports, connecting, and sending/receiving commands.31MIT
- AlicenseNot gradedqualityDmaintenanceEnables humans and AI agents to collaboratively control serial ports via MCP tools or Web UI, with real-time data sharing across all participants.MIT
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to interact with real terminal sessions across local and remote hosts, driving multi-turn interactive programs like TUIs, REPLs, and SSH prompts through MCP.76MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to interact with serial devices via MCP tools, providing serial port discovery, connection, read/write, and status management, while sharing the same serial connection with a browser-based terminal.3Apache 2.0