bonya-mcp
v1.0.3Model Context Protocol server for the Bonya Compute REST API — manage sandboxes, sessions, files, previews, and jobs from any MCP client.
A Model Context Protocol server for the Bonya Compute REST API — gives any MCP client (Claude Desktop, Claude Code, Cursor, …) direct tool access to spin up sandboxes, run commands and scripts in them, work with files, manage background sessions, expose preview URLs, and run one-off or scheduled jobs. Self-contained: it talks to the Bonya Compute REST API directly over fetch, with no dependency on the @bonya-ai/bonya or bonya SDKs. 1. Get an API key from the dashboard or via bonya login (see the bonya CLI). It looks like byk_.... 2.
Summary extracted from the README.
@bonya-ai/bonya-mcp
A Model Context Protocol server for the Bonya Compute REST API — gives any MCP client (Claude Desktop, Claude Code, Cursor, …) direct tool access to spin up sandboxes, run commands and scripts in them, work with files, manage background sessions, expose preview URLs, and run one-off or scheduled jobs.
Self-contained: it talks to the Bonya Compute REST API directly over fetch, with no dependency
on the @bonya-ai/bonya or bonya SDKs.
Quick start
- Get an API key from the dashboard or via
bonya login(see thebonyaCLI). It looks likebyk_.... - Add the server to your MCP client — see Connect a client below for Claude, Codex, Cursor, and others. Always pass the key as an env var, never as a command-line argument (it would end up in shell history and process listings).
- Restart your client. Try asking it to "list my Bonya sandboxes" or "create a sandbox and run
uname -ain it" — that exercisessandbox_list/sandbox_create+sandbox_execend to end.
No local install is required (npx fetches it on demand); npm install -g @bonya-ai/bonya-mcp
works too if you'd rather have bonya-mcp on PATH directly.
Configuration
Everything is read from the environment — there are no CLI flags:
| Env var | Required | Default | Notes |
|---|---|---|---|
BONYA_API_KEY |
yes | — | Personal API key, byk_.... The server doesn't validate it at startup; the first tool call fails with a clear error if it's missing or wrong. |
BONYA_ENDPOINT |
no | https://api.bonya.ai |
Override for self-hosted or staging deployments. |
BONYA_ORGANIZATION_ID |
no | your personal organization | Sent as X-Bonya-Organization-ID on every request. Set this to act on behalf of a team organization instead of your own. |
Connect a client
Most MCP clients read the same mcpServers JSON shape (see
examples/mcp-config.json):
{
"mcpServers": {
"bonya": {
"command": "npx",
"args": ["-y", "@bonya-ai/bonya-mcp"],
"env": { "BONYA_API_KEY": "byk_your_key_here" }
}
}
}
Claude Code
claude mcp add bonya --env BONYA_API_KEY=byk_your_key_here -- npx -y @bonya-ai/bonya-mcp
This registers the server for the current project directory only — it won't show up in other
projects, and an already-running session needs a full restart (not just a retry) to pick it up
since MCP servers only connect at session startup. To make it available in every project instead,
add -s user:
claude mcp add bonya -s user --env BONYA_API_KEY=byk_your_key_here -- npx -y @bonya-ai/bonya-mcp
Claude Desktop — Settings → Developer → Edit Config, and add the JSON above under
mcpServers (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json).
OpenAI Codex CLI — supports local stdio MCP servers; add the same JSON block to Codex's MCP
config (codex mcp add, or its config file — see the Codex CLI's own docs for the current path,
since this has moved between releases).
ChatGPT (web/desktop app) — the web app only supports remote HTTPS MCP connectors, not local stdio processes, so this server can't be added there directly. The desktop app's MCP support follows the same connector model; check OpenAI's current docs for whether local stdio servers are supported in your version.
Cursor — Settings → Tools & MCP → "Add new MCP server", or add the JSON above to
.cursor/mcp.json (project) or ~/.cursor/mcp.json (global).
Windsurf — add the JSON above to ~/.codeium/windsurf/mcp_config.json.
Cline (VS Code) — Command Palette → "Cline: Add MCP Server", or edit its MCP settings JSON from the Cline panel (⚙️ → MCP Servers → Configure).
Gemini CLI — gemini mcp add bonya --env BONYA_API_KEY=byk_your_key_here -- npx -y @bonya-ai/bonya-mcp
Any other MCP-compatible client should work the same way: point it at npx -y @bonya-ai/bonya-mcp
(or a global bonya-mcp install) as a stdio server, with BONYA_API_KEY in its environment.
What the tools cover
63 tools across 9 groups. Every tool takes/returns plain JSON — ids, not objects, are how you
chain calls together (e.g. sandbox_create → its sandbox_id → sandbox_exec).
Sandboxes — create, inspect, and manage compute environments
sandbox_create · sandbox_list · sandbox_get · sandbox_delete
A sandbox is created from a template (see template_list below). Creation is async by
default — sandbox_create returns immediately with the sandbox in CREATING state; pass
wait: true to block until it's ready. Sandboxes pause automatically when idle and wake by
themselves on exec, file access, or preview traffic. A warm pause keeps processes; a cold pause
keeps files but ends every process. sandbox_pause forces a pause. sandbox_keepalive holds a
sandbox awake; the server tells agents to call it only when the user asks for that.
// sandbox_create
{ "template_id": "bonya-dev", "name": "scratch", "wait": true }
// → { "sandbox": { "sandbox_id": "sbx-...", "state": "RUNNING", ... } }
Exec & filesystem — run commands and move files around
sandbox_exec · fs_read · fs_write · fs_list · fs_stat · fs_mkdir · fs_rename · fs_delete
sandbox_exec runs a command and blocks until it finishes (buffered stdout/stderr) — it's for
short, non-interactive commands. For anything long-running or interactive, use a session
instead (below). The API's WebSocket-based TTY exec and session attach endpoints aren't
exposed here; they don't fit a request/response tool.
// sandbox_exec
{ "sandbox_id": "sbx-...", "cmd": ["cat", "/etc/os-release"] }
// → { "exit_code": 0, "stdout": "...", "stderr": "", "output_encoding": "utf8" }
Sessions — long-lived background processes
session_create · session_list · session_kill
A session is a named process that keeps running after the tool call returns — a dev server, a
log tail, anything sandbox_exec shouldn't block on. Sessions are addressed by name, not id:
session_kill takes session_name, not name.
// session_create
{ "sandbox_id": "sbx-...", "name": "dev-server", "cmd": ["npm", "run", "dev"] }
// session_kill
{ "sandbox_id": "sbx-...", "session_name": "dev-server" }
A session survives a warm pause but not a cold one; it is not restarted after a cold pause. For a server that must come back by itself, see Hosting a website or app.
Previews — expose a port to the web
preview_create · preview_list · preview_delete
Proxies a port inside a sandbox to a public HTTPS URL. preview_create's result deliberately
omits the one-time capability_jws capability token the API also returns — it's sensitive and
not needed for the plain (token-gated or public) preview URL.
Hosting a website or app
A server started with session_create stays down after a cold pause. An image template's
command runs again on every cold wake, so a site hosted this way comes back by itself when
its preview URL is opened, with no agent call and no sandbox_keepalive. The server sends this
recipe to agents in its MCP instructions:
// 1. template_create (once; reuse it from template_list afterwards)
{
"name": "web-app-node",
"config": {
"image": "node:22-bookworm-slim",
"command": ["sh", "-c", "while [ ! -x /app/start.sh ]; do sleep 2; done; exec /app/start.sh"],
"previews": [{ "port": 3000, "visibility": "public" }]
}
}
// 2. sandbox_create — wait: true, or the template's previews are not created
{ "template_id": "<id>", "name": "my-site", "wait": true }
- Write the app under
/app(fs_mkdir,fs_write,sandbox_execfor installs), then an/app/start.shthat runs the server in the foreground on0.0.0.0:3000(#!/bin/sh/cd /app && exec node server.js).chmod +xit last; the template command starts it within about 2 seconds. - Share the preview URL from
preview_list.
Tested on api.bonya.ai: after a cold pause, opening the URL woke the sandbox and the server
answered within about 5 seconds. Meanwhile a browser gets a Bonya page that reloads by itself
once the app answers; other clients get a 502 and can retry. Other limits:
A running server counts as activity, so the sandbox stays awake until the plan's max awake time
or a manual pause. A server that exits while the sandbox runs is restarted only at the next cold
wake. The default template (no template_id) has no start-on-wake.
Jobs — one-off runs, tracked to completion
job_create · job_list · job_get · job_cancel
A job is a managed run of a command or script — on a new sandbox (created and, by default,
deleted for you) or an existing one. wait: false (default) returns a run_id immediately;
wait: true blocks for the result. There's no endpoint to edit a run in place: to "edit and
rerun" one, call job_get for its stored job spec, change what you need, and pass it to
job_create as a new run.
// job_create
{
"job": {
"new_sandbox": { "template_id": "bonya-dev" },
"cmd": ["./run-tests.sh"],
"wait": true,
"disposition": "delete"
}
}
// → { "run": { "run_id": "...", "status": "completed", "result": { "exit_code": 0, ... } } }
Job schedules — cron, interval, or one-shot triggers
job_schedule_create · job_schedule_list · job_schedule_get · job_schedule_update ·
job_schedule_delete · job_schedule_pause · job_schedule_trigger
A schedule wraps a job spec (same shape as job_create's) with timing: cron_expressions,
interval_s, or a one-shot run_at_unix_nanos — exactly one of the three. job_schedule_update
replaces the whole schedule (timing + job), so re-send every field you want to keep, not just the
one you're changing. job_schedule_trigger fires a run immediately, ignoring the schedule's own
timing — useful for testing a schedule without waiting for it.
Templates
template_list · template_get · template_create · template_update · template_delete
Saved, versioned launch configurations (image, resources, env, secrets, network, previews). Pass a
template's id as sandbox_create's template_id. Updating the config publishes a new immutable revision.
An image template's command runs again on every cold wake (see
Hosting a website or app).
Registry connections, secrets & secret sets
registry_connection_list/create/update/delete/validate · secret_list/create/update/delete ·
secret_set_list/get/create/update/delete
Credentials for private images, write-only secrets, and named groups of environment variables. Values
are never returned. Reference secret sets by name in secret_sets on templates, sandboxes and jobs.
Organizations
organization_list — the organizations your key belongs to; use an id as BONYA_ORGANIZATION_ID.
Lifecycle, snapshots & forks
sandbox_gpu_options, sandbox_pause, sandbox_keepalive, sandbox_network_update,
sandbox_fork, snapshot_create, snapshot_list, snapshot_get, snapshot_delete
sandbox_create also accepts snapshot, gpu, network (open / allowlist / airgap), env
and secret_sets. sandbox_keepalive is for an explicit user request to keep a sandbox awake; a
paused sandbox wakes without it.
Gotchas
- Sandbox capacity is capped per account (a low single-digit number by default). If
sandbox_createorjob_create'snew_sandboxpath returns429 rate_limited: request capacity is exhausted, you're at your limit — free a slot withsandbox_deleteor wait for a job-created sandbox to finish, rather than retrying immediately. session_kill's parameter issession_name, notname— easy to get wrong sincesession_createtakesname.- A job's
dispositiononly applies to a sandbox the job itself created (new_sandbox); it's ignored forexisting_sandbox_id. Default isdelete, so a job-created sandbox disappears automatically once the run ends, however it ends (including onjob_cancel). - Errors are RFC 9457
problem+json, surfaced asBonya API error <status> (<code>): <message>— thecodeis the stable machine-readable part if you're branching on error type.
Develop
npm install
npm run typecheck
npm run build # emits dist/index.js (executable)
npm run dev # run from source (tsx, no build step)
npm run inspect # launch the MCP Inspector against the built server
BONYA_API_KEY=byk_your_key_here npm run dev
Adding a new tool: each file under src/tools/ exports one register<X>Tools(server) function
registered in src/server.ts; request/response types live in src/types.ts, hand-transcribed
from the API's OpenAPI contract (this package intentionally doesn't import the generated SDK
types, to stay a standalone, dependency-light server). Follow the existing pattern in
src/tools/sandboxes.ts or src/tools/jobs.ts — local zod schemas per tool, a call through
getHttp(), wrapped in the tool() helper from src/format.ts for uniform error handling.
License
MIT