MCP 安装教程

如何在 Codex 中安装 MCP

Codex MCP 安装教程:config.toml 示例、CLI 命令和常见排查方法。

适合谁?

适合想给 Codex 增加本地工具、GitHub 上下文、文档和浏览器自动化能力的用户。

配置路径和示例

~/.codex/config.toml or .codex/config.toml

[mcp_servers."filesystem"]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "./"]

安装步骤

1

Pick a Codex-compatible MCP server

Prefer MCP servers with clear install commands, low risk, and recent maintenance.

2

Use Codex CLI or config.toml

For STDIO servers, use codex mcp add or paste a TOML block into the Codex config file.

codex mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem ./
3

Paste TOML config

Add a table under mcp_servers. For project-only config, use .codex/config.toml inside your repo.

[mcp_servers."filesystem"]
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "./"]
4

Restart Codex

Restart the Codex CLI session or IDE extension so MCP servers reload.

5

Confirm tools appear

If the server does not appear, check command availability, working directory, and TOML syntax.

常见问题

TOML syntax issue

Use quoted table names and array args. The config generator can produce the correct shape.

Command not found

Run the command in a terminal first to confirm npx, uvx, docker, or python is available.

Project vs global config

Use ~/.codex/config.toml globally or .codex/config.toml for a single project.

FAQ

Does Codex use JSON MCP config?

Codex uses TOML config, usually ~/.codex/config.toml or project-level .codex/config.toml.

Can Codex use remote MCP?

Codex can use Streamable HTTP MCP when the server provides a remote endpoint.