Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
id: 01M797QZADYX1MDFB6KKZ0CFH2
anchor: instructions(app:)
created: 2026-11-13T01:18:23Z
norm: '1'
---

The server instructions mirror githubnext/ace packages/channel/src/desktop.ts guidance; keep the two alike when either changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
id: 01M797QZB7GB6ADBEKXMV8RKAE
anchor: '@file'
created: 2026-11-13T01:18:23Z
norm: '1'
---

The app must keep linking <state>/desktop-client to its bundled client, beside its desktop-tools-mcp: npx launchers pinned to any release since v0.17.0 find the app's server only through that link (#237)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
id: 01M797R1R6VA9K7WETQ00ZKQNQ
anchor: '@file'
created: 2026-11-13T01:18:26Z
norm: '1'
---

--serve must keep working: createDesktop uses it, and npx setups pinned to v0.17.0 through v0.20.0 with --client, --socket or --name run their Node server through it (#237)
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Notable changes to Desktop Tools, newest first. Each release's GitHub release no

### Changed

- `desktop-tools-mcp` from npm (`dist/mcp.js`) is now only a launcher: it runs the app's own Swift server and hands stdin and stdout over to it, so no MCP traffic passes through Node. The Node MCP server is gone. With options, which used to keep the Node server, it now runs the server of the app that `--client` names, passing `--socket` and `--name` on. An app without a server of its own makes it exit with a message instead: Desktop Tools before 0.17.0 is named with its version and the release to install, and an embedding app that ships no `desktop-tools-mcp` beside its client, such as Ace Canary passed with `--client` today, is told to bundle one (docs/embed.md). Such setups used to run the Node server through that app's client. Prefer pointing the MCP config at `/Applications/Desktop Tools.app/Contents/MacOS/desktop-tools-mcp`, which needs no Node. Parity, bench and live-check scripts default to the app's own server. ([#237](https://github.com/githubnext/desktop-tools/issues/237))
- Tool descriptions, schemas and the rules they share are declared in Swift, in `native2/Sources/DesktopProtocol/ContractTools.swift`, which the app's MCP server serves. `@githubnext/desktop-tools/tools` and the key and wait-condition lists in `/protocol` are generated from those declarations (`npm run contract`) and export the same values as before. `desktopRequest` no longer checks the exclusive argument forms of `desktop_clipboard_write` and `desktop_dialog_answer` itself: the host refuses them with the same text. `DESKTOP_EXPECT_OPS` lists its ops in tool order. ([#237](https://github.com/githubnext/desktop-tools/issues/237))

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ You need macOS 15 or later. The MCP server ships inside the app.
}
```

An `npx` setup, `npx -y --package=github:githubnext/desktop-tools#v0.20.0 desktop-tools-mcp` (Node 22 or later), also works: it hands over to the app's server. One pinned before v0.17.0 is refused with `CLIENT_OUTDATED`, so update its tag. Updating the tag doesn't update the app, which holds the macOS permissions: install the app's release of the same version, since an app from before v0.17.0 has no server to hand over to, and a failed call then names both versions. A background job, such as `claude --bg`, doesn't load nvm from your shell, so give `npx` by its absolute path there.
An `npx` setup, `npx -y --package=github:githubnext/desktop-tools#v0.20.0 desktop-tools-mcp` (Node 22 or later), also works: it runs only a launcher that hands over to the app's server, so no MCP traffic passes through Node. One pinned before v0.17.0 is refused with `CLIENT_OUTDATED`, so update its tag. Updating the tag doesn't update the app, which holds the macOS permissions: install the app's release of the same version, since an app from before v0.17.0 has no server to hand over to, and the launcher then exits naming its version. A background job, such as `claude --bg`, doesn't load nvm from your shell, so give `npx` by its absolute path there.

4. **Verify.** Ask the agent to call `desktop_apps`. It should list the running apps with an `inventory_completeness` of `complete`. If it says the socket is missing, open the app.

