Skip to content

MCP for AI agents

Slice speaks the Model Context Protocol (MCP), so an AI agent can run the code it writes in a Slice sandbox instead of on your machine. There are two ways to connect:

Mode Runs code Needs Tools
Hosted On Slice Cloud An API key, or an OAuth sign-in slice_eval_ts, your functions as tools, and code mode on MCP servers you define
Local On your machine Node.js 18+, no account slice_eval_ts, slice_kv_get, slice_kv_set, slice_checkpoint

Use hosted mode when the agent should never run code on the machine it lives on, when you want your functions as tools, or when several people and CI share one setup. Use local mode for offline work and for the KV and checkpoint tools.

Property Value
Endpoint https://api.slicevm.com/mcp (default server), https://api.slicevm.com/mcp/<server id> (MCP servers)
Transport MCP Streamable HTTP, stateless, JSON responses (no SSE)
Auth Authorization: Bearer <api key>, or OAuth for clients that sign in
Protocol versions 2025-06-18, 2025-03-26, 2024-11-05

Create a key in the console first. For an agent, choose Sandbox eval only (scope sandbox:eval): see Scoping keys for agents.

Terminal window
claude mcp add --transport http slice https://api.slicevm.com/mcp \
--header "Authorization: Bearer $SLICE_API_KEY"

Run claude mcp list to check that slice is connected.

.cursor/mcp.json in your project, or ~/.cursor/mcp.json for every project:

{
"mcpServers": {
"slice": {
"url": "https://api.slicevm.com/mcp",
"headers": { "Authorization": "Bearer slice_live_xxxxxxxxxxxxxxxx" }
}
}
}

~/.codeium/windsurf/mcp_config.json:

{
"mcpServers": {
"slice": {
"serverUrl": "https://api.slicevm.com/mcp",
"headers": { "Authorization": "Bearer slice_live_xxxxxxxxxxxxxxxx" }
}
}
}

.vscode/mcp.json. VS Code asks for the key once and stores it securely, so it never sits in the file:

{
"inputs": [
{ "type": "promptString", "id": "slice-key", "description": "Slice API key", "password": true }
],
"servers": {
"slice": {
"type": "http",
"url": "https://api.slicevm.com/mcp",
"headers": { "Authorization": "Bearer ${input:slice-key}" }
}
}
}

Claude Desktop can also add Slice as a custom connector with OAuth, with no key in a file. Clients that only start local processes use the npm package in cloud mode: with SLICE_API_KEY set, @slicevm/mcp bridges stdio to the hosted endpoint. This requires @slicevm/mcp 0.14.1 or later; for an MCP server, also set SLICE_API_URL to the server’s URL.

claude_desktop_config.json (Settings, Developer, Edit Config):

{
"mcpServers": {
"slice": {
"command": "npx",
"args": ["-y", "@slicevm/mcp"],
"env": { "SLICE_API_KEY": "slice_live_xxxxxxxxxxxxxxxx" }
}
}
}

On Windows, if npx is not found, use "command": "cmd" and "args": ["/c", "npx", "-y", "@slicevm/mcp"].

