Skip to content

Remove Node from the MCP path: make the app's Swift server the only server and the contract's source #237

Closed

Description

@iamnbutler

Follows #143, whose Swift rewrite has shipped: since #233 (0.19.0), native2 is the only native build and wire, and the app bundles its own MCP server (desktop-tools-mcp). What Node still does:

  1. Launcher. dist/mcp.js (the npx setup, and configs that run it from a checkout) hands stdio over to the app's bundled server when no option is given. With --wire 2, --client, --socket or --name, it stays and forwards each call through the app's client.
  2. The tool contract's source. src/tools.ts holds every tool's description and schema. scripts/contract.mjs generates native2's ContractText.swift from it, so changing a tool means editing TypeScript and regenerating.
  3. The embedder API. createDesktop, /protocol and /tools are imported by embedders such as Ace (which pins its own commit).

Goal

The app's server is the only MCP server, and the contract lives in Swift. Node remains, if at all, only as a thin package for embedders.

Questions to settle first

  • Contract source: move descriptions and schemas into Swift and generate what /tools exports from it, or keep a language-neutral file (JSON) both sides read.
  • npx setups: keep a tiny shim that only execs the app's server and prints how to point the config at /Applications/Desktop Tools.app/Contents/MacOS/desktop-tools-mcp, or drop npx and document the app path only. Pinned #vX.Y.Z tags in users' configs must keep working or fail with a clear message.
  • Options that keep the Node server today (--client, --socket, --name, used with the dev app via DESKTOP_TOOLS_STATE): give the Swift server the same options, so the dev app needs no Node.
  • Embedders: what createDesktop becomes once there is no Node tool logic. It is already a wire-2 forwarder over the signed client.
  • Checks that run through Node: parity and bench scripts, test/version-skew.test.mjs, scripts/live-check.mjs.

Done when

  • A Claude Code or Codex config pointing at the app's desktop-tools-mcp needs no Node, including against the dev app.
  • Tool descriptions and schemas are edited in one place, without a generation step through TypeScript.
  • Ace and other embedders have a documented path.

