skip to content

Connecting MCP Servers

OpenClaw connects stdio and HTTP MCP servers and passes their tools through its own tool policy. Interviewers ask how a server is added, scoped and checked before an agent trusts it.

part ofAI coding toolsread it →
on this pageshow

explore

questions

6

In OpenClaw, how do you add a local stdio MCP server, such as a database tool server, and prove it actually works?

level: middleimportance: must knowfreq 12%

answer

  1. a command, not a URL
  2. openclaw mcp add with --command
  3. add probes before it saves
  4. doctor --probe opens a live connection
  5. the Gateway's environment, not your shell

basics

~20 s

Run openclaw mcp add <name> --command <exe> --arg <arg>, or write an mcp.servers entry with command, args, env and cwd, then run openclaw mcp doctor <name> --probe, which checks the definition and opens a live connection that lists the server's tools.

solid answer

~50 s

A stdio MCP server is a child process OpenClaw spawns and talks to over stdin and stdout, so its `mcp.servers.<name>` entry needs a `command`, plus optional `args`, `env` and `cwd`. `openclaw mcp add ledger-db --command node --arg ./dist/db-mcp.js --cwd /srv/openclaw-tools` builds that entry and probes the server before saving, refusing to save if the probe fails; `--no-probe`, `--disabled` and `--auth oauth` skip that probe. Hand edits, the Settings page and `openclaw mcp set` do not probe, and saving a definition proves nothing about reachability. So follow any change with `openclaw mcp doctor ledger-db --probe`: its static pass catches a command that does not resolve, a missing `cwd` and literal secrets under sensitive-looking `env` names, and the probe proves the server starts and lists its tools. The command has to resolve in the Gateway process's environment, not only in your shell.

code

json · 13 lines
json
{
  "mcp": {
    "servers": {
      "ledger-db": {
        "command": "node",
        "args": ["./dist/db-mcp.js"],
        "cwd": "/srv/openclaw-tools",
        "env": { "DATABASE_URL": "${LEDGER_DATABASE_URL}" },
        "toolFilter": { "include": ["list_tables", "run_readonly_query"] }
      }
    }
  }
}

go deeper

for a junior

Recall the two ways in: openclaw mcp add with --command and --arg, or an mcp.servers entry with command and args. Then name the one command that proves it works: doctor with --probe.

for a middle

Explain what add does before saving, which flags skip its probe, and why status and plain doctor never connect. Mention the env filter and keeping credentials out of literals.

for a senior

Show how you diagnose a server that works by hand but not under the Gateway: process environment, cwd, stripped env keys, stderr logs, and the startup backoff that hides a fix.

for a principal

Weigh standardising on add with a probe, plus a doctor --probe step in change review, against hand-edited config that silently ships unreachable servers to every agent run.

