🧠

CodexでStreamable HTTP対応のMCPを設定する

に公開

最近Codexを触っていて、Streamable HTTP対応のMCPを設定するのに沼ったので、記事にしました。この機能は、2025年9月27日に対応されたようです。

https://github.com/openai/codex/pull/4317

今回は例として、GithubのMCPを接続してみます。

https://github.com/github/github-mcp-server

設定する手順

1. ~/.codex/config.tomlを編集する

~/.codex/config.tomlを開き、下記の情報を追加します。

experimental_use_rmcp_client = true

[mcp_servers.サーバー名]
url = "url"
bearer_token_env_var = "環境変数名"

CodexはRust MCP client(RMCP)を使用しており、experimental_use_rmcp_client = trueはRMCPクライアントを有効にするための設定です。

[mcp_servers.サーバー名]は任意のサーバー名を指定してください。

urlはMCPサーバーのURLを指定します。

bearer_token_env_varは、MCPサーバーにアクセスするためのBearer Tokenを格納した環境変数名を指定します。間違えてもBearer Token自体を直接記載しないように注意してください。

したがって、最終的に下記のような設定になります。

experimental_use_rmcp_client = true

[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_MCP_PAT"

2. 環境変数を設定する

MCPサーバーにアクセスするためのBearer Tokenを環境変数に設定する必要があります。GitHub MCPの場合は、Personal Access Token(PAT)を発行して、それを環境変数に設定します。PATの作成方法は以下の記事がわかりやすいので、割愛します。

https://dev.classmethod.jp/articles/github-remote-mcp-ga/

今回はGITHUB_MCP_PATにPATの値を設定します。

echo 'export GITHUB_MCP_PAT="PATの値"' >> ~/.zshrc

この設定を行った後、ターミナルを再起動するか、source ~/.zshrcを実行して環境変数を反映させてください。

3. Codexで確認する

Codex CLIでMCPサーバーに接続できるか確認します。Codexを起動し/mcpコマンドを実行すると、接続されているMCPサーバーが表示されます。

🔌  MCP Tools

  • github
    • Status: enabled
    • Auth: Bearer token
    • URL: https://api.githubcopilot.com/mcp/
    • Tools: add_comment_to_pending_review, add_issue_comment, add_sub_issue, assign_copilot_to_issue, create_branch, create_issue, create_or_update_file, create_pull_request, create_repository, delete_file,
fork_repository, get_commit, get_file_contents, get_issue, get_issue_comments, get_label, get_latest_release, get_me, get_release_by_tag, get_tag, get_team_members, get_teams, list_branches, list_commits,
list_issue_types, list_issues, list_label, list_pull_requests, list_releases, list_sub_issues, list_tags, merge_pull_request, pull_request_read, pull_request_review_write, push_files, remove_sub_issue,
reprioritize_sub_issue, request_copilot_review, search_code, search_issues, search_pull_requests, search_repositories, search_users, update_issue, update_pull_request, update_pull_request_branch
    • Resources: (none)
    • Resource templates: Repository Content (repo://{owner}/{repo}/contents{/path*}), Repository Content for specific branch (repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}), Repository Content for
specific commit (repo://{owner}/{repo}/sha/{sha}/contents{/path*}), Repository Content for specific pull request (repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}), Repository Content for specific
tag (repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*})

これで、CodexでStreamable HTTP対応のMCPを設定できました。後は、AGENTS.mdにMCPの設定を追加すれば、よしなにMCPを使ってくれます。

まとめ

CodexでStreamable HTTP対応のMCPを設定する手順を紹介しました。設定自体はそこまで難しくありませんが、結構沼ったので、同じように困っている人の参考になれば幸いです。

Discussion