# Install Bitrise MCP Server in OpenAI Codex

## Prerequisites

1. The latest version of OpenAI Codex installed (the CLI or the IDE extension; see the [official Codex documentation](https://developers.openai.com/codex))
2. A Bitrise account
3. For local setup: [Go](https://go.dev/) (>=1.25) installed and a Bitrise PAT

## Bitrise MCP Server Configuration

Codex stores MCP servers in a `config.toml` file, under one `[mcp_servers.<name>]` table per server. The Codex CLI, the IDE extension, and the Codex desktop app share the same configuration.

- **Global configuration**: `~/.codex/config.toml` where `~` is your home directory
- **Project-specific**: `.codex/config.toml` in your project directory (Codex loads it for trusted projects only)

You can edit the file by hand or use the `codex mcp` commands. Start a new Codex session for manual changes to take effect.

### Remote Server Setup (Streamable HTTP) — Recommended

The remote server uses OAuth to authenticate you against your Bitrise account. No token to copy or paste.

1. Add the server:
   ```bash
   codex mcp add bitrise --url https://mcp.bitrise.io
   ```
   Or add it to `~/.codex/config.toml` yourself:
   ```toml
   [mcp_servers.bitrise]
   url = "https://mcp.bitrise.io"
   ```
2. Sign in:
   ```bash
   codex mcp login bitrise
   ```
   Codex opens your browser. Log in to Bitrise (or confirm your existing session) and approve the consent screen. On a machine without a browser, run `codex mcp login bitrise --no-browser` and open the URL it prints.
3. Verify that Codex works: [Verification](#verification).

#### Fallback: PAT-based authentication

If OAuth sign-in doesn't work in your setup, use a Personal Access Token.

1. [Create a Bitrise API Token](https://devcenter.bitrise.io/api/authentication) under [Account Settings → Security](https://app.bitrise.io/me/account/security).
2. Export the token as an environment variable. To keep it available in every new terminal, add the line to your shell profile, such as `~/.zshrc`:
   ```bash
   export BITRISE_TOKEN=your_token_here
   ```
3. Reference the variable in `~/.codex/config.toml`. Codex sends its value as a bearer token, so the token itself never goes into the file:
   ```toml
   [mcp_servers.bitrise]
   url = "https://mcp.bitrise.io"
   bearer_token_env_var = "BITRISE_TOKEN"
   ```
4. Restart the Codex app server from a shell where `BITRISE_TOKEN` is set, so that it picks up the variable:
   ```bash
   codex app-server daemon restart
   ```
5. Verify that Codex works: [Verification](#verification). Start `codex` from the same shell.

:::note

The Codex CLI connects to a background app server, which keeps the environment it was started with. If you export `BITRISE_TOKEN` after the app server started, Codex doesn't see it until you restart the app server, and opening a new terminal doesn't change that (see the [app server daemon README](https://github.com/openai/codex/blob/main/codex-rs/app-server-daemon/README.md)). See also [Server shows as failed](#server-shows-as-failed).

:::

### Local Server Setup (Go required)

The local server runs in stdio mode and authenticates with a Personal Access Token (no browser OAuth flow in stdio mode).

1. Add Bitrise to Codex. You have two options:

   - Store the token in `config.toml`. Run:

   ```bash
   codex mcp add bitrise --env BITRISE_TOKEN=YOUR_BITRISE_PAT -- go run github.com/bitrise-io/bitrise-mcp/v2@v2
   ```

   Codex writes the token into `~/.codex/config.toml` as plain text, under `[mcp_servers.bitrise.env]`, and passes it to the server when it starts. You don't need to export anything in your shell. Anyone who can read the file can read your token, so keep the file private and don't share or commit it.

   - Keep the token out of `config.toml`. Add the server to `~/.codex/config.toml` without the token:

   ```toml
   [mcp_servers.bitrise]
   command = "go"
   args = ["run", "github.com/bitrise-io/bitrise-mcp/v2@v2"]
   env_vars = ["BITRISE_TOKEN"]
   ```

   Codex forwards `BITRISE_TOKEN` from the environment of the Codex app server, so the token stays in your shell environment. Export the token:

   ```bash
   export BITRISE_TOKEN=your_token_here
   ```

   Restart the app server from the same shell so that it picks up the variable:

   ```bash
   codex app-server daemon restart
   ```

   :::note

   The Codex CLI connects to a background app server, which keeps the environment it was started with. If you export `BITRISE_TOKEN` after the app server started, Codex doesn't see it until you restart the app server, and opening a new terminal doesn't change that (see the [app server daemon README](https://github.com/openai/codex/blob/main/codex-rs/app-server-daemon/README.md)). See also [Server shows as failed](#server-shows-as-failed).

   :::

2. Verify that Codex works: [Verification](#verification). With option B, start `codex` from the same shell.

## Verification

1. **Check the configured servers**:
   ```bash
   codex mcp list
   ```
2. **Check the connection in Codex**: start Codex with `codex`, then type `/mcp` in the composer to see the connected servers and their tools.
3. **Test with a prompt**:
   ```
   List my Bitrise projects
   ```

## Advanced configuration

See [Tools](/bitrise-platform/ai/bitrise-mcp/tools) for enabling/disabling specific toolsets. To change the toolsets, add the `toolset` query parameter to the server URL (for the local server, set the `ENABLED_TOOLSET` environment variable instead):

```toml
[mcp_servers.bitrise]
url = "https://mcp.bitrise.io/?toolset=apps,builds,workspaces"
```

If a task needs a tool from a toolset you haven't enabled, the agent can call `list_toolset` to find out which toolset to add.

Codex also supports per-server settings such as `startup_timeout_sec` (default 10 seconds), `tool_timeout_sec` (default 60 seconds), and the `enabled_tools` and `disabled_tools` lists. See the [Codex MCP documentation](https://developers.openai.com/codex/mcp) for the full list.

## Troubleshooting

### Authentication Issues

- **OAuth flow doesn't open a browser**: Run `codex mcp login bitrise --no-browser` and open the URL manually, or fall back to PAT-based authentication
- **Token expired (PAT)**: Generate a new Bitrise token, update the environment variable, and restart the app server with `codex app-server daemon restart`
- **Authentication failed**: Run `codex mcp login bitrise` again, or remove the server with `codex mcp remove bitrise` and repeat the setup
- **Check that a PAT is valid**: The Bitrise API takes the token without a `Bearer` prefix. A `200` response means the token is valid:
    ```bash
    curl -s -o /dev/null -w "%{http_code}\n" -H "Authorization: $BITRISE_TOKEN" https://api.bitrise.io/v0.1/me
    ```

### Configuration Issues

#### Server shows as failed

If `/mcp` in Codex shows `bitrise: failed (0 tools)` and you use a PAT or the local server, the Codex app server probably doesn't have your environment variable. The app server runs in the background and keeps the environment it was started with, so a variable you export later is invisible to it. Run `codex doctor` to confirm: it reports `bearer token env var BITRISE_TOKEN is not set`.

1. Check that the variable is exported in your current shell:
    ```bash
    env | grep -c '^BITRISE_TOKEN='
    ```
    The output is `1` when it's exported.
2. Restart the app server from that shell, then start `codex` again from the same shell:
    ```bash
    codex app-server daemon restart
    ```

If the server still fails, stop the app server with `codex app-server daemon stop` and start `codex` again.

#### Other configuration issues

- **Invalid TOML**: Check the syntax of `~/.codex/config.toml`. Each server needs its own `[mcp_servers.<name>]` table
- **Project-level config ignored**: Codex loads `.codex/config.toml` only for trusted projects
- **Server doesn't start in time**: Raise `startup_timeout_sec` for the server. The `go run` command can take longer than the 10-second default on its first run
- **Tools not appearing**: Run `/mcp` in Codex to check the server status, then restart Codex
