# connect_repo

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

The CodePanel MCP tool that connects a GitHub repository and installs the webhook that starts a review on each new pull request.

`connect_repo` connects a GitHub repository to CodePanel and installs the webhook that starts a review on each new pull request. It takes one input, `repo`, needs the `repos:write` scope, and needs admin rights on the repository. A repository that is not connected is never reviewed, so this comes before everything else in the setup.

## When to call it

- **Once per repository,** after [`list_connectable_repos`](/docs/mcp-server/list_connectable_repos) shows `canInstallWebhook: true` for it.
- **To bring a disconnected repository back.** Connecting again reuses your own earlier row for that repository, with its settings, rather than adding a second one.
- **Only when the person asked.** Connecting installs a webhook on their GitHub repository.

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `repo` | string | yes | Repository as owner/name |

It writes: the server marks it `readOnlyHint: false`, so a client that asks before writes asks here.

`repo` must look like `owner/name`. Anything else is refused before any GitHub call. GitHub, not your call, supplies the repository id and default branch, so a made-up id cannot be claimed. A repository another CodePanel account already has live, with a working hook, blocks the connect.

The errors your agent can hit:

```text
CodePanel: Repository not found, or your GitHub account cannot access it.
CodePanel: GitHub token not found. Sign out and sign in again.
```

The first means GitHub does not show the repository to the signed-in account, or the account is not an admin of it. The second means CodePanel holds no usable GitHub sign-in, which a person fixes in the browser.

## What it returns

| Field | Meaning |
| --- | --- |
| `repoId` | CodePanel's id for the connected repository |
| `fullName` | The name as GitHub spells it |
| `webhookInstalled` | `true`. If the hook cannot be installed, the call errors and a repository that was not live before is left inactive |
| `nextSteps` | A list of strings. Empty once the default branch has both `.codepanel/rules.md` and a CodePanel section in `AGENTS.md` or `CLAUDE.md`. Otherwise one entry says how to add the missing ones in a single pull request, and to ask the owner first if they did not ask for setup |

A file GitHub could not read counts as missing. `nextSteps` is advice for your agent: it is not done for you, and opening that pull request is a separate task for the person to approve. A new connection starts with `autoReview` on and `maxAutoRounds` at 3. Reconnecting a repository you disconnected keeps the settings it had. Check them with [`list_repos`](/docs/mcp-server/list_repos), and change them with [`update_repo_settings`](/docs/mcp-server/update_repo_settings).

## Examples

A local test backend has no GitHub access, so there is no success result to show. This is what a caller sees when CodePanel holds no GitHub sign-in for the account:

```json title="Call"
{ "repo": "codepanel-dev/mobile-app" }
```

```text title="Result (tool error: GitHub access missing)"
CodePanel: GitHub token not found. Sign out and sign in again.
```

Connecting a repository that is already connected (`codepanel-dev/web-app`) reaches the same check first and fails the same way here, so this backend cannot show the already-connected case. A successful call returns the four fields in the table above.

## The same step without MCP

| Surface | Form |
| --- | --- |
| CLI | `codepanel repos connect <owner/name>` ([CLI](/docs/cli#repositories)) |
| HTTP API | [`POST /repos/connect`](/docs/api#post-reposconnect) with `{"repo":"owner/name"}` |

## What the server tells your agent

The description your agent reads when it lists the tools:

> Connect a GitHub repository and install CodePanel's webhook so new pull requests are reviewed. When the repository has no .codepanel/rules.md or no CodePanel section in AGENTS.md or CLAUDE.md, nextSteps says how to add them in one pull request.

## Related

- [`list_connectable_repos`](/docs/mcp-server/list_connectable_repos): find the name and check admin first.
- [`disconnect_repo`](/docs/mcp-server/disconnect_repo): stop reviewing it again.
- [`update_repo_settings`](/docs/mcp-server/update_repo_settings): the next step, round limits and the gate.
- [Repository setup](/docs/agent-setup): the pull request `nextSteps` points to.
- [MCP server](/docs/mcp-server#set-up-a-repository-from-an-agent): the full setup sequence.
