Skip to content

feat(core): default Cloudflare MCP servers to codemode false - #57193

Open
kobzevvv wants to merge 1 commit into
anomalyco:devfrom
kobzevvv:fix/mcp-codemode-default-cloudflare
Open

kobzevvv wants to merge 1 commit into
anomalyco:devfrom
kobzevvv:fix/mcp-codemode-default-cloudflare

Conversation

@kobzevvv

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Cloudflare's MCP server is a Code Mode server: https://mcp.cloudflare.com/mcp serves Cloudflare's Code Mode interface (4 meta-tools: search / docs / execute / whoami), while https://mcp.cloudflare.com/mcp?codemode=false serves the raw OpenAPI operation list (thousands of individual tools).

Today OpenCode wraps it in its own Code Mode, so the model gets a catalog of thousands of Cloudflare OpenAPI operations instead of Cloudflare's 4 meta-tools — a bad default for every user.

This adds Cloudflare's endpoints to the urls list in mcp-codemode-defaults.ts, which turns OpenCode Code Mode off for them (codemode: false). It mirrors the existing executor.sh handling exactly: Cloudflare's MCP is a Code Mode server in the same sense, so its own Code Mode no longer ends up nested inside OpenCode's.

An explicit codemode in config is still left exactly as configured, both true and false.

How did you verify your code works?

cd packages/core
bun test test/plugin/mcp-codemode-defaults.test.ts
 1 pass
 0 fail
 32 expect() calls
Ran 1 test across 1 file. [187.00ms]

bun run check from the repo root is also clean.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Cloudflare's MCP server is a Code Mode server itself, so OpenCode Code Mode
is turned off for it by default, the same way it already is for executor.sh.
Without this the model receives a catalog of thousands of Cloudflare OpenAPI
operations instead of Cloudflare's four Code Mode meta-tools.

An explicit `codemode` in config is still left exactly as configured.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reverses a deliberate earlier design. #43157 first exempted the Cloudflare API MCP from OpenCode Code Mode. #45377 then took that exemption out on purpose and made client.ts add ?codemode=false to remote URLs instead, so Cloudflare sends its individual API tools and they stay behind OpenCode's searchable catalog rather than being nested inside Cloudflare's own Code Mode. This PR goes back to Cloudflare's 4 meta-tools with OpenCode Code Mode off. That is a defensible choice, but it should engage with the reasoning in #45377 and needs a maintainer decision; the description doesn't mention it.

How I checked: the changed unit test passes and typecheck in packages/core is clean. I read how this interacts with the ?codemode=false logic in packages/core/src/mcp/client.ts. I could not test against a live Cloudflare MCP server.

Public API: unchanged. Only the default for Cloudflare MCP servers that don't set codemode changes; explicit codemode settings are respected as before.

Concerns (inline): a Cloudflare URL configured with ?codemode=false now also gets OpenCode Code Mode turned off, so thousands of tools go straight to the model; and docs.mcp.cloudflare.com is not a Code Mode server.

const urls = [/^https:\/\/executor\.sh\/[^/]+\/mcp$/]
const urls = [
/^https:\/\/executor\.sh\/[^/]+\/mcp$/,
/^https:\/\/mcp\.cloudflare\.com\/mcp$/,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin drops the query string before matching (${url.origin}${url.pathname}). So a URL configured as https://mcp.cloudflare.com/mcp?codemode=false, where the user explicitly asked Cloudflare for its raw OpenAPI tools, also gets codemode: false. All of those thousands of tools would then go straight to the model with no OpenCode catalog in front, which is worse than both the current behaviour and what this PR is aiming for. If Cloudflare is matched here, please skip it when the URL already has a codemode parameter set to false/off.

As far as I can tell, docs.mcp.cloudflare.com serves a few documentation-search tools, not its own Code Mode interface. That's different from executor.sh or mcp.cloudflare.com. This list is meant for servers that are Code Mode themselves, so I'd drop this entry unless you can show the docs server behaves like the API server.

codemode: false,
},
{
name: "cloudflare raw tools",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case asserts the behaviour described in the comment on the defaults file: a user who configured ?codemode=false to get Cloudflare's raw tools ends up with OpenCode Code Mode off too. I'd expect undefined here.

This branch has not been deployed

No deployments
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.

1 participant