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

> Source: <https://dev.to/kangchanghwan/from-a-headless-linux-server-to-a-browser-room-a-terminal-cli-and-mcp-server-bundled-from-my-web-39ep>
> Published: 2026-12-02 23:05:43+00:00

**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 the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

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`:

``` 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:

``` js
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`:

``` js
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.
