Minimal Model Context Protocol server for interacting with already opened PuTTY windows on Windows.
The server exposes 5 tools: list windows, read terminal output, send commands, clear scrollback, and chunked file upload.
| Tool | Description |
|---|---|
putty_list_windows |
List visible PuTTY windows with title and PID |
putty_read_window |
Read full text (screen + scrollback) from a selected PuTTY window |
putty_send_command |
Send text to a selected PuTTY window (optionally with Enter) |
putty_clear_window |
Clear scrollback/history in a selected PuTTY window |
putty_upload_text |
Upload long text/data to a remote path via short printf chunks |
When several PuTTY windows are open, pass one of these selectors to putty_read_window, putty_send_command, and putty_clear_window:
| Parameter | Description |
|---|---|
process_id |
PID from putty_list_windows (most reliable) |
host |
Substring matched against window title (case-insensitive) |
title_substring |
Same as host; alternative name for title matching |
If exactly one PuTTY window is open, the selector is optional.
putty_send_command
command(required) — text to sendappend_newline(default:true) — append Enter after the command
putty_upload_text
content(required) — payload to write remotelyremote_path(required) — destination path on the remote hostencoding—shell(default, UTF-8 text) orhex(binary-safe, no remotebase64)chunk_size— optional override; keep resulting shell lines under ~480 charsverify(default:true) — check remote size withwc -c
putty_read_window, putty_clear_window, putty_send_command, putty_upload_text
process_id,host, ortitle_substring— see Window selection
- Call
putty_list_windows. - Pick a window by
process_id(preferred) ortitle_substring. - Optionally call
putty_clear_windowto remove old scrollback before reading. - Call
putty_send_command. - Wait 1–2 seconds.
- Call
putty_read_windowto get the command output.
For AI agents, see AGENTS.md for selection rules, diagnostic markers, and context-reduction tips.
- Python 3.10+
- Windows
pywin32andmcp[cli](see Installation)- One or more PuTTY GUI windows already open (
putty.exe)
git clone https://github.com/pekishev/putty-mcp.git
cd putty-mcp
pip install -r requirements.txtOr install from pyproject.toml:
pip install .Example MCP server entry for Cursor or other MCP clients:
{
"mcpServers": {
"putty": {
"command": "python",
"args": ["C:/path/to/putty-mcp/putty_mcp.py"]
}
}
}Use the absolute path to putty_mcp.py on your machine.
- Read — sends PuTTY system command Copy All to Clipboard (
IDM_COPYALL) viaPostMessage, reads the clipboard, then restores the previous clipboard content. - Send — resolves the target window and delivers text primarily via clipboard paste (
IDM_PASTE). This avoids mid-line truncation of long shell commands that happened with per-characterWM_CHARstreams. Control characters (e.g. Ctrl+C) still useWM_CHAR. Messages are posted to the PuTTY hwnd, so a background or maximized window stays where it is: it is not restored, raised, or focused. - Upload — for payloads beyond the remote tty line limit (~400–500 chars), writes the file with many short
printfappends (shellor binary-safehexencoding) and optionally verifies size withwc -c. - Clear — sends PuTTY Clear Scrollback (
IDM_CLRSB) via system menu command ID; works regardless of UI locale.
PuTTY windows are detected by process name (putty.exe), not by window title alone.
All tools return JSON objects with a success field.
Examples:
putty_list_windows→{ "success": true, "windows": [{ "title": "...", "pid": 1234 }], "count": 1 }putty_read_window→{ "success": true, "content": "...", "window_title": "..." }putty_send_command→{ "success": true, "window_title": "...", "command_sent": "...\n", "activated": false, "delivery": "paste" }putty_upload_text→{ "success": true, "remote_path": "/tmp/x", "bytes": 2500, "chunks_sent": 21, "encoding": "shell" }putty_clear_window→{ "success": true, "window_title": "...", "message": "PuTTY scrollback was cleared." }
On errors, responses include error and, when relevant, a windows list to help pick the right target.
putty_send_commandconfirms that text was sent; it does not return command stdout. Read output withputty_read_window.- For content longer than ~400–500 characters, use
putty_upload_textinstead of one giantputty_send_command(remote tty line limit). - Prefer
process_idover title matching when multiple sessions are open. activatedreports whether that PuTTY window was already in the foreground. The tool does not change window size, z-order, or focus. A minimized window stays minimized and still receives the command.- Before diagnostics, use
putty_clear_windowor marker commands (echo DIAG_START/echo DIAG_END) to reduce noise in long scrollback.
putty_mcp.py # MCP server entry point (FastMCP, stdio transport)
putty_lib/
window_reader.py # List/read PuTTY windows
window_send.py # Send commands and clear scrollback
window_upload.py # Chunked remote file upload via printf
- Windows only (
pywin32required). - Works with existing PuTTY GUI windows; the server does not create SSH sessions.
- Only
putty.exewindows are supported (not KiTTY, PuTTYtel, or other forks unless they use the same executable name). - Reading depends on PuTTY responding to Copy All to Clipboard.
MIT