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/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for a single wrapped MCP server
|
|
3
|
+
*/
|
|
4
|
+
export interface WrappedServerConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Unique prefix name for this server (used to prefix tool names)
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* Command to execute to start the MCP server (for stdio transport)
|
|
11
|
+
* Either command or url must be specified, but not both
|
|
12
|
+
*/
|
|
13
|
+
command?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Arguments to pass to the command (only used with command)
|
|
16
|
+
*/
|
|
17
|
+
args?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Environment variables for the server process (only used with command)
|
|
20
|
+
*/
|
|
21
|
+
env?: Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Working directory for the server process (only used with command)
|
|
24
|
+
*/
|
|
25
|
+
cwd?: string;
|
|
26
|
+
/**
|
|
27
|
+
* URL to connect to the MCP server (for SSE transport)
|
|
28
|
+
* Either command or url must be specified, but not both
|
|
29
|
+
*/
|
|
30
|
+
url?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for the MCP wrapper server
|
|
34
|
+
*/
|
|
35
|
+
export interface WrapperConfig {
|
|
36
|
+
/**
|
|
37
|
+
* Name of this wrapper server
|
|
38
|
+
*/
|
|
39
|
+
name: string;
|
|
40
|
+
/**
|
|
41
|
+
* Version of this wrapper server (optional, defaults to "1.0.0")
|
|
42
|
+
*/
|
|
43
|
+
version?: string;
|
|
44
|
+
/**
|
|
45
|
+
* List of MCP servers to wrap
|
|
46
|
+
*/
|
|
47
|
+
servers: WrappedServerConfig[];
|
|
48
|
+
/**
|
|
49
|
+
* Separator used between server name and tool name (default: "__")
|
|
50
|
+
*/
|
|
51
|
+
separator?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Information about a wrapped tool
|
|
55
|
+
*/
|
|
56
|
+
export interface WrappedToolInfo {
|
|
57
|
+
/**
|
|
58
|
+
* Original tool name without prefix
|
|
59
|
+
*/
|
|
60
|
+
originalName: string;
|
|
61
|
+
/**
|
|
62
|
+
* Server name that owns this tool
|
|
63
|
+
*/
|
|
64
|
+
serverName: string;
|
|
65
|
+
/**
|
|
66
|
+
* Prefixed tool name (serverName + separator + originalName)
|
|
67
|
+
*/
|
|
68
|
+
prefixedName: string;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE7B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAE/B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for tool name prefixing
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates a prefixed tool name by combining server name and tool name
|
|
6
|
+
*/
|
|
7
|
+
export declare function prefixToolName(serverName: string, toolName: string, separator?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Parses a prefixed tool name and returns the server name and original tool name
|
|
10
|
+
* Returns null if the name doesn't contain the separator
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseToolName(prefixedName: string, separator?: string): {
|
|
13
|
+
serverName: string;
|
|
14
|
+
originalName: string;
|
|
15
|
+
} | null;
|
|
16
|
+
/**
|
|
17
|
+
* Validates that a server name doesn't contain the separator
|
|
18
|
+
*/
|
|
19
|
+
export declare function isValidServerName(serverName: string, separator?: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Validates that a tool name doesn't contain the separator
|
|
22
|
+
*/
|
|
23
|
+
export declare function isValidToolName(toolName: string, separator?: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns supplemental environment variables that should be passed to child processes
|
|
26
|
+
* to work around the SDK's restrictive env whitelist on Windows.
|
|
27
|
+
* On non-Windows platforms, returns an empty object.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSupplementalEnv(): Record<string, string>;
|
|
30
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAA0B,GACpC,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,MAA0B,GACpC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAcrD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,MAA0B,GACpC,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAA0B,GACpC,OAAO,CAET;AAWD;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAY3D"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for tool name prefixing
|
|
3
|
+
*/
|
|
4
|
+
const DEFAULT_SEPARATOR = "__";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a prefixed tool name by combining server name and tool name
|
|
7
|
+
*/
|
|
8
|
+
export function prefixToolName(serverName, toolName, separator = DEFAULT_SEPARATOR) {
|
|
9
|
+
return `${serverName}${separator}${toolName}`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parses a prefixed tool name and returns the server name and original tool name
|
|
13
|
+
* Returns null if the name doesn't contain the separator
|
|
14
|
+
*/
|
|
15
|
+
export function parseToolName(prefixedName, separator = DEFAULT_SEPARATOR) {
|
|
16
|
+
const separatorIndex = prefixedName.indexOf(separator);
|
|
17
|
+
if (separatorIndex === -1) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const serverName = prefixedName.substring(0, separatorIndex);
|
|
21
|
+
const originalName = prefixedName.substring(separatorIndex + separator.length);
|
|
22
|
+
if (!serverName || !originalName) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return { serverName, originalName };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates that a server name doesn't contain the separator
|
|
29
|
+
*/
|
|
30
|
+
export function isValidServerName(serverName, separator = DEFAULT_SEPARATOR) {
|
|
31
|
+
return !serverName.includes(separator);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validates that a tool name doesn't contain the separator
|
|
35
|
+
*/
|
|
36
|
+
export function isValidToolName(toolName, separator = DEFAULT_SEPARATOR) {
|
|
37
|
+
return !toolName.includes(separator);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Environment variables that are missing from the SDK's DEFAULT_INHERITED_ENV_VARS
|
|
41
|
+
* whitelist on Windows but are required by common tools (e.g. OpenSSH needs ProgramData).
|
|
42
|
+
*/
|
|
43
|
+
const ADDITIONAL_WINDOWS_ENV_VARS = [
|
|
44
|
+
'ProgramData',
|
|
45
|
+
'ALLUSERSPROFILE',
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* Returns supplemental environment variables that should be passed to child processes
|
|
49
|
+
* to work around the SDK's restrictive env whitelist on Windows.
|
|
50
|
+
* On non-Windows platforms, returns an empty object.
|
|
51
|
+
*/
|
|
52
|
+
export function getSupplementalEnv() {
|
|
53
|
+
if (process.platform !== 'win32') {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
const env = {};
|
|
57
|
+
for (const key of ADDITIONAL_WINDOWS_ENV_VARS) {
|
|
58
|
+
const value = process.env[key];
|
|
59
|
+
if (value !== undefined) {
|
|
60
|
+
env[key] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return env;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAkB,EAClB,QAAgB,EAChB,YAAoB,iBAAiB;IAErC,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,EAAE,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,YAAoB,EACpB,YAAoB,iBAAiB;IAErC,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvD,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IAC7D,MAAM,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAE/E,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,YAAoB,iBAAiB;IAErC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAgB,EAChB,YAAoB,iBAAiB;IAErC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,2BAA2B,GAAG;IAClC,aAAa;IACb,iBAAiB;CAClB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,GAAG,IAAI,2BAA2B,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { WrapperConfig } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* MCP Wrapper Server that prefixes tool names from multiple underlying MCP servers
|
|
4
|
+
* to prevent naming collisions.
|
|
5
|
+
*/
|
|
6
|
+
export declare class McpWrapper {
|
|
7
|
+
private config;
|
|
8
|
+
private separator;
|
|
9
|
+
private connectedServers;
|
|
10
|
+
private failedServers;
|
|
11
|
+
private server;
|
|
12
|
+
private toolToServerMap;
|
|
13
|
+
constructor(config: WrapperConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Creates a prefixed tool name
|
|
16
|
+
*/
|
|
17
|
+
private prefixToolName;
|
|
18
|
+
/**
|
|
19
|
+
* Looks up tool mapping from the tool name to server map
|
|
20
|
+
*/
|
|
21
|
+
private lookupToolMapping;
|
|
22
|
+
/**
|
|
23
|
+
* Connects to a single underlying MCP server
|
|
24
|
+
*/
|
|
25
|
+
private connectToServer;
|
|
26
|
+
/**
|
|
27
|
+
* Registers tool mappings for a connected server
|
|
28
|
+
*/
|
|
29
|
+
private registerToolMappings;
|
|
30
|
+
/**
|
|
31
|
+
* Helper method to connect and register a server
|
|
32
|
+
*/
|
|
33
|
+
private connectAndRegisterServer;
|
|
34
|
+
/**
|
|
35
|
+
* Reconnects to a specific server by name
|
|
36
|
+
*/
|
|
37
|
+
reconnectServer(serverName: string): Promise<{
|
|
38
|
+
success: boolean;
|
|
39
|
+
message: string;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Connects to all configured underlying MCP servers
|
|
43
|
+
* Skips servers that fail to connect and tracks them for retry
|
|
44
|
+
*/
|
|
45
|
+
connectToServers(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Cleans up all connected servers (used during error recovery)
|
|
48
|
+
*/
|
|
49
|
+
private cleanupConnectedServers;
|
|
50
|
+
/**
|
|
51
|
+
* Sets up request handlers for the wrapper server
|
|
52
|
+
*/
|
|
53
|
+
private setupHandlers;
|
|
54
|
+
/**
|
|
55
|
+
* Starts the wrapper server using stdio transport
|
|
56
|
+
*/
|
|
57
|
+
start(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Closes all connections and stops the server
|
|
60
|
+
*/
|
|
61
|
+
close(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Returns information about all wrapped tools
|
|
64
|
+
*/
|
|
65
|
+
getWrappedTools(): Array<{
|
|
66
|
+
serverName: string;
|
|
67
|
+
originalName: string;
|
|
68
|
+
prefixedName: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=wrapper.d.ts.map
|
|
@@ -0,0 +1 @@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