
swampcy
swampcy gives a coding agent a Linux desktop it can see and use. It is an MCP server, spoken
over stdio, that drives a headless sway session with no GPU and no
monitor. The agent takes screenshots, clicks, types and starts apps. It can also find an app's
buttons and text fields through the accessibility bus (AT-SPI) and press or fill them by name
instead of by pixel.
I wrote it because the computer-use tools coding agents ship with are for macOS, and the Linux
ones that work without a GPU are X11. It runs on a VM the agents work in, and I watch it from
my phone with swampcy web.
What it needs
- Linux, and sway run headless (
WLR_BACKENDS=headless WLR_RENDERER=pixman sway), with an
output of the size you want screenshots at. examples/ has a sway config and
systemd user units for it.
grim, for screenshots
at-spi2-core, for the widget tools
img2webp (libwebp) or ffmpeg, for the replay tool's clips
- for
swampcy web: Tailscale with HTTPS certificates on, and libaom
(AV1) or OpenH264 (H.264) as shared libraries, on x86-64 or arm64. swampcy loads them at run
time and needs no cgo; without them the MCP server still works.
The pointer and keyboard are swampcy's own: it holds a virtual pointer and keyboard on sway's
seat, because a headless seat has none and apps ignore input without them, and it types on
that keyboard. With several seats or outputs, -seat (default seat0) and -output (default
the top-left one) say which it joins and sees.
Install
go install github.com/nabkey/swampcy@latest
claude mcp add --scope user swampcy -- ~/go/bin/swampcy
Any MCP client that runs a stdio server works the same way. swampcy finds the session from
SWAYSOCK and WAYLAND_DISPLAY, or from the sockets in $XDG_RUNTIME_DIR when there is
exactly one sway. Start apps with its launch tool, so they get the display and accessibility
switched on.
| Tool |
|
screenshot, zoom |
the whole screen, or a region magnified |
click, move, drag, scroll |
the pointer, in screenshot pixels; modifiers for ctrl- and shift-clicks |
mouse_down, mouse_up |
a button held across other steps |
type, key |
any Unicode text; keys and shortcuts like ctrl+s, repeated or held |
clipboard_get, clipboard_set |
the clipboard's text |
windows, focus_window, move_window, close_window, launch |
sway's windows, and starting apps |
accessibility_tree, find_elements |
widgets, each with a ref like e12; popups and off-screen ones too |
click_element, set_text, get_text, set_value, scroll_to |
act on a widget by ref |
wait, wait_for |
until a widget or a window is there, or gone |
site_settings, set_site_settings |
where swampcy acts as a person would, site by site |
batch |
several of the above in one call |
replay |
an animated clip of what the agent did, saved under -replay-dir |
Every tool that acts takes screenshot: true, which waits for the screen to stop changing and
returns it with the result, so seeing what a click did is not a second call.
swampcy can move, click and type as a person's hand would: the pointer travels a bowed,
wavering path, sometimes runs past its target and comes back, and lands a pixel or two off;
buttons and keys are held for a moment; typing is at a person's uneven pace, with the odd
wrong letter noticed and backspaced. click_element, set_text, scroll_to and set_value
then use the pointer, wheel and keys too, where otherwise they ask the app over the
accessibility bus. It is for sites that balk at input no hand could make, and for testing
your own UI with the events real users send (hover, motion, each key in turn). Typing takes
about a fifth of a second a character.
It is one switch, and it is kept per site in ~/.config/swampcy/sites.json (-sites), which
the agent reads with site_settings and changes with set_site_settings:
{ "as_human": { "amazon.com": true, "localhost:3000": false } }
A site covers its subdomains, the most specific one wins, and "*" is every site with no
setting of its own. Where no setting says, -as-human decides (off by default), and
as_human on a call overrides both for that call. swampcy knows a window's site from the
address its browser gives the accessibility bus. How it works.
Coordinates are always pixels of swampcy's screenshots, which are scaled to at most 1568 on the
long edge (-max-edge); swampcy converts them to the screen's.
Watching: swampcy web
swampcy web serves the desktop to a browser, phone included: the screen as AV1 or H.264 over
WebRTC, encoded only when something on it changes, and your pointer, touch and keyboard sent
back. With a second output and seat in sway's config it also gives you a desktop of your own
beside the agents', and windows can move between the two.
swampcy web -login you@example.com -origin https://box.example.ts.net:8443
sudo tailscale serve --bg --https=8443 http://127.0.0.1:7682
It listens on loopback only and lets in the one Tailscale login given, trusting the
Tailscale-User-Login header that tailscale serve sets; the video goes over UDP 7683 on the
machine's Tailscale address. It assumes a single-user machine: anything that can reach its
loopback port can claim to be you.
What doesn't work yet
- libaom's and OpenH264's structs are laid out by hand from their headers (libaom v3.13.3,
OpenH264 v2.6.0), and a library update that moves one makes swampcy refuse to encode until it
is updated. Both work on x86-64 and arm64 Linux.
- One login, one viewer. A second browser tab ends the first.
- Chrome binds only the first seat, so while you type into Chrome on your own desktop, an
agent's keys go there too. Electron apps have the same problem and are not matched by
default; add them to
-single-seat-apps.
- sway only. Another compositor would need its own seat, output and input handling.
- Restarting sway closes every app on both desktops.
The full list is at the end of docs/design.md.
Good to know
- GTK 4 reports its widgets' positions a few pixels off.
click_element performs a widget's
action instead of clicking where GTK says it is.
- Several swampcy servers on one seat take turns: a lock file in
$XDG_RUNTIME_DIR/swampcy
keeps one agent's clicks and keys from landing between another's. They still share one
screen and one focus.
- GTK buttons act on a click 250 ms late and ignore another press until then, so
click_element waits 300 ms after a click in a GTK app before it returns.
- The apps run as you. A browser signed in on swampcy's screen lets every agent with swampcy act
as you on those sites; sign in only to what you would hand the agent anyway.
- swampcy itself opens no network port. If you run a VNC server instead of
swampcy web, keep
it on loopback.
Why it is built this way: docs/design.md. How it behaves:
docs/spec.md and, for the browser viewer, docs/web.md.
License
MIT