How to Add Web Search to Codex CLI with MCP

Codex CLI can read your codebase, write files, and run shell commands. It cannot search the internet. If you ask it about a library released last month or a bug reported yesterday, it works from training data alone. MCP lets you fix that.

The Limitation

OpenAI built Codex CLI as a terminal coding agent. It operates on local files and shell commands. That’s a deliberate design choice: keep the agent focused on your code. But development doesn’t happen in a vacuum. You need to check whether a dependency is still maintained, look up error messages, or verify that an API you’re calling hasn’t changed its auth scheme.

Without web search, Codex answers these questions from memory. Its training data has a cutoff date. Anything after that date is invisible to it. The agent might confidently recommend a package that was deprecated three months ago, or suggest an API endpoint that no longer exists.

How MCP Fills the Gap

The Model Context Protocol gives Codex CLI a way to call external tools. An MCP server advertises a set of tools (with names, descriptions, and input schemas), and Codex discovers them at startup. When a task would benefit from one of those tools, Codex calls it.

For web search, this means Codex can decide on its own that it needs to look something up. You don’t have to paste URLs into the prompt or copy search results from your browser. The agent searches, reads the results, and uses them to inform its next action.

MCP support in Codex CLI works through a config.toml file. You define the server command, pass any required environment variables, and Codex picks up the tools on its next launch.

You have a few paths:

  1. Build your own MCP server. Write a small server that wraps a search API (Google Custom Search, Bing Web Search, SerpAPI). You manage the API key, the server process, and any rate limiting.

  2. Use an open-source MCP search server. Several exist on GitHub. Quality varies. You still need your own API key for the underlying search provider.

  3. Use a managed MCP service. Services like AgentPatch bundle search (and other tools) behind a single MCP endpoint. One API key, no server to run yourself.

The tradeoff is the usual one: more control vs. less setup.

Setup with AgentPatch

AgentPatch provides Google Search, Bing Search, and other tools through one MCP connection. Here’s how to wire it up:

The AgentPatch CLI is designed for AI agents to use via shell access. Install it, and your agent can discover and invoke any tool on the marketplace.

Install (zero dependencies, Python 3.10+):

pip install agentpatch

Set your API key:

export AGENTPATCH_API_KEY=your_api_key

Example commands your agent will use:

ap search "web search"
ap run google-search --input '{"query": "test"}'

Get your API key from the AgentPatch dashboard.

Add AgentPatch to ~/.codex/config.toml:

[mcp_servers.agentpatch]
url = "https://agentpatch.ai/mcp"
bearer_token_env_var = "AGENTPATCH_API_KEY"

Then set your API key:

export AGENTPATCH_API_KEY=your_api_key

Replace your_api_key with your actual key from the AgentPatch dashboard. Codex discovers all AgentPatch tools automatically on next start.

Example

You’re debugging a CORS issue with a third-party API:

“Search for whether the Stripe API changed its CORS headers in 2026. I’m getting blocked on preflight requests.”

Codex calls the search tool, finds a recent Stripe changelog entry, and reports back:

Searching Google for "Stripe API CORS headers change 2026"...

Stripe updated their CORS policy in January 2026 to restrict allowed origins
for client-side requests. You now need to add your domain to the Stripe
Dashboard under Developers > CORS Settings. Updating your integration now...

Without search, Codex would have guessed based on training data. With it, the agent pulled the actual change and applied the correct fix.

Wrapping Up

Codex CLI is a strong terminal agent, but it’s blind to anything published after its training cutoff. Adding web search through MCP removes that blind spot. AgentPatch handles the setup in one config block, and the same connection gives you access to image generation, email, news, and more. Check it out at agentpatch.ai.