# add_connection

URL: https://codepanel.ai/docs/mcp-server/add_connection

The CodePanel MCP tool that approves an MCP server for agent app runs, pinning each allowed tool by the hash of its definition.

`add_connection` approves an MCP server for agent app runs and pins the tools a run may call on it. It needs the `agents:write` scope, and adds remote (`http`) servers; a local (`stdio`) program is added by the account owner in the dashboard.

## When to call it

- **To give runs a tool**: an issue tracker, a database read replica, a docs search.
- **To approve a changed tool again**: a server that changes a tool's definition loses that tool in every run until the account owner adds the connection again. `codepanel connections add` shows the current definition and pins it. Adding a name that exists replaces it.
- **To approve a repository's `.mcp.json` server**: the runner never starts a server a repository names. It reports the server in the run's log with the input that would approve it, and for an `http` server this call is the approval; a `stdio` one the owner adds in the dashboard.

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | yes | Connection name, unique per account: 1-32 lower-case letters, digits and single dashes. A run sees its tools as mcp__<name>__<tool>. |
| `transport` | `http` or `stdio` | yes |  |
| `url` | string | no | For http: https, or http on localhost |
| `command` | string | no | For stdio: the program, run without a shell |
| `args` | array of strings | no | For stdio: its arguments |
| `environment` | `dev` or `staging` or `production` | yes | What the server touches; production only ever offers read-only tools |
| `tools` | array of objects | yes | The tools to allow, each pinned |
| `tools[].name` | string | yes | The tool's name as the server lists it |
| `tools[].hash` | string | yes | SHA-256 hex pin of the tool's definition, as codepanel connections add prints it or a run's refusal notice reports it |
| `tools[].readOnly` | boolean | no | Marks the tool read-only; on production only these are offered. Default false |
| `agentIds` | array of strings | no | Coding agent ids (list_coding_agents) whose runs get it; absent: every agent |

It writes: the server marks it `readOnlyHint: false` and `destructiveHint: true` (it can change what is already there), so a client that asks before writes asks here.

Each tool's `hash` is the SHA-256 pin of its definition (name, description and schemas). `codepanel connections add` starts or calls the server on your machine, lists its tools and pins the ones you name, so you approve what you saw. A run's log says a tool changed but does not carry the new hash: the agent in the run is not the one to approve it.

A `stdio` server is your program, and the pin covers its tools, not its code. The local runner starts it in an empty private directory of its own, its working directory and HOME, never the worktree the agent edits, with the same scrubbed environment as a shell command in the run: no tokens, keys or the owner's HOME. A command line that reaches, by any path (absolute, relative or through a link), the run's worktree, its HOME or the temp directory is refused: the server is not started, and its tools are reported as `command_refused` in the run's notices, which [`get_run`](/docs/mcp-server/get_run) shows. Name programs and files outside those. An `http` server must be `https`, or `http` on localhost.

## Who can add a local program

This tool adds and changes `http` connections. A `stdio` connection is added only by the account owner, signed in to the dashboard, since an agent could otherwise give itself a program to run ([Who can add a local program](/docs/mcp-connections#who-can-add-a-local-program)). Adding one, turning an `http` connection into `stdio`, or, on a `stdio` connection, changing its `command`, `args` or `environment`, granting it more `agentIds`, or granting, re-approving or marking read-only a tool is refused: `403`, code `forbidden`, `fields` naming each change, nothing saved, and a `nextAction` that names the dashboard page to send the owner to. Adding a `stdio` connection again with the same command and fewer agents or tools is allowed, as is [`remove_connection`](/docs/mcp-server/remove_connection).

## What it returns

`{ connection, replaced }`. `connection` is as [`list_connections`](/docs/mcp-server/list_connections) shows it. `replaced` is `null`, or the connection the name held before: add it again to undo. To undo a new one, call [`remove_connection`](/docs/mcp-server/remove_connection).

## The same step without MCP

| Surface | Form |
| --- | --- |
| HTTP API | `POST /autopilot/connections` with the `agents:write` scope |
| CLI | `codepanel connections add <name> --environment dev --tools a,b (--url <url> \| -- <command> [args...])` |

## What the server tells your agent

The description your agent reads when it lists the tools:

> Use it to let agent app runs call an MCP server's tools, or to approve a changed tool again. Approve the server: name, transport (http with an https url, or stdio with command and args, started by the runner in a private directory of its own with a scrubbed environment; a command line reaching the run's worktree, HOME or temp directory by any path is refused, reported as command_refused), environment (dev|staging|production) and tools, the allow-list of { name, hash, readOnly }. Get each hash by running codepanel connections add, which lists the server's tools and pins them. Optional agentIds limits it to those coding agents' runs. A name that exists is replaced: that is how a changed tool is approved again, and the same call again changes nothing more. Needs agents:write. A stdio connection is a local program, which only the account owner adds, in the dashboard: adding one, turning an http one stdio, or changing a stdio one's command, args or environment, granting it more agents, or granting, re-approving or marking read-only a tool on it is refused with 403 (forbidden, fields naming each), nothing saved, and nextAction names the dashboard page. Adding it again with the same command and fewer agents or tools is allowed. Returns { connection, replaced }; undo with remove_connection, or add again with replaced.

## Related

- [`list_connections`](/docs/mcp-server/list_connections): read what is approved.
- [Scopes](/docs/mcp-server#scopes): what `agents:write` allows.
- [MCP server](/docs/mcp-server): install, sign-in and every other tool.
