# Connect an agent

Use the built-in Model Context Protocol (MCP) server to let a local agent read or edit the open workbook.

## Start JSheets and choose access

Open the workbook you want the agent to use. The server starts automatically. Choose **Agent › Copy config** to get the current URL, or **Agent › Show agent** to see it in the Agent panel. If the listener is not running, choose **Agent › Start MCP**.

The default is `http://127.0.0.1:47110/mcp`. If that port is busy, JSheets uses a free port. From a terminal, launch JSheets with `--mcp` to open a blank workbook, or pass a workbook path and `--mcp [port]`. Use `--mcp 47111` to request a fixed port or `--mcp 0` to pick a free port. See [Install JSheets](https://jsheets.app/docs/install.md) for the executable on each platform.

Set access in **File › Agents** or in the **Agent** panel:

- **Read only** lets the agent inspect the workbook without editing it. Start here.
- **Edit** (the default) lets the agent edit the workbook.
- **None** refuses tool calls without stopping the listener.

JSheets does not show a connection approval dialog. The workbook’s access setting is the grant; a native `.jsheets` save keeps it. Client trust or tool approval prompts are separate. When a client connects, its name appears in the Agent panel with a green dot. Choose **Disconnect** there to end the current session without changing the URL.

There is no JSheets sign-in, OAuth flow, or bearer token. Any local process can reach the listener. Keep it on loopback. Use a client running on the same computer, not a cloud session. For every example below, substitute the URL shown by JSheets if it differs. Merge the entry into existing settings rather than replacing other entries.

## Connect Claude Code

Run this on the same computer, using the URL from JSheets if it differs:

```sh
claude mcp add --transport http jsheets http://127.0.0.1:47110/mcp
```

Or use **Agent › Copy config** for the JSON below. Add it to Claude Code’s `.mcp.json`, merging the `jsheets` entry into `mcpServers` if the file already has other servers.

```json
{
  "mcpServers": {
    "jsheets": {
      "type": "http",
      "url": "http://127.0.0.1:47110/mcp"
    }
  }
}
```

Use `/mcp` in Claude Code to check the connection. See [Claude Code’s MCP setup guide](https://code.claude.com/docs/en/mcp) for configuration and approval options.

## Connect Claude Desktop

Claude Desktop starts local MCP servers as programs, so it reaches JSheets through the `mcp-remote` bridge. It needs [Node.js](https://nodejs.org) 18 or later.

Choose **Settings › Developer › Edit Config** in Claude Desktop. Add this to `claude_desktop_config.json`, merging the `jsheets` entry into `mcpServers` if the file already has other servers:

```json
{
  "mcpServers": {
    "jsheets": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "http://127.0.0.1:47110/mcp"]
    }
  }
}
```

Quit and reopen Claude Desktop. JSheets appears in the tools menu of a new chat. Custom connectors added under **Settings › Connectors** run from the cloud and cannot reach JSheets on your computer, so use this file instead.

## Connect Cursor

In the local editor, add the following to `.cursor/mcp.json` for the workspace or `~/.cursor/mcp.json` for your user account. See the [Cursor MCP guide](https://cursor.com/docs/mcp).

```json
{
  "mcpServers": {
    "jsheets": { "url": "http://127.0.0.1:47110/mcp" }
  }
}
```

## Connect VS Code and Copilot

For the editor-managed configuration, add this to `.vscode/mcp.json` in the workspace:

```json
{
  "servers": {
    "jsheets": { "type": "http", "url": "http://127.0.0.1:47110/mcp" }
  }
}
```

For a new Copilot configuration, use `~/.copilot/mcp-config.json` instead (or `$COPILOT_HOME/mcp-config.json` if set). Copilot can receive eligible editor-managed entries, but reads its own config directly. See the [VS Code MCP configuration reference](https://code.visualstudio.com/docs/agents/reference/mcp-configuration).

```json
{
  "mcpServers": {
    "jsheets": { "type": "http", "url": "http://127.0.0.1:47110/mcp", "tools": ["*"] }
  }
}
```

## Connect Windsurf

In Cascade’s MCP menu, choose **Open MCP config file**. Add this to the `mcp_config.json` file it opens, then refresh the MCP list. See the [Windsurf MCP guide](https://docs.devin.ai/windsurf/plugins/cascade/mcp).

```json
{
  "mcpServers": {
    "jsheets": { "serverUrl": "http://127.0.0.1:47110/mcp" }
  }
}
```

## Connect OpenAI Codex CLI

Add this to `~/.codex/config.toml`, then start Codex. See the [Codex MCP guide](https://learn.chatgpt.com/docs/extend/mcp?surface=cli).

```toml
[mcp_servers.jsheets]
url = "http://127.0.0.1:47110/mcp"
```

## Connect Gemini CLI

Add this to `~/.gemini/settings.json`, then start Gemini CLI. Use `httpUrl` for Streamable HTTP, not the `url` field for SSE. See the [Gemini CLI MCP guide](https://geminicli.com/docs/tools/mcp-server).

```json
{
  "mcpServers": {
    "jsheets": { "httpUrl": "http://127.0.0.1:47110/mcp" }
  }
}
```

## Connect any MCP client

| Setting | Value |
| --- | --- |
| Server name | `jsheets` |
| Transport | Streamable HTTP, not stdio or legacy SSE |
| Endpoint | `http://127.0.0.1:47110/mcp` by default; use the URL from the Agent panel |
| Authentication | None. Leave token, OAuth, and custom headers unset. |

JSheets rejects requests with an `Origin` header or a non-loopback `Host`. Use a local client, not a browser page.

## Check the connection

Ask: “Use the JSheets `workbook_overview` tool to list the sheets in the open workbook. Do not edit anything.” Confirm that the names match the workbook you opened.

## Troubleshoot

- **Connection refused:** Open JSheets and a workbook. If **Agent › Start MCP** is available, select it. Keep the client and JSheets on the same computer.
- **Port in use or wrong workbook:** Copy the URL from the intended workbook’s Agent panel and reconnect. If you requested a fixed port that is busy, relaunch with a different port.
- **Tools blocked:** Check **File › Agents**. **None** blocks all calls; **Read only** blocks edits. If the client asks you to trust the server or approve a call, review and approve it there.
- **Another client is connected:** Use **Disconnect** in the Agent panel or close the other client’s session before reconnecting.

## Review agent work

The first write locks human editing, not inspection. Committed steps appear in [Changes](https://jsheets.app/docs/changes.md) under the agent’s task and share your undo history. **Take over** stops the task, rolls back the uncommitted step, and leaves earlier committed steps in place. The agent stays connected but needs a new task ID to write again. `finish_task` or two minutes without a call also unlocks editing.

**Agent time limit** in Preferences defaults to **1 minute** per covered operation. It applies to transactions, dry runs, reversions, Solver, and workbook inspection, not save, export, or external link refresh. Other choices are **5 minutes**, **15 minutes**, and **Off**. A write that times out before commit rolls back and returns `committed: false` with the unchanged revision. If a committed write reports recalculation still pending, use `wait_recalculation`.

## MCP tools

Start with `workbook_overview`. Use `help` for arguments and examples.

- `accept_solution` — Apply a staged Solver solution as one history step.
- `apply_map` — Annotate the Model map in one step.
- `apply_transaction` — Apply an atomic workbook step or preview it with a dry run.
- `cell_detail` — Inspect a cell or trace its dependencies up to five levels.
- `compare_formulas` — Compare adjacent formulas by their relative references.
- `evaluate` — Calculate an unplaced formula without writing to the workbook.
- `evaluate_formula` — Trace an existing formula’s steps, branches, and references.
- `export_xlsx` — Export an Excel copy beside the current workbook.
- `find` — Search visible sheets or a specified scope.
- `find_errors` — Count and page through workbook errors or compare them with a revision.
- `finish_task` — Close a task and report its notes, changes, and remaining errors.
- `help` — Get operation arguments and examples by topic.
- `history` — Read recent workbook history.
- `list_charts` — List charts across the workbook or on one sheet.
- `list_names` — List defined names, their scopes, and formulas.
- `list_pivots` — List PivotTables across the workbook or on one sheet.
- `pivot_cell` — Explain a PivotTable cell and give its `GETPIVOTDATA` formula.
- `read_chart` — Read chart settings, appearance, or plotted data.
- `read_map` — Inspect the Model map and its links.
- `read_pivot` — Read a PivotTable’s definition, resolved settings, or layout.
- `read_presentation` — Read styles, dimensions, and merged cells.
- `read_range` — Read a range’s values, formulas, and formats in pages.
- `recalc_status` — Read the current recalculation status.
- `render_chart` — Render a chart as PNG or SVG.
- `render_range` — Render a grid range as PNG.
- `revert_to` — Restore an earlier revision without crossing another session’s edits.
- `review_task` — Read a task’s steps and before-and-after results before finishing it.
- `save` — Save the workbook to its current native file.
- `save_as` — Save to an absolute `.jsheets` path.
- `selection_viewport` — Read the current selection and visible grid area.
- `set_date_order` — Change text-date order and recalculate in one undoable step.
- `solve` — Stage a Solver solution without changing cells.
- `table_sources` — List loaded tables and their sources.
- `task_notes` — List a task’s findings.
- `update_links` — Refresh one external workbook link from an explicit `.xlsx` path.
- `wait_recalculation` — Wait for recalculation and report errors.
- `workbook_overview` — List sheets, used ranges, tables, names, and import notes.
