cd /news/ai-tools/from-a-headless-linux-server-to-a-br… · home › topics › ai-tools › article
[ARTICLE · art-180598] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

From a Headless Linux Server to a Browser Room: A Terminal CLI and MCP Server Bundled from My Web App's Code

A developer built clipshare, a terminal CLI and MCP server that lets a headless Linux server join the same browser-based Clipboard Share rooms used for file transfer. The CLI imports crypto and folder-diff modules directly from the web app's frontend/src to prevent protocol drift, with esbuild bundling the entry point into a single clipshare.mjs and a two-line vue-shim re-exporting ref from @vue/reactivity to avoid bundling all of Vue. Room keys travel only through SPAKE2, and a systemd user unit keeps folder sync running after the terminal closes.

recommendation

Import shared crypto and state-machine modules from the web app into the CLI rather than reimplementing them, and shim browser-only dependencies like Vue's ref so the bundle stays small and the two sides stay compatible.

more in playbook: Designing agent systems
by read5 min views10 publishedDec 2, 2026

The goal was narrow: send and receive files from a headless Linux server, the kind you only reach over SSH.

Clipboard Share already has rooms on the web. A phone and a PC join the same room and swap files. So the question was simple: can a terminal join that same room? That became clipshare. A file uploaded from the server shows up in the browser room right away.

I built it with Claude Code. I made the design calls and checked the results. The work started with PR #164 (feat/cli), with stages 1 to 3 landing on 2026-11-30 and npm plus MCP on 2026-12-01.

This was the part I cared about most. If I write separate crypto for the CLI, it will drift from the web version, and then the two sides can't open each other's files.

So the CLI imports modules straight from frontend/src. This is the top of share.js:

import { diffFolder } from '../../frontend/src/utils/folderDiff.js'
import { isCopyOfOther } from '../../frontend/src/utils/folderDedupe.js'
import { makeFolderEp, makeFolderEr } from '../../frontend/src/utils/privateFolder.js'
import { ctPartCount } from '../../frontend/src/utils/lockCrypto.js'
import { scanDir, FOLDER_MAX_FILES } from './files.js'
import { uploadLockedFile, contentHash } from './transfer.js'

The catch is browser globals. Anything touching document or window won't run in Node. So I split out the parts that don't need a browser: lockedUploadCore.js, lockedStream.js, identityName.js, receivePath.js and folderDedupe.js. The web app and the CLI use the same files.

esbuild turns the entry point into one file, clipshare.mjs:

await build({
  entryPoints: [path.join(cli, 'src', 'cli.js')],
  outfile: path.join(outDir, 'clipshare.mjs'),
  bundle: true,
  platform: 'node',
  target: 'node18',
  format: 'esm',
  // codeJoin.js only uses vue's ref: alias vue to the reactivity module
  alias: { vue: path.join(cli, 'src', 'vue-shim.js') },
  nodePaths: [path.join(frontend, 'node_modules')],
})

The web codeJoin.js uses ref from Vue. I didn't want all of Vue in a CLI bundle, so vue-shim.js re-exports ref from @vue/reactivity. The file is two lines.

Node 18 has no globalThis.crypto, so the entry file fills it from node:crypto's webcrypto before anything else loads. The web code calls Web Crypto directly, so this keeps it unchanged.

On the web, you join a room by entering four pictures. A terminal has no pictures, so the same code is written as numbers, 00 to 23 per picture:

curl -fsSL clipboardapp.org/c | sh -s 1704-2311

One line installs the CLI and joins. You still have to press "admit" on the web side. The code is single-use and lasts 5 minutes.

codejoin.js is thin. It reuses the web state machine through a small adapter:

import { createCodeJoiner } from '../../frontend/src/services/codeJoin.js'

export function codeAdapter(session) {
  return {
    emit: (event, payload) => session.emitAck(event, payload),
    on: (event, fn) => session.socket.on(event, fn),
    off: (event, fn) => session.socket.off(event, fn)
  }
}

The room key travels only through SPAKE2, so the server never sees it.

I kept the folder rules the same as the web:

share ~/docs uploads a folder and checks for changes every 2 seconds. Dotfiles are skipped, with a cap of 1000 files and depth 8.receive ~/inbox saves room files into the same folder structure. Name collisions become name (1).ext. Downloads go to a .xxxx.clipshare.part temp file and get renamed when done.sync ~/docs runs both in one process. Closing the terminal kills a folder share, so clipshare service install writes a user unit:

clipshare service install --room myroom --sync ~/docs
clipshare service list | status | logs | uninstall

The unit goes to ~/.config/systemd/user/clipshare-<name>.service. At first I followed XDG_CONFIG_HOME, but if you only change it in your shell, systemctl can't find the unit. I pinned the path to ~/.config (commit f6d9915).

To keep it running after logout you need loginctl enable-linger $USER. The CLI doesn't run that for you. Changing system settings behind your back felt wrong.

When I tried to publish, npm rejected clipshare because it's too similar to the existing clip-share. The package is now clipboardapp, and the command is still clipshare (commit 0a16202):

npx clipboardapp join-code 1234-5678

I also had to fix the MCP registry name. mcpName has to match the GitHub account's capitalization: io.github.Kangchanghwan/clipshare (PR #170).

clipshare mcp is a stdio MCP server with JSON-RPC 2.0 written by hand, no SDK. It has five tools: send_file, send_text, list_files, get_file and list_rooms.

The tools don't have their own logic. They call the existing commands with --json:

export function toArgv(name, a = {}) {
  const room = str(a.room) ? ['--room', a.room] : []
  if (name === 'send_file') { if (!str(a.path)) throw new Error('path is required'); return ['send', '--json', ...room, '--', a.path] }
  if (name === 'send_text') { if (!str(a.text)) throw new Error('text is required'); return ['text', '--json', ...room, '--', a.text] }
  if (name === 'list_files') return ['ls', '--json', ...room]
  if (name === 'list_rooms') return ['rooms', '--json']
  return null
}

Reusing the commands the CLI tests already cover means fewer new places to break.

With stdio MCP, stdout is for JSON-RPC only. One stray log line and the client can't parse the stream. So every log goes to stderr:

export async function runMcp({ run, env = process.env, input = process.stdin, output = process.stdout, err = (s) => console.error(s) }) {
  err(`clipshare mcp ${VERSION}: stdio server ready`)
  await createMcpServer({ run, env, log: err }).serve(input, output)
  return 0
}

If no room is saved, a tool call returns an error telling you to run clipshare join-code first.

Registering it in Claude Code is one line:

claude mcp add clipshare -- npx -y clipboardapp mcp

Now I can tell Claude Code to put a server log into a room.

Only things I can confirm from the code and README:

--net (same-network rooms) supports send, list and receive only.cli/server.json is a draft for the official MCP registry. I haven't submitted it.~/.config/clipshare/rooms.json (directory 700, file 600). If that machine is compromised, so are those rooms. The CLI is part of Clipboard Share. I'd like feedback from anyone who tries it, including the "feedback" link at the bottom of the site.

── more in #ai-tools 4 stories · sorted by recency
── more on @clipboard share 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/from-a-headless-linu…] indexed:0 read:5min 2026-12-02 · —