返回 CodeWhale
MCP.md
根目录 / docs / MCP.md
1 # MCP (External Tool Servers)
2
3 In the terminal, `/mcp` (also `/mcps`) opens **Plugins → Connectors**. Enter opens the selected server’s recovery action or read-only details. An empty inventory offers server suggestions; browsing them installs nothing. Explicit subcommands such as `/mcp status`, `/mcp doctor`, `/mcp login`, and `/mcp add` retain their existing behavior.
4
5
6 > 阅读简体中文版:[zh_hans/MCP.md](zh_hans/MCP.md)
7
8 Everything you add to Codewhale is a plugin. An MCP server you configure is a
9 plugin of the kind **Connector**, and a plugin bundle can also carry connectors.
10 Connectors are managed under Plugins → Connectors in the terminal and
11 Customize › Connectors on the desktop. The configuration
12 files, sign-in and the `/mcp` commands are unchanged. "Connection" on this page
13 means the live link to a server; as a product noun it is the word for a model
14 provider or another agent.
15
16 Codewhale can load additional tools via MCP (Model Context Protocol). MCP servers can be local stdio processes that Codewhale starts, or remote URL-based servers that speak Streamable HTTP with legacy SSE fallback.
17
18 ## Version scope
19
20 This page describes the current MCP runtime and transport surface: local stdio, remote HTTP/SSE, environment-backed
21 authentication, direct remote OAuth (including issuer/resource-bound
22 credentials and hosted client metadata), bounded catalog refresh, verified
23 skill resource reads, and reviewed plugin-contributed MCP. By default it uses
24 the official MCP SDK 2.4.0 host (with explicit Rust backend selection still
25 available) and a 120-second default connect budget for package-runner commands
26 unless overridden per server.
27
28 The default SDK host needs a supported Node runtime (`^22.19 || >=24`);
29 Bun 1.4.0 or newer is opt-in. See [plugin runtime requirements](EXTENSIONS.md).
30 An MCP server's own executable, dependencies, authentication and OS requirements
31 remain separate from Codewhale's transport support.
32
33 Browsing note:
34 - `Web` is the canonical, deferred built-in browsing tool; it provides
35 `search`, `fetch`, and `wait` actions when network policy permits.
36 - `web_search`, `fetch_url`, and `wait_for_dev_server` are hidden replay-only
37 aliases. New prompts and integrations should use `Web`.
38
39 Server mode note:
40 - `codewhale serve --mcp` runs the MCP stdio server.
41 - `codewhale serve --http` runs the runtime HTTP/SSE API (separate mode).
42 - `codewhale mcp-server` is an equivalent stdio entrypoint on the same
43 consolidated runtime.
44
45 The legacy child-server aggregation proxy has been removed. `mcp-server`
46 now uses the same native tool server as `serve --mcp`; it does not launch the
47 legacy `mcp.server_definitions` list. Saved definitions are left intact. Configure
48 external servers in `mcp.json` for the existing MCP client, or connect to those
49 servers directly from your external client. Native server write tools remain
50 withheld unless the operator explicitly permits them in its server configuration.
51
52 The native stdio server supports MCP **2026-07-28** with required per-request
53 metadata and `server/discover`; no initialization handshake is needed for that
54 revision. It also supports the explicit legacy revisions **2024-11-05**,
55 **2025-03-26**, **2025-06-18** and **2025-11-25** through `initialize`.
56 Initialization never selects a modern revision; unsupported initialization
57 versions fall back to 2025-11-25. Legacy callers should send
58 `notifications/initialized`, but calls may proceed after a valid initialize
59 response. This describes Codewhale as a server; outbound MCP client version
60 support is configured separately.
61
62 `resources/list` pages through the effective native skill instruction catalog,
63 and `resources/read` returns the accepted instruction body for an exact listed
64 `codewhale://skills/...` URI. Discovery follows the configured skill roots,
65 precedence and workspace trust; disabled skills are omitted. Reads supply inert
66 Markdown and never activate a skill. These are instruction-body resources, not
67 original SKILL.md files or complete skill packages. Plugin skills, arbitrary
68 filesystem paths and session transcripts are not exposed by this catalog.
69 The old workspace/session entries, which had no resource reader, are removed.
70 Resource templates are empty. Lists and reads use private caching with a zero
71 TTL; restart pagination if a changed catalog invalidates a cursor.
72
73 Only tools and resources are advertised. Subscriptions, list-change
74 notifications, the Skills extension, Apps, tasks and interactive approval are
75 not implemented by this server. Tool execution remains serialized through the
76 Rust registry, and request cancellation reaches the existing tool context.
77 Keep stdin open until responses arrive; closing it cancels outstanding work.
78 Malformed JSON and oversized input frames are discarded by the bounded SDK
79 transport, while well-formed invalid JSON-RPC receives an error.
80
81 ## Setup wizard vs manual MCP setup (#3407)
82
83 The `/setup` hub includes an optional **Tools and MCP**
84 step. That step is discovery/readiness only:
85
86 | Wizard can do | Still requires manual / explicit action |
87 | --- | --- |
88 | Show configured servers as `healthy` / `needs_config` / `off` | Start or connect MCP servers |
89 | Report config path presence (global + project) | Write or edit `mcp.json` contents |
90 | Safe static health probe (missing command/url, broken absolute path, missing bearer env) | `codewhale mcp validate`, live connect, OAuth login |
91 | Point at safe on-ramps (`/mcp`, `codewhale mcp init`, `codewhale doctor`) | Install community skills, trust skills, enable plugins |
92 | Share Hotbar source counts from the same skill/MCP adapters (#3399) | Bind Hotbar slots (Hotbar step / `H`) |
93 | Record optional/`needs_action` setup_state without blocking first-run | Anything that spawns processes or installs packages |
94
95 Empty inventory is **not** an error: first-run users see “nothing configured
96 yet, that’s fine.” Failing or incomplete configured servers surface as
97 `needs_config` with an actionable hint and never block setup completion.
98 Enumeration never executes MCP/plugin commands beyond the static probe.
99 Summaries redact commands, args, env, headers, and tokens.
100
101 `codewhale doctor --full` reports MCP/skills/tools/plugins health with the same
102 optional-surface intent (paths, counts, static checks) so wizard and doctor
103 stay consistent.
104
105 ## Plugin-contributed MCP
106
107 A reviewed local plugin bundle may contribute MCP servers without creating a
108 second transport or approval system. The servers use the same MCP manager,
109 tool approval, resource, prompt, timeout, and network-policy paths documented
110 here, and appear under collision-resistant
111 `plugin-<plugin-name-byte-length>-<plugin>-<server>` identities.
112
113 Authentication differs from direct user-authored MCP configuration. Plugin
114 remotes may use `env_headers` or `bearer_token_env_var`, but plugin-contributed
115 MCP OAuth is disabled. Declaring OAuth,
116 scopes or an OAuth resource in a plugin MCP manifest fails validation. To use
117 OAuth, configure the remote server directly in your own `mcp.json` instead.
118
119 The bundle boundary is intentionally stricter than user-authored `mcp.json`:
120 unknown fields and ambiguous transports fail closed; stdio environment values
121 must be exact environment-source references; remote literal headers and
122 secret-bearing URLs are rejected; declared network hosts must exactly match
123 the normalized endpoint host set; and redirects remain on the reviewed origin.
124 Reviewed plugin remotes also bypass ambient HTTP proxy configuration entirely;
125 proxy credentials and proxy-observed traffic are not part of the v1 review.
126 The plugin review discloses local host-user authority, structural argv,
127 environment provenance, endpoint, auth source names, and tool filters
128 without reading or printing secret values.
129
130 Trust stages reviewed content but does not enable it. Enablement attaches that
131 staged snapshot to the current workspace's MCP pool. Disable, revoke, and other
132 cross-process generation changes remove catalog entries, cancel in-flight
133 operations, and terminate plugin stdio children. Source or staged-tree drift is
134 fully revalidated before each dispatch/catalogue boundary and fails the next
135 boundary closed; Codewhale does not continuously hash mutable trees during an
136 already-running call and therefore does not promise drift-triggered mid-call
137 cancellation. MCP subscriptions are not exposed through plugin bundles. See
138 [Plugin bundles](PLUGIN_BUNDLES.md) for the complete lifecycle contract.
139
140 ## Bootstrap MCP Config
141
142 Create a starter MCP config at your resolved MCP path:
143
144 ```bash
145 codewhale mcp init
146 ```
147
148 `codewhale setup --mcp` performs the same MCP bootstrap alongside skills setup.
149
150 Common management commands:
151
152 ```bash
153 codewhale mcp list
154 codewhale mcp tools [server]
155 codewhale mcp add <name> --command "<cmd>" --arg "<arg>"
156 codewhale mcp add <name> --url "http://localhost:3000/mcp"
157 codewhale mcp add <name> --url "https://example.com/mcp" --bearer-token-env-var MCP_TOKEN
158 codewhale mcp login <name>
159 codewhale mcp logout <name>
160 codewhale mcp enable <name>
161 codewhale mcp disable <name>
162 codewhale mcp remove <name>
163 codewhale mcp validate
164 ```
165
166 Shell commands inspect their own process's MCP pool. In particular,
167 `codewhale mcp validate` starts and connects enabled, allowed servers and reports
168 connection/discovery failures; it is not a static configuration check and does
169 not attach those connections to a running TUI. In the TUI, `/mcp validate`
170 reports the last recorded snapshot without reconnecting; `/mcp reload` rebuilds
171 that session's live pool. `codewhale doctor` is the static diagnostic path
172 unless an explicit probe is requested.
173
174 `codewhale mcp logout <name>` (and `/mcp logout`) clears locally stored
175 OAuth credentials only — the provider may keep its standing grant. The next
176 login forces the consent screen, so the authorized account/workspace can
177 change; to sever the grant remotely, revoke the app from the provider's
178 account settings.
179
180 ## In-TUI Manager
181
182 Inside the interactive TUI, `/mcp` opens a compact manager for the resolved
183 MCP config path. It shows each configured server, whether it is enabled or
184 disabled, its transport, command or URL, timeout values, connection errors,
185 and discovered tools/resources/prompts when discovery has been run.
186
187 Supported in-TUI actions:
188
189 ```text
190 /mcp init
191 /mcp init --force
192 /mcp import
193 /mcp recommendations
194 /mcp add recommended <id>
195 /mcp add stdio <name> <command> [args...]
196 /mcp add http <name> <url>
197 /mcp login <name> [--scope scope]
198 /mcp logout <name>
199 /mcp enable <name>
200 /mcp disable <name>
201 /mcp remove <name>
202 /mcp validate
203 /mcp reload
204 ```
205
206 ### Suggested plugins and companion integrations
207
208 `/mcp recommendations` is Codewhale's native, curated suggestions surface.
209 The entries are described as product plugins, with their component type and
210 provenance, but `/mcp add recommended <id>` still writes only the named MCP
211 server component. Viewing recommendations never fetches, installs, trusts, or
212 enables anything. Adding one writes configuration; the server is first started
213 only after an explicit `/mcp restart`.
214
215 The built-in product suggestions use these reviewed, pinned definitions. The
216 Plugins view is the product/install surface; MCP, Skills, and sandbox adapters
217 are transparent component kinds and their own tabs remain operational and
218 diagnostic surfaces:
219
220 | Plugin | Component | Pinned definition | Provenance and maturity | Installation boundary |
221 | --- | --- | --- | --- | --- |
222 | Chrome DevTools | MCP server (stdio) | `npx -y chrome-devtools-mcp@1.7.0` (`npx.cmd` on Windows) | [Official ChromeDevTools project](https://github.com/ChromeDevTools/chrome-devtools-mcp) | npm may download the pinned package when the user restarts MCP. |
223 | Playwright | MCP server (stdio) | `npx -y @playwright/mcp@0.0.79 --isolated` (`npx.cmd` on Windows) | [Official Microsoft project](https://github.com/microsoft/playwright-mcp) | `--isolated` starts a fresh browser profile; npm may download the pinned package only after an explicit restart. |
224 | Computer Use | First-party plugin (MCP + skill) | Install `computer-use` from the first-party catalog; updates independently | Codewhale; install, review and enable through Connectors or `/plugin` | This is the only computer-use integration Codewhale recommends. Third-party desktop-control MCPs are not listed here. |
225 | Browser Use | Skill plus separately installed Python runtime | Skill/runtime release `0.13.8` | [Official browser-use project](https://github.com/browser-use/browser-use) | Optional companion: not an MCP server. Codewhale does not auto-run the upstream Skill installer or install its browser/runtime dependencies. |
226 | Anthropic Sandbox Runtime | Sandbox adapter companion | `@anthropic-ai/sandbox-runtime@0.0.73` | [Official anthropic-experimental project](https://github.com/anthropic-experimental/sandbox-runtime); beta | Documentation-only adapter candidate: not an MCP server and not an active Codewhale plugin adapter. It does not replace Codewhale's sandbox policy. |
227
228 [Container Use](https://github.com/dagger/container-use) remains an additional
229 experimental suggestion with an MCP server component (`container-use stdio`).
230 The binary must be installed separately; `/mcp add recommended container-use`
231 only writes config and Codewhale never downloads it.
232
233 This presentation follows the same useful boundary found in the local
234 Grokbuild extensions view (one product plugin may expose MCP or Skill
235 components while component tabs stay inspectable), the Kimi marketplace's
236 explicit display name/tier/source fields, and the Codex marketplace's explicit
237 source and install-policy fields.
238 Codewhale keeps its stricter rule: provenance and foreign policy are display
239 metadata only, never inherited trust or automatic installation. For full
240 bundle and marketplace semantics, see [Plugin bundles](PLUGIN_BUNDLES.md).
241
242 `/mcp validate` (alias `/mcp doctor`) with no name reports each server's state
243 from the last MCP snapshot the TUI recorded, in a pager over
244 **Plugins → Connectors**. That snapshot is usually the engine pool's latest report,
245 but some actions, such as `/mcp import`, replace it with a separate UI
246 discovery pass that also connects `lazy` servers the engine has not started.
247 Validate also re-reads the MCP config files without connecting: it
248 reports a config load error first, lists configured servers the snapshot has
249 not observed, and says when a `/mcp reload` is pending. It does not reconnect
250 anything or change the catalog the model gets; `/mcp reload` is the fresh
251 probe.
252
253 `/mcp reload` (aliases `/mcp reconnect`, `/mcp restart`) is the hot-reload path.
254 It re-reads the MCP config sources and reconnects the servers session boot starts (see [Connection Lifecycle](#connection-lifecycle)) through the engine-owned pool,
255 so the rebuilt catalog is the exact one the next model turn uses — no TUI
256 restart. Config edits made from the TUI are written immediately and the manager
257 marks the snapshot reload-required until you run it; a failed reload leaves the
258 previous live pool intact and says so.
259
260 Headless surfaces are the exception: the `ConfigReload` app-server request does
261 **not** refresh MCP connections, so a headless runtime still needs a restart
262 after MCP config changes.
263
264 ## Remote network authority
265
266 Direct HTTP/SSE requests to public hostnames validate every DNS answer and pin
267 connections to a public address. This also applies to configured servers,
268 redirects, and OAuth HTTP requests. The configured network allow/deny policy
269 applies to login and token refresh as well as MCP tool requests.
270
271 A configured `localhost` name or private IP literal explicitly permits that
272 local endpoint. For a private DNS name, opt in on the server configuration:
273
274 ```json
275 {
276 "mcpServers": {
277 "internal": {
278 "url": "https://mcp.internal.example/mcp",
279 "allow_private_network": true
280 }
281 }
282 }
283 ```
284
285 `allow_private_network` defaults to false. This exception applies only to the
286 configured origin (scheme, host, and port); it does not authorize a different
287 redirect or OAuth origin. Servers added by the model during a session cannot
288 use this exception, even if their configuration contains the flag.
289
290 Operator-configured servers continue to honor `HTTP_PROXY`, `HTTPS_PROXY`, and
291 `NO_PROXY`. When a proxy is selected for the configured origin, destination DNS
292 resolution and private-network filtering are delegated to that operator-chosen
293 proxy; a local DNS pin cannot constrain a proxy's own resolution. A `NO_PROXY`
294 match uses the direct guarded connection instead. Model-added servers,
295 reviewed plugin remotes, and secondary redirect/OAuth origins do not inherit
296 ambient proxy authority.
297
298 ## Remote HTTP Auth
299
300 Direct URL-based MCP servers can use static headers, env-derived headers,
301 bearer-token env vars, or OAuth. Plugin-contributed remotes are limited to
302 environment-backed headers/bearer tokens and cannot use MCP OAuth; see
303 [Plugin-contributed MCP](#plugin-contributed-mcp). Authorization precedence for
304 direct servers is conservative:
305
306 1. `headers` and `env_headers` are applied first.
307 2. `bearer_token_env_var` adds `Authorization: Bearer <env value>` when no
308 Authorization header was already set.
309 3. Stored OAuth credentials are used only when no Authorization header exists.
310
311 For bearer-token auth, prefer env-backed config:
312
313 ```json
314 {
315 "servers": {
316 "remote": {
317 "url": "https://example.com/mcp",
318 "bearer_token_env_var": "EXAMPLE_MCP_TOKEN"
319 }
320 }
321 }
322 ```
323
324 For generic remote MCP OAuth, add the URL server and run login:
325
326 ```bash
327 codewhale mcp add remote --url "https://example.com/mcp"
328 codewhale mcp login remote
329 ```
330
331 Codewhale discovers the server OAuth metadata, opens the authorization URL in
332 your browser, listens on a local callback, exchanges the code, and stores the
333 token response through the Codewhale secrets backend. Stored OAuth tokens are
334 looked up by server name plus URL and refreshed when possible before requests.
335 Each saved credential also records the exact discovered authorization issuer
336 and resource. Reload compares both before installing credentials; a changed
337 issuer or resource requires a new login. Existing records without this binding
338 are preserved but cannot be reused: run `codewhale mcp login <name>` to replace
339 them after authorization.
340 During login, the CLI prints the authorization URL and a waiting status while
341 the local callback listener is active. If a URL-based server returns 401 or
342 Unauthorized during connect/discovery, `codewhale mcp connect <name>` reports
343 that OAuth authentication is required and points to
344 `codewhale mcp login <name>`. Resource helper listings also surface an
345 `authentication_required` entry for auth-shaped failures instead of silently
346 looking empty.
347
348 Optional OAuth fields:
349
350 ```json
351 {
352 "servers": {
353 "remote": {
354 "url": "https://example.com/mcp",
355 "scopes": ["tools/read"],
356 "oauth": {
357 "client_id": "public-client-id",
358 "issuer": "https://auth.example.com"
359 },
360 "oauth_resource": "https://example.com/mcp"
361 }
362 }
363 }
364 ```
365
366 A pre-registered `oauth.client_id` requires its exact `oauth.issuer`. The CLI
367 accepts `--oauth-client-id` together with `--oauth-issuer`. The optional
368 `oauth_resource` is an exact pin for the SDK-discovered resource; it does not
369 append or override a second audience value.
370
371 Alternatively, configure `oauth.client_metadata_url` (CLI:
372 `--oauth-client-metadata-url`) with the HTTPS URL of an operator-hosted client
373 metadata document. Codewhale uses it when the authorization server advertises
374 CIMD support, otherwise tries advertised dynamic registration. Pre-registration
375 takes priority. Codewhale identifies this desktop/CLI client as `native`; a
376 hosted document must describe that client and its actual callback URLs. No
377 Codewhale-hosted metadata document is supplied by this setting. Servers must
378 publish discoverable authorization metadata; guessed legacy OAuth endpoints
379 are not used for login or credential reload.
380
381 User-level config can set callback behavior when the provider requires a fixed
382 redirect:
383
384 ```toml
385 mcp_oauth_callback_port = 1455
386 mcp_oauth_callback_url = "http://127.0.0.1:1455/callback"
387 ```
388
389 These callback fields are ignored from project-scope config overlays.
390
391 ## Hugging Face MCP
392
393 Hugging Face provides a hosted MCP server for Hub resources, documentation,
394 datasets, Spaces, and community tools. Codewhale does not call Hugging Face's
395 Hub HTTP APIs from `/hf`; it only helps you inspect and set up the MCP config
396 that the regular MCP manager will load.
397
398 The recommended setup path is Hugging Face's settings-generated configuration:
399
400 1. Visit <https://huggingface.co/settings/mcp> while signed in.
401 2. Choose the MCP client closest to your Codewhale config shape and copy the
402 generated server snippet.
403 3. Paste the Hugging Face server entry into your resolved MCP config file.
404 4. Run `/mcp reload` to rebuild the live model-visible tool pool.
405
406 Codewhale reads both `servers` and `mcpServers`, so settings-generated snippets
407 can be adapted without changing the rest of the MCP file. A placeholder-only
408 shape looks like this:
409
410 ```json
411 {
412 "servers": {
413 "huggingface": {
414 "url": "https://huggingface.co/mcp",
415 "bearer_token_env_var": "HF_TOKEN"
416 }
417 }
418 }
419 ```
420
421 Set `HF_TOKEN` in the environment that launches Codewhale; the example contains
422 only its variable name. Literal `headers` values do not expand `${HF_TOKEN}`.
423 Adapt the settings-generated server entry and never commit real tokens.
424
425 Interactive helpers:
426
427 ```text
428 /hf mcp status
429 /hf mcp setup
430 /hf concepts
431 ```
432
433 `/hf mcp status` checks the configured MCP file for common Hugging Face server
434 names or Hugging Face MCP URLs. `/hf concepts` explains the difference between
435 the Hugging Face provider route, Hugging Face MCP, and explicit Hub workflows.
436
437 Official docs: <https://huggingface.co/docs/hub/hf-mcp-server>
438
439 ## OpenDesign
440
441 [OpenDesign](https://github.com/nexu-io/open-design) ships a stdio MCP server
442 (`od mcp`) that lets an agent read files from local OpenDesign projects and
443 create project-scoped artifacts. Its `od mcp install` has no Codewhale target,
444 so add the entry by hand:
445
446 1. Start OpenDesign so its daemon is running.
447 2. Copy the launch spec your install generated, from **Settings → MCP server**
448 in the desktop app or from `curl -s http://127.0.0.1:7456/api/mcp/install-info`
449 (use your daemon's port). It has a `command` (the absolute path of
450 OpenDesign's Node-compatible runtime), `args` (the absolute path of its CLI
451 entry, then `mcp`, then `--daemon-url http://127.0.0.1:<port>` unless the
452 daemon runs as a sidecar) and an `env` map that pins `OD_DATA_DIR`.
453 3. Put those three fields under one server name in your resolved MCP config,
454 inside the server map the file already has. Files written by
455 `codewhale mcp init` and `codewhale mcp add` use `servers`; OpenDesign's
456 generic snippet uses `mcpServers`. Keep exactly one of the two keys: a file
457 with both fails to parse.
458 4. Run `/mcp reload`, or check from a shell with
459 `codewhale mcp tools open-design`.
460
461 A placeholder-only shape:
462
463 ```json
464 {
465 "servers": {
466 "open-design": {
467 "command": "/absolute/path/to/node",
468 "args": ["/absolute/path/to/open-design/cli.js", "mcp", "--daemon-url", "http://127.0.0.1:7456"],
469 "env": { "OD_DATA_DIR": "/absolute/path/to/open-design-data" }
470 }
471 }
472 }
473 ```
474
475 Copy every `env` entry the snippet gives you; a packaged app adds more, such
476 as `ELECTRON_RUN_AS_NODE=1` when `command` is the app's own binary.
477 `codewhale mcp add` cannot set `env`, so edit the file instead. By default the
478 `od mcp` process exits after 30 idle minutes; set `OD_MCP_STDIO_IDLE_EXIT_MS`
479 to `"0"` in `env` to keep it running until Codewhale disconnects.
480
481 OpenDesign can also launch Codewhale as its agent. Its "DeepSeek TUI" runtime
482 adapter runs `deepseek`, falling back to `codewhale`, as
483 `exec --auto [--model <id>] <prompt>`, reads plain-text output, and caps the
484 prompt at 30,000 bytes of argv. A dedicated adapter could instead pipe the
485 prompt into `codewhale exec --auto --output-format stream-json --prompt-file -`,
486 list models with `codewhale models --json`, and continue a run with
487 `codewhale exec --resume <id>`, taking the id from the `saved_session_id` field
488 of the `session_capture` event; the terminal `metadata` event carries only a
489 fingerprint. `--auto` enables Full Access by default (no Codewhale shell
490 sandbox, trust mode on); adding `--sandbox workspace-write` keeps the shell
491 sandbox and file-tool workspace restrictions, with trust mode off. These
492 tool-offering exec runs are saved with either plain-text or streaming output.
493 [Agent runtime](AGENT_RUNTIME.md#event-vocabulary) describes the event stream.
494
495 ## Config File Location
496
497 Default path:
498
499 - `~/.codewhale/mcp.json` (`~/.deepseek/mcp.json` is still read when the Codewhale file is absent)
500
501 Overrides:
502
503 - Config: `mcp_config_path = "/path/to/mcp.json"`
504 - Env: `CODEWHALE_MCP_CONFIG=/absolute/path/to/mcp.json` (takes precedence over
505 the legacy `DEEPSEEK_MCP_CONFIG` spelling)
506
507 Custom paths must be absolute; a relative `mcp_config_path` falls back to the
508 user-global path rather than changing with the launch directory.
509
510 Codewhale also reads `<workspace>/.codewhale/mcp.json`, but only after the
511 workspace is trusted in user-owned configuration **and** you have approved the
512 exact contents of that file. A stdio entry is a command line and a server that
513 is not `lazy` starts at session start, so the project file is executable
514 configuration, like project hooks. Use `/mcp review` to see the file and its
515 digest, then `/mcp approve <digest>` to load those bytes. The approval is stored
516 in user-owned configuration under the workspace's `projects` entry
517 (`mcp_sha256`), never in the repository, and a symlinked `.codewhale` or
518 `mcp.json` is refused. Any later change to the file, such as a pull or a branch
519 switch, loads none of its servers until you review and approve again.
520 `/mcp revoke` removes the approval. `/mcp disable`, `/mcp enable` and
521 `/mcp remove` on a project server edit the file and keep its approval. Review
522 any scripts a server command runs as well: the approval covers the file, not
523 the files it points to. `codewhale doctor --full` and `/mcp validate` report a project
524 file that is waiting for approval. Project entries override same-named global
525 servers; project-local files cannot grant trust or approval themselves or
526 redirect the global `mcp_config_path`. Global and approved-project entries take
527 precedence over a colliding plugin-contributed identity. Project stdio commands default
528 their working directory to the workspace. In the main candidate,
529 `always_allow_tools` is accepted only from the global server configuration,
530 not from project or plugin declarations.
531
532 `codewhale mcp init` (and `codewhale setup --mcp`) writes to this resolved path.
533
534 #### Delegated connector reads
535
536 An operator can authorize a child to send a specific read to a static HTTP connector. Put the declaration in the global MCP config outside the workspace. Verify the connector implementation and operation before declaring its effect. The child needs network access, the exact tool name in its scope, and the session's per-call approval. Each declaration pins the server URL, literal authorization headers, advertised input schema and allowed argument objects. Changing the binding or schema requires a new declaration. OAuth, environment-supplied credentials, runtime servers, project files and plugins cannot supply this grant.
537
538 For a server named `books` that advertises `lookup`, the child tool name is `mcp_books_lookup`. This example adds its read policy to the global config.
539
540 ```json
541 {
542 "delegated_operations": {
543 "books": {
544 "lookup": {
545 "effect": "read",
546 "binding_sha256": "<binding digest>",
547 "input_schema": {"type": "object", "properties": {"isbn": {"type": "string"}}},
548 "allowed_arguments": [{"isbn": "sample"}]
549 }
550 }
551 }
552 }
553 ```
554
555 Compute the binding digest locally using the exact URL and all literal headers. This example reads the selected server and prints only its digest.
556
557 ```sh
558 python3 - /path/to/global/mcp.json books <<'PYTHON'
559 import hashlib, json, sys
560 with open(sys.argv[1], encoding="utf-8") as source:
561 config = json.load(source)
562 server = (config.get("servers") or config["mcpServers"])[sys.argv[2]]
563 binding = json.dumps([server["url"], server["headers"]], sort_keys=True, ensure_ascii=False, separators=(",", ":"))
564 print(hashlib.sha256(binding.encode()).hexdigest())
565 PYTHON
566 ```
567
568 The interactive `/config` editor also exposes `mcp_config_path`. Changing it in
569 the TUI updates the path used by `/mcp` and marks the pool reload-required;
570 `/mcp reload` then switches the live pool to the new config source.
571
572 After editing the MCP file or changing `mcp_config_path`, run `/mcp reload`. No
573 TUI restart is needed.
574
575 ## Tool Naming
576
577 Discovered MCP tools are exposed to the model as:
578
579 - `mcp_<server>_<tool>`
580
581 Example: a server named `git` with a tool named `status` becomes `mcp_git_status`.
582
583 The command palette includes MCP entries grouped by server. It shows disabled
584 and failed servers instead of hiding them, and uses the same runtime tool names
585 shown to the model.
586
587 ## Resource and Prompt Helpers
588
589 The CLI also exposes helper tools when MCP is enabled:
590
591 - `list_mcp_resources` (optional `server` filter)
592 - `list_mcp_resource_templates` (optional `server` filter)
593 - `mcp_read_resource` / `read_mcp_resource` (aliases)
594 - `mcp_get_prompt`
595
596 ## Minimal Example
597
598 ```json
599 {
600 "timeouts": {
601 "connect_timeout": 30,
602 "execute_timeout": 1800,
603 "read_timeout": 120
604 },
605 "servers": {
606 "example": {
607 "command": "node",
608 "args": ["./path/to/your-mcp-server.js"],
609 "env": {},
610 "disabled": false
611 }
612 }
613 }
614 ```
615
616 You can also use `mcpServers` instead of `servers` for compatibility with other
617 clients. Use exactly one map key in a file: a file containing both fails to
618 parse.
619
620 ## Running Codewhale as an MCP Server
621
622 You can register your local Codewhale binary as a stdio MCP server for another
623 Codewhale session or a client supporting one of its advertised protocol
624 revisions. This exposes native tools; it is separate from connecting Codewhale
625 to external servers.
626
627 ### Client configuration vs server configuration
628
629 `mcp.json` tells a client which servers to launch or contact. The native
630 `codewhale serve --mcp` process separately reads `[server]` from the retained
631 legacy path `~/.deepseek/mcp_server.toml`. By default it exposes only
632 `file_read` and `search`. Writing files or running commands requires naming
633 those tools in `expose_tools` and explicitly setting `require_approval = false`
634 in that server file. This stdio server has no interactive approval channel;
635 with approval required, writing/executing tools are withheld and refused.
636
637 ### Quick Setup
638
639 ```bash
640 codewhale mcp add-self
641 ```
642
643 This resolves the current binary path, generates a config entry that runs
644 `codewhale serve --mcp`, and writes it to your MCP config file. The default
645 server name is `codewhale`.
646
647 Options:
648
649 - `--name <NAME>` — custom server name (default: `codewhale`)
650 - `--workspace <PATH>` — workspace directory for the server
651
652 ### Manual Config
653
654 Equivalent manual entry in `~/.codewhale/mcp.json`:
655
656 ```json
657 {
658 "servers": {
659 "codewhale": {
660 "command": "/path/to/codewhale",
661 "args": ["serve", "--mcp"],
662 "env": {}
663 }
664 }
665 }
666 ```
667
668 The consolidated `codewhale` runtime supports `serve --mcp` directly and also
669 offers the equivalent `codewhale mcp-server` stdio entrypoint. Release
670 installers expose the same runtime as `codew`; `mcp add-self` automatically
671 resolves the command that invoked it.
672
673 ### Prerequisites
674
675 - The binary referenced in `command` must exist and be executable.
676 - The MCP server runs as a child process via stdio — no network ports required.
677 - Each MCP client session spawns its own server process.
678
679 ### Tool Naming
680
681 Tools from an MCP server follow the standard naming convention:
682
683 - `mcp_<server>_<tool>`
684
685 For example, the `shell` tool from the default server (named `codewhale`)
686 becomes `mcp_codewhale_shell`.
687
688 ### MCP Server vs HTTP/SSE API vs ACP
689
690 | | `codewhale serve --mcp` | `codewhale serve --http` | `codewhale serve --acp` |
691 |---|---|---|---|
692 | **Protocol** | MCP stdio | HTTP/SSE JSON-RPC | ACP stdio |
693 | **Use case** | Tool server for MCP clients | Runtime API for apps | Editor agent for Zed/custom ACP clients |
694 | **Config** | `~/.codewhale/mcp.json` entry | Direct URL connection | Editor `agent_servers` custom command |
695 | **Lifecycle** | Spawned per client session | Long-running daemon | Spawned per editor agent session |
696
697 Use `mcp add-self` when you want Codewhale tools available to other MCP clients.
698 Use `serve --http` when building applications that consume the API directly.
699 Use `serve --acp` when an editor wants to talk to Codewhale as an ACP agent.
700
701 ### Verification
702
703 After adding, test the connection:
704
705 ```bash
706 codewhale mcp validate
707 codewhale mcp tools codewhale
708 ```
709
710 ## Connection Lifecycle
711
712 As a client, Codewhale connects servers through the official MCP SDK (2.4)
713 behind its Rust broker by default (`[extension_host] mcp_backend = "host"` in
714 your user config; `"rust"` selects the previous Rust client and stays available
715 for one release, and a host refusal never falls back to it). Servers that speak
716 the 2026-07-28 revision are discovered with `server/discover`. Other stdio and
717 HTTP servers, including ones that answer the discovery probe with an error or
718 an unrelated result, connect through the legacy `initialize` handshake, and
719 configured SSE servers keep theirs. A server that rejects sign-in reports its
720 real 401 with the `/mcp login` hint, and one whose command cannot start says
721 why. Rust keeps process, network, credential, catalog, approval and
722 cancellation authority.
723
724 Session boot connects in the background: every enabled, allowed server —
725 user-configured or contributed by an enabled plugin — is started at session
726 start, concurrently and without holding the first turn. A plugin server passes
727 the same review, trust and enablement checks at session start as it does on
728 first use. Mark a heavy user-configured server `lazy = true` to keep it
729 unstarted until something asks for it — a turn whose
730 `allowed_tools`/`tools.always_load` selection covers its `mcp_<server>_*`
731 names, a model call that resolves to one of its tools, or an explicit
732 `/mcp retry <name>`. Servers marked `required` connect at boot even if
733 `lazy`, so their failure surfaces before the first turn. A server that has not
734 connected yet shows as `not connected` in `/mcp`, never `connecting`; the
735 connecting label only describes handshakes actually in flight. After an OAuth
736 login finishes, that one server reconnects automatically. `codewhale mcp tools`
737 and `codewhale mcp connect` run in their own process, so a server they just
738 reached from the shell still reads `not connected` inside a running session
739 until that session connects it.
740
741 `/new`, `/resume`, `/load`, switching sessions from the resume picker, and a
742 provider, profile or plugin change keep user-configured stdio servers running:
743 each live process moves to the new conversation or engine without a restart,
744 provided its config, the workspace and the MCP backend are unchanged. Anything
745 the server holds in memory, such as a browser session and its logins, comes
746 along; run `/mcp reload` for fresh servers. HTTP/SSE servers reconnect, so they
747 pick up current credentials and `[network]` policy. Servers added at runtime
748 and plugin-contributed servers are not handed over and close at each of these
749 boundaries, even when the conversation continues; plugin-contributed servers
750 connect again with the next session boot, while a server added at runtime must
751 be started again. A workspace switch restarts
752 every server. If an MCP call from the previous conversation is still running
753 at the boundary, nothing is handed over and the servers restart as before;
754 otherwise later calls from that conversation's background work fail instead of
755 reconnecting.
756
757 MCP-focused discovery — `tools.search`, `tools.describe`, and
758 `tools.list("<server>")` inside `execute_tools` (or `tool_search` on surfaces
759 without eager `execute_tools`, such as `code_mode = false`) — is also explicit
760 discovery intent: search a configured server name (for example `engram`) or a
761 part of it,
762 an exact `mcp_<server>_...` name, `mcp` for any permitted server, or use
763 `{"query":"mcp_.*","match":"regex"}`. An exact `mcp_<server>_...` term matches
764 only the server whose prefix it carries. Other words in a ranked (`bm25`)
765 search also match a server's name tokens, plugin name, `enabled_tools`, URL
766 host labels and the package basename of an `npx`, `pnpx`, `bunx` or `uvx`
767 launch. Paths, flags, other arguments, server descriptions and tool
768 descriptions never start a server, and neither do common words such as
769 `search`, `list` or `file` in that metadata. Servers that are already connected
770 need no start and are not counted.
771
772 The current turn's allow/deny ceiling filters the configured servers before a
773 batch of at most eight connects. Exact names and prefixes come first, then
774 partial names, then metadata matches, then a bare `mcp`, alphabetically within
775 each group. The existing five-second wait and cancellation remain in force.
776 General searches do not boot all optional servers. Only actual `tools/list`
777 schemas enter the deferred catalogue; failed, disabled, or revoked servers do
778 not acquire fabricated tools. Narrow a broad search by server name when more
779 than eight configured servers match.
780
781 Before a model request, one bounded runtime note records the current connection
782 observations for permitted servers. It uses fixed states: `configured` (no
783 connection outcome recorded), `connecting`, `failed`, `authorization_required`,
784 `unknown` and `connected`. Failures and authorization needs are listed first;
785 at most 24 names are shown, with 64 characters per name and an omission count.
786 A connected server with at least one tool visible in the turn also gets a
787 summary: its visible tool count, its advertised capabilities, up to five
788 visible tool names of 48 characters, and the first line of its own
789 instructions, sanitized and cut to 120 characters (or the plugin name when it
790 sent none). Summaries stop once the note reaches 4 KiB; the remaining rows keep
791 name and status only. Server-written summaries are third-party text. Names and
792 summaries are inert data, never instructions. Raw errors, commands, URLs and
793 credentials are excluded. A child agent receives rows only for the servers it
794 is admitted to.
795
796 The note supersedes earlier snapshots and lives in session history, after the
797 cached system prompt. Unchanged observations are recorded once and are recorded
798 again if compaction removes them. No server is started or schema loaded by this
799 observation. When the turn has a discovery surface (`tools.search` inside
800 `execute_tools`, or `tool_search` on surfaces without eager `execute_tools`),
801 the model can search a permitted configured
802 name to obtain actual tools or retry a relevant connection. Without one, only servers identified by their actually exposed MCP tools are included.
803 Disabled servers and servers outside the current discovery ceiling are omitted.
804 `connected` means a current authorized transport was observed; it does not
805 promise available schemas, tool permissions or a successful call.
806
807 The same nonblocking capture supplies server guidance. A busy pool, changed
808 configuration source or removed scope withdraws old guidance and status instead
809 of replaying stale success. Restore withdraws saved MCP notes until the live
810 runtime observes the current pool. Child, RLM, ACP and isolated hosts do not
811 acquire new discovery authority from these notes. Observations happen at request
812 boundaries; this is not continuous monitoring or semantic verification of server
813 claims. The existing MCP manager owns configuration and authorization recovery.
814
815 `codewhale mcp connect`, `validate`, and `tools` inspect their own process's
816 pool. They do not attach transports to a running TUI or exec session. Use
817 in-session discovery or explicit tool selection. In the TUI,
818 `/mcp retry <name>` connects through the current session's pool;
819 `/mcp reload` re-reads its MCP configuration.
820
821 ### Catalog freshness
822
823 A server's tools, resources, resource templates, prompts and skills are kept
824 on its own live connection, so they are never shared between servers,
825 credentials, sessions or reconnects. Every reconnect, login and config reload
826 discovers them again, and allow/deny rules and approvals are checked on each
827 call rather than cached with the catalog. Within one connection the catalog is
828 revalidated in place, on the five-second supervision sweep, when either:
829
830 - a list page carried `ttlMs` and the earliest of those TTLs (held between
831 60 seconds and 24 hours) has passed, or
832 - the server sent `notifications/tools/list_changed`,
833 `notifications/resources/list_changed` or
834 `notifications/prompts/list_changed`.
835
836 A list without `ttlMs` stays valid until one of those events. Because nothing
837 is shared beyond the connection, `cacheScope: "public"` and `"private"` are
838 both held to the stricter private rule. Pagination, item and byte bounds are
839 the same as at connect, and ordering stays sorted. When revalidation changes
840 the catalog, a tool call resolved against the previous catalog is refused with
841 "retry the call", a removed tool can no longer run, and the next model request
842 carries the new tool list. When revalidation fails, the connection is retired
843 and ordinary reconnect supervision takes over; the stale catalog is not served.
844
845 Known limits: the Rust backend reads list-change notices only while it waits
846 for a reply, so an idle stdio server's notice is acted on after its next
847 request. The 2026-07-28 `subscriptions/listen` stream and `resources/subscribe`
848 are not opened; modern servers are kept fresh through their required `ttlMs`.
849
850 ### Skills from MCP servers
851
852 A server that advertises the published Skills extension
853 (`capabilities.extensions["io.modelcontextprotocol/skills"]`) has its
854 `skills/list` read with the rest of its catalog, under the same bounds and
855 freshness rules. An entry is kept only when its `SKILL.md` URI is listed among
856 its own resources, its frontmatter has a name and description, every file sits
857 beneath the skill's root without `.`/`..`, `%`, `?` or `#` segments, every
858 digest is `sha256:` plus 64 lowercase hex characters, and it stays within 512
859 files and 16 MiB. `"dynamic"` skills cannot be verified and are skipped.
860
861 Kept skills appear in `list_mcp_resources` with a `skill` field naming their
862 files. Listing a skill never loads or activates it. Reading one of its files
863 with `read_mcp_resource` checks that the server returned exactly that URI with
864 the listed size and digest; a mismatch is refused and nothing is loaded. MCP
865 skills are not yet merged into the native skill catalog, `/skills` or skill
866 activation.
867
868 ## Server Fields
869
870 Per-server settings:
871
872 - `command` (string, required for a local stdio server): executable to start.
873 Remote servers use `url` instead; a URL-only entry is valid.
874 - `args` (array of strings, optional)
875 - `env` (object, optional)
876 - `connect_timeout`, `execute_timeout`, `read_timeout` (seconds, optional). A per-server value overrides the global `timeouts` block, and each budget is independent of the others:
877 - `connect_timeout` (default 30) covers spawn, `initialize` and the first `tools/list`, so a cold `uvx`/`npx` package download counts against it. A server launched through `npx`, `pnpx`, `bunx` or `uvx` without its own `connect_timeout` gets at least 120 seconds for that first download.
878 - `execute_timeout` (default 1800) is the budget for each `tools/call` and `prompts/get`. An explicit shorter value is respected, and `read_timeout` never cuts a running tool short.
879 - `read_timeout` (default 120) bounds each reply wait during the handshake and tool discovery, and is the budget for `resources/read`.
880 - A request that runs out of budget fails with a timeout. The connection is kept, and a reply that arrives later is discarded instead of being handed to another call. Interrupting the turn stops the wait at once, but Codewhale does not send `notifications/cancelled` yet, so a server that handles one request at a time finishes the abandoned call before it answers the next one.
881 - Streamable HTTP servers return the reply inside the POST itself; the request's own budget bounds that POST too. A request that expires while still sending closes the connection, which is rebuilt before the next call.
882 - `disabled` (bool, optional)
883 - `enabled` (bool, optional, default `true`)
884 - `required` (bool, optional): startup/connect validation fails if this server cannot initialize.
885 - `lazy` (bool, optional, default `false`): keep this server unstarted until a turn, tool call or `/mcp retry` asks for it. Without it, the server connects at session start. Plugin manifests have no `lazy` field: an enabled plugin's servers connect at session start, and disabling the plugin stops them.
886 - `enabled_tools` (array, optional): allowlist of tool names for this server.
887 - `disabled_tools` (array, optional): denylist applied after `enabled_tools`.
888 - `always_allow_tools` (optional array): Exact tool names the person allows across workspaces on this computer. Set these in the global server configuration. Off takes precedence. Computer Use consent and scripts still require the person’s approval.
889 - `url` (string, optional): Streamable HTTP endpoint for a remote MCP server.
890 - `allow_private_network` (boolean, default false): operator opt-in for private DNS addresses on this configured origin; ignored for model-added servers.
891 - `transport` (string, optional): set to `"sse"` for legacy SSE endpoints.
892 - `headers` (object, optional): literal HTTP headers for URL-based servers.
893 - `env_headers` or `env_http_headers` (object, optional): header names mapped to environment variable names.
894 - `bearer_token_env_var` (string, optional): environment variable containing a bearer token.
895 - `scopes` (array, optional): default OAuth scopes for `mcp login`.
896 - `oauth.client_id` (string, optional): pre-registered OAuth client ID; requires `oauth.issuer`.
897 - `oauth.issuer` (string, optional): exact authorization issuer pin; required for a pre-registered client.
898 - `oauth.client_metadata_url` (string, optional): HTTPS URL with a non-root path for an operator-hosted client metadata document.
899 - `oauth_resource` (string, optional): exact resource pin checked against SDK discovery.
900
901 ## Safety Notes
902
903 MCP tools go through approval (skipped in Full Access, except Computer Use consent, registration and script cards), exact-name rules in
904 `permissions.toml` (with no `path`), and `enabled_tools` / `disabled_tools` on
905 the server. Read-only MCP helpers (resource/prompt listing and reads) can run
906 without prompts in Ask and Auto-Review when policy permits, while side-effectful
907 MCP tools require approval. In Full Access, explicit `deny` rules and
908 `disabled_tools` still block an MCP tool, while repository law does not apply
909 to MCP tools.
910
911 A local stdio MCP server is started as an ordinary child process with a
912 scrubbed environment and no OS sandbox wrapper. Codewhale does not check MCP
913 tool arguments against the workspace boundary, the read deny-list
914 (`sandbox_denied_read_paths`), or repository law.
915
916 You should still only configure MCP servers you trust, and treat MCP server configuration as equivalent to running code on your machine.
917 Avoid committing literal `Authorization` headers. Prefer `env_headers`,
918 `bearer_token_env_var`, or OAuth login so secrets stay outside the MCP file.
919
920 ## Troubleshooting
921
922 - Run `codewhale doctor --full` to confirm the MCP config path it resolved and whether it exists.
923 - In the TUI, run `/mcp validate` to see each server's state from the last
924 recorded MCP snapshot, plus any config load error and configured servers that
925 have not connected.
926 - If tools are missing from the model's catalog after a config or credential
927 change, run `/mcp reload` — `/mcp validate` only reports the last recorded
928 snapshot and never reconnects.
929 - If the MCP config is missing, run `codewhale mcp init --force` to regenerate it.
930 - If tools don’t appear, verify the server command works from your shell and that the server supports MCP `tools/list`.
931
931 lines MARKDOWN