Skip to content

feat: add web-fetch MCP server for Codex engine#30400

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-web-fetch-tool-codex
Closed

feat: add web-fetch MCP server for Codex engine#30400
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-web-fetch-tool-codex

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

Smoke-codex runs were failing because the model reported "web-fetch MCP tool was not exposed in this session." Unlike Claude/Copilot/Gemini which expose web-fetch as a native built-in, Codex has no discoverable MCP tool by that name — the -c fetch config flag does not surface as a callable MCP tool.

Changes

  • web_fetch_server.cjs — new minimal Node.js MCP stdio server providing a fetch tool. Runs in a node:lts-alpine container with --network host. Includes SSRF guards (http/https-only protocol validation, redirect URL validation), a bounded redirect counter (max 5), and a 10 MiB response size cap.

  • mcp_setup_generator.gocollectMCPTools now accepts the engine ID; injects "web-fetch" into mcpTools only for Codex. Other engines are unaffected.

  • mcp_renderer_builtin.go — adds RenderWebFetchMCP (dispatches to TOML or JSON), renderWebFetchTOML, and renderWebFetchMCPConfigWithOptions. The generated gateway JSON entry:

    "web-fetch": {
      "container": "node:lts-alpine",
      "entrypoint": "node",
      "entrypointArgs": ["${RUNNER_TEMP}/gh-aw/actions/web_fetch_server.cjs"],
      "mounts": ["${RUNNER_TEMP}/gh-aw:${RUNNER_TEMP}/gh-aw:ro"],
      "args": ["--init", "--network", "host"]
    }

    After the gateway starts the container, convert_gateway_config_codex.cjs converts it to an HTTP URL entry in the final Codex config.toml.

  • mcp_renderer.go / mcp_renderer_types.go / mcp_rendering.go — adds RenderWebFetch field to MCPToolRenderers and wires it through buildStandardJSONMCPRenderers; nil-safe so non-Codex engines silently skip it.

  • codex_mcp.go — adds case "web-fetch" in the Codex TOML switch.

  • job_constants.go — adds WebFetchMCPServerID = "web-fetch" constant.

  • TestsTestCodexWebFetchMCPServer asserts the server appears in compiled Codex output; TestNonCodexEnginesDoNotGetWebFetchMCPServer asserts Claude and Copilot do not include it.

Copilot AI and others added 2 commits May 4, 2026 19:04
The smoke-codex test was failing because `web-fetch MCP tool was not
exposed` — the model reported no MCP tool named "web-fetch" was available.

Root cause: the Codex CLI's native `-c fetch` flag does not expose a
discoverable MCP tool by that name. Other engines (Claude, Copilot,
Gemini) provide web-fetch as a native built-in, but Codex requires an
explicit MCP server.

Fix:
- Add `web_fetch_server.cjs`: a minimal Node.js MCP stdio server that
  provides a `fetch` tool for HTTP/HTTPS content retrieval.  Runs inside
  a `node:lts-alpine` Docker container managed by the MCP gateway, with
  `--network host` so it can reach external URLs.
- Extend `collectMCPTools` to accept the engine ID and inject
  "web-fetch" into `mcpTools` only for the Codex engine.
- Add `RenderWebFetchMCP` to `MCPConfigRendererUnified`, generating both
  the preliminary TOML and gateway JSON configs.
- Add `case "web-fetch"` in `RenderJSONMCPConfig` and in the Codex TOML
  switch in `codex_mcp.go`.
- Add `WebFetchMCPServerID` constant.
- Add two unit tests: one verifying Codex includes the web-fetch server,
  one verifying Claude/Copilot do not.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/4a89b377-91b0-4c54-9237-4e50fead8e64

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add bounded redirect counter (MAX_REDIRECTS=5) to prevent infinite loops
- Validate redirect target URL is http/https before following (SSRF guard)
- Validate input URL protocol before making request
- Add response size limit (MAX_RESPONSE_BYTES=10MiB) to prevent memory exhaustion
- Extract duplicated serverScript path to package-level constant webFetchServerScript

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/4a89b377-91b0-4c54-9237-4e50fead8e64

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants