dynmcp 0.4.0 → 0.5.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/README.md +29 -195
- package/dist/index.cjs +1538 -295
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1650 -407
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
- package/schema/mcp-config.json +0 -138
package/README.md
CHANGED
|
@@ -2,28 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
A proxy MCP that exposes meta-tools so agents can discover and call upstream MCP tools on demand, without loading every tool schema into the context window.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Full documentation:** [dynamicmcp.tools](https://dynamicmcp.tools)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Features
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- **Two meta-tools instead of N.** Wraps one or more upstream MCPs and exposes only `discover_tool` and `use_tool` to the agent. Full schemas of irrelevant tools never enter context.
|
|
10
|
+
- **Dynamic discovery of whole MCPs.** Mark MCPs with a `description` in your config and they stay disconnected until the agent calls `load_mcp` — deferring entire MCP catalogs out of context until they are actually needed.
|
|
11
|
+
- **Full-fidelity proxying.** Resources, prompts, completion, logging, notifications, cancellation, progress, and server-initiated requests (sampling, elicitation, roots) pass through unchanged.
|
|
12
|
+
- **Multiple transports for upstreams.** `stdio` child processes, `streamable-http`, and `sse` — all in one config.
|
|
13
|
+
- **JSON or YAML config** with shell-style `${VAR}` and `${VAR:-default}` environment variable interpolation.
|
|
14
|
+
- **Local-only.** Single Node.js process speaking MCP over stdio. No daemon, no remote endpoint.
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
## Getting Started
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
- **`use_tool`** — executes a tool by name, proxying the call to the upstream MCP and returning its output unchanged.
|
|
15
|
-
|
|
16
|
-
The agent workflow: scan the catalog in `discover_tool`'s description to find relevant tools, call `discover_tool` to load the full schema of the one it needs, then call `use_tool` to execute it. Full schemas of tools the agent never needs never enter the context window.
|
|
17
|
-
|
|
18
|
-
For larger configurations, an optional third tool — **`load_mcp`** — lets the agent defer **whole MCP servers** until needed. Servers declared with a `description` field aren't connected at startup; they appear in a `<mcp_servers>` block in `discover_tool`'s description with their description, and the agent calls `load_mcp` with the server's name to bring it online. See [Dynamic Discovery](#dynamic-discovery).
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
|
|
22
|
-
Requires Node.js >= 20.
|
|
23
|
-
|
|
24
|
-
### Single MCP (quick start)
|
|
25
|
-
|
|
26
|
-
Prefix any MCP invocation with `dynmcp --`:
|
|
18
|
+
### Wrap a single upstream MCP
|
|
27
19
|
|
|
28
20
|
```bash
|
|
29
21
|
# Before — tool schemas go straight into context
|
|
@@ -33,29 +25,15 @@ npx -y chrome-devtools-mcp@latest
|
|
|
33
25
|
npx dynmcp@latest -- npx -y chrome-devtools-mcp@latest
|
|
34
26
|
```
|
|
35
27
|
|
|
36
|
-
Everything after `--` is the command used to launch the upstream MCP.
|
|
37
|
-
|
|
38
|
-
### Multiple MCPs (config file)
|
|
39
|
-
|
|
40
|
-
To proxy several MCPs at once, create a config file:
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
# Auto-discover mcp.json or .mcp.json in cwd
|
|
44
|
-
npx dynmcp@latest
|
|
45
|
-
|
|
46
|
-
# Or specify explicitly
|
|
47
|
-
npx dynmcp@latest --config ./my-config.json
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
When using a config file, tool names are namespaced as `<mcp-name>/<tool-name>` to avoid collisions.
|
|
28
|
+
Everything after `--` is the command used to launch the upstream MCP. In this mode tool names are exposed as-is (no namespace prefix).
|
|
51
29
|
|
|
52
|
-
|
|
30
|
+
### Proxy multiple MCPs from a config file
|
|
53
31
|
|
|
54
|
-
|
|
32
|
+
Create a `mcp.json` in your project root:
|
|
55
33
|
|
|
56
34
|
```json
|
|
57
35
|
{
|
|
58
|
-
"$schema": "https://
|
|
36
|
+
"$schema": "https://dynamicmcp.tools/config.json",
|
|
59
37
|
"mcp": {
|
|
60
38
|
"chrome-devtools": {
|
|
61
39
|
"transport": "stdio",
|
|
@@ -66,59 +44,30 @@ The config file declares upstream MCPs under a top-level `mcp` key. Three transp
|
|
|
66
44
|
"transport": "stdio",
|
|
67
45
|
"command": "npx",
|
|
68
46
|
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
|
69
|
-
},
|
|
70
|
-
"aws-knowledge": {
|
|
71
|
-
"transport": "streamable-http",
|
|
72
|
-
"url": "https://knowledge-mcp.global.api.aws"
|
|
73
|
-
},
|
|
74
|
-
"remote-sse": {
|
|
75
|
-
"transport": "sse",
|
|
76
|
-
"url": "https://example.com/sse",
|
|
77
|
-
"headers": {
|
|
78
|
-
"Authorization": "Bearer my-token"
|
|
79
|
-
}
|
|
80
47
|
}
|
|
81
48
|
}
|
|
82
49
|
}
|
|
83
50
|
```
|
|
84
51
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
### Transport Types
|
|
88
|
-
|
|
89
|
-
| Transport | Fields | Description |
|
|
90
|
-
|---|---|---|
|
|
91
|
-
| `stdio` | `command`, `args?`, `env?` | Spawns the MCP as a child process |
|
|
92
|
-
| `streamable-http` | `url`, `headers?` | Connects to a remote MCP over HTTP |
|
|
93
|
-
| `sse` | `url`, `headers?` | Connects to a remote MCP over Server-Sent Events |
|
|
52
|
+
Then run:
|
|
94
53
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
1. Path from `-c` / `--config` flag
|
|
100
|
-
2. `mcp.json` in the current directory
|
|
101
|
-
3. `.mcp.json` in the current directory
|
|
54
|
+
```bash
|
|
55
|
+
# Auto-discover mcp.json or .mcp.json
|
|
56
|
+
npx dynmcp@latest
|
|
102
57
|
|
|
103
|
-
|
|
58
|
+
# Or specify explicitly
|
|
59
|
+
npx dynmcp@latest --config ./my-config.json
|
|
60
|
+
```
|
|
104
61
|
|
|
105
|
-
|
|
62
|
+
In config-file mode tool names are namespaced as `<mcp-name>/<tool-name>` to avoid collisions.
|
|
106
63
|
|
|
107
64
|
## Dynamic Discovery
|
|
108
65
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
When dynamic discovery is on:
|
|
112
|
-
|
|
113
|
-
- A third meta-tool **`load_mcp`** is exposed to the host.
|
|
114
|
-
- `discover_tool`'s description gains a `<mcp_servers>` block listing every lazy MCP with the description from your config.
|
|
115
|
-
- `<tools>` shows only the catalog of eager (non-lazy) MCPs at startup. As the agent calls `load_mcp`, loaded servers are promoted into `<tools>`.
|
|
116
|
-
|
|
117
|
-
### Example config
|
|
66
|
+
For configs with heavier MCPs you only sometimes need (Chrome DevTools, remote APIs, anything expensive to keep open), give the entry a `description`. That MCP becomes *lazy*: `dynmcp` doesn't open the connection at startup, and the agent only sees a short summary of what the MCP does. When the agent decides it actually needs that MCP, it calls `load_mcp` with the server's name and the connection opens on demand.
|
|
118
67
|
|
|
119
68
|
```json
|
|
120
69
|
{
|
|
121
|
-
"$schema": "https://
|
|
70
|
+
"$schema": "https://dynamicmcp.tools/config.json",
|
|
122
71
|
"mcp": {
|
|
123
72
|
"filesystem": {
|
|
124
73
|
"transport": "stdio",
|
|
@@ -126,135 +75,20 @@ When dynamic discovery is on:
|
|
|
126
75
|
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
|
127
76
|
},
|
|
128
77
|
"chrome-devtools": {
|
|
129
|
-
"description": "Chrome browser automation and DevTools control. Navigate pages, take screenshots, inspect the DOM, run JavaScript
|
|
78
|
+
"description": "Chrome browser automation and DevTools control. Navigate pages, take screenshots, inspect the DOM, run JavaScript. Use when you need to interact with or debug a live web page.",
|
|
130
79
|
"transport": "stdio",
|
|
131
80
|
"command": "npx",
|
|
132
81
|
"args": ["-y", "chrome-devtools-mcp@latest"]
|
|
133
|
-
},
|
|
134
|
-
"aws-knowledge": {
|
|
135
|
-
"description": "AWS documentation, code samples, and best-practice guidance. Search and read AWS docs, API references, blog posts, CDK/CloudFormation templates, and regional availability info. Use when the task involves AWS services or infrastructure-as-code.",
|
|
136
|
-
"transport": "streamable-http",
|
|
137
|
-
"url": "https://knowledge-mcp.global.api.aws"
|
|
138
82
|
}
|
|
139
83
|
}
|
|
140
84
|
}
|
|
141
85
|
```
|
|
142
86
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Writing good descriptions
|
|
146
|
-
|
|
147
|
-
The description is what an agent reads to decide whether to load a server. Write it as if you were briefing a teammate who has never seen the MCP:
|
|
148
|
-
|
|
149
|
-
- **Lead with the verbs** the MCP enables ("navigate, click, screenshot...").
|
|
150
|
-
- **Mention the domain** ("Jira tickets", "AWS docs", "Chrome browser").
|
|
151
|
-
- **Include a "use when..." clause** describing the kind of task it's appropriate for.
|
|
152
|
-
- Keep it to a few sentences. The agent reads every lazy server's description on every `discover_tool` call.
|
|
153
|
-
|
|
154
|
-
### `load_mcp`
|
|
155
|
-
|
|
156
|
-
The `load_mcp` tool takes a single `mcp_name` argument matching a key under `mcp` in your config. On success it returns a structured listing of the now-available tools, resources, resource templates, and prompts, and the host receives `notifications/tools/list_changed` (plus `resources/list_changed` and `prompts/list_changed` when applicable) so `discover_tool`'s description refreshes.
|
|
157
|
-
|
|
158
|
-
Notable semantics:
|
|
159
|
-
|
|
160
|
-
- **Idempotent** — calling `load_mcp` for a server that is already loaded (or for an eager server) is a successful no-op returning the current listing.
|
|
161
|
-
- **Permanent** — loaded servers stay loaded for the lifetime of the `dynmcp` process. There is no `unload_mcp`.
|
|
162
|
-
- **Atomic on failure** — if the upstream fails to connect, initialize, or return its catalog, the partial state is torn down; the lazy entry remains in `<mcp_servers>` and the agent can retry.
|
|
163
|
-
- **Retry budget** — after **three** consecutive failed `load_mcp` attempts, the entry is evicted from `<mcp_servers>` entirely. Further calls return "unknown server". This prevents an agent from burning context retrying a permanently broken upstream.
|
|
164
|
-
- **Concurrency** — concurrent `load_mcp` calls for the same name coalesce onto one connection attempt; calls for different names run in parallel.
|
|
165
|
-
|
|
166
|
-
### Capability caveat
|
|
87
|
+
`filesystem` connects at startup. `chrome-devtools` stays lazy until the agent loads it. Once loaded, it behaves exactly like an eager MCP for the rest of the session.
|
|
167
88
|
|
|
168
|
-
|
|
89
|
+
See the [Dynamic Discovery guide](https://dynamicmcp.tools/guides/dynamic-discovery/) for the capability caveat, the retry budget, and tips on writing descriptions agents can act on.
|
|
169
90
|
|
|
170
|
-
|
|
171
|
-
- A lazy MCP's **resources or prompts** work reliably only if at least one eager MCP in your config also advertises that capability, so the host negotiated to listen for them. The proxy still emits the relevant `*/list_changed` notification on load — but hosts that strictly gate on negotiated capabilities may ignore it.
|
|
91
|
+
---
|
|
172
92
|
|
|
173
|
-
|
|
93
|
+
Full [docs](https://dynamicmcp.tools) cover environment variable interpolation, all transport options, and the complete CLI reference.
|
|
174
94
|
|
|
175
|
-
## Environment Variable Interpolation
|
|
176
|
-
|
|
177
|
-
Config files can reference environment variables in any string-typed leaf value using shell-style syntax. This is useful for keeping secrets (bearer tokens, API keys) and host-specific values (paths, ports) out of the config file itself.
|
|
178
|
-
|
|
179
|
-
```json
|
|
180
|
-
{
|
|
181
|
-
"mcp": {
|
|
182
|
-
"remote": {
|
|
183
|
-
"transport": "streamable-http",
|
|
184
|
-
"url": "${MCP_URL:-https://example.com/mcp}",
|
|
185
|
-
"headers": {
|
|
186
|
-
"Authorization": "Bearer ${MCP_TOKEN}"
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Syntax
|
|
194
|
-
|
|
195
|
-
| Form | Behavior |
|
|
196
|
-
|---|---|
|
|
197
|
-
| `${VAR}` | Replaced with the value of `VAR`. Hard error at startup if `VAR` is undefined. |
|
|
198
|
-
| `${VAR:-default}` | Replaced with `VAR` if set and non-empty, otherwise the literal `default` (may contain spaces, colons, etc.). |
|
|
199
|
-
| `$${...}` | Escape — emits a literal `${...}` with no interpolation. |
|
|
200
|
-
|
|
201
|
-
Interpolation only applies to **leaf string values** inside the `mcp` map (and nested objects/arrays within it). Map keys, the top-level `$schema` field, and the top-level `env` field are never interpolated. Partial-string interpolation works — `"Bearer ${TOKEN}"` is valid.
|
|
202
|
-
|
|
203
|
-
If any referenced variables are missing without a default, `dynmcp` exits at startup with an error listing **all** of them at once (not one at a time).
|
|
204
|
-
|
|
205
|
-
### Sources (`env` field)
|
|
206
|
-
|
|
207
|
-
A top-level `env` field controls where variables are read from:
|
|
208
|
-
|
|
209
|
-
| Value | Behavior |
|
|
210
|
-
|---|---|
|
|
211
|
-
| `"enable"` (default) | Loads `.env` file (if present) and merges with `process.env`. `.env` values take precedence over `process.env` for the same key. |
|
|
212
|
-
| `"dotenv"` | Loads from `.env` file only. `process.env` is ignored. |
|
|
213
|
-
| `"process"` | Reads from `process.env` only. No `.env` file is loaded. |
|
|
214
|
-
| `"disable"` | Disables interpolation entirely — `${VAR}` is left literal. |
|
|
215
|
-
|
|
216
|
-
```json
|
|
217
|
-
{
|
|
218
|
-
"env": "process",
|
|
219
|
-
"mcp": { /* ... */ }
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
### `.env` File Discovery
|
|
224
|
-
|
|
225
|
-
By default, `dynmcp` looks for a file literally named `.env` in the current working directory. To use a different path, pass `--env` / `-e`:
|
|
226
|
-
|
|
227
|
-
```bash
|
|
228
|
-
dynmcp --env ./secrets.env
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
Combining `--env` with `env: "disable"` or `env: "process"` is rejected as incoherent (no `.env` would be loaded). If `--env` points to a file that does not exist, `dynmcp` exits with an error.
|
|
232
|
-
|
|
233
|
-
## CLI Reference
|
|
234
|
-
|
|
235
|
-
```
|
|
236
|
-
dynmcp [options] [-- <upstream-command> [upstream-args...]]
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
| Flag | Short | Description |
|
|
240
|
-
|---|---|---|
|
|
241
|
-
| `--version` | `-v` | Print the package version and exit |
|
|
242
|
-
| `--help` | `-h` | Print usage information and exit |
|
|
243
|
-
| `--config <path>` | `-c` | Path to config file (JSON or YAML) |
|
|
244
|
-
| `--env <path>` | `-e` | Path to a custom `.env` file for variable interpolation |
|
|
245
|
-
| `--` | | Everything after is the upstream MCP command (single-MCP mode) |
|
|
246
|
-
|
|
247
|
-
### Mode Resolution
|
|
248
|
-
|
|
249
|
-
1. If `--` is present, single-MCP mode is used (config file is ignored).
|
|
250
|
-
2. Otherwise, config file mode is used.
|
|
251
|
-
|
|
252
|
-
## Development
|
|
253
|
-
|
|
254
|
-
```bash
|
|
255
|
-
npm install
|
|
256
|
-
npm run build # Compile to dist/
|
|
257
|
-
npm run typecheck # Type-check without emitting
|
|
258
|
-
npm run check # Biome lint + format
|
|
259
|
-
npm test # Run tests
|
|
260
|
-
```
|