# How to connect Codex to a server

Codex, OpenAI's coding agent, can work with a server in two ways: through an MCP server added to its settings, or by running SSH commands in your terminal. Here is how each one works, what can go wrong, and a way that needs no server of your own.

## Tell your AI

1. Connect BitHut to your AI (Claude, ChatGPT or Codex): add the address `https://api.bithut.app/mcp`. How: https://bithut.app/connect.md
2. Then tell it:

```
Put this project online on BitHut and give me the address
```

## The short answer

Codex can reach a server in two ways.

- **An MCP server.** MCP (Model Context Protocol) is a standard way to give an AI a set of tools: "deploy", "show logs", "restart". You add the server to Codex once, and from then on Codex calls those tools by itself. The server can run on your computer or sit at an internet address.
- **SSH commands.** Codex types `ssh` commands in your terminal, logs in to the server and runs commands there, just as a person would.

For someone who doesn't want to look after a server, the safer route is a service that already has an MCP server, such as BitHut. Codex then gets a short list of clear tools instead of full control over a machine.

Everything about Codex on this page comes from OpenAI's own documentation, checked 23 November 2026.

## Where Codex keeps its connections

Codex stores MCP servers in a settings file, `~/.codex/config.toml`, and each server gets its own `[mcp_servers.<name>]` section ([OpenAI, MCP](https://learn.chatgpt.com/docs/extend/mcp?surface=cli)). The Codex CLI, the Codex IDE extension and the ChatGPT desktop app share this setup on the same computer, so a server you add once shows up in all three. ChatGPT on the web is different: it doesn't read these local files.

Commands worth knowing ([OpenAI, CLI reference](https://learn.chatgpt.com/docs/developer-commands?surface=cli)):

| Command | What it does |
|---|---|
| `codex mcp add <name> --url <address>` | adds a server that lives at an internet address |
| `codex mcp login <name>` | signs you in to that server, if it uses OAuth |
| `codex mcp list` | shows the servers Codex knows about |
| `codex mcp remove <name>` | deletes a server from the settings |
| `/mcp` inside Codex | shows the servers that are active right now |

## Your own VPS, option A: let Codex use SSH

If you already have a VPS, the quickest start is to let Codex log in over SSH and run commands. It works, but think about what you are handing over.

- **Codex acts as that user.** Whatever the SSH user can do on the server, Codex can do too, including deleting files or stopping a database. Make a separate user with only the rights the job needs, not `root`.
- **Keys, not passwords.** Log in with an SSH key, so no password ends up in a chat or a script.
- **Keep approvals on.** Codex has two separate controls: the sandbox decides which files and network it can reach, approvals decide when it stops to ask you. In the default Auto mode Codex works freely in your project folder and asks before editing files outside it or using the network ([OpenAI, approvals and security](https://learn.chatgpt.com/docs/agent-approvals-security)). An SSH connection needs the network, so you get to see the command first.
- **Avoid full access.** The `--dangerously-bypass-approvals-and-sandbox` flag (also `--yolo`) turns off both the sandbox and the questions. OpenAI marks it "not recommended". You can switch modes inside Codex with `/permissions`.

The catch with SSH is that you still run the server yourself: updates, the firewall, HTTPS certificates, backups, restarting things after a crash. Codex can type the commands, but deciding what is safe stays with you.

## Your own VPS, option B: run an MCP server on it

The other way is to put an MCP server on the VPS and give Codex its address. Codex then sees only the tools that server offers, not the whole machine.

1. **Run the server so it answers at an address.** Codex connects to such servers over "Streamable HTTP" ([OpenAI, MCP](https://learn.chatgpt.com/docs/extend/mcp?surface=cli)).
2. **Add it to Codex:**

   ```
   codex mcp add myserver --url https://mcp.example.com/mcp
   ```

3. **Sign in.** If the server uses OAuth, run `codex mcp login myserver`; a sign-in page opens in your browser. If the server takes a fixed token instead, `--bearer-token-env-var` tells Codex which environment variable holds it, and Codex sends it with every request ([OpenAI, CLI reference](https://learn.chatgpt.com/docs/developer-commands?surface=cli)).

The command writes a section like this to `config.toml`, which you can also edit by hand:

```toml
[mcp_servers.myserver]
url = "https://mcp.example.com/mcp"
```

Other keys from the documentation: `enabled = false` switches a server off without deleting it, `enabled_tools` limits which tools Codex may use, `startup_timeout_sec` (10 seconds by default) and `tool_timeout_sec` (60 seconds by default) set how long Codex waits.

What you have to take care of on the VPS:

- **HTTPS.** The address is on the open internet, so traffic should be encrypted. That means a domain and a certificate.
- **A sign-in check.** Without one, anyone who finds the address can call your tools.
- **Keeping it running.** The server must restart after a crash or a reboot, or Codex loses its tools.
- **The firewall.** Open only the port the server needs.

This is the right choice if you are building tools of your own. If all you want is to put a project online, it is a lot of work before the first deploy.

## The BitHut way: nothing to host

BitHut already runs an MCP server at `https://api.bithut.app/mcp`. You don't set up a VPS, a domain or a certificate. You add BitHut to Codex once and sign in. Step by step, with a prompt Codex runs by itself: [connect Codex to BitHut](/connect#codex).

After that you talk to Codex as usual, and it uses BitHut's tools:

- puts a project online and gives you its address: a site, a bot, a script on a schedule or a webhook receiver;
- stores keys and tokens apart from the code;
- reads logs and explains what went wrong;
- rolls back to an earlier version, pauses a project, restores data.

Sites start private behind a password page, and you open them when you want. One price for the account, any number of projects within the plan; see [pricing](/pricing).

## If something doesn't work

- **Codex doesn't see the server.** Run `codex mcp list`, or type `/mcp` inside Codex. If the server isn't there, add it again.
- **The server is there, but its tools fail.** Your sign-in may be missing or expired: run `codex mcp login <name>` again. Without a browser on that machine, add `--no-browser` and open the printed link yourself.
- **The server takes too long to start.** Raise `startup_timeout_sec` for it in `config.toml`.
- **Added in the terminal, missing in ChatGPT on the web.** That's expected: the web version doesn't read local Codex settings. The CLI, the IDE extension and the ChatGPT desktop app on the same computer do.
- **Codex asks before every SSH command.** That's the approval mode at work. Keep it on for servers you care about.