Activity

  1. iamnbutler commented on Nov 12, 2026

    @iamnbutler
    ContributorAuthor

    Plan

    The first question is settled: descriptions and schemas move into Swift, and what /tools exports for embedders is generated from Swift. This plan covers the rest, from a read of src/tools.ts, src/mcp.ts, src/client.ts, scripts/contract.mjs, ContractText.swift, desktop-tools-mcp/main.swift, the tests and the dev scripts, and of how Ace uses the package today (packages/channel/src/desktop.ts, apps/host/src/desktop.ts, apps/desktop/scripts/helper.ts).

    What exists now

    • src/tools.ts (982 lines) builds 48 tools from desktopTools({ place, app }). place appears in 3 descriptions and app in the shared rules plus one description. Shared shapes (windowTarget, expect, key…) and limits (WAIT_MAX_MS…) are interpolated in, and the key and wait-condition enums come from src/protocol.ts.
    • scripts/contract.mjs runs node dist/mcp.js --wire 2, reads initialize and tools/list, and writes them into ContractText.swift as two raw strings. Contract.swift parses those at startup. CI's ubuntu job runs contract.mjs --check.
    • Swift reads the contract in three places. The MCP server serves it. Contract.actions, derived from readOnlyHint, queues actions and feeds Admission and Hooks. A tool name must be in Contract.names to be called. The host also keeps its own hand-written Tools.actionTools and Tools.expectTools, and protocol.ts keeps a third list in isDesktopAction.
    • The Swift server already takes --socket and DESKTOP_TOOLS_STATE, and it finds its own app with HostApp.containing(). A dev app's server already picks ~/.local/state/desktop-tools-dev from its .dev bundle ID. So pointing a config at Desktop Tools Dev.app/Contents/MacOS/desktop-tools-mcp already works without Node. The one thing it gets wrong is the app name in the instructions: "Desktop Tools" is baked into ContractText.swift.
    • createDesktop holds no tool logic. It forwards calls through desktop-tools-client <socket> --serve. The host already enforces the exclusive argument forms in desktopRequest, with the same messages (TextClipboard.swift:137, Dialogs.swift:112).
    • Ace imports createDesktop, desktopTools (with place: "this channel's execution host", app: "Ace"), desktopRequest, isDesktopAction and the /protocol types, and builds natively through dist/build.js.

    1. How the contract moves into Swift

    Declarations. Add a Tool value in DesktopProtocol with name, op, kind (read or action), takesExpect, a description and a JSON schema. Build the list in Contract.tools(place:app:), using Swift string interpolation where TS used template literals. Split the declarations across a few files by area (Contract+Read.swift, Contract+Input.swift, Contract+Manage.swift…), with the shared shapes and limits in Contract+Shapes.swift. Add ExpressibleByDictionaryLiteral to JSON, which keeps source order, so schemas read like the TS objects. The rules and instructions become Contract.rules(app:) and Contract.instructions(app:). The key, system-key and wait-condition lists move into Swift constants beside them.

    One source for derived sets. Contract.actions, Tools.expectTools, and the generated isDesktopAction all come from kind and takesExpect. Tools.actionTools decides which tools report a bad argument as a refused action, a quirk ported from Node's action runner. It already differs from the MCP "action" set: it leaves out desktop_system_key, desktop_input_source, desktop_set_cell, desktop_dock and others. Derive it from kind only if that difference turns out to be accidental. Otherwise give it its own flag on Tool so the difference is visible. Adding expect to a tool then means one change in one place, instead of Tools.swift plus src/tools.ts (docs/tools.md:56).

    Proving the port. The first PR keeps ContractText.swift and adds a Swift test: Contract.tools(place: "this Mac", app: "Desktop Tools") and the instructions must serialize to exactly the JSON in ContractText.swift. The ported text then matches the old text exactly, whitespace and key order included, before anything switches over.

    2. How /tools gets generated

    • desktop-tools-mcp --contract prints one JSON document: the version, the tools (each with name, op, kind, description and parameters), the rules, the instruction lines, the limits and the enums. The exporter passes the sentinels {{place}} and {{app}}, and refuses to export if either string appears anywhere else. Putting this on the shipped binary, instead of a separate dev-only executable, also lets anyone dump the contract of an installed app for comparison.
    • npm run contract builds desktop-tools-mcp and writes its output to src/contract.ts as export const contract = {…} as const. A .ts file goes through tsc into dist/, which keeps npm run check and the literal types. Git installs read dist/, so the generated file is committed.
    • src/tools.ts shrinks to a wrapper with the same exports. desktopTools({ place, app }) substitutes the sentinels, desktopToolRules(app) returns the rules, desktopRequest filters arguments to the schema, and the limit constants are re-exported. Ace's import surface doesn't change. The exclusive-form checks in desktopRequest are dropped because the host already makes them with the same text. That changes only who reports the error, not what it says.
    • protocol.ts keeps the hand-written DesktopRequest union, because generating TS types from JSON Schema isn't worth it. Its key and condition constants and isDesktopAction come from contract.ts. A type-level check in tools.ts confirms that every contract op is a DesktopRequest["op"] and the reverse, so tsc fails on drift.
    • CI: npm run contract -- --check moves to the macOS native job, since it needs Swift. The ubuntu job keeps npm test against the committed contract.ts, so hosted consumers still import /protocol and /tools without macOS.

    The tool text is then edited in one place: Swift. The MCP server needs no generation step. Only the embedder export is regenerated, Swift to TS, and CI fails if it's stale.

    3. Open questions, with recommendations

    a. npx: shim, or app path only? Recommend keeping desktop-tools-mcp as a shim of about 40 lines with no server in it, and leading every doc with the app path, as the README already does.

    • Old pinned tags keep working whatever main does. #v0.17.0–#v0.20.0 run their own dist/mcp.js, which hands over to the app's server. That works as long as the app keeps writing <state>/desktop-client as a symlink into its bundle, next to desktop-tools-mcp. Tags with options (--client, --socket, --name) keep their Node server, which needs the client's --serve mode, and createDesktop keeps that alive anyway. Tags before v0.17.0 already fail clearly with CLIENT_OUTDATED. Both constraints get lane notes, on app.swift and on the client's --serve mode.
    • New tags are what the shim is for. Dropping the bin means someone who bumps the tag gets npx's unclear "could not determine executable to run". With the shim, the bump just works.
    • What the shim does:
      • With no options, it execs the bundled server it finds through <state>/desktop-client, as it does today.
      • With --client <App>/Contents/MacOS/desktop-tools-client, it execs that app's desktop-tools-mcp, passing --socket and --name through.
      • It accepts --wire 2 and ignores it.
      • If it finds no bundled server (no app, or an app before 0.17.0), it writes one stderr line naming the app's version, the release to install and the app-path config, then exits 1.
    • Tradeoff: Node stays on the npx path only, as a launcher that does an exec and no more. The MCP traffic never passes through Node.

    b. --client / --socket / --name in the Swift server. Recommend:

    • --socket: already there; keep it.
    • --name: add it, defaulting to HostApp.containing()?.name, so the dev app's server says "Desktop Tools Dev" with no option at all. The instructions and rules are built from it at startup.
    • --client: don't add it. The Swift server talks to its own app's host directly, and a signed host accepts only programs bundled in its own app (HostTrust and the host's client check). A --client that points at another app's client can't work from this binary. The shim maps it to that app's own server instead.
    • Also fix the stale error at main.swift call(): "The Desktop Tools 2 host… Start it with: native2/.build/debug/desktop-tools-host" should name the app or the socket.
    • Result: the dev config becomes claude mcp add desktop-dev -- "$HOME/Library/Application Support/desktop-tools/dev/Desktop Tools Dev.app/Contents/MacOS/desktop-tools-mcp", and npm run dev-app prints that line in place of DESKTOP_TOOLS_STATE=… node dist/mcp.js. A custom DESKTOP_TOOLS_STATE still works, since HostApp.stateFolder reads it.

    c. What createDesktop becomes. Recommend no change. It is already only a transport, the client's --serve protocol, and Ace runs its own signed client (ace-desktop-client) against its own host. Replacing it with "spawn desktop-tools-mcp and speak MCP" would add a process and a protocol layer and gain nothing. The npm package becomes what the issue describes, a thin embedder package:

    • createDesktop
    • /protocol types
    • /tools, generated from Swift
    • desktop-tools-build and desktop-tools-app, the Swift build drivers
    • the desktop-tools-mcp shim

    docs/node.md gets an "Embedding from Node" section that says this, and Ace's path is "bump the pin; nothing to change".

    d. The Node-based checks. Recommend keeping them in Node: they are MCP clients and dev harnesses, not part of the MCP path. Point them at Swift servers.

    • native2/scripts/parity.mjs: change the --baseline default from node dist/mcp.js to /Applications/Desktop Tools.app/Contents/MacOS/desktop-tools-mcp, the last release.
    • scripts/bench.mjs and native2/scripts/bench.mjs: change the installed server the same way. Merging the two bench scripts is a separate cleanup.
    • scripts/live-check.mjs: by default, use the dev app's bundled server. --server stays.
    • scripts/result-sizes.mjs: keep createDesktop (an embedder path), and take tool names from the generated /tools.
    • test/version-skew.test.mjs: its subject, the Node server forwarding to a client from before 0.17.0, goes away. Replace it with shim tests that use fake bundles:
      • it execs the bundled server;
      • --client maps to the sibling server, and --socket and --name pass through;
      • with no server, it fails with the app's version and the fix.
        These run on any OS.
    • scripts/contract.mjs: deleted. test/tools.test.mjs: schema assertions move to a Swift ContractTests, and the JS side keeps a smoke test (load, substitute place and app, 48 tools). test/setup-docs.test.mjs: stays while the shim does.

    4. Order of PRs (main works after each)

    1. Wait for the fix train (769ac35e) to land its src/tools.ts and native2 changes. Between PR 1 and PR 2, a description change would have to be made twice, so freeze src/tools.ts edits from PR 1 until PR 2 merges.
    2. Port the contract to Swift, unused. Add the declarations and JSON dictionary literals, plus the test that the new declarations serialize to exactly what ContractText.swift holds. Nothing that is served changes, and contract.mjs --check still runs.
    3. Flip the source. The server, Contract.actions and Tools.expectTools read the declarations. Delete ContractText.swift and scripts/contract.mjs. Add desktop-tools-mcp --contract and npm run contract (with --check in the macOS CI job), and the generated src/contract.ts. src/tools.ts becomes the wrapper, and isDesktopAction plus the protocol constants come from the contract. A JS test checks that desktopTools({ place: "this Mac", app: "Desktop Tools" }) equals the output from before the flip, saved once as a fixture. Update the docs: AGENTS.md, native2/README.md, docs/tools.md and docs/mcp.md:31. Retire the lane notes on src/tools.ts and src/mcp.ts.
    4. Swift server options. Add --name, defaulting to the containing app's name, and fix the stale error message. dev-app prints the bundled-server config. Update docs/app.md and docs/build.md for a dev setup without Node. node dist/mcp.js still works here, so nothing breaks.
    5. Shim. src/mcp.ts becomes the launcher from 3a. Remove the Node server and its skew logic, and replace version-skew.test.mjs with the shim tests. Point parity, bench and live-check at Swift servers. Rewrite docs/mcp.md around the app path, and add a CHANGELOG entry saying that --client now selects that app's own server.
    6. Embedder docs and release. Write docs/node.md "Embedding from Node", cut the release, and open the Ace pin bump. It needs no code change; check its desktop_open URL sentence survives, as its lane note asks.

    PRs 1 and 2 are the large ones, mostly moved text. PRs 3–5 are small. PR 3 could land before 1–2 if the --name substitution is first done by plain string replacement, but it is cleaner after PR 2, once the rules take app as a parameter.

    Done-when check

    • A config pointing at the app's desktop-tools-mcp needs no Node, including against the dev app: true today for the release app, and fully true for the dev app after PR 3.
    • Descriptions and schemas are edited in one place, with no generation step through TypeScript: after PR 2.
    • Embedders have a documented path: PR 5, with no API break for Ace.
  2. iamnbutler commented on Nov 14, 2026

    @iamnbutler
    ContributorAuthor

    Done

    The plan above landed in five PRs.

    Step PR What
    1 #252 The tools, the shared rules and the server instructions are declared in Swift (native2/Sources/DesktopProtocol/ContractTools.swift). A test checked them byte for byte against the generated contract.
    2 #253 Swift became the source. The server, Contract.actions and the host's expect set read the declarations, and ContractText.swift is gone. desktop-tools-mcp --contract with npm run contract writes src/contract.ts, which /tools and /protocol export, and CI's macOS job checks it is fresh. Type assertions keep the hand-written request types in step with the declared ops and actions.
    3 #254 The Swift server takes --name, which defaults to the app it ships in, so the dev app's own desktop-tools-mcp serves "Desktop Tools Dev" with no Node. npm run dev-app prints that claude mcp add line.
    4 #256 The Node MCP server is gone. dist/mcp.js only launches the app's own server, the one beside the linked client or beside the client --client names, and passes --socket and --name on. If there is no server to run, it exits with what to do: an embedder is told to bundle desktop-tools-mcp (docs/embed.md). The version-skew test became launcher tests. Parity, bench and live-check default to the app's server.
    5 #257 Embedder docs: "Embedding from Node" in docs/node.md, and the bundled server's --socket in docs/embed.md.

    Done-when:

    • A config pointing at the app's desktop-tools-mcp needs no Node, including against the dev app: yes, since MCP server: --name, defaulting to its own app, so the dev app needs no Node (#237) #254.
    • Descriptions and schemas are edited in one place, with no generation step through TypeScript: yes. They live in ContractTools.swift, and only the embedder export is regenerated from it.
    • Ace and other embedders have a documented path: yes. The /tools and /protocol values are unchanged, except that DESKTOP_EXPECT_OPS is now in tool order. Ace will bundle desktop-tools-mcp beside its client so its --client npx setup keeps working. That Ace PR is drafted and waits for the release with these changes, 0.21.0 if it is cut.

    The changes are in CHANGELOG's Unreleased section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions