Skip to content
Back to search

mcp-code-mode

Code mode for any remote MCP server: one run(code) tool instead of many tool round trips

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/saurabhrkp-fiftyfive--mcp-code-mode/badge.svg)](/listings/saurabhrkp-fiftyfive--mcp-code-mode)

HTML

<a href="/listings/saurabhrkp-fiftyfive--mcp-code-mode"><img src="/api/listings/saurabhrkp-fiftyfive--mcp-code-mode/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

# 1. See what the server offers and how each tool is classified
npx -y github:saurabhrkp-fiftyfive/mcp-code-mode tools --url https://mcp.deepwiki.com/mcp

# 2. Add it to Claude Code (any MCP client that runs stdio servers works)
claude mcp add deepwiki-code -s user -- npx -y github:saurabhrkp-fiftyfive/mcp-code-mode serve \
  --url https://mcp.deepwiki.com/mcp --name dw \
  --read-only read_wiki_structure,read_wiki_contents,ask_wiki_question

The agent now has `mcp__deepwiki-code__run`. It writes code such as:

const repos = ['modelcontextprotocol/typescript-sdk', 'cloudflare/agents'];
const pages = await Promise.all(repos.map(repoName => dw.read_wiki_structure({ repoName })));
return pages.map(p => p.result.split('\n').slice(0, 5));

Servers that need sign-in

npx -y github:saurabhrkp-fiftyfive/mcp-code-mode login --url https://mcp.example.com/mcp
npx -y github:saurabhrkp-fiftyfive/mcp-code-mode login --url https://mcp.example.com/mcp --scope "read write"

`login` finds the auth server from the MCP server's metadata (RFC 9728, then RFC 8414 or OpenID), registers its own client (RFC 7591), opens the browser and saves the token to `~/.config/mcp-code-mode/tokens/<host>_<path>.json` (mode 600). It refreshes the token itself. For a server without dynamic registration, pass `--client-id`. For API-key servers, use `--token` or `--header "X-Api-Key: …"` instead.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 128 lines
  1. # mcp-code-mode
  2. Code mode for any remote MCP server, after Cloudflare's
  3. ["Code Mode"](https://blog.cloudflare.com/code-mode/) idea.
  4. An agent that uses MCP tools one by one pays a full model round trip per call, and every raw result
  5. lands in its context. Reading 27 chat channels means 28 tool calls and about 20,000 characters the model
  6. did not need.
  7. `mcp-code-mode` sits between the agent and a remote MCP server and gives the agent **one** tool:
  8. `run(code)`. The agent writes a short JavaScript script. The script calls the server's tools (in
  9. parallel if it likes), filters the data, and returns only the answer.
  10. ```js
  11. // one run() call instead of 28 tool calls
  12. const { channels } = await chat.list_channels({ limit: 50 });
  13. const convs = await Promise.all(channels.map(c => chat.read_conversation({ channel_id: c.id, limit: 20 })));
  14. return channels
  15. .map((c, i) => ({ name: c.name, unanswered: convs[i].messages.filter(m => m.text.includes('?')).length }))
  16. .filter(c => c.unanswered > 0);
  17. ```
  18. The `run` tool's description lists every remote tool as a typed function, built from the server's live
  19. `tools/list`. So the agent knows what it can call without any extra round trip.
  20. - Works with any MCP server over Streamable HTTP.
  21. - OAuth sign-in with dynamic client registration and PKCE, a static bearer token, or custom headers.
  22. - Read-only by default. You choose which tools count as read-only.
  23. - Plain Node 22+, no dependencies.
  24. ## Quick start
  25. ```sh
  26. # 1. See what the server offers and how each tool is classified
  27. npx -y github:saurabhrkp-fiftyfive/mcp-code-mode tools --url https://mcp.deepwiki.com/mcp
  28. # 2. Add it to Claude Code (any MCP client that runs stdio servers works)
  29. claude mcp add deepwiki-code -s user -- npx -y github:saurabhrkp-fiftyfive/mcp-code-mode serve \
  30. --url https://mcp.deepwiki.com/mcp --name dw \
  31. --read-only read_wiki_structure,read_wiki_contents,ask_wiki_question
  32. ```
  33. The agent now has `mcp__deepwiki-code__run`. It writes code such as:
  34. ```js
  35. const repos = ['modelcontextprotocol/typescript-sdk', 'cloudflare/agents'];
  36. const pages = await Promise.all(repos.map(repoName => dw.read_wiki_structure({ repoName })));
  37. return pages.map(p => p.result.split('\n').slice(0, 5));
  38. ```
  39. ### Servers that need sign-in
  40. ```sh
  41. npx -y github:saurabhrkp-fiftyfive/mcp-code-mode login --url https://mcp.example.com/mcp
  42. npx -y github:saurabhrkp-fiftyfive/mcp-code-mode login --url https://mcp.example.com/mcp --scope "read write"
  43. ```
  44. `login` finds the auth server from the MCP server's metadata (RFC 9728, then RFC 8414 or OpenID),
  45. registers its own client (RFC 7591), opens the browser and saves the token to
  46. `~/.config/mcp-code-mode/tokens/<host>_<path>.json` (mode 600). It refreshes the token itself.
  47. For a server without dynamic registration, pass `--client-id`. For API-key servers, use
  48. `--token` or `--header "X-Api-Key: …"` instead.
  49. ## Commands and options
  50. ```
  51. mcp-code-mode <serve|login|status|tools|run FILE> --url <mcp-url> [options]
  52. ```
  53. | Option | Env var | Meaning |
  54. |---|---|---|
  55. | `--url URL` | `MCP_URL` | Remote MCP endpoint. Required. |
  56. | `--name NAME` | `MCP_NAME` | Name of the object scripts use. Default `mcp`. |
  57. | `--read-only a,b,c` | `MCP_READ_ONLY` | Tools allowed in read-only mode. |
  58. | `--trust-hints` | `MCP_TRUST_HINTS=1` | Also allow tools the server marks `readOnlyHint: true`. |
  59. | `--write` | `MCP_WRITE=1` | Allow every tool, including writes. |
  60. | `--header "K: V"` | `MCP_HEADERS` (JSON) | Extra HTTP header. Repeatable. |
  61. | `--token TOKEN` | `MCP_TOKEN` | Static bearer token instead of OAuth. |
  62. | `--scope "a b"` | `MCP_SCOPE` | OAuth scope to ask for at login. |
  63. | `--client-id ID` | `MCP_CLIENT_ID` | OAuth client id for servers without dynamic registration. |
  64. `tools` prints each tool as `read` or `write` under your options, so you can check the list before you
  65. connect an agent. `run FILE` runs a script once from the shell, which is handy for testing.
  66. ## How it works
  67. ```
  68. agent ──run(code)──▶ mcp-code-mode (stdio MCP server, holds the token)
  69. │ fork: node --permission, empty env, no token
  70. ▼
  71. sandbox child: vm context with only <name>.*, console, sleep
  72. │ each <name>.tool(args) = IPC message to the parent
  73. ▼
  74. parent checks the tool is allowed, then calls the remote server over HTTP
  75. ```
  76. - Each run starts a fresh child process with Node's permission model: no file reads except the runner
  77. script, no child processes, no workers, an empty environment and a 256 MB heap.
  78. - The script runs in a `vm` context with no `require`, `import`, `process`, `fetch` or `eval`.
  79. - The child never sees the token. The parent makes every HTTP call and enforces the tool policy.
  80. - Limits per run: 120 s by default (max 300 s), 200 tool calls, 6 at a time, 4 MB per server reply,
  81. 20,000 log characters, 60,000 return-value characters, 40,000 characters of output.
  82. ## Safety
  83. - **Read-only by default, and you decide what read-only means.** A tool is allowed only if it is on
  84. `--read-only`, or if you pass `--trust-hints` and the server marks it `readOnlyHint: true`. With
  85. neither, every tool is blocked until you pass `--write`. A new tool the server adds later stays
  86. blocked.
  87. - `--write` lets scripts do anything the account can do. Use it only for servers and accounts you would
  88. let the agent use directly.
  89. - Tool results and tool descriptions come from the remote server. Treat them as data, not as
  90. instructions.
  91. - The sandbox is defence in depth, not a hard security boundary. Node has no network permission flag
  92. yet, so code that escapes the `vm` context could reach the network. It would still have no token, no
  93. environment and no file access.
  94. - Several agent sessions can share one login: refresh runs under a lockfile.
  95. ## Develop
  96. ```sh
  97. git clone https://github.com/saurabhrkp-fiftyfive/mcp-code-mode && cd mcp-code-mode
  98. npm test
  99. ```
  100. ## License
  101. MIT

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.