Expand Down
226 changes: 47 additions & 179 deletions dist/mcp.js
Original file line number Diff line number Diff line change
@@ -1,202 +1,70 @@
#!/usr/bin/env node
// desktop-tools-mcp for npx setups and checkouts: it runs the Desktop Tools app's own MCP server, written in Swift, and
// hands stdin and stdout over to it. No MCP traffic passes through Node. Point the MCP config at the app's
// `desktop-tools-mcp` directly to need no Node at all (#237).
import { spawn } from "node:child_process";
import { existsSync, readFileSync, realpathSync } from "node:fs";
import { constants as osConstants, homedir } from "node:os";
import { dirname, join } from "node:path";
import { createInterface } from "node:readline";
import { parseArgs } from "node:util";
import { createDesktop } from "./client.js";
import { isDesktopAction } from "./protocol.js";
import { desktopRequest, desktopToolRules, desktopTools } from "./tools.js";
const { values } = parseArgs({
options: { client: { type: "string" }, socket: { type: "string" }, name: { type: "string" }, wire: { type: "string" } },
strict: true,
});
// Desktop Tools.app links its client and serves its socket here; pass all three to use another host app.
const state = process.env.DESKTOP_TOOLS_STATE || join(homedir(), ".local", "state", "desktop-tools");
// The app bundles its own MCP server beside the client it links (0.17.0 and later), so existing npx configs hand over to
// it. Any option keeps this server, which forwards each call through that client, as does an app without one.
const bundled = (() => {
try {
return join(dirname(realpathSync(join(state, "desktop-client"))), "desktop-tools-mcp");
}
catch {
return undefined;
}
})();
if (Object.keys(values).length === 0 && bundled && existsSync(bundled)) {
const server = spawn(bundled, [], { stdio: "inherit" });
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"])
process.on(signal, () => server.kill(signal));
server.on("error", (error) => {
process.stderr.write(`Cannot run ${bundled}: ${error.message}\n`);
process.exit(1);
});
server.on("exit", (code, signal) => process.exit(code ?? (signal ? 128 + osConstants.signals[signal] : 1)));
// The bundled server owns stdin and stdout from here.
await new Promise(() => { });
}
const { client = join(state, "desktop-client"), socket = join(state, "desktop.sock"), name: host = "Desktop Tools", } = values;
// --wire 2 chose the Swift host's wire while the Peekaboo stack's was the default. It is the only wire now, but the option
// still keeps this server instead of handing over.
// --wire 2 chose the Swift host's wire while the Peekaboo stack's was the default; it is the only wire now.
if (values.wire !== undefined && values.wire !== "2") {
throw new Error("--wire 1 was the Peekaboo stack, which is gone; pass --wire 2 or leave it out.");
}
const config = { client, socket, name: host };
const desktop = createDesktop(config);
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
// An app from before 0.17.0 bundles no MCP server, so this one stays, and an npx tag updated without the app runs
// against an older client and host (#179), whose Peekaboo wire this server no longer speaks. Every failed call names
// both versions, since nothing else shows the skew.
const app = (() => {
// Desktop Tools.app links its client here. --client names another app's, as <App>.app/Contents/MacOS/desktop-tools-client;
// that app's own server, beside it, is the one that serves it, since a signed host serves only its own app's programs.
const state = process.env.DESKTOP_TOOLS_STATE || join(homedir(), ".local", "state", "desktop-tools");
const client = values.client ?? join(state, "desktop-client");
const linked = (() => {
try {
// <App>.app/Contents/MacOS/desktop-tools-client
const contents = dirname(dirname(realpathSync(client)));
if (!contents.endsWith(".app/Contents"))
return undefined;
const plist = readFileSync(join(contents, "Info.plist"), "utf8");
const found = /<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/.exec(plist);
return found ? { path: dirname(contents), version: found[1] } : undefined;
return realpathSync(client);
}
catch {
return undefined;
}
})();
const skew = app && app.version !== version
? `${app.path} is version ${app.version}, but this MCP server is ${version}. Updating the npx tag doesn't update the app, `
+ `which holds the macOS permissions: ask the user to install Desktop Tools ${version} from its GitHub release, or to pin `
+ `the MCP server to v${app.version}.`
: undefined;
if (skew)
process.stderr.write(`desktop-tools-mcp: ${skew}\n`);
// Newest first; an unsupported client version gets the newest, as the MCP lifecycle requires.
const VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
// Guidance mirrors Ace's desktop extension so agents behave alike; tools and their shared rules come from the shared definitions.
const instructions = [
`Use desktop_* tools to observe and operate native apps on this Mac through ${host}, which holds the macOS permissions.`,
"Shell commands remain appropriate for builds, files, and preparing clipboard fixtures directly.",
"",
"Do not silently substitute AppleScript, osascript, System Events, or self-built Accessibility or CGEvent programs for desktop tools.",
"Apple Events can raise a separate macOS Automation prompt for each target app, attributed to the calling terminal or agent; Accessibility and Screen Recording grants do not cover them.",
"Custom input programs bypass the desktop tools' snapshot and exact-target checks, even when they raise no permission prompt.",
"Before using a fallback, tell the user which native tool or capability cannot do the step and why the fallback is needed, including any Automation prompts it can trigger.",
"Use the user's existing authorization; this guidance adds no separate approval requirement.",
"",
"Action results start with their outcome: completed, refused, or unknown.",
"For a refusal before dispatch, follow its concrete recovery hint once when applicable, then refresh the observation; a refusal alone does not prove the capability is missing.",
"After completed, interrupted, or uncertain input, inspect the current target before deciding whether another action is needed. Never replay input just because its follow-up observation failed.",
"",
...desktopToolRules(host),
].join("\n");
const tools = desktopTools({ place: "this Mac", app: host });
const byName = new Map(tools.map((tool) => [tool.name, tool]));
const listed = tools.map(({ name, op, description, parameters }) => ({
name,
description,
inputSchema: parameters,
annotations: { readOnlyHint: !isDesktopAction({ op }) },
}));
// The host labels the window in use with the agent's name; unknown clients show as "Agent".
const AGENTS = [
[/claude/i, "Claude"],
[/codex/i, "Codex"],
[/cursor/i, "Cursor"],
[/gemini/i, "Gemini"],
[/copilot/i, "Copilot"],
];
function agentName(info) {
const { name, title } = (info ?? {});
const known = AGENTS.find(([pattern]) => typeof name === "string" && pattern.test(name));
if (known)
return known[1];
return typeof title === "string" && title.trim() ? title.trim().slice(0, 40) : undefined;
}
const send = (value) => process.stdout.write(`${JSON.stringify(value)}\n`);
const fail = (id, code, message) => send({ jsonrpc: "2.0", id, error: { code, message } });
const running = new Map();
// Actions run one at a time, as in Ace; each input depends on the state the previous one left.
let actions = Promise.resolve();
async function call(tool, args, signal) {
try {
const result = await desktop(desktopRequest(tool, args), signal);
const content = [{ type: "text", text: result.text }];
if (result.outcome)
content.unshift({ type: "text", text: `Outcome: ${result.outcome}.` });
if (result.image)
content.push({ type: "image", ...result.image });
if (result.isError && skew)
content.push({ type: "text", text: skew });
return { content, isError: result.isError || false };
}
catch (error) {
const text = error instanceof Error ? error.message : String(error);
return { content: [{ type: "text", text }, ...(skew ? [{ type: "text", text: skew }] : [])], isError: true };
}
}
async function handle(message) {
const { id, method, params = {} } = message;
// This server sends no requests, so a message without a method is a stray response.
if (!method)
return;
if (id === undefined) {
if (method === "notifications/cancelled") {
running.get(params.requestId)?.abort(new Error(String(params.reason || "Cancelled.")));
const server = linked && join(dirname(linked), "desktop-tools-mcp");
if (!server || !existsSync(server)) {
const releases = `https://github.com/githubnext/desktop-tools/releases/tag/v${version}`;
// <App>.app/Contents/MacOS/desktop-tools-client
const contents = linked && dirname(dirname(linked));
const plist = (() => {
try {
return contents?.endsWith(".app/Contents") ? readFileSync(join(contents, "Info.plist"), "utf8") : undefined;
}
return;
}
if (method === "initialize") {
const requested = String(params.protocolVersion);
config.agent = agentName(params.clientInfo);
return send({
jsonrpc: "2.0",
id,
result: {
protocolVersion: VERSIONS.includes(requested) ? requested : VERSIONS[0],
capabilities: { tools: {} },
serverInfo: { name: "desktop-tools", version },
instructions,
},
});
}
if (method === "ping")
return send({ jsonrpc: "2.0", id, result: {} });
if (method === "tools/list")
return send({ jsonrpc: "2.0", id, result: { tools: listed } });
if (method !== "tools/call")
return fail(id, -32601, `Method not found: ${method}`);
const tool = byName.get(String(params.name));
if (!tool)
return fail(id, -32602, `Unknown tool: ${params.name}`);
const args = (params.arguments || {});
const controller = new AbortController();
running.set(id, controller);
const { signal } = controller;
let pending;
if (isDesktopAction({ op: tool.op })) {
pending = actions.then(() => call(tool, args, signal));
actions = pending;
}
else {
pending = call(tool, args, signal);
}
const result = await pending;
running.delete(id);
// A cancelled request gets no response.
if (!signal.aborted)
send({ jsonrpc: "2.0", id, result });
catch {
return undefined;
}
})();
const appVersion = plist && /<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/.exec(plist)?.[1];
const appName = plist && /<key>CFBundleName<\/key>\s*<string>([^<]+)<\/string>/.exec(plist)?.[1];
const appPath = "/Applications/Desktop Tools.app/Contents/MacOS/desktop-tools-mcp";
const message = !linked
? `No Desktop Tools app has linked its client at ${client}: install and open Desktop Tools ${version} (${releases}). `
+ `Then set the MCP server up as "${appPath}", which needs no Node.`
: appName && !appName.startsWith("Desktop Tools")
// A signed host serves only its own app's programs, so an embedder's app serves MCP only through its own server.
? `${appName} bundles no desktop-tools-mcp beside its client, ${linked}, so it can't serve the desktop tools over MCP. `
+ `To serve them, ${appName} must bundle desktop-tools-mcp from the same native build beside that client, signed with `
+ `the client's identifier: see https://github.com/githubnext/desktop-tools/blob/main/docs/embed.md. `
+ "Then set the MCP server up as that desktop-tools-mcp, with --socket for the socket the app serves."
: `${dirname(contents)} is version ${appVersion ?? "unknown"}, which has no MCP server of its own (0.17.0 and later `
+ `bundle one): install Desktop Tools ${version} (${releases}). Then set the MCP server up as "${appPath}", `
+ "which needs no Node.";
process.stderr.write(`desktop-tools-mcp: ${message}\n`);
process.exit(1);
}
createInterface({ input: process.stdin }).on("line", (line) => {
if (!line.trim())
return;
let message;
try {
message = JSON.parse(line);
}
catch {
return fail(null, -32700, "Parse error");
}
if (!message || typeof message !== "object" || Array.isArray(message)) {
return fail(null, -32600, "Invalid request");
}
void handle(message);
const args = [...(values.socket ? ["--socket", values.socket] : []), ...(values.name ? ["--name", values.name] : [])];
const child = spawn(server, args, { stdio: "inherit" });
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"])
process.on(signal, () => child.kill(signal));
child.on("error", (error) => {
process.stderr.write(`desktop-tools-mcp: Cannot run ${server}: ${error.message}\n`);
process.exit(1);
});
child.on("exit", (code, signal) => process.exit(code ?? (signal ? 128 + osConstants.signals[signal] : 1)));
2 changes: 1 addition & 1 deletion docs/live-checks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Live checks

The live checks in [#42](https://github.com/githubnext/desktop-tools/issues/42) need an unlocked Mac. `npm run live-check` runs the ones that can be automated, through the same MCP server (`dist/mcp.js`) and host that agents use:
The live checks in [#42](https://github.com/githubnext/desktop-tools/issues/42) need an unlocked Mac. `npm run live-check` runs the ones that can be automated, through the app's own MCP server (`<App>.app/Contents/MacOS/desktop-tools-mcp`, found through the client the app links in its state folder) and host that agents use:

```sh
npm run live-check # the installed app
Expand Down
Loading
Loading