Quarry documentation Open the editor →

Connect an AI coding agent (MCP)

Quarry can be driven by an external AI coding agent — Claude Code, GitHub Copilot, or anything that speaks the Model Context Protocol. The agent gets Quarry's whole editing suite as tools: it can read the world, place blocks and shapes, paint biomes, generate structures, toggle Vibrant Visuals, take screenshots to see what it built, and export .mcworld / .mcstructure files.

No API key is needed in Quarry itself: your agent is the brain and Quarry is its hands — it can look at the world, build, screenshot, look again, and iterate.

Why a bridge is needed

Quarry runs entirely in your browser tab, and browsers can't accept incoming connections. So a tiny program — mcp/server.mjs, shipped in the repo — sits between the two. There are two ways to connect it:

Local — a plain ws://localhost link to the bridge on your machine:

your AI agent  ⇄ (MCP/stdio) ⇄  mcp/server.mjs  ⇄ (ws://localhost) ⇄  Quarry tab

Cloud relay — a secure wss:// link through Quarry's relay Worker:

your AI agent ⇄ (stdio) ⇄ mcp/server.mjs ⇄ (WSS) ⇄ Quarry relay ⇄ (WSS) ⇄ Quarry tab

Either way, the agent talks MCP to that program; the program relays each tool call to your open Quarry tab, which runs it on the live world. Every edit goes through Quarry's normal undo history, so anything the agent does is undoable — and exports stay byte-for-byte non-destructive, exactly as with hand edits.

Which one?

It comes down to how Quarry's page is served, not just where the agent runs:

The panel picks the right one for where you've opened Quarry automatically.

Getting the bridge program

The bridge is a tiny Node program (Node 18+). You don't need to clone Quarry — download the self-contained, single-file build:

curl -fsSL https://quarry.refrag.com/quarry-mcp.mjs -o quarry-mcp.mjs

(The Cloud relay panel gives you a copy-paste snippet with this line already filled in. If you do have the repo checked out, node mcp/server.mjs / npm run mcp works identically.)

Setup (local)

Open Quarry from a local http server first — run npm run dev and use http://localhost:5173. (Local mode won't connect from the deployed https site; use Cloud relay there.)

  1. Download the bridge (above), or use your checkout.

  2. Register it with your agent. For Claude Code:

    claude mcp add quarry -- node /absolute/path/to/quarry-mcp.mjs
    

    (Or just run node quarry-mcp.mjs in a terminal to start it and read the token.)

  3. The bridge prints a pairing token to its output, for example:

    [quarry-mcp] listening on ws://127.0.0.1:7331
    [quarry-mcp] pairing token: 3f9a1c0b7e2d4a55
    
  4. In Quarry (opened from http://localhost), load or create a world, open the app menu and choose AI agent (MCP)… — it opens in Local mode; click Connect and paste the token. The status dot turns green.

  5. Ask your agent to use the Quarry tools — for example "read the area around 0,64,0, then build a small stone tower there and show me a screenshot."

Setup (cloud relay)

Use this on the deployed site (https://quarry.refrag.com) — for any agent, on your own machine or remote — and any time the agent and Quarry's web server aren't the same machine. The agent and the tab meet in a private room on Quarry's collaboration Worker; no inbound ports or tunnels are needed (both sides connect out).

It's tied to your GitHub sign-in (the same one collaboration uses), so the agent pairs to your account — you set it up once and never reconfigure it.

  1. In Quarry on the deployed site, open AI agent (MCP)… — it opens in Cloud relay mode (if you're on http://localhost, use the "On the deployed site, or the agent is elsewhere? Use the cloud relay" link). Sign in with GitHub if you haven't. Quarry shows your stable room (mcp-<your-id>) and a personal token, plus a ready-to- paste snippet. Click Connect — your tab joins your room and waits.

  2. On the agent's machine, run the snippet from the panel — it downloads the bridge and registers it with your personal token (no room needed — the bridge derives it from the token):

    curl -fsSL https://quarry.refrag.com/quarry-mcp.mjs -o quarry-mcp.mjs
    claude mcp add quarry \
      --env QUARRY_MCP_RELAY=wss://your-collab-host \
      --env QUARRY_MCP_TOKEN=your-personal-token \
      -- node ./quarry-mcp.mjs
    

    The bridge reports tab attached once it finds your Quarry tab. Because the token is stable, this config keeps working across sessions and machines — no removing/re-adding the server. (For Copilot CLI, put the same env in the quarry entry of ~/.copilot/mcp-config.json.)

  3. Drive it exactly as in local mode. Large results (screenshots, exported worlds) are split into chunks and reassembled automatically, so they stream across fine despite the relay's per-message size limit.

If your token ever leaks, click rotate token in the panel — it invalidates every old agent token at once; re-copy the new snippet to your agent.

Self-hosting / local dev: a relay Worker without SESSION_SECRET configured stays in the original ad-hoc mode (a random room + pairing token, no GitHub) — the panel falls back to that automatically.

What the agent can do

A smart build loop

A capable agent decomposes a request and works in passes: world_overview to get the lay of the land → surface_scan to find flat ground → run_build (or place_structure) for each piece → screenshot to see the result → adjust and repeat. Building a village becomes: scan the area, run_build one house, save_structure it, then place_structure it across the flat columns with variation — a handful of calls instead of thousands.

Staying safe

In local mode the bridge listens on 127.0.0.1 only, checks the page origin, and requires the pairing token, which keeps stray web pages from connecting. In cloud relay mode the room is gated by a private, high-entropy room id plus the pairing token (and the relay only accepts browser connections from Quarry's own origin); anyone with both the room and token can drive your tab, so treat the snippet like a password and rotate it with New room if it leaks.

Either way, treat this as opt-in convenience rather than a hardened sandbox. Because every edit is undoable and exports are non-destructive, anything an agent does is easy to walk back. Keep the tab open (and focused, for screenshots) while the agent works.