Setting Effect
SLICE_API_KEY env var or --api-key=<key> Switches to cloud mode.
--local Forces local mode even when a key is set.
SLICE_API_URL Overrides the base URL (default https://api.slicevm.com).

In cloud mode the tools come from the hosted server. The local-only flags (--allow-read, --allow-write, --allow-net, --audit-egress) are ignored with a warning on stderr, and slice_kv_* and slice_checkpoint are not available.

Config files that hold a key are secrets. Keep them out of version control, or use a client feature that reads the key from the environment or a prompt.

tools/list shows only the tools your key’s scopes allow.

Tool Scope Input Returns
slice_eval_ts sandbox:eval { code: string, allowNet?: string[], fuel?: number, memoryKb?: number, timeoutMs?: number, artifacts?: boolean } stdout, return value, error, violation, refused capabilities, limits, telemetry and the files written under /artifacts
fn_<name> functions:invoke or functions:invoke:<name> The function’s input schema, or { input?: any } The function’s result, plus the name and version that ran

slice_eval_ts runs the code in a fresh isolate with the same defaults, plan caps and security model as POST /v1/sandbox/eval. The result is the value of a top-level return statement or of the last expression, so code can end with return await main(); or await main();. Network is off unless the call lists hosts in allowNet. Nothing persists between calls.

There is one fn_<name> tool for every function on your account with a live version. Function names may contain -; the tool name replaces it with _, so send-invoice becomes fn_send_invoice. The tool description is the function’s description, so write it for the model. Function tools need a key created in the console.

A function tool’s input schema comes from the TypeScript type of the function’s first parameter, read at deploy: export default async function (input: { id: number; /** Customer email */ email?: string }) gives the agent a schema with a required number id and an optional, described email, and the tool’s arguments are the input itself. Interfaces and type aliases declared in the same file work too. You can edit the schema in the console (function page, Input schema). A function without a typed parameter keeps the generic { input } argument.

A tool result has a text summary for the model (stdout, any violation, refused capabilities, limits that were reduced to the plan, and the result) and structuredContent with the sandbox result: ok, stdout, result, violation, exitCode, deniedCapabilities, limits, limitsCapped (only when a requested limit was above the plan) and telemetry. The tool schema states your plan’s default and maximum fuel, memory and time, so the agent knows how much room it has. Each tool publishes an output schema that explains these fields to the agent. Telemetry here is cost and speed only (totalUs, vmExecUs, coldBootUs, fuelConsumed, peakMemoryKb); the REST API returns the full set. Isolation is the same on every plan and has no setting. When ok is false (an uncaught error, a non-zero exit or a sandbox trap), the result has isError: true.

Files the code writes under /artifacts come back too, so an agent can see a chart it drew: PNG, JPEG, GIF and WebP images up to 1 MB as image content, text files (CSV, JSON, logs, Markdown, and SVG and HTML as source) up to 256 KB as embedded text with the URI slice://artifacts/<name>. structuredContent.artifacts lists every returned file with its name, size, type and SHA-256. With a console key, files are also kept, and a kept file the content cannot carry (a binary or a large file) comes as a resource_link with a download link valid for 15 minutes. Pass artifacts: false to turn it off. Rules and caps are on Sandbox. Function tools return their function’s files the same way.

A call that cannot start, for example because monthly runs are used up or all runs in flight are taken, also comes back as a tool result with isError: true and text such as quota_exceeded: ... or rate_limited: ..., so the agent can read it and retry. A tool the key may not call is a JSON-RPC error (unknown tool). Only a missing, invalid or revoked key fails the whole request with HTTP 401.

An agent can be talked into doing things you did not intend, so give it the least access that works:

The agent should Key access Scope
Run code it writes Sandbox eval only sandbox:eval
Call one of your functions Invoke one function functions:invoke:<name>
Call any of your functions Invoke any function functions:invoke

Avoid Full access keys in agent configs. Set an expiry on keys you hand out, and rotate or revoke a key that may have leaked.

The default server at /mcp shows every function to any key that may call it, including functions deployed later. For an agent you hand to someone else, create an MCP server in the console (MCP servers, plan limits: Free 2, Pro 20, Scale 100) and choose exactly what it exposes. Each server has its own URL, https://api.slicevm.com/mcp/<server id>, and these settings (the server page’s Compose tab holds the first three, Settings the rest):

Setting Effect
Run code Lists slice_eval_ts (on by default).
Tools The functions it exposes. New functions never appear on a server until you add them. Per tool: name, description (written for the model), version (pinned, or follow the active one), read-only and destructive hints, and a calls-per-minute limit.
Code mode Exposes the chosen functions as a typed API inside one script tool instead of one tool each (code mode).
Daily run cap Stops the server’s calls for the rest of the UTC day once reached.
Log inputs Stores each call’s input in the call log (first 4 KB). Off by default.

A version pin protects a production agent from your next deploy: pin the production server to a version and let a staging server follow the active one.

Reach a server with a key whose access is One MCP server (scope mcp:<server id>; the server page has a button that creates one), or with OAuth. Such a key can reach that server and nothing else. Full access keys reach every server. Compose shows the server the way an agent meets it: the agent, the server, then each tool and the function version it runs (live or pinned), with your functions in a list beside it to add. Cards open to edit a tool, arrows change the order, and Agent view renders the tool list or the code-mode declaration from your draft before you save. The server page also shows what your agent sees (the exact instructions and tools/list, readable or as JSON, with their size in tokens), a Try panel (arguments as Raw JSON or Structured fields from the tool’s schema, and a script editor beside the fn API for slice_run_script), ready-made Connect snippets for each client, and the Log.

Agents choose tools worse as the list grows, and chaining tool calls costs a round trip each. With code mode on, the server’s functions are not separate tools: the agent gets one tool, slice_run_script, whose description declares them as a typed TypeScript API:

declare const fn: {
/** Looks up an order. */
orderLookup(input: {
/** Order id */
id: number;
}): Promise<unknown>;
issueRefund(input: { orderId: number; reason?: string }): Promise<unknown>;
};

The agent writes one script that loops, joins and filters, and returns only what it needs:

const orders = await Promise.all([7, 8, 9].map((id) => fn.orderLookup({ id })));
return orders.filter((o) => o.status === "late").map((o) => o.id);

Each fn call runs the function in its own fresh isolate with the function’s own settings, allowed hosts and version, and resolves to its result; a failing function rejects with its error message. The script never sees a function’s source, settings or hosts, and has no network access of its own: it holds capabilities, not credentials. A script may make up to 50 calls, and up to twice your plan’s runs in flight at once (Free 2, Pro 8, Scale 16). The script and each call count as one run each. Only the script’s own files under /artifacts come back to the agent: function runs called through fn have no /artifacts, so a function cannot pass files (or secrets in them) to the script except through its result. Turn code mode on once a server has more than a handful of functions.

claude.ai and Claude Desktop connectors, and other clients that sign in instead of taking a header, connect with OAuth 2.1:

  1. In the client, add a custom connector with the server URL (https://api.slicevm.com/mcp or https://api.slicevm.com/mcp/<server id>).
  2. The client opens the Slice console. Sign in with your email, check the client and the server it will reach, and choose Allow.
  3. The client receives a token that works only on that server (for the default server: its MCP tools, not the REST API).

The connection appears on the API keys page as an OAuth key named after the client; revoke it there to disconnect. OAuth keys do not count against your key limit. The token lasts 30 days and the client renews it on its own. The discovery documents are at https://api.slicevm.com/.well-known/oauth-protected-resource and https://api.slicevm.com/.well-known/oauth-authorization-server (dynamic client registration, PKCE S256).

Every tool call on every server, and every function call from a script (shown as slice_run_script > fn_x), is logged with time, tool, result, duration, key and error, and kept 30 days. The Log filters by outcome, opens a call for its run id, input (when logged) and error, and links the files the call kept to Artifacts. A call over the server’s daily cap or a tool’s per-minute limit returns a tool error that says when to retry.

Each tools/call (slice_eval_ts, a function tool or slice_run_script) is one run, and so is each fn call inside a script, drawn from your account’s monthly allowance. initialize and tools/list are free. Runs in flight are limited per account (Free 1, Pro 4, Scale 8), so on Free a second tool call made while one is still running returns rate_limited and should be retried. See Plans and limits.

Any MCP client library that supports Streamable HTTP can connect. Each request is a single JSON-RPC message (no batches, body up to 512 KB) answered with a JSON body; there is no session to keep, so you can call tools/list or tools/call without initialize. Notifications get 202 with no body. GET /mcp returns 405. Every request, including initialize, needs the key.

Terminal window
curl https://api.slicevm.com/mcp \
-H "Authorization: Bearer $SLICE_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

Without an API key, npx -y @slicevm/mcp starts the built-in Slice MCP server (slice mcp) on your machine over stdio. No account, no network calls to Slice Cloud, and four tools:

Tool Does
slice_eval_ts Runs TypeScript or JavaScript in a fresh, capability-attenuated isolate and returns stdout, the return value, fuel used and any violation.
slice_kv_get / slice_kv_set Reads and writes the in-memory Slice.kv store, shared across calls while the server runs.
slice_checkpoint Creates or restores an in-memory VFS and KV snapshot for Tree-of-Thought branching.

The local slice_eval_ts takes more arguments than the hosted one (memory in bytes, allowRead, allowWrite, auditSecrets, deterministicSeed, checkpoints and others). Per-call arguments can narrow what the server grants but never widen it.

Claude Desktop (claude_desktop_config.json), Cursor (.cursor/mcp.json) and Windsurf (mcp_config.json) use the same shape:

{
"mcpServers": {
"slice-local": {
"command": "npx",
"args": ["-y", "@slicevm/mcp", "--allow-read=/workspace", "--audit-egress=auto"]
}
}
}

Claude Code:

Terminal window
claude mcp add slice-local -- npx -y @slicevm/mcp --audit-egress=auto

If SLICE_API_KEY is set in your environment and you want local mode anyway, add --local.

Flag Effect
--allow-read=<prefix> Grants read access to a virtual filesystem prefix. Repeatable.
--allow-write=<prefix> Grants write access to a prefix. Repeatable.
--allow-net=<host[:port]> Allows egress to one host. Repeatable. Default is deny all.
--audit-egress=<secret> Blocks the secret from leaving the sandbox in raw, Base64 or Base64URL form. Repeatable.
--audit-egress=auto Reads .env in the working directory and guards every value whose key looks sensitive (SECRET, TOKEN, KEY, PASSWORD, PRIVATE).
--no-checkpoints, --max-checkpoints=<n> Disables or caps Slice.checkpoint() for evaluated code.

The full slice mcp reference is in AI sandboxes and MCP.

Terminal window
npx -y @slicevm/mcp --smoke-test

In local mode the smoke test runs an initialize handshake, lists tools, evaluates TypeScript, writes and reads KV, and takes a checkpoint. In cloud mode (with SLICE_API_KEY set) it runs initialize and tools/list, then calls slice_eval_ts with 1 + 1, which uses one run.