## What a stdio MCP server is to OpenClaw The **Model Context Protocol (MCP)** lets an agent borrow tools from another program. A **stdio** server is the local kind: OpenClaw launches it as a **child process** and exchanges messages over its standard input and output. A database tool server that runs next to the Gateway is the typical case. OpenClaw keeps every server it manages under **`mcp.servers`** in its config, one named entry each, and the Gateway projects those servers' tools into agent runs. An enabled entry needs either a `command` (stdio) or a `url` (an HTTP transport). For stdio the fields are: - `command`: the executable to spawn (required) - `args`: an array of arguments - `env`: extra environment variables for the child - `cwd`: the working directory If an entry carries both `command` and `url`, OpenClaw treats it as stdio. ## Adding it from the CLI or from config ```bash openclaw mcp add ledger-db \ --command node \ --arg ./dist/db-mcp.js \ --cwd /srv/openclaw-tools openclaw mcp doctor ledger-db --probe ``` The same server written into `openclaw.json` is `"ledger-db": {"command": "node", "args": ["./dist/db-mcp.js"], "cwd": "/srv/openclaw-tools"}` under `mcp.servers`. The Control UI's **Settings → MCP** page writes the same entry through the Gateway. ## What `openclaw mcp add` does before it saves - It refuses a name that already exists; use `openclaw mcp configure` or `openclaw mcp set` to change an existing server. - It **probes the new server** with a live connection and fails instead of saving when the probe reports a problem. - It skips that probe when you pass `--no-probe`, save the server with `--disabled`, or use `--auth oauth` (OAuth needs `openclaw mcp login` first). - `--include` and `--exclude` write a `toolFilter`, so only the tools you name become OpenClaw tools. ## Proving it works | Command | Connects to the server? | What it tells you | |---|---|---| | `openclaw mcp status --verbose` | No | Resolved transport, timeouts, filters and auth, from config only | | `openclaw mcp doctor <name>` | No | Static problems: unresolvable command, missing `cwd`, disabled server, literal secrets | | `openclaw mcp doctor <name> --probe` | Yes, after static checks pass | Adds the live proof: tools and capabilities the server advertises | | `openclaw mcp probe <name>` | Yes | Tool counts, resources and prompts support, diagnostics | The docs put it bluntly: saving a definition proves nothing about reachability; the probe does. ## Environment and secrets The child inherits the **Gateway process's** environment, not your interactive shell's, so a `command` found through your shell's `PATH` may not resolve under a service manager. Prefer absolute paths, and confirm `cwd` exists. OpenClaw also filters the `env` block before it spawns the server. Interpreter-startup, loader-hijack and shell-init keys such as `NODE_OPTIONS`, `PYTHONSTARTUP` and the `LD_*`, `DYLD_*` and `BASH_FUNC_*` prefixes are dropped silently with a logged warning. An explicit allowlist keeps direct credentials such as `DATABASE_URL`, `GITHUB_TOKEN` and `AWS_ACCESS_KEY_ID` usable. A server that truly needs a blocked variable gets it from the Gateway host process instead. Keep credentials out of config literals: `${VAR}` substitution reads them from the environment. Doctor warns about literal values only under sensitive-looking names (ending in `token`, `secret`, `password` or `api_key`, or an `authorization` header), so a literal connection string in `DATABASE_URL` is not flagged; keeping it out is on you. ## When it still will not start 1. Run `openclaw mcp doctor <name> --probe` and read the first error. 2. Check that `command` resolves for the Gateway's user and that `cwd` exists; arguments belong in `args`. 3. Read the debug log: stderr from servers OpenClaw launches is prefixed `bundle-mcp:<name>:`. 4. Expect a pause after failures: new runtimes skip a server that would not start for 30 seconds, doubling up to 10 minutes. A successful connection, a config publication or an explicit MCP reload clears it. 5. Remember that `openclaw mcp reload` only refreshes runtimes owned by the CLI process; a Gateway running elsewhere needs its own reload or restart.

  • The server starts from your terminal but the probe fails under the Gateway. What do you check?
    The Gateway spawns the child with its own environment, so a `command` found through your shell's `PATH`, or a relative `cwd`, may not resolve; use absolute paths. Then check whether the server depends on an `env` key OpenClaw strips before spawn, such as `NODE_OPTIONS` or an `LD_*` variable. A server that really needs one must get it from the Gateway host process.
  • You fixed a broken stdio server, yet agents keep reporting it unavailable for a few minutes. Why?
    After a start failure, new runtimes skip the server under an exponential backoff: 30 seconds, doubling up to 10 minutes. A successful connection, a config publication or an explicit MCP reload clears it. `openclaw mcp reload` only reaches runtimes owned by the CLI process, so a Gateway running elsewhere needs its own reload or restart.

  • Saving the server in Settings or in config proves it is reachable.
  • openclaw mcp status connects to each server to check it.
  • NODE_OPTIONS set in the server's env block reaches the child process.
  • If the command runs in my shell, the Gateway can run it too.
  • A stdio server needs a url with transport set to stdio.
open as a page

An OpenClaw assistant that also answers strangers gains a database MCP server; do its tools bypass tool policy, and how do you scope them?

level: seniorimportance: must knowfreq 10%

basics

~20 s

No. MCP tools become OpenClaw tools under the bundle-mcp plugin id, named server__tool, and pass the same tool profile, allow and deny lists, per-sender limits and sandbox gate as built-in tools; filter the server's tools and deny them to strangers.

open as a page

In OpenClaw, what is the difference between openclaw mcp serve and openclaw mcp add, and which side is the MCP server in each?

level: juniorimportance: should knowfreq 8%

basics

~20 s

openclaw mcp add saves a third-party MCP server under mcp.servers so OpenClaw's agents can use its tools. openclaw mcp serve makes OpenClaw itself a stdio MCP server that another client spawns to read and reply to its channel conversations.

open as a page

In OpenClaw's mcp.servers, how do you configure a hosted HTTP MCP server, and which transport does it get if you omit one?

level: middleimportance: should knowfreq 6%

basics

~20 s

Give the mcp.servers entry a url and set transport to streamable-http, because an entry with no transport uses sse. Authenticate with auth set to oauth plus openclaw mcp login, or with headers fed from an environment variable, then probe it.

open as a page

For a small team's OpenClaw Gateway connected to a hosted issue-tracker MCP server, would you configure shared or per-requester OAuth, and why?

level: principalimportance: should knowfreq 4%

basics

~20 s

Shared OAuth, the default, suits one operator: every allowed caller acts through the account saved by openclaw mcp login. Per-requester gives each sender their own account and attribution, but needs gateway.publicOrigin and bearer sign-in links, so it fits only a mutually trusting team.

open as a page

For Codex runs in OpenClaw, how are MCP tool calls approved, and what does openclaw mcp configure --approval change?

level: seniorimportance: nice to knowfreq 3%

basics

~10 s

By default, Codex MCP approvals follow the session's permission posture: full permission never prompts, stricter postures check unannotated tools. openclaw mcp configure <server> --approval auto|prompt|approve writes codex.defaultToolsApprovalMode and overrides that default for one server.

open as a page