mcp-multiplexer 1.0.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 +201 -0
- package/README.md +283 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +122 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +30 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +65 -0
- package/dist/utils.js.map +1 -0
- package/dist/wrapper.d.ts +72 -0
- package/dist/wrapper.d.ts.map +1 -0
- package/dist/wrapper.js +511 -0
- package/dist/wrapper.js.map +1 -0
- package/package.json +52 -0
package/dist/wrapper.js
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
|
+
import { SSEClientTransport, SseError } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
5
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
6
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import { prefixToolName as utilPrefixToolName, isValidServerName, getSupplementalEnv } from "./utils.js";
|
|
9
|
+
const DEFAULT_SEPARATOR = "__";
|
|
10
|
+
const DEFAULT_VERSION = "1.0.0";
|
|
11
|
+
const SERVER_CLOSE_TIMEOUT_MS = 5000;
|
|
12
|
+
const SERVER_CONNECT_TIMEOUT_MS = 30000; // 30 seconds timeout for connecting to child servers
|
|
13
|
+
/**
|
|
14
|
+
* Error class for server configuration validation errors
|
|
15
|
+
* These errors should fail fast and not be caught by resilient connection handling
|
|
16
|
+
*/
|
|
17
|
+
class ConfigurationError extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'ConfigurationError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* MCP Wrapper Server that prefixes tool names from multiple underlying MCP servers
|
|
25
|
+
* to prevent naming collisions.
|
|
26
|
+
*/
|
|
27
|
+
export class McpWrapper {
|
|
28
|
+
config;
|
|
29
|
+
separator;
|
|
30
|
+
connectedServers = new Map();
|
|
31
|
+
failedServers = new Map();
|
|
32
|
+
server;
|
|
33
|
+
toolToServerMap = new Map();
|
|
34
|
+
constructor(config) {
|
|
35
|
+
this.config = config;
|
|
36
|
+
this.separator = config.separator ?? DEFAULT_SEPARATOR;
|
|
37
|
+
// Validate server names don't contain separator and are unique
|
|
38
|
+
const seenServerNames = new Set();
|
|
39
|
+
const reservedNames = ['wrapper'];
|
|
40
|
+
for (const serverConfig of config.servers) {
|
|
41
|
+
// Validate required fields
|
|
42
|
+
if (!serverConfig.name || typeof serverConfig.name !== 'string') {
|
|
43
|
+
throw new Error(`Invalid server configuration: each server must have a 'name' field (string)`);
|
|
44
|
+
}
|
|
45
|
+
// Check for reserved names
|
|
46
|
+
const lowerName = serverConfig.name.toLowerCase();
|
|
47
|
+
if (reservedNames.includes(lowerName)) {
|
|
48
|
+
throw new Error(`Invalid server name "${serverConfig.name}": server name cannot be "wrapper" as it is reserved for wrapper management tools`);
|
|
49
|
+
}
|
|
50
|
+
if (!isValidServerName(serverConfig.name, this.separator)) {
|
|
51
|
+
throw new Error(`Invalid server name "${serverConfig.name}": server names cannot contain the separator "${this.separator}"`);
|
|
52
|
+
}
|
|
53
|
+
if (seenServerNames.has(serverConfig.name)) {
|
|
54
|
+
throw new Error(`Duplicate server name "${serverConfig.name}": each server must have a unique name`);
|
|
55
|
+
}
|
|
56
|
+
seenServerNames.add(serverConfig.name);
|
|
57
|
+
}
|
|
58
|
+
this.server = new Server({
|
|
59
|
+
name: config.name,
|
|
60
|
+
version: config.version ?? DEFAULT_VERSION,
|
|
61
|
+
}, {
|
|
62
|
+
capabilities: {
|
|
63
|
+
tools: {},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
this.setupHandlers();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a prefixed tool name
|
|
70
|
+
*/
|
|
71
|
+
prefixToolName(serverName, toolName) {
|
|
72
|
+
return utilPrefixToolName(serverName, toolName, this.separator);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Looks up tool mapping from the tool name to server map
|
|
76
|
+
*/
|
|
77
|
+
lookupToolMapping(prefixedName) {
|
|
78
|
+
const mapping = this.toolToServerMap.get(prefixedName);
|
|
79
|
+
if (mapping) {
|
|
80
|
+
return mapping;
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Connects to a single underlying MCP server
|
|
86
|
+
*/
|
|
87
|
+
async connectToServer(serverConfig) {
|
|
88
|
+
// Validate that either command or url is provided, but not both
|
|
89
|
+
const hasCommand = !!serverConfig.command;
|
|
90
|
+
const hasUrl = !!serverConfig.url;
|
|
91
|
+
if (!hasCommand && !hasUrl) {
|
|
92
|
+
throw new ConfigurationError(`Server "${serverConfig.name}" must specify either "command" or "url"`);
|
|
93
|
+
}
|
|
94
|
+
if (hasCommand && hasUrl) {
|
|
95
|
+
throw new ConfigurationError(`Server "${serverConfig.name}" cannot specify both "command" and "url"`);
|
|
96
|
+
}
|
|
97
|
+
let transport;
|
|
98
|
+
let parsedUrl;
|
|
99
|
+
if (serverConfig.url) {
|
|
100
|
+
// Validate URL format
|
|
101
|
+
try {
|
|
102
|
+
parsedUrl = new URL(serverConfig.url);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw new ConfigurationError(`Server "${serverConfig.name}" has invalid URL format: "${serverConfig.url}"`);
|
|
106
|
+
}
|
|
107
|
+
// Try Streamable HTTP first (modern protocol), fall back to SSE (legacy)
|
|
108
|
+
// Streamable HTTP is the recommended protocol and what VS Code/Claude use
|
|
109
|
+
transport = new StreamableHTTPClientTransport(parsedUrl);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Use stdio transport for command-based servers
|
|
113
|
+
// serverConfig.command is guaranteed to exist due to validation above
|
|
114
|
+
transport = new StdioClientTransport({
|
|
115
|
+
command: serverConfig.command,
|
|
116
|
+
args: serverConfig.args,
|
|
117
|
+
env: { ...getSupplementalEnv(), ...serverConfig.env },
|
|
118
|
+
cwd: serverConfig.cwd,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const client = new Client({
|
|
122
|
+
name: `${this.config.name}-client`,
|
|
123
|
+
version: this.config.version ?? DEFAULT_VERSION,
|
|
124
|
+
}, {
|
|
125
|
+
capabilities: {},
|
|
126
|
+
});
|
|
127
|
+
try {
|
|
128
|
+
await client.connect(transport);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
// If Streamable HTTP fails, try SSE as fallback for legacy servers
|
|
132
|
+
if (serverConfig.url && parsedUrl && transport instanceof StreamableHTTPClientTransport) {
|
|
133
|
+
console.warn(`Streamable HTTP connection failed, trying SSE fallback for "${serverConfig.name}"...`);
|
|
134
|
+
try {
|
|
135
|
+
// Create a new client for SSE fallback to ensure clean state
|
|
136
|
+
const sseClient = new Client({
|
|
137
|
+
name: `${this.config.name}-client`,
|
|
138
|
+
version: this.config.version ?? DEFAULT_VERSION,
|
|
139
|
+
}, {
|
|
140
|
+
capabilities: {},
|
|
141
|
+
});
|
|
142
|
+
transport = new SSEClientTransport(parsedUrl);
|
|
143
|
+
await sseClient.connect(transport);
|
|
144
|
+
// Success with SSE fallback - replace the original client
|
|
145
|
+
Object.assign(client, sseClient);
|
|
146
|
+
console.warn(`Connected to "${serverConfig.name}" using legacy SSE transport`);
|
|
147
|
+
}
|
|
148
|
+
catch (sseError) {
|
|
149
|
+
// Both transports failed, provide helpful error message
|
|
150
|
+
if (sseError instanceof SseError) {
|
|
151
|
+
const statusCode = sseError.code ?? "unknown";
|
|
152
|
+
if (statusCode === 405) {
|
|
153
|
+
throw new Error(`Server "${serverConfig.name}" at URL "${serverConfig.url}" returned HTTP 405 (Method Not Allowed). ` +
|
|
154
|
+
`This URL does not support MCP Streamable HTTP or SSE transports. ` +
|
|
155
|
+
`Make sure the URL points to an actual MCP server endpoint.`);
|
|
156
|
+
}
|
|
157
|
+
else if (statusCode === 404) {
|
|
158
|
+
throw new Error(`Server "${serverConfig.name}" at URL "${serverConfig.url}" returned HTTP 404 (Not Found). ` +
|
|
159
|
+
`Please check that the URL is correct and the MCP server is running.`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
throw new Error(`Server "${serverConfig.name}" at URL "${serverConfig.url}" failed to connect with HTTP ${statusCode}. ` +
|
|
163
|
+
`Tried both Streamable HTTP and SSE transports. ` +
|
|
164
|
+
`Make sure the URL points to a valid MCP server endpoint.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Re-throw if not an SseError
|
|
168
|
+
throw new Error(`Server "${serverConfig.name}" at URL "${serverConfig.url}" failed to connect. ` +
|
|
169
|
+
`Streamable HTTP error: ${error instanceof Error ? error.message : String(error)}. ` +
|
|
170
|
+
`SSE fallback error: ${sseError instanceof Error ? sseError.message : String(sseError)}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// For stdio errors or other failures, re-throw original error
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// List tools from the server
|
|
179
|
+
const toolsResult = await client.listTools();
|
|
180
|
+
const tools = toolsResult.tools;
|
|
181
|
+
return {
|
|
182
|
+
config: serverConfig,
|
|
183
|
+
client,
|
|
184
|
+
transport,
|
|
185
|
+
tools,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Registers tool mappings for a connected server
|
|
190
|
+
*/
|
|
191
|
+
registerToolMappings(serverName, connectedServer) {
|
|
192
|
+
for (const tool of connectedServer.tools) {
|
|
193
|
+
const prefixedName = this.prefixToolName(serverName, tool.name);
|
|
194
|
+
// Warn about tool name collisions
|
|
195
|
+
if (this.toolToServerMap.has(prefixedName)) {
|
|
196
|
+
const previous = this.toolToServerMap.get(prefixedName);
|
|
197
|
+
console.warn(`Tool name collision detected: "${prefixedName}" is being overwritten. ` +
|
|
198
|
+
`Previous: server "${previous?.serverName}", tool "${previous?.originalName}". ` +
|
|
199
|
+
`New: server "${serverName}", tool "${tool.name}".`);
|
|
200
|
+
}
|
|
201
|
+
this.toolToServerMap.set(prefixedName, {
|
|
202
|
+
serverName: serverName,
|
|
203
|
+
originalName: tool.name,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Helper method to connect and register a server
|
|
209
|
+
*/
|
|
210
|
+
async connectAndRegisterServer(serverName, serverConfig) {
|
|
211
|
+
try {
|
|
212
|
+
const connectedServer = await this.connectToServer(serverConfig);
|
|
213
|
+
this.connectedServers.set(serverName, connectedServer);
|
|
214
|
+
this.failedServers.delete(serverName);
|
|
215
|
+
this.registerToolMappings(serverName, connectedServer);
|
|
216
|
+
console.error(`Connected to server "${serverName}" with ${connectedServer.tools.length} tools`);
|
|
217
|
+
return {
|
|
218
|
+
success: true,
|
|
219
|
+
message: `Successfully connected to server "${serverName}" with ${connectedServer.tools.length} tool(s)`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
224
|
+
this.failedServers.set(serverName, {
|
|
225
|
+
config: serverConfig,
|
|
226
|
+
error: errorMessage,
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
success: false,
|
|
230
|
+
message: `Failed to connect to server "${serverName}": ${errorMessage}`,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Reconnects to a specific server by name
|
|
236
|
+
*/
|
|
237
|
+
async reconnectServer(serverName) {
|
|
238
|
+
// Check if it's already connected
|
|
239
|
+
if (this.connectedServers.has(serverName)) {
|
|
240
|
+
return {
|
|
241
|
+
success: false,
|
|
242
|
+
message: `Server "${serverName}" is already connected`,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
// Check if server is in failed list
|
|
246
|
+
const failedServer = this.failedServers.get(serverName);
|
|
247
|
+
if (failedServer) {
|
|
248
|
+
return this.connectAndRegisterServer(serverName, failedServer.config);
|
|
249
|
+
}
|
|
250
|
+
// Check if it exists in config
|
|
251
|
+
const serverConfig = this.config.servers.find(s => s.name === serverName);
|
|
252
|
+
if (!serverConfig) {
|
|
253
|
+
return {
|
|
254
|
+
success: false,
|
|
255
|
+
message: `Server "${serverName}" not found in configuration`,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return this.connectAndRegisterServer(serverName, serverConfig);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Connects to all configured underlying MCP servers
|
|
262
|
+
* Skips servers that fail to connect and tracks them for retry
|
|
263
|
+
*/
|
|
264
|
+
async connectToServers() {
|
|
265
|
+
for (const serverConfig of this.config.servers) {
|
|
266
|
+
try {
|
|
267
|
+
// Add timeout to prevent hanging on slow or unresponsive servers
|
|
268
|
+
// Assign timeoutId before starting the race to avoid race condition
|
|
269
|
+
let timeoutId;
|
|
270
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
271
|
+
timeoutId = setTimeout(() => reject(new Error(`Connection timeout after ${SERVER_CONNECT_TIMEOUT_MS}ms`)), SERVER_CONNECT_TIMEOUT_MS);
|
|
272
|
+
});
|
|
273
|
+
const connectedServer = await Promise.race([
|
|
274
|
+
this.connectToServer(serverConfig).finally(() => {
|
|
275
|
+
clearTimeout(timeoutId);
|
|
276
|
+
}),
|
|
277
|
+
timeoutPromise,
|
|
278
|
+
]);
|
|
279
|
+
this.connectedServers.set(serverConfig.name, connectedServer);
|
|
280
|
+
// Remove from failed servers if it was previously failing
|
|
281
|
+
this.failedServers.delete(serverConfig.name);
|
|
282
|
+
// Register tool mappings
|
|
283
|
+
this.registerToolMappings(serverConfig.name, connectedServer);
|
|
284
|
+
console.error(`Connected to server "${serverConfig.name}" with ${connectedServer.tools.length} tools`);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
// Handle all errors gracefully - log and continue with other servers
|
|
288
|
+
// This includes both configuration errors and connection errors
|
|
289
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
290
|
+
console.error(`Failed to connect to server "${serverConfig.name}": ${errorMessage}`);
|
|
291
|
+
// Track failed server for potential retry
|
|
292
|
+
this.failedServers.set(serverConfig.name, {
|
|
293
|
+
config: serverConfig,
|
|
294
|
+
error: errorMessage,
|
|
295
|
+
});
|
|
296
|
+
// Continue to next server instead of throwing
|
|
297
|
+
console.error(`Skipping server "${serverConfig.name}", will continue with remaining servers`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Log summary
|
|
301
|
+
console.error(`Successfully connected to ${this.connectedServers.size} server(s)`);
|
|
302
|
+
if (this.failedServers.size > 0) {
|
|
303
|
+
console.error(`Failed to connect to ${this.failedServers.size} server(s): ${Array.from(this.failedServers.keys()).join(', ')}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Cleans up all connected servers (used during error recovery)
|
|
308
|
+
*/
|
|
309
|
+
async cleanupConnectedServers() {
|
|
310
|
+
for (const [serverName, connectedServer] of this.connectedServers) {
|
|
311
|
+
try {
|
|
312
|
+
await connectedServer.transport.close();
|
|
313
|
+
console.error(`Cleaned up connection to server "${serverName}"`);
|
|
314
|
+
}
|
|
315
|
+
catch (closeError) {
|
|
316
|
+
console.error(`Error cleaning up connection to "${serverName}":`, closeError);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
this.connectedServers.clear();
|
|
320
|
+
this.toolToServerMap.clear();
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Sets up request handlers for the wrapper server
|
|
324
|
+
*/
|
|
325
|
+
setupHandlers() {
|
|
326
|
+
// Handle tools/list request
|
|
327
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
328
|
+
const allTools = [];
|
|
329
|
+
for (const [serverName, connectedServer] of this.connectedServers) {
|
|
330
|
+
for (const tool of connectedServer.tools) {
|
|
331
|
+
const prefixedName = this.prefixToolName(serverName, tool.name);
|
|
332
|
+
allTools.push({
|
|
333
|
+
...tool,
|
|
334
|
+
name: prefixedName,
|
|
335
|
+
description: `[${serverName}] ${tool.description ?? ""}`,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// Add wrapper management tools
|
|
340
|
+
allTools.push({
|
|
341
|
+
name: "wrapper__reconnect_server",
|
|
342
|
+
description: "Reconnect to a failed MCP server",
|
|
343
|
+
inputSchema: {
|
|
344
|
+
type: "object",
|
|
345
|
+
properties: {
|
|
346
|
+
serverName: {
|
|
347
|
+
type: "string",
|
|
348
|
+
description: "Name of the server to reconnect",
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
required: ["serverName"],
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
allTools.push({
|
|
355
|
+
name: "wrapper__list_servers",
|
|
356
|
+
description: "List all configured servers with their connection status",
|
|
357
|
+
inputSchema: {
|
|
358
|
+
type: "object",
|
|
359
|
+
properties: {},
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
return { tools: allTools };
|
|
363
|
+
});
|
|
364
|
+
// Handle tools/call request
|
|
365
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
366
|
+
const { name: prefixedName, arguments: args } = request.params;
|
|
367
|
+
// Handle wrapper management tools
|
|
368
|
+
if (prefixedName === "wrapper__reconnect_server") {
|
|
369
|
+
const serverName = args?.serverName;
|
|
370
|
+
if (!serverName || typeof serverName !== 'string') {
|
|
371
|
+
return {
|
|
372
|
+
content: [
|
|
373
|
+
{
|
|
374
|
+
type: "text",
|
|
375
|
+
text: "Error: serverName parameter is required and must be a string",
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
isError: true,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
const result = await this.reconnectServer(serverName);
|
|
382
|
+
return {
|
|
383
|
+
content: [
|
|
384
|
+
{
|
|
385
|
+
type: "text",
|
|
386
|
+
text: result.message,
|
|
387
|
+
},
|
|
388
|
+
],
|
|
389
|
+
isError: !result.success,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
if (prefixedName === "wrapper__list_servers") {
|
|
393
|
+
const serverList = {
|
|
394
|
+
connected: Array.from(this.connectedServers.entries()).map(([name, server]) => ({
|
|
395
|
+
name,
|
|
396
|
+
toolCount: server.tools.length,
|
|
397
|
+
status: "connected",
|
|
398
|
+
})),
|
|
399
|
+
failed: Array.from(this.failedServers.entries()).map(([name, failed]) => ({
|
|
400
|
+
name,
|
|
401
|
+
status: "failed",
|
|
402
|
+
error: failed.error,
|
|
403
|
+
})),
|
|
404
|
+
};
|
|
405
|
+
return {
|
|
406
|
+
content: [
|
|
407
|
+
{
|
|
408
|
+
type: "text",
|
|
409
|
+
text: JSON.stringify(serverList, null, 2),
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
const mapping = this.lookupToolMapping(prefixedName);
|
|
415
|
+
if (!mapping) {
|
|
416
|
+
return {
|
|
417
|
+
content: [
|
|
418
|
+
{
|
|
419
|
+
type: "text",
|
|
420
|
+
text: `Error: Unknown tool "${prefixedName}"`,
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
isError: true,
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
const { serverName, originalName } = mapping;
|
|
427
|
+
const connectedServer = this.connectedServers.get(serverName);
|
|
428
|
+
if (!connectedServer) {
|
|
429
|
+
return {
|
|
430
|
+
content: [
|
|
431
|
+
{
|
|
432
|
+
type: "text",
|
|
433
|
+
text: `Error: Server "${serverName}" is not connected`,
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
isError: true,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const result = await connectedServer.client.callTool({
|
|
441
|
+
name: originalName,
|
|
442
|
+
arguments: args,
|
|
443
|
+
});
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
catch (error) {
|
|
447
|
+
return {
|
|
448
|
+
content: [
|
|
449
|
+
{
|
|
450
|
+
type: "text",
|
|
451
|
+
text: `Error calling tool "${originalName}" on server "${serverName}": ${error instanceof Error ? error.message : String(error)}`,
|
|
452
|
+
},
|
|
453
|
+
],
|
|
454
|
+
isError: true,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Starts the wrapper server using stdio transport
|
|
461
|
+
*/
|
|
462
|
+
async start() {
|
|
463
|
+
const transport = new StdioServerTransport();
|
|
464
|
+
await this.server.connect(transport);
|
|
465
|
+
console.error(`MCP Wrapper "${this.config.name}" started`);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Closes all connections and stops the server
|
|
469
|
+
*/
|
|
470
|
+
async close() {
|
|
471
|
+
for (const [serverName, connectedServer] of this.connectedServers) {
|
|
472
|
+
try {
|
|
473
|
+
await connectedServer.transport.close();
|
|
474
|
+
console.error(`Disconnected from server "${serverName}"`);
|
|
475
|
+
}
|
|
476
|
+
catch (error) {
|
|
477
|
+
console.error(`Error closing connection to "${serverName}":`, error);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
this.connectedServers.clear();
|
|
481
|
+
this.toolToServerMap.clear();
|
|
482
|
+
// Add a timeout to server.close() to prevent hanging
|
|
483
|
+
try {
|
|
484
|
+
await Promise.race([
|
|
485
|
+
this.server.close(),
|
|
486
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout closing wrapper server")), SERVER_CLOSE_TIMEOUT_MS)),
|
|
487
|
+
]);
|
|
488
|
+
}
|
|
489
|
+
catch (error) {
|
|
490
|
+
console.error("Error closing wrapper server:", error);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Returns information about all wrapped tools
|
|
495
|
+
*/
|
|
496
|
+
getWrappedTools() {
|
|
497
|
+
const result = [];
|
|
498
|
+
for (const [serverName, connectedServer] of this.connectedServers) {
|
|
499
|
+
for (const tool of connectedServer.tools) {
|
|
500
|
+
result.push({
|
|
501
|
+
serverName,
|
|
502
|
+
originalName: tool.name,
|
|
503
|
+
prefixedName: this.prefixToolName(serverName, tool.name),
|
|
504
|
+
description: tool.description,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return result;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
//# sourceMappingURL=wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACr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AAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,eAAe;QAMb,MAAM,MAAM,GAKP,EAAE,CAAC;QAER,KAAK,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAClE,KAAK,MAAM,IAAI,IAAI,eAAe,CAAC,KAAK,EAAE,CAAC;gBACzC,MAAM,CAAC,IAAI,CAAC;oBACV,UAAU;oBACV,YAAY,EAAE,IAAI,CAAC,IAAI;oBACvB,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;oBACxD,WAAW,EAAE,IAAI,CAAC,WAAW;iBAC9B,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-multiplexer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP 服务器多路复用器——将多个 MCP 服务器合并为一个,自动为工具名添加服务器前缀以避免命名冲突",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"mcp-multiplexer": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"lint": "tsc --noEmit",
|
|
19
|
+
"prepare": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"mcp",
|
|
23
|
+
"model-context-protocol",
|
|
24
|
+
"multiplexer",
|
|
25
|
+
"wrapper",
|
|
26
|
+
"tools",
|
|
27
|
+
"copilot",
|
|
28
|
+
"claude"
|
|
29
|
+
],
|
|
30
|
+
"author": "埃博拉酱-机器人",
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/Ebola-Chan-bot/mcp-wrapper.git"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/Ebola-Chan-bot/mcp-wrapper#readme",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/Ebola-Chan-bot/mcp-wrapper/issues"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
45
|
+
"zod": "^4.3.6"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^25.3.3",
|
|
49
|
+
"typescript": "^5.9.3",
|
|
50
|
+
"vitest": "^4.0.18"
|
|
51
|
+
}
|
|
52
|
+
}
|