mcp-proxy-conductor 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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/index.js +426 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Cornelißen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# ai-conductor
|
|
2
|
+
|
|
3
|
+
A local **MCP proxy / aggregator**. You register it **once** with an MCP client (e.g.
|
|
4
|
+
Claude Desktop or Claude Code), and it sits in front of multiple, **dynamically managed**
|
|
5
|
+
downstream MCP servers.
|
|
6
|
+
|
|
7
|
+
> Published on npm as [`mcp-proxy-conductor`](https://www.npmjs.com/package/mcp-proxy-conductor).
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
Individual MCP servers are fiddly to set up and force an agent restart on every change.
|
|
12
|
+
ai-conductor decouples that: downstream servers are added/removed **at runtime**, without
|
|
13
|
+
restarting the upstream client. New tools appear immediately via MCP `listChanged`
|
|
14
|
+
notifications.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Claude (MCP client)
|
|
18
|
+
│ upstream: stdio
|
|
19
|
+
▼
|
|
20
|
+
┌─────────────────────────┐
|
|
21
|
+
│ ai-conductor │ MCP server upstream, MCP client downstream
|
|
22
|
+
└─────────────────────────┘
|
|
23
|
+
│ downstream: stdio | Streamable HTTP | SSE
|
|
24
|
+
▼
|
|
25
|
+
Server A Server B Server C … (managed at runtime)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- **Runtime management** of downstream servers via built-in meta-tools — no client restart.
|
|
31
|
+
- Downstream transports: **stdio**, **Streamable HTTP**, **SSE**.
|
|
32
|
+
- Aggregates **tools, resources, and prompts** from all downstreams, with per-server
|
|
33
|
+
namespacing (`serverId__name`) so names never collide.
|
|
34
|
+
- **Persistence** — added servers are stored and reconnected on the next start.
|
|
35
|
+
- Auth passed through per downstream (env vars for stdio, headers for HTTP/SSE), behind a
|
|
36
|
+
pluggable `SecretProvider` interface.
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
|
|
40
|
+
- Node.js ≥ 20
|
|
41
|
+
|
|
42
|
+
## Install & register
|
|
43
|
+
|
|
44
|
+
Register ai-conductor with your MCP client. With the Claude Code CLI:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
claude mcp add conductor -s user -- npx -y mcp-proxy-conductor
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or add it manually to your client's MCP config:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"conductor": { "command": "npx", "args": ["-y", "mcp-proxy-conductor"] }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Restart the client once. ai-conductor then exposes its meta-tools.
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
Manage downstream servers conversationally through the meta-tools:
|
|
65
|
+
|
|
66
|
+
- **`add_server`** — add and connect a downstream server at runtime (persists).
|
|
67
|
+
- `id`: unique, alphanumeric/hyphen, no underscores.
|
|
68
|
+
- `transport`: one of
|
|
69
|
+
- `{ "type": "stdio", "command": "...", "args": [...], "env": { ... } }`
|
|
70
|
+
- `{ "type": "http", "url": "https://…/mcp", "headers": { ... } }`
|
|
71
|
+
- `{ "type": "sse", "url": "https://…/sse", "headers": { ... } }`
|
|
72
|
+
- **`remove_server`** — disconnect and remove a downstream server (persists).
|
|
73
|
+
- `id`: the server id.
|
|
74
|
+
- **`list_servers`** — list managed servers with connection state and capability counts.
|
|
75
|
+
|
|
76
|
+
### Example
|
|
77
|
+
|
|
78
|
+
Adding an stdio-based downstream:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"id": "filesystem",
|
|
83
|
+
"transport": {
|
|
84
|
+
"type": "stdio",
|
|
85
|
+
"command": "npx",
|
|
86
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/some/dir"]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Once connected, its tools appear as `filesystem__<toolname>` and are callable
|
|
92
|
+
immediately — no restart.
|
|
93
|
+
|
|
94
|
+
### Secrets
|
|
95
|
+
|
|
96
|
+
`env` and `headers` values support `${VAR}` references that are expanded from the
|
|
97
|
+
environment at connect time, so you can avoid hardcoding tokens, e.g.
|
|
98
|
+
`"Authorization": "Bearer ${UPTIMEROBOT_TOKEN}"`.
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pnpm install
|
|
104
|
+
pnpm test # vitest
|
|
105
|
+
pnpm typecheck
|
|
106
|
+
pnpm build # tsup → dist/index.js
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Status & limitations
|
|
110
|
+
|
|
111
|
+
This is an MVP focused on the local, single-user case. Known limitations:
|
|
112
|
+
|
|
113
|
+
- No automatic reconnect/backoff for a downstream that crashes (remove + add to recover).
|
|
114
|
+
- Change notifications are coarse (all `listChanged` types emitted on any change).
|
|
115
|
+
- HTTP downstreams do not auto-fall back to SSE; the transport type is explicit.
|
|
116
|
+
|
|
117
|
+
Planned, not yet implemented: multi-tenant/SaaS mode, MCP registry lookup, OS-keychain
|
|
118
|
+
secret backend.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
[MIT](LICENSE) © Patrick Cornelißen
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
|
|
6
|
+
// src/config/store.ts
|
|
7
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
8
|
+
import { dirname } from "path";
|
|
9
|
+
import envPaths from "env-paths";
|
|
10
|
+
|
|
11
|
+
// src/config/schema.ts
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
var ServerIdSchema = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9-]*$/, "id must be alphanumeric/hyphen, no underscores");
|
|
14
|
+
var StdioTransportSchema = z.object({
|
|
15
|
+
type: z.literal("stdio"),
|
|
16
|
+
command: z.string().min(1),
|
|
17
|
+
args: z.array(z.string()).default([]),
|
|
18
|
+
env: z.record(z.string(), z.string()).default({})
|
|
19
|
+
});
|
|
20
|
+
var HttpTransportSchema = z.object({
|
|
21
|
+
type: z.literal("http"),
|
|
22
|
+
url: z.string().url(),
|
|
23
|
+
headers: z.record(z.string(), z.string()).default({})
|
|
24
|
+
});
|
|
25
|
+
var SseTransportSchema = z.object({
|
|
26
|
+
type: z.literal("sse"),
|
|
27
|
+
url: z.string().url(),
|
|
28
|
+
headers: z.record(z.string(), z.string()).default({})
|
|
29
|
+
});
|
|
30
|
+
var TransportSchema = z.discriminatedUnion("type", [
|
|
31
|
+
StdioTransportSchema,
|
|
32
|
+
HttpTransportSchema,
|
|
33
|
+
SseTransportSchema
|
|
34
|
+
]);
|
|
35
|
+
var ServerDefinitionSchema = z.object({
|
|
36
|
+
id: ServerIdSchema,
|
|
37
|
+
enabled: z.boolean().default(true),
|
|
38
|
+
transport: TransportSchema
|
|
39
|
+
});
|
|
40
|
+
var ConfigSchema = z.object({
|
|
41
|
+
servers: z.array(ServerDefinitionSchema).default([])
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// src/config/store.ts
|
|
45
|
+
function defaultConfigPath() {
|
|
46
|
+
return `${envPaths("ai-conductor", { suffix: "" }).config}/config.json`;
|
|
47
|
+
}
|
|
48
|
+
var ConfigStore = class {
|
|
49
|
+
constructor(path = defaultConfigPath()) {
|
|
50
|
+
this.path = path;
|
|
51
|
+
}
|
|
52
|
+
path;
|
|
53
|
+
async load() {
|
|
54
|
+
let raw;
|
|
55
|
+
try {
|
|
56
|
+
raw = await readFile(this.path, "utf8");
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if (err.code === "ENOENT") return ConfigSchema.parse({});
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
return ConfigSchema.parse(JSON.parse(raw));
|
|
62
|
+
}
|
|
63
|
+
async save(config) {
|
|
64
|
+
const validated = ConfigSchema.parse(config);
|
|
65
|
+
await mkdir(dirname(this.path), { recursive: true });
|
|
66
|
+
await writeFile(this.path, JSON.stringify(validated, null, 2), "utf8");
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/secrets/provider.ts
|
|
71
|
+
var REF = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
72
|
+
var EnvSecretProvider = class {
|
|
73
|
+
constructor(env = process.env) {
|
|
74
|
+
this.env = env;
|
|
75
|
+
}
|
|
76
|
+
env;
|
|
77
|
+
async resolve(value) {
|
|
78
|
+
return value.replace(REF, (_, name) => {
|
|
79
|
+
const v = this.env[name];
|
|
80
|
+
if (v === void 0) throw new Error(`Secret reference \${${name}} is not set in the environment`);
|
|
81
|
+
return v;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async resolveRecord(record) {
|
|
85
|
+
const out = {};
|
|
86
|
+
for (const [k, v] of Object.entries(record)) out[k] = await this.resolve(v);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/registry/transport.ts
|
|
92
|
+
import { StdioClientTransport, getDefaultEnvironment } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
93
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
94
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
95
|
+
async function buildTransport(def, secrets) {
|
|
96
|
+
const t = def.transport;
|
|
97
|
+
if (t.type === "stdio") {
|
|
98
|
+
const env = await secrets.resolveRecord(t.env);
|
|
99
|
+
return new StdioClientTransport({ command: t.command, args: t.args, env: { ...getDefaultEnvironment(), ...env } });
|
|
100
|
+
}
|
|
101
|
+
const headers = await secrets.resolveRecord(t.headers);
|
|
102
|
+
const requestInit = { headers };
|
|
103
|
+
if (t.type === "http") return new StreamableHTTPClientTransport(new URL(t.url), { requestInit });
|
|
104
|
+
return new SSEClientTransport(new URL(t.url), { requestInit });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/registry/connection.ts
|
|
108
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
109
|
+
import {
|
|
110
|
+
ToolListChangedNotificationSchema,
|
|
111
|
+
ResourceListChangedNotificationSchema,
|
|
112
|
+
PromptListChangedNotificationSchema
|
|
113
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
114
|
+
var DownstreamConnection = class {
|
|
115
|
+
constructor(def, transportFactory, onChange) {
|
|
116
|
+
this.def = def;
|
|
117
|
+
this.transportFactory = transportFactory;
|
|
118
|
+
this.onChange = onChange;
|
|
119
|
+
this.client = new Client({ name: "ai-conductor", version: "0.1.0" });
|
|
120
|
+
}
|
|
121
|
+
def;
|
|
122
|
+
transportFactory;
|
|
123
|
+
onChange;
|
|
124
|
+
state = "connecting";
|
|
125
|
+
error;
|
|
126
|
+
capabilities = { tools: [], resources: [], prompts: [] };
|
|
127
|
+
client;
|
|
128
|
+
async connect() {
|
|
129
|
+
this.state = "connecting";
|
|
130
|
+
try {
|
|
131
|
+
const transport = await this.transportFactory(this.def);
|
|
132
|
+
await this.client.connect(transport);
|
|
133
|
+
this.client.onclose = () => {
|
|
134
|
+
if (this.state === "connected") this.state = "disconnected";
|
|
135
|
+
this.onChange?.();
|
|
136
|
+
};
|
|
137
|
+
this.registerNotificationHandlers();
|
|
138
|
+
await this.refresh();
|
|
139
|
+
this.state = "connected";
|
|
140
|
+
} catch (err) {
|
|
141
|
+
this.state = "error";
|
|
142
|
+
this.error = err instanceof Error ? err.message : String(err);
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
registerNotificationHandlers() {
|
|
147
|
+
const refreshAndNotify = async () => {
|
|
148
|
+
await this.refresh().catch(() => void 0);
|
|
149
|
+
this.onChange?.();
|
|
150
|
+
};
|
|
151
|
+
this.client.setNotificationHandler(ToolListChangedNotificationSchema, refreshAndNotify);
|
|
152
|
+
this.client.setNotificationHandler(ResourceListChangedNotificationSchema, refreshAndNotify);
|
|
153
|
+
this.client.setNotificationHandler(PromptListChangedNotificationSchema, refreshAndNotify);
|
|
154
|
+
}
|
|
155
|
+
async refresh() {
|
|
156
|
+
const caps = this.client.getServerCapabilities() ?? {};
|
|
157
|
+
this.capabilities = {
|
|
158
|
+
tools: caps.tools ? (await this.client.listTools()).tools : [],
|
|
159
|
+
resources: caps.resources ? (await this.client.listResources()).resources : [],
|
|
160
|
+
prompts: caps.prompts ? (await this.client.listPrompts()).prompts : []
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async close() {
|
|
164
|
+
await this.client.close().catch(() => void 0);
|
|
165
|
+
this.state = "disconnected";
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// src/registry/manager.ts
|
|
170
|
+
var DownstreamManager = class {
|
|
171
|
+
constructor(transportFactory, onChange = () => void 0) {
|
|
172
|
+
this.transportFactory = transportFactory;
|
|
173
|
+
this.onChange = onChange;
|
|
174
|
+
}
|
|
175
|
+
transportFactory;
|
|
176
|
+
onChange;
|
|
177
|
+
conns = /* @__PURE__ */ new Map();
|
|
178
|
+
// Connect all enabled definitions. Individual failures are captured as error state;
|
|
179
|
+
// they never reject start() or prevent other servers from connecting.
|
|
180
|
+
async start(defs) {
|
|
181
|
+
await Promise.all(defs.filter((d) => d.enabled).map((d) => this.connectOne(d)));
|
|
182
|
+
}
|
|
183
|
+
async connectOne(def) {
|
|
184
|
+
const conn = new DownstreamConnection(def, this.transportFactory, this.onChange);
|
|
185
|
+
this.conns.set(def.id, conn);
|
|
186
|
+
await conn.connect().catch(() => void 0);
|
|
187
|
+
this.onChange();
|
|
188
|
+
return conn;
|
|
189
|
+
}
|
|
190
|
+
async add(def) {
|
|
191
|
+
if (this.conns.has(def.id)) throw new Error(`server '${def.id}' already exists`);
|
|
192
|
+
return this.connectOne(def);
|
|
193
|
+
}
|
|
194
|
+
async remove(id) {
|
|
195
|
+
const conn = this.conns.get(id);
|
|
196
|
+
if (!conn) return;
|
|
197
|
+
await conn.close();
|
|
198
|
+
this.conns.delete(id);
|
|
199
|
+
this.onChange();
|
|
200
|
+
}
|
|
201
|
+
get(id) {
|
|
202
|
+
return this.conns.get(id);
|
|
203
|
+
}
|
|
204
|
+
connected() {
|
|
205
|
+
return [...this.conns.values()].filter((c) => c.state === "connected");
|
|
206
|
+
}
|
|
207
|
+
list() {
|
|
208
|
+
return [...this.conns.values()].map((c) => ({
|
|
209
|
+
id: c.def.id,
|
|
210
|
+
state: c.state,
|
|
211
|
+
error: c.error,
|
|
212
|
+
toolCount: c.capabilities.tools.length,
|
|
213
|
+
resourceCount: c.capabilities.resources.length,
|
|
214
|
+
promptCount: c.capabilities.prompts.length
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
async closeAll() {
|
|
218
|
+
await Promise.all([...this.conns.values()].map((c) => c.close()));
|
|
219
|
+
this.conns.clear();
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// src/aggregator/namespace.ts
|
|
224
|
+
var DELIM = "__";
|
|
225
|
+
function encodeName(serverId, name) {
|
|
226
|
+
return `${serverId}${DELIM}${name}`;
|
|
227
|
+
}
|
|
228
|
+
function decodeName(qualified) {
|
|
229
|
+
const idx = qualified.indexOf(DELIM);
|
|
230
|
+
if (idx === -1) throw new Error(`Not a namespaced name: ${qualified}`);
|
|
231
|
+
return { serverId: qualified.slice(0, idx), name: qualified.slice(idx + DELIM.length) };
|
|
232
|
+
}
|
|
233
|
+
function encodeUri(serverId, uri) {
|
|
234
|
+
const u = new URL("conductor://route/");
|
|
235
|
+
u.searchParams.set("s", serverId);
|
|
236
|
+
u.searchParams.set("u", uri);
|
|
237
|
+
return u.toString();
|
|
238
|
+
}
|
|
239
|
+
function decodeUri(qualified) {
|
|
240
|
+
const u = new URL(qualified);
|
|
241
|
+
const s = u.searchParams.get("s");
|
|
242
|
+
const orig = u.searchParams.get("u");
|
|
243
|
+
if (!s || orig === null) throw new Error(`Not a namespaced uri: ${qualified}`);
|
|
244
|
+
return { serverId: s, uri: orig };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/aggregator/aggregate.ts
|
|
248
|
+
var Aggregator = class {
|
|
249
|
+
constructor(manager) {
|
|
250
|
+
this.manager = manager;
|
|
251
|
+
}
|
|
252
|
+
manager;
|
|
253
|
+
async listTools() {
|
|
254
|
+
return this.manager.connected().flatMap(
|
|
255
|
+
(c) => c.capabilities.tools.map((t) => ({ ...t, name: encodeName(c.def.id, t.name) }))
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
async listPrompts() {
|
|
259
|
+
return this.manager.connected().flatMap(
|
|
260
|
+
(c) => c.capabilities.prompts.map((p) => ({ ...p, name: encodeName(c.def.id, p.name) }))
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
async listResources() {
|
|
264
|
+
return this.manager.connected().flatMap(
|
|
265
|
+
(c) => c.capabilities.resources.map((r) => ({ ...r, uri: encodeUri(c.def.id, r.uri) }))
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
async callTool(qualifiedName, args) {
|
|
269
|
+
const { serverId, name } = decodeName(qualifiedName);
|
|
270
|
+
return this.connOrThrow(serverId).client.callTool({ name, arguments: args });
|
|
271
|
+
}
|
|
272
|
+
async getPrompt(qualifiedName, args) {
|
|
273
|
+
const { serverId, name } = decodeName(qualifiedName);
|
|
274
|
+
return this.connOrThrow(serverId).client.getPrompt({ name, arguments: args });
|
|
275
|
+
}
|
|
276
|
+
async readResource(qualifiedUri) {
|
|
277
|
+
const { serverId, uri } = decodeUri(qualifiedUri);
|
|
278
|
+
return this.connOrThrow(serverId).client.readResource({ uri });
|
|
279
|
+
}
|
|
280
|
+
connOrThrow(serverId) {
|
|
281
|
+
const conn = this.manager.get(serverId);
|
|
282
|
+
if (!conn || conn.state !== "connected") {
|
|
283
|
+
throw new Error(`downstream server '${serverId}' is not connected`);
|
|
284
|
+
}
|
|
285
|
+
return conn;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/meta/tools.ts
|
|
290
|
+
var ok = (text) => ({ content: [{ type: "text", text }] });
|
|
291
|
+
var fail = (text) => ({ content: [{ type: "text", text }], isError: true });
|
|
292
|
+
var MetaTools = class {
|
|
293
|
+
constructor(manager, store) {
|
|
294
|
+
this.manager = manager;
|
|
295
|
+
this.store = store;
|
|
296
|
+
}
|
|
297
|
+
manager;
|
|
298
|
+
store;
|
|
299
|
+
definitions() {
|
|
300
|
+
return [
|
|
301
|
+
{
|
|
302
|
+
name: "add_server",
|
|
303
|
+
description: "Add and connect a downstream MCP server at runtime. Persists across restarts.",
|
|
304
|
+
inputSchema: {
|
|
305
|
+
type: "object",
|
|
306
|
+
properties: {
|
|
307
|
+
id: { type: "string", description: "Unique id, alphanumeric/hyphen, no underscores" },
|
|
308
|
+
transport: { type: "object", description: 'Transport: {type:"stdio",command,args?,env?} | {type:"http",url,headers?} | {type:"sse",url,headers?}' }
|
|
309
|
+
},
|
|
310
|
+
required: ["id", "transport"]
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: "remove_server",
|
|
315
|
+
description: "Disconnect and remove a downstream MCP server. Persists across restarts.",
|
|
316
|
+
inputSchema: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: "list_servers",
|
|
320
|
+
description: "List managed downstream servers with connection state and capability counts.",
|
|
321
|
+
inputSchema: { type: "object", properties: {} }
|
|
322
|
+
}
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
has(name) {
|
|
326
|
+
return ["add_server", "remove_server", "list_servers"].includes(name);
|
|
327
|
+
}
|
|
328
|
+
async call(name, args) {
|
|
329
|
+
try {
|
|
330
|
+
if (name === "add_server") return await this.addServer(args);
|
|
331
|
+
if (name === "remove_server") return await this.removeServer(args);
|
|
332
|
+
if (name === "list_servers") return ok(JSON.stringify(this.manager.list(), null, 2));
|
|
333
|
+
return fail(`unknown meta-tool: ${name}`);
|
|
334
|
+
} catch (err) {
|
|
335
|
+
return fail(err instanceof Error ? err.message : String(err));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async addServer(args) {
|
|
339
|
+
const def = ServerDefinitionSchema.parse({ id: args.id, transport: args.transport, enabled: true });
|
|
340
|
+
await this.manager.add(def);
|
|
341
|
+
const config = await this.store.load();
|
|
342
|
+
config.servers = [...config.servers.filter((s) => s.id !== def.id), def];
|
|
343
|
+
await this.store.save(config);
|
|
344
|
+
const state = this.manager.get(def.id)?.state;
|
|
345
|
+
return ok(`server '${def.id}' added (state: ${state}).`);
|
|
346
|
+
}
|
|
347
|
+
async removeServer(args) {
|
|
348
|
+
const id = String(args.id ?? "");
|
|
349
|
+
if (!id) return fail("id is required");
|
|
350
|
+
await this.manager.remove(id);
|
|
351
|
+
const config = await this.store.load();
|
|
352
|
+
config.servers = config.servers.filter((s) => s.id !== id);
|
|
353
|
+
await this.store.save(config);
|
|
354
|
+
return ok(`server '${id}' removed.`);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
// src/server/upstream.ts
|
|
359
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
360
|
+
import {
|
|
361
|
+
ListToolsRequestSchema,
|
|
362
|
+
CallToolRequestSchema,
|
|
363
|
+
ListResourcesRequestSchema,
|
|
364
|
+
ReadResourceRequestSchema,
|
|
365
|
+
ListPromptsRequestSchema,
|
|
366
|
+
GetPromptRequestSchema
|
|
367
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
368
|
+
function buildUpstreamServer(aggregator, meta) {
|
|
369
|
+
const server = new Server(
|
|
370
|
+
{ name: "ai-conductor", version: "0.1.0" },
|
|
371
|
+
{ capabilities: { tools: { listChanged: true }, resources: { listChanged: true }, prompts: { listChanged: true } } }
|
|
372
|
+
);
|
|
373
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
374
|
+
tools: [...meta.definitions(), ...await aggregator.listTools()]
|
|
375
|
+
}));
|
|
376
|
+
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
377
|
+
const name = req.params.name;
|
|
378
|
+
const args = req.params.arguments ?? {};
|
|
379
|
+
if (!name.includes(DELIM)) return meta.call(name, args);
|
|
380
|
+
return aggregator.callTool(name, args);
|
|
381
|
+
});
|
|
382
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => ({ resources: await aggregator.listResources() }));
|
|
383
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (req) => aggregator.readResource(req.params.uri));
|
|
384
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts: await aggregator.listPrompts() }));
|
|
385
|
+
server.setRequestHandler(
|
|
386
|
+
GetPromptRequestSchema,
|
|
387
|
+
async (req) => aggregator.getPrompt(req.params.name, req.params.arguments ?? {})
|
|
388
|
+
);
|
|
389
|
+
return server;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/index.ts
|
|
393
|
+
async function createConductor(opts = {}) {
|
|
394
|
+
const store = opts.store ?? new ConfigStore();
|
|
395
|
+
const secrets = new EnvSecretProvider();
|
|
396
|
+
const transportFactory = opts.transportFactory ?? ((def) => buildTransport(def, secrets));
|
|
397
|
+
let server;
|
|
398
|
+
const onChange = () => {
|
|
399
|
+
if (!server?.transport) return;
|
|
400
|
+
server.sendToolListChanged();
|
|
401
|
+
server.sendResourceListChanged();
|
|
402
|
+
server.sendPromptListChanged();
|
|
403
|
+
};
|
|
404
|
+
const manager = new DownstreamManager(transportFactory, onChange);
|
|
405
|
+
const aggregator = new Aggregator(manager);
|
|
406
|
+
const meta = new MetaTools(manager, store);
|
|
407
|
+
server = buildUpstreamServer(aggregator, meta);
|
|
408
|
+
const config = await store.load();
|
|
409
|
+
await manager.start(config.servers);
|
|
410
|
+
return {
|
|
411
|
+
server,
|
|
412
|
+
manager,
|
|
413
|
+
async start() {
|
|
414
|
+
await server.connect(new StdioServerTransport());
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
419
|
+
createConductor().then((c) => c.start()).catch((err) => {
|
|
420
|
+
console.error("ai-conductor failed to start:", err);
|
|
421
|
+
process.exit(1);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
export {
|
|
425
|
+
createConductor
|
|
426
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-proxy-conductor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local MCP proxy that aggregates dynamically managed downstream MCP servers, managed at runtime without restarting the client.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Patrick Cornelißen (https://github.com/pcornelissen)",
|
|
8
|
+
"homepage": "https://github.com/pc-software-org/ai-conductor#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/pc-software-org/ai-conductor.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/pc-software-org/ai-conductor/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mcp",
|
|
18
|
+
"model-context-protocol",
|
|
19
|
+
"proxy",
|
|
20
|
+
"aggregator",
|
|
21
|
+
"claude",
|
|
22
|
+
"llm",
|
|
23
|
+
"ai"
|
|
24
|
+
],
|
|
25
|
+
"bin": {
|
|
26
|
+
"mcp-proxy-conductor": "dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsx src/index.ts",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@modelcontextprotocol/sdk": "1.29.0",
|
|
44
|
+
"env-paths": "^3.0.0",
|
|
45
|
+
"zod": "^3.23.8"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^25.9.2",
|
|
49
|
+
"tsup": "^8.3.0",
|
|
50
|
+
"tsx": "^4.19.0",
|
|
51
|
+
"typescript": "^5.6.0",
|
|
52
|
+
"vitest": "^2.1.0"
|
|
53
|
+
}
|
|
54
|
+
}
|