---
title: "API, MCP, and CLI"
description: "How Forge's HTTP contract drives the REST API, the Code Mode MCP server, and the CLI."
---

> Documentation Index
> Fetch the complete documentation index at: https://buildrforge.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# API, MCP, and CLI

Forge defines its whole API in one contract. The same contract drives the HTTP API, the [API reference](https://buildrforge.com/docs/api/), the `forge` CLI, and the operations that agent code calls through the MCP server, so an operation takes the same inputs and answers the same errors everywhere it's offered. The CLI and MCP leave out the operations that only a browser or npm completes: authorizing and completing a connection request, registering an org's OAuth client, following an attachment's content redirect, and reading packages from the npm registry. The CLI also leaves out the endpoints that other services call with no Forge credential: the webhook delivery endpoints and the one that takes Stripe's billing events.

## Authentication and permissions

Every API request requires a credential, except health checks, signing up and in at `/auth/...`, and the [webhook](https://buildrforge.com/docs/extensions/webhooks/) deliveries that third-party services send to `/hooks/...`. Forge issues six kinds of credentials:

- **Sessions**: Created when a person signs in on the dashboard, and kept only in the browser's session cookie, never as a bearer token. A session ends seven days after it was last renewed. The dashboard renews its session when it opens.
- **CLI access tokens**: Issued to the `forge` CLI when a person approves its code on the site's `/device` page, through OAuth device authorization. A CLI token acts as the person, for the API only, and can call the same operations as a session. It lasts an hour, and the CLI renews it with a refresh token that lasts 30 days from its last use.
- **iOS app access tokens**: Issued to Forge's iOS app when a person signs in to it. Like a CLI token, it acts as the person, for the API only, and can call the same operations as a session. It lasts an hour, and the app renews it with a refresh token that lasts 30 days from its last use. See [Native app sign-in](#native-app-sign-in).
- **MCP OAuth access tokens**: Issued when a user authorizes an MCP client (such as Claude Code, Claude, ChatGPT, or Codex) through Forge's OAuth 2.1 authorization server. An MCP token acts as the user who granted it, except that it can't call personal session-only operations: submitting connection secrets, registering OAuth client secrets, or starting and completing a third-party OAuth authorization. It lasts 12 hours, and the client renews it with a refresh token that lasts 30 days from its last use.
- **Agent access tokens**: Issued to an agent that registered for a person through [agentic registration](#agentic-registration), once the person confirms its code. An agent token acts as the person, for the API only, except that, like an MCP token, it can't call personal session-only operations. It lasts an hour. The agent renews it with an identity assertion that lasts 30 days.
- **npm tokens**: Created with the MCP tool `create_npm_token` or `forge registry create-npm-token`, for npm to read `@buildr/sdk` and the org's extension packages under `/npm/` while you [develop an extension locally](https://buildrforge.com/docs/extensions/authoring-overview/#how-buildrsdk-is-linked-and-upgraded). An `npm_…` token reads only those packages, as the person who created it, and lasts 24 hours.

An extension's code holds none of these. A browser signs in to an [extension's UI](https://buildrforge.com/docs/extensions/extension-ui/#ui-addresses) with a token for that UI alone, which Forge keeps in a cookie that the page's scripts can't read. When a tool or an extension's UI calls the API, Forge makes the call itself, as [whoever the run acts as](https://buildrforge.com/docs/permissions/#who-a-run-acts-as), a user or the extension itself. Like an MCP token, a run can't call personal session-only operations. It also can't create an npm token, and one that acts as the extension can't create an organization.

Every credential but a session goes in the `Authorization: Bearer <token>` header. Each credential can make 600 API calls a minute. Every request is authorized by the org or repo that holds its data. If the org's policies don't let a user read a repo, Forge answers `RepoNotFound`, so a request never reveals whether a private repo exists. See [Permissions](https://buildrforge.com/docs/permissions/) for how policies decide, and [Hidden and forbidden](https://buildrforge.com/docs/permissions/#hidden-and-forbidden) for how Forge answers a refusal.

## Agentic registration

An agent that has no Forge credential, but has the email of the person it works for, can register to act as that person. `/auth.md` on the site's origin, such as `https://app.onforge.com/auth.md`, gives the agent the steps with that stage's URLs, after [WorkOS's auth.md](https://github.com/workos/auth.md). The authorization server's metadata names it in its `agent_auth` block, and so does the API's `/.well-known/oauth-protected-resource`.

1. The agent registers the person's email at `/auth/agent/identity` and gets a link to the site's `/agent/claim` page and a six-digit code.
2. The person opens the link, signs in or creates an account with that email, and types the code. Only the account with that email can confirm it. After 5 wrong codes, or 10 minutes, the code stops working and the agent asks for a new one.
3. The agent polls the token endpoint until the person confirms, then gets an access token and an identity assertion. It trades the assertion for a new access token whenever the last one expires, for 30 days.

The person sees every agent that acts as them in **Your settings**, which **Settings** in their profile menu opens, under **Apps and agents**. The same list shows connected apps, such as Claude, ChatGPT, and other MCP clients, and devices, such as the CLI and the iOS app. The person can revoke any one of them there. A revoked app, agent, or device is signed out at once: it can't renew its access, and the access token it holds stops working.

**Sign out everywhere** in Your settings revokes all of them at once and signs out every browser, including the one it was clicked in. Resetting a password does the same. Either way, each has to sign in again, and an access token one of them already holds stops working at once. Changing a password in Your settings signs out the person's other browsers and leaves apps, agents, and devices connected.

Forge accepts only registrations for a person's email, which auth.md calls `service_auth`. It refuses anonymous registrations and identity assertions from other issuers.

## Native app sign-in

Forge's iOS app signs in from the site's origin alone, such as `https://app.onforge.com`, as one of Forge's own public OAuth clients, with PKCE:

1. It reads `/.well-known/oauth-authorization-server` on that origin. The document names the authorization, token, and revocation endpoints, and `forge_api_url`, the API's origin. The app calls the API there and names it as the `resource` of its tokens.
2. It opens the authorization endpoint with an S256 code challenge. On a site that it's associated with, it signs in as `forge-ios` and returns to `/oauth/ios/callback` on the site's origin, which the site associates with the app through `/.well-known/apple-app-site-association`, so iOS returns the code to that app alone, and the person sees no consent page. On a site it isn't associated with, such as a local stage or a pull request's preview opened from a development build, it signs in as `forge-ios-scheme` and returns to `forge://oauth/callback`. Any app on the device can claim that scheme, so the person approves each sign-in there, and only local stages and pull request previews declare that client.
3. It redeems the code at the token endpoint with its code verifier. Each refresh answers a new refresh token. To sign out, it revokes its refresh token at the revocation endpoint.

## Submit feedback

When an agent runs into something in Forge that got in its way, such as an unhelpful error or a missing operation, it calls the top-level MCP tool `submit_feedback` directly, outside `execute`. It takes a one-line `summary` of up to 200 characters, an `impact` of `blocked`, `worked_around`, or `friction`, and `details` of up to 10,000 characters describing what it did, what happened, and what it expected. Leave out secrets and people's data. Feedback goes to the people who build Forge, not to an org, and is attributed to the connected user. Feedback submission is MCP-only; the REST API and CLI offer neither submission nor listing.

## HTTP API conventions

When calling the HTTP API directly, keep these conventions in mind:

- **Resource IDs**: Every resource uses a prefixed TypeID, such as `org_…`, `repo_…`, `branch_…`, `commit_…`, `tag_family_…`, `tag_…`, or `field_…`. Custom models are addressed by their `api_name` in paths, and custom records use a prefix minted with their model, which a rename doesn't change.
- **Revisions**: Repo reads have paired endpoints for branch working state (`/repos/:repo_id/branches/:branch/...`) and immutable commit snapshots (`/repos/:repo_id/commits/:commit_id/...`). Repo writes always target a branch path.
- **Pagination**: Collection endpoints that can grow large, such as `listRepoCustomRecordsAtBranch` and `listRepoExtensionInstallationWorkflowRuns`, accept `limit` (up to 1,000 for custom records and 100 for other lists, and the maximum by default) and `cursor` query parameters and return `{ "data": [...], "next_cursor": "..." | null }`. Pass `next_cursor` back unchanged with the same query scope to fetch the next page. A page can hold fewer items than `limit` while more follow, such as a page of custom records that ends at about 2 MB, so read until `next_cursor` is null. Record searches also return `total`, how many records they hold in all.
- **Filtering**: `searchRepoCustomRecordsAtBranch` and `searchRepoCustomRecordsAtCommit` take a filter, a sort, and a page in a JSON body; see [Searching records](https://buildrforge.com/docs/introduction/schema-and-records/#searching-records).
- **Typed errors**: Every domain refusal returns an HTTP error status and a JSON body with a `_tag` discriminator and structured details explaining what blocked the operation (for example, `CommitRefused` with `violations`, `MergeRefused` with `check`, or `ExtensionInstallationInUse` with `blockers`). A request whose path, query, headers, or body doesn't match the operation's schema returns `400 InvalidRequest`, whose `issues` give each failing input's `path` and what the schema expects there, never the value sent. A query parameter or body key the operation doesn't declare is refused the same way, never ignored.

## The Code Mode MCP server

Forge's MCP server doesn't expose each API operation as an MCP tool of its own, which crowds an agent's context window. It uses **Code Mode** instead, with `search` and `execute`, plus top-level tools for feedback and local extension development:

| MCP tool | Purpose |
| --- | --- |
| `search` | Finds API operations and the tools of extensions installed in your repos by keyword. With 10 or fewer matches, it returns their TypeScript declarations. With more, it returns only names and paths, so narrow the query. An empty query lists everything. |
| `execute` | Runs an `async () => { ... }` JavaScript function in an isolated sandbox with the `forge` and `tools` clients already set up. It returns the function's result and what the code printed with `console.log`. |
| `submit_feedback` | Sends feedback about Forge to its builders as the connected user, without running code. |
| `create_npm_token` | Creates a token for npm to read the org's extension registry during local development. |
| `sync_extension_files` | Writes a local extension's files to its branch in Forge. |
| `show_mcp_ui` | Shows an installed extension's [MCP UI](https://buildrforge.com/docs/extensions/mcp-ui/#how-an-agent-shows-an-mcp-ui) in the chat. Offered only to clients that render MCP Apps. |

The server also offers three skills to MCP clients that support them: `forge` explains the model and how to call it, `forge-setup` sets up a new org and its first repo, and `forge-extension-authoring` covers writing, releasing, and installing extensions. It also serves the agent skills of every repo you can read, as `main` holds them, at `skill://repos/<repo_id>/<skill>/SKILL.md`: the repo's own, those of the extensions it defines, and the copies of the extensions it installs.

### MCP client connection

Add the server's URL, `https://mcp.onforge.com/mcp`, to your client as a remote (Streamable HTTP) server, and sign in to Forge in the browser when the client asks. The client gets its own OAuth grant, so you never copy a token:

| Client | Steps |
| --- | --- |
| Claude Code | Run `claude mcp add --transport http forge https://mcp.onforge.com/mcp`, then `claude mcp login forge`. Or, in a session, run `/mcp`, choose `forge`, and authenticate. See [Claude Code's guide](https://code.claude.com/docs/en/mcp). |
| Codex | Run `codex mcp add forge --url https://mcp.onforge.com/mcp`, which starts the sign-in. To sign in again later, run `codex mcp login forge`. The Codex CLI, app, and IDE extension share the server. See [Codex's guide](https://developers.openai.com/codex/mcp). |
| Claude | Add a custom connector with the URL under **Customize → Connectors**, then connect. On a Team or Enterprise plan, an owner adds it first under **Organization settings → Connectors**. Keep the sign-in settings that Claude detects. See [Claude's guide](https://support.claude.com/en/articles/11175166-get-started-with-custom-connectors-using-remote-mcp). |
| ChatGPT | Under **Plugins**, select the plus button, then **Add custom MCP server**. Enter the URL and choose OAuth as its authentication. In a workspace, an admin may have to allow it first. See [ChatGPT's guide](https://help.openai.com/en/articles/12584461-connecting-custom-mcp-servers-in-chatgpt). |
| Cursor | Add `{ "mcpServers": { "forge": { "url": "https://mcp.onforge.com/mcp" } } }` to `~/.cursor/mcp.json`, and sign in when Cursor asks. See [Cursor's guide](https://cursor.com/docs/mcp). |
| Another client | Add the URL wherever the client takes a remote MCP server. If it asks for OAuth details, see [Manual OAuth setup](#manual-oauth-setup). |

In the dashboard, **Connect an agent** copies a prompt with the URL that asks your agent to add the server itself.

A client that you added at `mcp.buildr-forge.com`, before Forge moved to `onforge.com`, no longer connects. Add the server again with the URL above. A client set up on `mcp.buildr-forge.dev` should also be added again with `https://mcp.onforge.com/mcp`.

### Manual OAuth setup

Most clients need only the URL. The server answers a request without a token with `401` and a `WWW-Authenticate` header that names its resource metadata, `https://mcp.onforge.com/.well-known/oauth-protected-resource/mcp`. That document names Forge's authorization server, whose metadata at `https://app.onforge.com/.well-known/oauth-authorization-server` names every endpoint. A client that can't read these asks for the OAuth details instead. Enter these:

- **MCP server URL**: `https://mcp.onforge.com/mcp`. Where the client sends MCP requests.
- **Issuer**: `https://app.onforge.com`. Names Forge's authorization server. The access token and the authorization response carry it as `iss`. It's the site's origin, not `onforge.com` or the API's origin.
- **Authorization URL**: `https://api.onforge.com/auth/oauth2/authorize`. Where the client sends your browser to sign in to Forge and allow the client.
- **Token URL**: `https://api.onforge.com/auth/oauth2/token`. Where the client trades the authorization code for tokens, and later refreshes them.
- **Registration URL**: `https://api.onforge.com/auth/oauth2/register`. Where a client that has no client ID registers itself (RFC 7591). It needs no credential.
- **Revocation URL**: `https://api.onforge.com/auth/oauth2/revoke`. Where the client revokes its refresh token when you disconnect it, so that it can't renew its access. Optional.
- **Client authentication** (`token_endpoint_auth_method`): `none`. The client is public: it holds no client secret, and proves itself with PKCE instead.
- **PKCE**: `S256`. Required. Forge accepts no other `code_challenge_method`.
- **Scopes**: `forge offline_access`. `forge` lets the client act as you in Forge. `offline_access` gives it a refresh token. Without it, you sign in again every 12 hours.
- **Resource**: `https://mcp.onforge.com/mcp`. The `resource` parameter of the authorization and token requests (RFC 8707), which makes the token one for the MCP server. Without it, the MCP server refuses the token with `401`.

The issuer and the endpoints are on different hosts, as the metadata says. For a client that requires the endpoints on the issuer's host, `https://app.onforge.com` serves the same four paths, such as `https://app.onforge.com/auth/oauth2/token`.

There's no client ID to copy from Forge. A client names itself with a Client ID Metadata Document, as Claude Code and Codex do, or registers itself at the registration URL. If yours asks you for a client ID and can do neither, register it yourself with the redirect URI that the client's documentation gives, and enter the `client_id` from the answer:

```sh
curl https://api.onforge.com/auth/oauth2/register --json '{
  "client_name": "My MCP client",
  "redirect_uris": ["https://client.example.com/oauth/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}'
```

A redirect URI that starts with `http://` must be on `localhost`, `127.0.0.1`, or `[::1]`, for a client on your own machine. Any other web address must start with `https://`. For a client that requires a client secret, register with `"token_endpoint_auth_method": "client_secret_post"` or `"client_secret_basic"`, and the answer also holds a `client_secret`, which Forge shows only then.

When a manual setup fails, check these first:

| What you see | Why |
| --- | --- |
| The sign-in succeeds, then the MCP server answers `401` with `error="invalid_token"` | The client sent no `resource`, so its token isn't for the MCP server. |
| The client asks you to sign in again every 12 hours | It didn't ask for `offline_access`, or it registered without the `refresh_token` grant, so it has no refresh token. |
| Forge's page says `client not found` | The client ID isn't one that Forge registered. Let the client register itself, or register it as above. |
| `invalid_redirect_uri` when registering | A redirect URI starts with `http://` on a host other than the three above. |
| `invalid_target` | The client named a `resource` other than `https://mcp.onforge.com/mcp`. |
| `pkce is required` | The client sent no `code_challenge` with `code_challenge_method=S256`. |

### Code execution in `execute`

Inside `execute`, the global `forge` client mirrors the API groups (`forge.<group>.<operation>(input)`). Path and query parameters are top-level fields on the `input` object, and the JSON request body is passed under `body`:

```js
async () => {
  const family = await forge.tags.createRepoTagFamily({
    repo_id: "repo_01j...",
    branch: "main",
    body: { name: "Departments", kind: "flat" },
  });
  await forge.tags.createRepoTag({
    repo_id: "repo_01j...",
    branch: "main",
    family_id: family.id,
    body: { name: "Engineering", code: "ENG", parent_id: null, position: 0 },
  });
  return forge.commits.createRepoCommit({
    repo_id: "repo_01j...",
    branch: "main",
    body: { message: "Add engineering department tag" },
  });
}
```

Extension tools are callable in the same sandbox in three ways:

- `tools["<repo slug>.<name>"].<repoId>.<tool>(input)` calls a tool of an extension that `repoId` installed, named by its qualified name, such as `tools["integrations.procore"]`, at the version that repo's `main` head commit pins.
- `forge.extensions.callRepoExtensionTool({ repo_id, branch, name, tool, body })` calls a tool of a repo's own extension on a branch, `main` included, at the version that the branch's head commit publishes.
- `forge.extensions.callOrgExtensionServiceTool({ org_id, name, tool, body })` calls a tool of a [service extension](https://buildrforge.com/docs/extensions/installing-and-updating/#service-extensions), which no repo installs, by its qualified name, at the version that its repo's `main` publishes.

The sandbox has no network access and never receives your bearer token. Each call on `forge` or `tools` leaves the sandbox through Forge's MCP server, which sends it to the API with your credential. These limits apply to `execute`:

- Each run stops after 30 seconds, or after 10 seconds of CPU time.
- A result comes back whole, however large, and fills the agent's context, so return only what the next step needs.
- Each user can start 30 runs a minute, and every API call inside a run counts toward the credential's 600 calls a minute. Prefer one run that does several steps over many small runs.

A call that fails rejects with a `ForgeError` whose `operation`, `status`, and `error` name the operation, the HTTP status, and the API's tagged error body.

## The `forge` CLI

The `forge` CLI isn't published yet. It runs only from a checkout of Forge's repository, as `./bin/forge`. If you don't have the repository, use the [MCP server](#the-code-mode-mcp-server) or the HTTP API instead.

The CLI provides a command for every API operation except the ones that only a browser, npm, or another service calls. Each command is named for its operation, as `forge <group> <operation>`, kebab-cased, with the operation's `Repo` or `Org` scope left out: `forge.tags.createRepoTagFamily` is `forge tags create-tag-family`. A read served at both a branch and a commit is one command that takes `--branch` or `--commit`. Its flags are the operation's path and query parameters, named without an `_id`, `_api_name`, or `_name` suffix, so `repo_id` is `--repo`. `attachment-blobs upload` and `download` wrap the attachment upload and download operations.

```sh
# Sign in through your browser: open the link it prints and approve the code
forge login --url https://api.onforge.com

# Check who you're signed in as
forge users get-user --url https://api.onforge.com

# Revoke the saved sign-in and forget it
forge logout --url https://api.onforge.com
```

`login` prints a link to the site's `/device` page and a code, and waits while you sign in there, check that the page shows the same code, and approve it. It saves the sign-in in Forge's XDG state directory, and later commands use it and renew it. Set `FORGE_URL` in your environment so that you don't need to pass `--url` on every command. To use another token, set `FORGE_TOKEN` or pass `--token`. Either takes the place of the saved sign-in, even when `login` checks the sign-in it just saved, so unset `FORGE_TOKEN` before you run `forge login`. A stale one ends the login with `InvalidCredentials`.

Commands that send a request body take it as `--data '<json>'`, or as `--data-file <path>`, where `-` reads standard input. Every command prints JSON to stdout on success, or nothing when the API answers with no body, as a delete does. On failure, it exits nonzero and prints a blank line, `ERROR`, and then a message to stderr. When the API refused the request, the message is the API's tagged error JSON. For other failures, such as an invalid `--url` or an API it can't reach, it's plain text. `forge <command> --help` lists each command's flags.

Source: https://buildrforge.com/docs/introduction/api-mcp-and-cli/index.mdx
