# Use MCP servers with your coding tools

> MCP servers run in your coding tool, not on the gateway. How to add one in Claude Code, Codex CLI, OpenCode, Cline, Cursor, Kilo Code and Zed, and the cost.

Source: https://oneaiapikey.com/docs/mcp

The [Model Context Protocol](https://modelcontextprotocol.io) (MCP) lets a coding tool connect to extra tools and data: a file system, a database, an issue tracker, a browser. MCP servers run **inside your coding tool**, on your machine or at a URL you choose. Relaykit does not run or host MCP servers. The gateway only sees the model requests your tool sends, so any MCP server that works in your tool works the same way when the model runs through Relaykit.

## How it fits together

1. Your coding tool starts or connects to the MCP servers in its config and reads the list of tools they offer.
2. With each model request, the tool sends those tool definitions along with your conversation, through the gateway, to the model.
3. When the model asks to call a tool, your coding tool runs it through the MCP server and sends the result back in the next request.

To the gateway, this is ordinary [tool calling](https://oneaiapikey.com/docs/tool-calling). Two things follow from that:

- **The model must support tool calling.** Pick a model with the Tools capability on the [models page](https://oneaiapikey.com/docs/models#current-models).
- **Tool definitions and tool results are input tokens.** They are billed at the model’s input rate on every request, and they reach the model’s provider like the rest of the conversation. A server with dozens of tools adds thousands of tokens to each turn. [Prompt caching](https://oneaiapikey.com/docs/prompt-caching) lowers the cost of the repeated part.

> **Only run servers you trust:** A local MCP server runs with your user’s permissions, and whatever it returns is sent to the model. Install servers from sources you trust, give file-system servers only the folders they need, and keep secrets out of tool results.

The examples below add the reference [filesystem server](https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem), which needs Node.js for `npx`. Replace `/path/to/project` with the folder it may read and write. `https://example.com/mcp` stands for any remote server you use. Set up the tool for Relaykit first with its guide.

## Claude Code

Set up: [Claude Code guide](https://oneaiapikey.com/docs/guides/claude-code). Add servers with `claude mcp add`. They are saved for you in the current project by default; add `--scope project` to write a shared `.mcp.json` in the project, or `--scope user` to use the server in every project.

Terminal:

```bash
# A local server (stdio): everything after -- is the command that starts it
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/project

# A remote server (Streamable HTTP)
claude mcp add --transport http docs https://example.com/mcp

# Check what is configured
claude mcp list
```

.mcp.json (project scope):

```json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
      "env": {}
    }
  }
}
```

Inside Claude Code, `/mcp` shows each server’s status. On native Windows (not WSL), wrap `npx` servers as `cmd /c npx ...`.

> **Tool search is off with a custom base URL:** When `ANTHROPIC_BASE_URL` points to a host other than Anthropic’s, Claude Code turns off its tool search, so the definitions of every connected MCP tool are sent with each request. Keep only the servers you need connected. Leave `ENABLE_TOOL_SEARCH` unset: it relies on a request feature that the gateway does not promise to pass through.

Claude Code warns when one tool result exceeds 10,000 tokens and cuts it at 25,000 by default (`MAX_MCP_OUTPUT_TOKENS`). Official docs: [Claude Code MCP](https://code.claude.com/docs/en/mcp).

## Codex CLI

Set up: [Codex CLI guide](https://oneaiapikey.com/docs/guides/codex-cli). Add a server from the terminal, or write it into `~/.codex/config.toml` next to your provider settings.

Terminal:

```bash
codex mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/project
codex mcp list
```

~/.codex/config.toml:

```toml
# A local server (stdio)
[mcp_servers.filesystem]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]

# A remote server; the token is read from an environment variable
[mcp_servers.docs]
url = "https://example.com/mcp"
bearer_token_env_var = "DOCS_MCP_TOKEN"
```

In the Codex interface, `/mcp` lists the connected servers. Official docs: [Codex MCP](https://learn.chatgpt.com/docs/extend/mcp?surface=cli).

## OpenCode

Set up: [OpenCode guide](https://oneaiapikey.com/docs/guides/opencode). Add an `mcp` block to the same `opencode.json` that holds your provider. `{env:NAME}` reads an environment variable.

opencode.json:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "filesystem": {
      "type": "local",
      "command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
      "enabled": true
    },
    "docs": {
      "type": "remote",
      "url": "https://example.com/mcp",
      "headers": { "Authorization": "Bearer {env:DOCS_MCP_TOKEN}" }
    }
  }
}
```

Check with `opencode mcp list`. Official docs: [OpenCode MCP servers](https://opencode.ai/docs/mcp-servers/).

## Cline

Set up: [Cline guide](https://oneaiapikey.com/docs/guides/cline). In the Cline panel, open the **MCP Servers** icon, then **Configure** and **Configure MCP Servers**. This opens `cline_mcp_settings.json`. Remote servers need `"type": "streamableHttp"`; without it Cline uses the older SSE transport.

cline_mcp_settings.json:

```json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
      "disabled": false,
      "autoApprove": []
    },
    "docs": {
      "type": "streamableHttp",
      "url": "https://example.com/mcp"
    }
  }
}
```

`autoApprove` lists tools Cline may run without asking. Leave it empty until you trust a server. Official docs: [Cline MCP overview](https://docs.cline.bot/mcp/mcp-overview).

## Cursor

Set up: [Cursor guide](https://oneaiapikey.com/docs/guides/cursor). Put servers in `.cursor/mcp.json` in a project, or in `~/.cursor/mcp.json` for every project. `${env:NAME}` reads an environment variable.

.cursor/mcp.json:

```json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
    },
    "docs": {
      "url": "https://example.com/mcp",
      "headers": { "Authorization": "Bearer ${env:DOCS_MCP_TOKEN}" }
    }
  }
}
```

MCP tools are used in Agent chats. Requests use your Relaykit key only with the models you added under your own key; the [Cursor guide](https://oneaiapikey.com/docs/guides/cursor) explains which Cursor features use Cursor’s own infrastructure instead. Official docs: [Cursor MCP](https://cursor.com/docs/mcp).

## Kilo Code

Set up: [Kilo Code guide](https://oneaiapikey.com/docs/guides/kilo-code). In VS Code, open Kilo Code’s **Settings**, then **MCP** and **Add Server**. The CLI reads `~/.config/kilo/kilo.jsonc`, or `kilo.jsonc` in a project. Remote servers use the same `type: "remote"` form as OpenCode.

kilo.jsonc:

```jsonc
{
  "mcp": {
    "filesystem": {
      "type": "local",
      "command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
      "enabled": true
    }
  }
}
```

Official docs: [Kilo Code MCP](https://kilo.ai/docs/automate/mcp/using-in-kilo-code).

## Zed

Set up: [Zed guide](https://oneaiapikey.com/docs/guides/zed). Add servers under `context_servers` in Zed’s `settings.json`. Remote servers take `url` and optional `headers` instead of `command`.

settings.json:

```json
{
  "context_servers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
      "env": {}
    }
  }
}
```

Under **Settings**, **AI**, **MCP Servers**, a green dot means the server is running. Official docs: [Zed MCP](https://zed.dev/docs/ai/mcp).

## Aider

Aider has no built-in MCP support. It is an [open feature request](https://github.com/Aider-AI/aider/issues/4506). Use one of the tools above if you need MCP.

## Troubleshooting

- **The server does not start.** Run its command in a terminal yourself. Most failures are a missing Node.js or Python, a wrong path, or a missing environment variable. The gateway is not involved at this stage.
- **The tools are listed but the model never uses them.** Check that the model has the Tools capability on the [models page](https://oneaiapikey.com/docs/models#current-models), and ask for the tool by name once to test.
- **Requests got expensive.** Every connected tool’s definition is sent with each request. Disconnect servers you are not using and check the input tokens per request on the [usage page](https://oneaiapikey.com/console/usage).
- **`400` about context length.** Long tool results build up in the conversation. Start a new session, or ask for smaller results (one file, not a folder).
- **`401` or `403`.** These come from your key or model list, not from MCP. See [Errors](https://oneaiapikey.com/docs/errors#access-denied).

## Related

- [Tool calling](https://oneaiapikey.com/docs/tool-calling): the request format behind every MCP tool call.
- [Coding tools overview](https://oneaiapikey.com/docs/guides): set up each tool for Relaykit.
- [Cost control](https://oneaiapikey.com/docs/cost-control): spend limits for keys used by agents.
