mcp-patchbay 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +103 -0
- package/NOTICE +8 -0
- package/README.md +374 -4
- package/SECURITY-MODEL.md +229 -0
- package/SECURITY.md +26 -0
- package/examples/servers.json +54 -0
- package/package.json +38 -12
- package/src/children.js +521 -0
- package/src/cli.js +155 -0
- package/src/config.js +465 -0
- package/src/doctor.js +124 -0
- package/src/fsutil.js +55 -0
- package/src/import.js +168 -0
- package/src/instructions.js +88 -0
- package/src/log.js +22 -0
- package/src/naming.js +96 -0
- package/src/permissions.js +72 -0
- package/src/process.js +367 -0
- package/src/redact.js +132 -0
- package/src/rename-permissions.js +158 -0
- package/src/server.js +864 -0
- package/src/version.js +4 -0
- package/bin/mcp-patchbay.js +0 -9
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## 0.1.0 - 2026-11-14
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- An MCP server over stdio that hosts configured MCP servers as child processes, with the tools
|
|
12
|
+
`servers`, `enable`, `disable`, `restart` and `info`. Each carries
|
|
13
|
+
`_meta: {"anthropic/alwaysLoad": true}`.
|
|
14
|
+
- Policies `allow`, `confirm` and `deny`. `confirm` asks a person through a form-mode
|
|
15
|
+
elicitation, and fails closed when the client has no elicitation support.
|
|
16
|
+
- Live tool publishing with `notifications/tools/list_changed`. `enable` waits up to 2 s for the
|
|
17
|
+
client's re-list.
|
|
18
|
+
- Proxying:
|
|
19
|
+
- pass-through tool definitions and results, with `outputSchema` not enforced;
|
|
20
|
+
- cancellation and progress (original progress tokens);
|
|
21
|
+
- `roots/list` and elicitation forwarding, and roots `list_changed` fan-out;
|
|
22
|
+
- sampling refused;
|
|
23
|
+
- merging of children's own `list_changed`;
|
|
24
|
+
- a per-server `timeoutMs`.
|
|
25
|
+
- Children:
|
|
26
|
+
- full env inheritance with per-entry `env`;
|
|
27
|
+
- a process group per child on POSIX;
|
|
28
|
+
- tolerance of non-JSON stdout;
|
|
29
|
+
- redacted stderr ring buffers;
|
|
30
|
+
- crash isolation;
|
|
31
|
+
- pidfiles, and reaping of leftovers after a crash.
|
|
32
|
+
- Remote servers through mcp-remote 0.15.2:
|
|
33
|
+
- header values kept out of argv;
|
|
34
|
+
- `MCP_REMOTE_CONFIG_DIR` at 0700;
|
|
35
|
+
- sign-in detection with a URL-mode elicitation (or a form fallback);
|
|
36
|
+
- the state `waiting-for-sign-in`.
|
|
37
|
+
- Autostart per project (`CLAUDE_PROJECT_DIR`), and instructions folded into the patchbay's own,
|
|
38
|
+
capped at 4,096 characters.
|
|
39
|
+
- Redaction of tokens, URL query strings, and entries' own env, args and headers in everything
|
|
40
|
+
the patchbay emits.
|
|
41
|
+
- CLI: `import` (from a Claude Code config), `doctor`, and `rename-permissions`.
|
|
42
|
+
- The `examples/write-gate` PreToolUse hook example, with tests.
|
|
43
|
+
- `confirmVia`, a top-level config setting: `"elicitation"` (the default, unchanged behaviour) or
|
|
44
|
+
`"host"`. With `"host"`, `enable` and `restart` refuse to start a `confirm` server and point to
|
|
45
|
+
a new tool, `enable_confirm {name}`. The host's own permission prompt for that tool is the
|
|
46
|
+
person's approval. This makes `confirm` servers usable in clients that do not show form
|
|
47
|
+
elicitation to the person, such as the Claude Code VS Code extension, which answers it
|
|
48
|
+
`decline`. `enable_confirm` refuses `allow` and `deny` servers and is listed only in host mode.
|
|
49
|
+
- `import` writes `confirmVia: "host"`.
|
|
50
|
+
- `doctor` prints `confirmVia` and warns about Claude Code allow rules that would approve
|
|
51
|
+
`enable_confirm` without asking (the exact name, `mcp__patchbay__*`, `mcp__patchbay`, `*` and
|
|
52
|
+
other wildcards) and about `defaultMode: "bypassPermissions"`, in the user's settings and, with
|
|
53
|
+
`--project <dir>`, the project's. In host mode a warning exits 1. `--no-start` skips starting
|
|
54
|
+
servers.
|
|
55
|
+
- `rename-permissions` never writes a rule that matches `enable_confirm`.
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- Shutdown no longer orphans children that ignore SIGTERM. A detached helper sends SIGKILL to the
|
|
60
|
+
remaining process groups after 500 ms, without delaying the patchbay's exit. Pidfiles are kept
|
|
61
|
+
until a child's exit is observed, and the startup reaper now escalates to SIGKILL. After a
|
|
62
|
+
crash, the leftover group members also get a SIGKILL follow-up.
|
|
63
|
+
- A remote server's `url` is now treated as a secret. The whole url, each path segment, each
|
|
64
|
+
query value and any userinfo (6+ characters) are redacted from `info`, `lastError` and logs.
|
|
65
|
+
mcp-remote logs the url to stderr, and many endpoints carry their key in the path. The url
|
|
66
|
+
is still on mcp-remote's argv (mcp-remote has no other way to take it), which is now
|
|
67
|
+
documented.
|
|
68
|
+
- Only mcp-remote children (`url` entries, an `mcp-remote` command, or `npx mcp-remote`) can
|
|
69
|
+
trigger the sign-in prompt, and only while they are starting. The prompt is always labelled
|
|
70
|
+
`[<server>] `. A re-auth request while a server is on is logged instead of prompting. The
|
|
71
|
+
sign-in URL is no longer written to the log, not even in redacted form.
|
|
72
|
+
- `rename-permissions` without `--config` now loads the default config (`$MCP_PATCHBAY_CONFIG`
|
|
73
|
+
or `~/.config/mcp-patchbay/servers.json`) and applies server prefixes. Before, deny rules for
|
|
74
|
+
prefixed servers silently stopped matching. Without a config file, it warns that names were
|
|
75
|
+
mapped as they are.
|
|
76
|
+
- A `restart` racing a `disable` no longer turns a `confirm` server back on: the disable cancels
|
|
77
|
+
the restart. An `enable` in that window joins the restart instead of showing a prompt whose
|
|
78
|
+
answer was ignored. A crash marks the server `failed` at once (it used to wait 20 ms), so a
|
|
79
|
+
restart right after a crash asks a person again.
|
|
80
|
+
- Autostart names that are inherited object keys (`constructor`, `toString`, `__proto__`) are
|
|
81
|
+
now rejected as unknown servers at load time (exit 78); before, they crashed `initialize`.
|
|
82
|
+
The same `hasOwn` check now covers `import --project` and `rename-permissions`' prefix lookup.
|
|
83
|
+
An env key named `__proto__` is now kept as a key instead of being dropped.
|
|
84
|
+
- A JSON syntax error in the config, in `import --from <claude.json>`, or in the
|
|
85
|
+
`rename-permissions` settings file is reported as the file path plus line and column. Node's
|
|
86
|
+
parser message quoted the surrounding text, which could include a token.
|
|
87
|
+
- Kills can no longer hit an unrelated process through a reused pid. Post-exit cleanup and the
|
|
88
|
+
startup reaper never fall back to signalling a bare pid. Pidfiles now record the process start
|
|
89
|
+
time (Linux, `v: 2`), and the reaper requires it to match and requires the pid to still lead
|
|
90
|
+
its own process group. A pidfile without a start time is not trusted on Linux.
|
|
91
|
+
- The config permission check is now complete (POSIX). The file is opened once, `fstat`ed and
|
|
92
|
+
read through that descriptor (no check-then-read race). A group- or world-writable (or
|
|
93
|
+
foreign-owned) parent directory is refused. A symlinked config is accepted only if its target
|
|
94
|
+
and the target's directory pass the same checks. A FIFO is refused without blocking.
|
|
95
|
+
|
|
96
|
+
### Documentation
|
|
97
|
+
|
|
98
|
+
- SECURITY-MODEL.md, SPEC.md and README now say exactly what happens to tool results: they are
|
|
99
|
+
parsed with `CallToolResultSchema`, which drops unknown keys inside content blocks and
|
|
100
|
+
rejects unknown content types. The docs no longer claim "unchanged".
|
|
101
|
+
- The redaction guarantee now states its 6-character minimum and covers the url. The sign-in
|
|
102
|
+
URL text matches the code.
|
|
103
|
+
- README: `npm test` takes about 20 s, not 40 s.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
mcp-patchbay
|
|
2
|
+
Copyright 2026 Distronode Corporation
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Distronode Corporation, licensed
|
|
5
|
+
under the Apache License, Version 2.0. The full licence text is in LICENSE.
|
|
6
|
+
|
|
7
|
+
mcp-patchbay is original work, not a fork, and no third-party source code is
|
|
8
|
+
vendored into this repository.
|
package/README.md
CHANGED
|
@@ -1,7 +1,377 @@
|
|
|
1
1
|
# mcp-patchbay
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
0.1.0.
|
|
3
|
+
[](https://www.bestpractices.dev/projects/16485)
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
> **If you allow `mcp__patchbay` as a whole in your client's permissions, you approve every tool of every server it hosts.**
|
|
6
|
+
> Allow individual tools (`mcp__patchbay__<server>__<tool>`) instead. See [Policy and safety model](#policy-and-safety-model).
|
|
7
|
+
|
|
8
|
+
`mcp-patchbay` is an MCP server that hosts other MCP servers as child processes, and lets the AI
|
|
9
|
+
agent switch them on and off in the middle of a session.
|
|
10
|
+
|
|
11
|
+
- The agent sees five small tools: `servers`, `enable`, `disable`, `restart` and `info`.
|
|
12
|
+
- When the agent enables a server, the patchbay starts it, and its tools appear straight away as
|
|
13
|
+
`<server>__<tool>`. The patchbay sends `notifications/tools/list_changed`, so the client
|
|
14
|
+
refreshes its tool list.
|
|
15
|
+
- When a server is disabled, its tools disappear the same way.
|
|
16
|
+
- For servers you mark `confirm`, **a person**, not the agent, approves each enable, through an
|
|
17
|
+
MCP elicitation prompt in the client.
|
|
18
|
+
|
|
19
|
+
**Why.** Every connected MCP server costs context (its tool definitions) and a running process,
|
|
20
|
+
whether or not the session needs it. With the patchbay, you configure all your servers once, and
|
|
21
|
+
only the ones a task needs are running and visible.
|
|
22
|
+
|
|
23
|
+
**Requirements**
|
|
24
|
+
|
|
25
|
+
- Node.js 22 or later.
|
|
26
|
+
- An MCP client that honours `notifications/tools/list_changed` and supports elicitation (form
|
|
27
|
+
mode, and ideally URL mode for sign-ins). For Claude Code, that means **2.1.287 or later**.
|
|
28
|
+
|
|
29
|
+
Without elicitation support, `confirm` servers cannot be enabled. That is deliberate: the
|
|
30
|
+
patchbay fails closed.
|
|
31
|
+
|
|
32
|
+
Contents: [Quick start](#quick-start) · [Config reference](#config-reference) ·
|
|
33
|
+
[Naming contract](#naming-contract) · [Moving from Claude Code: `import` and
|
|
34
|
+
`rename-permissions`](#moving-from-claude-code) · [Policy and safety model](#policy-and-safety-model) ·
|
|
35
|
+
[Known limits](#known-limits) · [Comparison](#comparison) · [Uninstall and rollback](#uninstall-and-rollback)
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
This example hosts the public filesystem server
|
|
40
|
+
([`@modelcontextprotocol/server-filesystem@2.2.0`](https://www.npmjs.com/package/@modelcontextprotocol/server-filesystem)).
|
|
41
|
+
|
|
42
|
+
1. Write a config file and make it private. The patchbay refuses to start if the file, or the
|
|
43
|
+
directory it is in, is group- or world-writable.
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
mkdir -p -m 700 ~/.config/mcp-patchbay
|
|
47
|
+
cat > ~/.config/mcp-patchbay/servers.json <<'EOF'
|
|
48
|
+
{
|
|
49
|
+
"version": 1,
|
|
50
|
+
"servers": {
|
|
51
|
+
"example-files": {
|
|
52
|
+
"description": "Read and write files in /path/to/project",
|
|
53
|
+
"policy": "confirm",
|
|
54
|
+
"command": "npx",
|
|
55
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem@2.2.0", "/path/to/project"]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
EOF
|
|
60
|
+
chmod 600 ~/.config/mcp-patchbay/servers.json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
2. Check it. `doctor` validates the file and briefly starts every `allow` server. Add `--all` to
|
|
64
|
+
also start `confirm` servers like this one.
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npx -y mcp-patchbay@0.1.0 doctor --all
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
3. Register the patchbay with Claude Code under the name **`patchbay`**. The naming contract and
|
|
71
|
+
the 128-character rule assume that name.
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
claude mcp add --scope user patchbay -- npx -y mcp-patchbay@0.1.0
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
4. In a session, ask the agent to "enable example-files". Claude Code shows the prompt
|
|
78
|
+
*"Allow the agent to turn on example-files (Read and write files in /path/to/project)?"*.
|
|
79
|
+
Once you approve, tools such as `mcp__patchbay__example-files__read_text_file` are available.
|
|
80
|
+
|
|
81
|
+
A longer, synthetic example is in [`examples/servers.json`](examples/servers.json).
|
|
82
|
+
|
|
83
|
+
## Config reference
|
|
84
|
+
|
|
85
|
+
The config location is `--config <path>`, else `$MCP_PATCHBAY_CONFIG`, else
|
|
86
|
+
`~/.config/mcp-patchbay/servers.json`. The file is read **once**, at startup. To apply changes,
|
|
87
|
+
restart the patchbay (in Claude Code: `/mcp`, then reconnect `patchbay`).
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"version": 1,
|
|
92
|
+
"confirmVia": "host",
|
|
93
|
+
"servers": {
|
|
94
|
+
"example-files": {
|
|
95
|
+
"description": "Files in /path/to/project",
|
|
96
|
+
"policy": "allow",
|
|
97
|
+
"command": "npx",
|
|
98
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem@2.2.0", "/path/to/project"],
|
|
99
|
+
"env": { "EXAMPLE_LOG_LEVEL": "info" },
|
|
100
|
+
"cwd": "/path/to",
|
|
101
|
+
"prefix": "files",
|
|
102
|
+
"timeoutMs": 0
|
|
103
|
+
},
|
|
104
|
+
"example-remote": {
|
|
105
|
+
"description": "A remote MCP server",
|
|
106
|
+
"policy": "confirm",
|
|
107
|
+
"url": "https://mcp.example.com/mcp",
|
|
108
|
+
"headers": { "X-Example-Tenant": "example" }
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"autostart": {
|
|
112
|
+
"default": [],
|
|
113
|
+
"projects": { "/path/to/project": ["example-files"] }
|
|
114
|
+
},
|
|
115
|
+
"oauth": { "configDir": "~/.config/mcp-patchbay/oauth", "authTimeoutSeconds": 300 }
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Validation is strict: an unknown key anywhere is an error that names its path. Any config error
|
|
120
|
+
exits with code **78** and a message on stderr.
|
|
121
|
+
|
|
122
|
+
| Key | Meaning |
|
|
123
|
+
|---|---|
|
|
124
|
+
| `version` | Must be `1`. |
|
|
125
|
+
| `confirmVia` | How a person approves a `confirm` server. `"elicitation"` (the default): `enable` asks through the client's form elicitation. `"host"`: `enable` refuses, and the agent calls `enable_confirm`, which the host's own tool-permission prompt asks the person about. `import` writes `"host"`. See [confirmVia](#confirmvia-elicitation-or-host). |
|
|
126
|
+
| `servers.<name>` | The name uses 1–64 characters from `[A-Za-z0-9_-]`, with no `__` and no trailing `_`. |
|
|
127
|
+
| `description` | One line, at most 300 characters. The agent sees it in `servers` and in the patchbay's instructions. |
|
|
128
|
+
| `policy` | `allow` (the agent may enable it), `confirm` (a person must approve each enable; the default), or `deny` (it can never be enabled). |
|
|
129
|
+
| `command`, `args`, `env`, `cwd` | A stdio server. `cwd` must be absolute. The child gets `{...the patchbay's env, ...env}`, the same as Claude Code gives its own servers. |
|
|
130
|
+
| `url`, `headers` | A remote server, launched through the bundled [`mcp-remote`](https://www.npmjs.com/package/mcp-remote) 0.15.2. The URL must be `https`, except for `localhost` and `127.0.0.1`. Header names use `[A-Za-z0-9_-]`. `env` is also allowed and is passed to mcp-remote. |
|
|
131
|
+
| `prefix` | A short alias used instead of the name in tool names. Names and prefixes must be unique, ignoring case. |
|
|
132
|
+
| `timeoutMs` | The cap on one tool call, in milliseconds. `0` (the default) means no cap. |
|
|
133
|
+
| `autostart.default` | Servers started at launch, with no confirmation. Not allowed for `deny` servers. |
|
|
134
|
+
| `autostart.projects` | Per-project lists, keyed by absolute directory. The key is matched against `CLAUDE_PROJECT_DIR`, or else the current directory. A matching list replaces `default`. |
|
|
135
|
+
| `oauth.configDir` | Where mcp-remote keeps OAuth state for `url` servers. It is created with mode 0700. |
|
|
136
|
+
| `oauth.authTimeoutSeconds` | How long a sign-in may take (1–86400, default 300). |
|
|
137
|
+
|
|
138
|
+
Each server has exactly one of `command` or `url`.
|
|
139
|
+
|
|
140
|
+
Autostart is your own config choice, so it counts as consent. The instructions of autostarted
|
|
141
|
+
servers are folded into the patchbay's own `instructions`, within 4,096 characters in total and
|
|
142
|
+
shared fairly between servers.
|
|
143
|
+
|
|
144
|
+
**Headers and secrets.** Header values are not put on mcp-remote's command line, where other
|
|
145
|
+
local users could read them. Instead the patchbay passes `--header Name:${MCP_PATCHBAY_HEADER_n}`
|
|
146
|
+
and puts the value in mcp-remote's environment, which expands it. A value that already contains
|
|
147
|
+
a `${VAR}` placeholder is passed as it is, and mcp-remote expands it from its own environment
|
|
148
|
+
(that is, the patchbay's env plus the entry's `env`).
|
|
149
|
+
|
|
150
|
+
**Other environment variables.**
|
|
151
|
+
|
|
152
|
+
- `MCP_PATCHBAY_DEBUG=1` copies every child's stderr (redacted) into the patchbay's own stderr log.
|
|
153
|
+
- `MCP_PATCHBAY_MCP_REMOTE_BIN` replaces the mcp-remote script. This is for tests, and you should
|
|
154
|
+
not normally set it.
|
|
155
|
+
|
|
156
|
+
## The agent's tools
|
|
157
|
+
|
|
158
|
+
| Tool | Input | What it does |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| `servers` | — | Lists every configured server: name, description, policy, state (`off`, `starting`, `on`, `failed`, `waiting-for-sign-in`), its tool count when on, its redacted last error when failed, skipped tools, and whether it can be enabled (and if not, why). |
|
|
161
|
+
| `enable` | `{name}` | Starts the server, after asking a person if the policy is `confirm`. Returns its tool count, up to 10 sample tool names, and its instructions (cut to 2,000 characters). With `confirmVia: "host"` it refuses `confirm` servers and points to `enable_confirm`. |
|
|
162
|
+
| `enable_confirm` | `{name}` | Only with `confirmVia: "host"`. Turns on a `confirm` server; the host asks the person before it runs, and that yes is the approval. Refuses `allow` servers (use `enable`) and `deny` servers. Marked `destructiveHint: true`. |
|
|
163
|
+
| `disable` | `{name}` | Stops the server and removes its tools. Refused while that server has calls in flight; the refusal says how many. |
|
|
164
|
+
| `restart` | `{name}` | Stops and starts the server again. There is no new confirmation if it was already on. If it was off, this is the same as `enable`. |
|
|
165
|
+
| `info` | `{name}` | Description, policy, state, the last stderr lines (redacted), and its full instructions when on. |
|
|
166
|
+
|
|
167
|
+
Every one of these tools carries `_meta: {"anthropic/alwaysLoad": true}`.
|
|
168
|
+
|
|
169
|
+
### confirmVia: elicitation or host
|
|
170
|
+
|
|
171
|
+
Some clients declare form elicitation but never show it: in the Claude Code VS Code extension
|
|
172
|
+
(2.1.319), the patchbay's question is answered `decline` with nothing shown to the person. The
|
|
173
|
+
patchbay fails closed, so `confirm` servers cannot be turned on there with the default
|
|
174
|
+
`"elicitation"`. With `"host"`, the approval is the host's own permission prompt for
|
|
175
|
+
`mcp__patchbay__enable_confirm`, which those clients do show, and which the model cannot answer.
|
|
176
|
+
|
|
177
|
+
That prompt only appears if nothing approves the tool in advance. **Do not allow
|
|
178
|
+
`mcp__patchbay__enable_confirm`, `mcp__patchbay__*`, `mcp__patchbay` or `*`**, and do not run in
|
|
179
|
+
a mode that skips prompts (Claude Code's `bypassPermissions`, or `dontAsk` with the tool
|
|
180
|
+
allowed): there, every `enable_confirm` is approved automatically. `mcp-patchbay doctor
|
|
181
|
+
--project <dir>` reads your Claude Code settings and warns about such rules. There is no generic
|
|
182
|
+
"call any tool" or "exec" tool, and there never will be.
|
|
183
|
+
|
|
184
|
+
## Naming contract
|
|
185
|
+
|
|
186
|
+
This mapping is a public contract. Permission rules and hooks can depend on it.
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
exposed name = <prefix or server name> "__" <tool name with every char outside [A-Za-z0-9_-] replaced by "_">
|
|
190
|
+
client name = "mcp__patchbay__" + exposed name (when registered as "patchbay")
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
- A server name or prefix never contains `__` and never ends with `_`. So the **first `__`**
|
|
194
|
+
after `mcp__patchbay__` always separates the server from the tool, even when the tool name
|
|
195
|
+
contains `__` or begins with `_`.
|
|
196
|
+
- For example, `mcp__patchbay__files___hidden` is server `files` and tool `_hidden`.
|
|
197
|
+
- If the client name would be longer than 128 characters, the tool is **skipped** and reported
|
|
198
|
+
in `servers` and `info`. The server part is never shortened.
|
|
199
|
+
- If two tools of one server sanitize to the same name, the first one listed wins and the others
|
|
200
|
+
are skipped and reported.
|
|
201
|
+
- These tools are also skipped: tools whose definition is invalid, and tools that require
|
|
202
|
+
task-augmented calls.
|
|
203
|
+
- Everything else passes through unchanged: `title`, `description`, `inputSchema`,
|
|
204
|
+
`outputSchema`, `annotations`, `_meta` and any other field.
|
|
205
|
+
|
|
206
|
+
## Moving from Claude Code
|
|
207
|
+
|
|
208
|
+
### `import`
|
|
209
|
+
|
|
210
|
+
```sh
|
|
211
|
+
mcp-patchbay import --from ~/.claude.json --project /path/to/project --out ~/.config/mcp-patchbay/servers.json
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`import` only reads your Claude Code config; it never changes it.
|
|
215
|
+
|
|
216
|
+
- **Sources.** It reads the top-level `mcpServers`, plus `projects[<dir>].mcpServers` when
|
|
217
|
+
`--project` is given.
|
|
218
|
+
- **Mapping.** `http`/`sse` entries become `url` entries, with their headers. stdio entries
|
|
219
|
+
become `command` entries.
|
|
220
|
+
- **Policy.** Servers in that project's `disabledMcpServers` become `confirm`; everything else
|
|
221
|
+
becomes `allow`.
|
|
222
|
+
- **Autostart.** With `--project`, `autostart.projects[<dir>]` lists the servers *not* disabled
|
|
223
|
+
there. `autostart.default` is left empty.
|
|
224
|
+
- **Skips.** It skips, and reports, servers it cannot host: `claude.ai …` connectors,
|
|
225
|
+
`plugin:…` servers, `claude-in-chrome`, `ws` transports, names that are invalid here, and the
|
|
226
|
+
patchbay itself.
|
|
227
|
+
- **Output.** It backs up an existing output file to `<out>.bak-<timestamp>` first. It writes the
|
|
228
|
+
file at mode 0600, and never prints env or header values.
|
|
229
|
+
|
|
230
|
+
Afterwards, remove the imported servers from Claude Code (`claude mcp remove <name>`), or they run
|
|
231
|
+
twice: once directly and once through the patchbay.
|
|
232
|
+
|
|
233
|
+
Claude Code expands `${VAR}` in its own server configs. The patchbay does not do this for
|
|
234
|
+
`command`, `args` or `env`; mcp-remote does it for header values. Check imported entries that
|
|
235
|
+
relied on expansion.
|
|
236
|
+
|
|
237
|
+
### `rename-permissions`
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
mcp-patchbay rename-permissions ~/.claude/settings.json # dry run: prints a diff
|
|
241
|
+
mcp-patchbay rename-permissions ~/.claude/settings.json --write # backs up, then writes
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
For each rule in `permissions.allow`, `ask` and `deny`, it **adds** a patchbay twin, and keeps
|
|
245
|
+
every existing rule:
|
|
246
|
+
|
|
247
|
+
- `mcp__X__tool` adds `mcp__patchbay__<seg>__tool`.
|
|
248
|
+
- `mcp__X` (a whole server) adds `mcp__patchbay__<seg>__*`.
|
|
249
|
+
|
|
250
|
+
`<seg>` is server `X`'s `prefix` if it has one, else `X`. The prefixes come from the patchbay
|
|
251
|
+
config: `--config <servers.json>`, else the same file the patchbay would load
|
|
252
|
+
(`$MCP_PATCHBAY_CONFIG`, else `~/.config/mcp-patchbay/servers.json`). If there is no config
|
|
253
|
+
file, it warns that prefixes are unknown and maps names as they are.
|
|
254
|
+
|
|
255
|
+
It skips rules it cannot proxy: `mcp__claude-in-chrome__*`, `mcp__plugin_*`, `mcp__claude_ai_*`,
|
|
256
|
+
rules with parentheses, and existing patchbay rules. It never adds a rule that would match
|
|
257
|
+
`mcp__patchbay__enable_confirm`.
|
|
258
|
+
|
|
259
|
+
### `doctor`
|
|
260
|
+
|
|
261
|
+
```sh
|
|
262
|
+
mcp-patchbay doctor --project /path/to/project --no-start
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
It validates the config and prints `confirmVia`. It then reads `~/.claude/settings.json` and
|
|
266
|
+
`settings.local.json`, plus the project's `.claude/settings.json` and `settings.local.json`
|
|
267
|
+
with `--project`, and names every allow rule that would approve `enable_confirm` without asking
|
|
268
|
+
(the exact name, `mcp__patchbay`, and wildcards such as `mcp__patchbay__*` and `*`), and any
|
|
269
|
+
`defaultMode: "bypassPermissions"`. With `confirmVia: "host"` these are warnings and the exit
|
|
270
|
+
code is 1. Without `--no-start` it then starts each `allow` server briefly (`--all`: `confirm`
|
|
271
|
+
ones too) and reports its tool count.
|
|
272
|
+
|
|
273
|
+
## Policy and safety model
|
|
274
|
+
|
|
275
|
+
The full threat model is in [SECURITY-MODEL.md](SECURITY-MODEL.md). In short:
|
|
276
|
+
|
|
277
|
+
- **The config is trusted. The agent is not.** The agent can only pick a configured name. It
|
|
278
|
+
cannot add servers or change commands, and it cannot run anything that is not in the file.
|
|
279
|
+
This is why the patchbay refuses a config that others can write to.
|
|
280
|
+
- **`confirm` means a person said yes**, for this session's enable. With `confirmVia:
|
|
281
|
+
"elicitation"` that is the client's elicitation UI, and only an accept with `allow: true`
|
|
282
|
+
counts; a client without elicitation support cannot enable `confirm` servers at all. With
|
|
283
|
+
`"host"` it is the host's permission prompt for `enable_confirm`, so it is only as strong as
|
|
284
|
+
your permission rules (see [confirmVia](#confirmvia-elicitation-or-host)).
|
|
285
|
+
- **`confirm` does not vet individual calls.** After a server is on, its tools are governed by
|
|
286
|
+
your client's permission rules, exactly like directly connected servers. **Do not allow
|
|
287
|
+
`mcp__patchbay` as a whole**: that approves every tool of every hosted server, including
|
|
288
|
+
servers you have not yet thought about.
|
|
289
|
+
- **Children are isolated from each other.** One server's `env` never reaches another child. A
|
|
290
|
+
crashing child marks only itself `failed`. Children are never restarted automatically.
|
|
291
|
+
- **Redaction.** Errors, logs and the `servers`/`info` output are redacted: URL query strings,
|
|
292
|
+
bearer tokens, `sk-…`, `ghp_…`, JWT-shaped strings, long hex and base64 runs, and the entry's own
|
|
293
|
+
env, args, header values and url (path segments, query values) all become `[redacted]`.
|
|
294
|
+
Exact values are only matched from 6 characters up, so shorter ones are not hidden.
|
|
295
|
+
- **Tool results are not redacted or sanitised.** They are parsed with the SDK's
|
|
296
|
+
`CallToolResultSchema`, like any SDK client parses them. Unknown keys inside content blocks are
|
|
297
|
+
dropped, and a content block of an unknown `type` makes the call fail. Everything else passes
|
|
298
|
+
through as the server sent it.
|
|
299
|
+
- **A remote server's url is on mcp-remote's command line**, so other local users can see it
|
|
300
|
+
with `ps`. Do not use a url that carries a key if other people share the machine; use a header.
|
|
301
|
+
- **Elicitations from hosted servers** are forwarded to you, prefixed with `[<server>]`.
|
|
302
|
+
Sampling requests from hosted servers are refused.
|
|
303
|
+
- **Process hygiene.** On POSIX each child leads its own process group. Every group gets SIGTERM
|
|
304
|
+
when the patchbay gets SIGINT or SIGTERM or its stdin closes, within milliseconds. Pidfiles let
|
|
305
|
+
the next start clean up after a crash.
|
|
306
|
+
|
|
307
|
+
## Known limits
|
|
308
|
+
|
|
309
|
+
- **Tools only.** v1 proxies tools. Resources, prompts, completions, logging and tasks of hosted
|
|
310
|
+
servers are not available through the patchbay.
|
|
311
|
+
- **The patchbay must be registered as `patchbay`.** The 128-character rule and
|
|
312
|
+
`rename-permissions` assume the client name prefix `mcp__patchbay__`.
|
|
313
|
+
- **OAuth goes through mcp-remote.**
|
|
314
|
+
- Remote servers sign in through mcp-remote's flow. The patchbay shows you the sign-in link
|
|
315
|
+
as a URL elicitation, or as a form with the link if the client lacks URL mode. mcp-remote
|
|
316
|
+
also tries to open a browser.
|
|
317
|
+
- Tokens are stored by mcp-remote under `oauth.configDir`. They are **not** the tokens Claude
|
|
318
|
+
Code holds for its own direct connections, so you sign in once more per server.
|
|
319
|
+
- Claude Code's `/mcp` → "Authenticate" / re-auth **does not cover** servers behind the
|
|
320
|
+
patchbay. Claude Code only sees the patchbay, which is a local stdio server. To re-authenticate
|
|
321
|
+
a hosted server, `restart` it. To sign out, `disable` it and remove its files from
|
|
322
|
+
`oauth.configDir/mcp-remote-v1/`.
|
|
323
|
+
- Sign-in detection depends on the exact stderr text of mcp-remote 0.15.2.
|
|
324
|
+
- **Windows** is untested by the author. The CI matrix covers it, and these limits are known:
|
|
325
|
+
- Config permission checks are skipped.
|
|
326
|
+
- Children are not detached. Trees are killed with `taskkill /T /F /PID`, which runs as a
|
|
327
|
+
separate process, so a child may outlive the patchbay by a moment.
|
|
328
|
+
- When a child exits on its own, processes it started are not cleaned up: Windows has no
|
|
329
|
+
process group to address, and killing the exited pid could hit a process that reused it.
|
|
330
|
+
- `.cmd` shims such as `npx` cannot be spawned directly. Use
|
|
331
|
+
`"command": "cmd", "args": ["/c", "npx", ...]`.
|
|
332
|
+
- Command-line checks for reaping use PowerShell (`Get-CimInstance`).
|
|
333
|
+
- The signal tests are skipped.
|
|
334
|
+
- **Config changes need a restart** of the patchbay.
|
|
335
|
+
|
|
336
|
+
## Comparison
|
|
337
|
+
|
|
338
|
+
| | mcp-patchbay | Docker Dynamic MCP | Magg | Claude Code subagent `mcpServers` |
|
|
339
|
+
|---|---|---|---|---|
|
|
340
|
+
| Runtime | Node.js, child processes | Docker MCP Gateway; needs Docker Desktop | Python | Built into Claude Code |
|
|
341
|
+
| License | Apache-2.0 | — | AGPL-3.0 | — |
|
|
342
|
+
| Who decides what runs | Your config. The agent enables configured names, and a person confirms `confirm` ones | The agent can find and add catalogue servers at run time | The agent can manage the server list through Magg's tools | Fixed per subagent definition |
|
|
343
|
+
| Generic call/exec tool | None, by design | Yes (`mcp-exec`) | — | None |
|
|
344
|
+
| Tools appear | In the main session, via `tools/list_changed` | In the session, via the gateway | In the session, via the aggregator | Only inside that subagent |
|
|
345
|
+
|
|
346
|
+
Docker's approach suits container-isolated catalogue servers. Subagent-scoped `mcpServers` need no
|
|
347
|
+
extra process, when a fixed set per subagent is enough.
|
|
348
|
+
|
|
349
|
+
## Uninstall and rollback
|
|
350
|
+
|
|
351
|
+
1. `claude mcp remove patchbay` (add `--scope user` if you added it that way).
|
|
352
|
+
2. Re-add any servers you had moved, from your backup or with `claude mcp add …`. `import` never
|
|
353
|
+
changed `~/.claude.json`.
|
|
354
|
+
3. Restore permission rules from the backup that `rename-permissions --write` made
|
|
355
|
+
(`settings.json.bak-<timestamp>`). Or keep them: the extra `mcp__patchbay__…` rules are
|
|
356
|
+
harmless without the patchbay.
|
|
357
|
+
4. Remove the patchbay's files:
|
|
358
|
+
`rm -rf ~/.config/mcp-patchbay` (this includes `oauth/` with mcp-remote tokens) and
|
|
359
|
+
`${XDG_RUNTIME_DIR:-/tmp}/mcp-patchbay-$(id -u)` (pidfiles).
|
|
360
|
+
5. If you installed it globally: `npm uninstall -g mcp-patchbay`.
|
|
361
|
+
|
|
362
|
+
## Development
|
|
363
|
+
|
|
364
|
+
```sh
|
|
365
|
+
npm ci
|
|
366
|
+
npm test # node:test, about 20 s
|
|
367
|
+
python3 -m unittest discover -s examples/write-gate -v
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), [SPEC.md](SPEC.md) (the protocol and lifecycle contract)
|
|
371
|
+
and [DECISIONS.md](DECISIONS.md).
|
|
372
|
+
|
|
373
|
+
Issues and source: <https://github.com/distronode-corporation/mcp-patchbay>.
|
|
374
|
+
Security reports: see [SECURITY.md](SECURITY.md).
|
|
375
|
+
This project follows the [Contributor Covenant](CODE_OF_CONDUCT.md).
|
|
376
|
+
|
|
377
|
+
Licensed under the Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|