@mcp-z/client 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/AGENTS.md +159 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cjs/auth/capability-discovery.d.cts +25 -0
- package/dist/cjs/auth/capability-discovery.d.ts +25 -0
- package/dist/cjs/auth/capability-discovery.js +280 -0
- package/dist/cjs/auth/capability-discovery.js.map +1 -0
- package/dist/cjs/auth/index.d.cts +9 -0
- package/dist/cjs/auth/index.d.ts +9 -0
- package/dist/cjs/auth/index.js +28 -0
- package/dist/cjs/auth/index.js.map +1 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.cts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.js +537 -0
- package/dist/cjs/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/cjs/auth/oauth-callback-listener.d.cts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.js +333 -0
- package/dist/cjs/auth/oauth-callback-listener.js.map +1 -0
- package/dist/cjs/auth/pkce.d.cts +17 -0
- package/dist/cjs/auth/pkce.d.ts +17 -0
- package/dist/cjs/auth/pkce.js +192 -0
- package/dist/cjs/auth/pkce.js.map +1 -0
- package/dist/cjs/auth/rfc9728-discovery.d.cts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.js +436 -0
- package/dist/cjs/auth/rfc9728-discovery.js.map +1 -0
- package/dist/cjs/auth/types.d.cts +137 -0
- package/dist/cjs/auth/types.d.ts +137 -0
- package/dist/cjs/auth/types.js +9 -0
- package/dist/cjs/auth/types.js.map +1 -0
- package/dist/cjs/client-helpers.d.cts +55 -0
- package/dist/cjs/client-helpers.d.ts +55 -0
- package/dist/cjs/client-helpers.js +128 -0
- package/dist/cjs/client-helpers.js.map +1 -0
- package/dist/cjs/config/server-loader.d.cts +27 -0
- package/dist/cjs/config/server-loader.d.ts +27 -0
- package/dist/cjs/config/server-loader.js +111 -0
- package/dist/cjs/config/server-loader.js.map +1 -0
- package/dist/cjs/config/validate-config.d.cts +15 -0
- package/dist/cjs/config/validate-config.d.ts +15 -0
- package/dist/cjs/config/validate-config.js +128 -0
- package/dist/cjs/config/validate-config.js.map +1 -0
- package/dist/cjs/connection/connect-client.d.cts +59 -0
- package/dist/cjs/connection/connect-client.d.ts +59 -0
- package/dist/cjs/connection/connect-client.js +536 -0
- package/dist/cjs/connection/connect-client.js.map +1 -0
- package/dist/cjs/connection/existing-process-transport.d.cts +40 -0
- package/dist/cjs/connection/existing-process-transport.d.ts +40 -0
- package/dist/cjs/connection/existing-process-transport.js +274 -0
- package/dist/cjs/connection/existing-process-transport.js.map +1 -0
- package/dist/cjs/connection/types.d.cts +61 -0
- package/dist/cjs/connection/types.d.ts +61 -0
- package/dist/cjs/connection/types.js +53 -0
- package/dist/cjs/connection/types.js.map +1 -0
- package/dist/cjs/connection/wait-for-http-ready.d.cts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.js +232 -0
- package/dist/cjs/connection/wait-for-http-ready.js.map +1 -0
- package/dist/cjs/dcr/dcr-authenticator.d.cts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.js +655 -0
- package/dist/cjs/dcr/dcr-authenticator.js.map +1 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.cts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js +245 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/cjs/dcr/index.d.cts +8 -0
- package/dist/cjs/dcr/index.d.ts +8 -0
- package/dist/cjs/dcr/index.js +24 -0
- package/dist/cjs/dcr/index.js.map +1 -0
- package/dist/cjs/index.d.cts +21 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.js +94 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/monkey-patches.d.cts +6 -0
- package/dist/cjs/monkey-patches.d.ts +6 -0
- package/dist/cjs/monkey-patches.js +236 -0
- package/dist/cjs/monkey-patches.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/response-wrappers.d.cts +41 -0
- package/dist/cjs/response-wrappers.d.ts +41 -0
- package/dist/cjs/response-wrappers.js +443 -0
- package/dist/cjs/response-wrappers.js.map +1 -0
- package/dist/cjs/search/index.d.cts +6 -0
- package/dist/cjs/search/index.d.ts +6 -0
- package/dist/cjs/search/index.js +25 -0
- package/dist/cjs/search/index.js.map +1 -0
- package/dist/cjs/search/search.d.cts +22 -0
- package/dist/cjs/search/search.d.ts +22 -0
- package/dist/cjs/search/search.js +630 -0
- package/dist/cjs/search/search.js.map +1 -0
- package/dist/cjs/search/types.d.cts +122 -0
- package/dist/cjs/search/types.d.ts +122 -0
- package/dist/cjs/search/types.js +10 -0
- package/dist/cjs/search/types.js.map +1 -0
- package/dist/cjs/spawn/spawn-server.d.cts +83 -0
- package/dist/cjs/spawn/spawn-server.d.ts +83 -0
- package/dist/cjs/spawn/spawn-server.js +410 -0
- package/dist/cjs/spawn/spawn-server.js.map +1 -0
- package/dist/cjs/spawn/spawn-servers.d.cts +151 -0
- package/dist/cjs/spawn/spawn-servers.d.ts +151 -0
- package/dist/cjs/spawn/spawn-servers.js +911 -0
- package/dist/cjs/spawn/spawn-servers.js.map +1 -0
- package/dist/cjs/types.d.cts +11 -0
- package/dist/cjs/types.d.ts +11 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/logger.d.cts +24 -0
- package/dist/cjs/utils/logger.d.ts +24 -0
- package/dist/cjs/utils/logger.js +80 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/cjs/utils/path-utils.d.cts +45 -0
- package/dist/cjs/utils/path-utils.d.ts +45 -0
- package/dist/cjs/utils/path-utils.js +158 -0
- package/dist/cjs/utils/path-utils.js.map +1 -0
- package/dist/cjs/utils/sanitizer.d.cts +30 -0
- package/dist/cjs/utils/sanitizer.d.ts +30 -0
- package/dist/cjs/utils/sanitizer.js +124 -0
- package/dist/cjs/utils/sanitizer.js.map +1 -0
- package/dist/esm/auth/capability-discovery.d.ts +25 -0
- package/dist/esm/auth/capability-discovery.js +110 -0
- package/dist/esm/auth/capability-discovery.js.map +1 -0
- package/dist/esm/auth/index.d.ts +9 -0
- package/dist/esm/auth/index.js +6 -0
- package/dist/esm/auth/index.js.map +1 -0
- package/dist/esm/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/esm/auth/interactive-oauth-flow.js +217 -0
- package/dist/esm/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/esm/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/esm/auth/oauth-callback-listener.js +166 -0
- package/dist/esm/auth/oauth-callback-listener.js.map +1 -0
- package/dist/esm/auth/pkce.d.ts +17 -0
- package/dist/esm/auth/pkce.js +41 -0
- package/dist/esm/auth/pkce.js.map +1 -0
- package/dist/esm/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/esm/auth/rfc9728-discovery.js +157 -0
- package/dist/esm/auth/rfc9728-discovery.js.map +1 -0
- package/dist/esm/auth/types.d.ts +137 -0
- package/dist/esm/auth/types.js +7 -0
- package/dist/esm/auth/types.js.map +1 -0
- package/dist/esm/client-helpers.d.ts +55 -0
- package/dist/esm/client-helpers.js +81 -0
- package/dist/esm/client-helpers.js.map +1 -0
- package/dist/esm/config/server-loader.d.ts +27 -0
- package/dist/esm/config/server-loader.js +49 -0
- package/dist/esm/config/server-loader.js.map +1 -0
- package/dist/esm/config/validate-config.d.ts +15 -0
- package/dist/esm/config/validate-config.js +76 -0
- package/dist/esm/config/validate-config.js.map +1 -0
- package/dist/esm/connection/connect-client.d.ts +59 -0
- package/dist/esm/connection/connect-client.js +272 -0
- package/dist/esm/connection/connect-client.js.map +1 -0
- package/dist/esm/connection/existing-process-transport.d.ts +40 -0
- package/dist/esm/connection/existing-process-transport.js +103 -0
- package/dist/esm/connection/existing-process-transport.js.map +1 -0
- package/dist/esm/connection/types.d.ts +61 -0
- package/dist/esm/connection/types.js +34 -0
- package/dist/esm/connection/types.js.map +1 -0
- package/dist/esm/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/esm/connection/wait-for-http-ready.js +43 -0
- package/dist/esm/connection/wait-for-http-ready.js.map +1 -0
- package/dist/esm/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/esm/dcr/dcr-authenticator.js +235 -0
- package/dist/esm/dcr/dcr-authenticator.js.map +1 -0
- package/dist/esm/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/esm/dcr/dynamic-client-registrar.js +66 -0
- package/dist/esm/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/esm/dcr/index.d.ts +8 -0
- package/dist/esm/dcr/index.js +5 -0
- package/dist/esm/dcr/index.js.map +1 -0
- package/dist/esm/index.d.ts +21 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/monkey-patches.d.ts +6 -0
- package/dist/esm/monkey-patches.js +32 -0
- package/dist/esm/monkey-patches.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/response-wrappers.d.ts +41 -0
- package/dist/esm/response-wrappers.js +201 -0
- package/dist/esm/response-wrappers.js.map +1 -0
- package/dist/esm/search/index.d.ts +6 -0
- package/dist/esm/search/index.js +3 -0
- package/dist/esm/search/index.js.map +1 -0
- package/dist/esm/search/search.d.ts +22 -0
- package/dist/esm/search/search.js +236 -0
- package/dist/esm/search/search.js.map +1 -0
- package/dist/esm/search/types.d.ts +122 -0
- package/dist/esm/search/types.js +8 -0
- package/dist/esm/search/types.js.map +1 -0
- package/dist/esm/spawn/spawn-server.d.ts +83 -0
- package/dist/esm/spawn/spawn-server.js +145 -0
- package/dist/esm/spawn/spawn-server.js.map +1 -0
- package/dist/esm/spawn/spawn-servers.d.ts +151 -0
- package/dist/esm/spawn/spawn-servers.js +406 -0
- package/dist/esm/spawn/spawn-servers.js.map +1 -0
- package/dist/esm/types.d.ts +11 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +24 -0
- package/dist/esm/utils/logger.js +59 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/path-utils.d.ts +45 -0
- package/dist/esm/utils/path-utils.js +89 -0
- package/dist/esm/utils/path-utils.js.map +1 -0
- package/dist/esm/utils/sanitizer.d.ts +30 -0
- package/dist/esm/utils/sanitizer.js +43 -0
- package/dist/esm/utils/sanitizer.js.map +1 -0
- package/package.json +92 -0
- package/schemas/servers.d.ts +90 -0
- package/schemas/servers.schema.json +104 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level single server spawning utilities.
|
|
3
|
+
* Provides core process spawning with path resolution, environment management, and lifecycle control.
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "spawnProcess", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return spawnProcess;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
var _child_process = require("child_process");
|
|
15
|
+
var _process = /*#__PURE__*/ _interop_require_wildcard(require("process"));
|
|
16
|
+
var _loggerts = require("../utils/logger.js");
|
|
17
|
+
var _pathutilsts = require("../utils/path-utils.js");
|
|
18
|
+
function _array_like_to_array(arr, len) {
|
|
19
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
20
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
21
|
+
return arr2;
|
|
22
|
+
}
|
|
23
|
+
function _array_with_holes(arr) {
|
|
24
|
+
if (Array.isArray(arr)) return arr;
|
|
25
|
+
}
|
|
26
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
27
|
+
try {
|
|
28
|
+
var info = gen[key](arg);
|
|
29
|
+
var value = info.value;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
reject(error);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (info.done) {
|
|
35
|
+
resolve(value);
|
|
36
|
+
} else {
|
|
37
|
+
Promise.resolve(value).then(_next, _throw);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function _async_to_generator(fn) {
|
|
41
|
+
return function() {
|
|
42
|
+
var self = this, args = arguments;
|
|
43
|
+
return new Promise(function(resolve, reject) {
|
|
44
|
+
var gen = fn.apply(self, args);
|
|
45
|
+
function _next(value) {
|
|
46
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
47
|
+
}
|
|
48
|
+
function _throw(err) {
|
|
49
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
50
|
+
}
|
|
51
|
+
_next(undefined);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function _define_property(obj, key, value) {
|
|
56
|
+
if (key in obj) {
|
|
57
|
+
Object.defineProperty(obj, key, {
|
|
58
|
+
value: value,
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
obj[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
69
|
+
if (typeof WeakMap !== "function") return null;
|
|
70
|
+
var cacheBabelInterop = new WeakMap();
|
|
71
|
+
var cacheNodeInterop = new WeakMap();
|
|
72
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
73
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
74
|
+
})(nodeInterop);
|
|
75
|
+
}
|
|
76
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
77
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
78
|
+
return obj;
|
|
79
|
+
}
|
|
80
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
81
|
+
return {
|
|
82
|
+
default: obj
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
86
|
+
if (cache && cache.has(obj)) {
|
|
87
|
+
return cache.get(obj);
|
|
88
|
+
}
|
|
89
|
+
var newObj = {
|
|
90
|
+
__proto__: null
|
|
91
|
+
};
|
|
92
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
93
|
+
for(var key in obj){
|
|
94
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
95
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
96
|
+
if (desc && (desc.get || desc.set)) {
|
|
97
|
+
Object.defineProperty(newObj, key, desc);
|
|
98
|
+
} else {
|
|
99
|
+
newObj[key] = obj[key];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
newObj.default = obj;
|
|
104
|
+
if (cache) {
|
|
105
|
+
cache.set(obj, newObj);
|
|
106
|
+
}
|
|
107
|
+
return newObj;
|
|
108
|
+
}
|
|
109
|
+
function _iterable_to_array_limit(arr, i) {
|
|
110
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
111
|
+
if (_i == null) return;
|
|
112
|
+
var _arr = [];
|
|
113
|
+
var _n = true;
|
|
114
|
+
var _d = false;
|
|
115
|
+
var _s, _e;
|
|
116
|
+
try {
|
|
117
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
118
|
+
_arr.push(_s.value);
|
|
119
|
+
if (i && _arr.length === i) break;
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
_d = true;
|
|
123
|
+
_e = err;
|
|
124
|
+
} finally{
|
|
125
|
+
try {
|
|
126
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
127
|
+
} finally{
|
|
128
|
+
if (_d) throw _e;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return _arr;
|
|
132
|
+
}
|
|
133
|
+
function _non_iterable_rest() {
|
|
134
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
135
|
+
}
|
|
136
|
+
function _object_spread(target) {
|
|
137
|
+
for(var i = 1; i < arguments.length; i++){
|
|
138
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
139
|
+
var ownKeys = Object.keys(source);
|
|
140
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
141
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
142
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
ownKeys.forEach(function(key) {
|
|
146
|
+
_define_property(target, key, source[key]);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return target;
|
|
150
|
+
}
|
|
151
|
+
function _sliced_to_array(arr, i) {
|
|
152
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
153
|
+
}
|
|
154
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
155
|
+
if (!o) return;
|
|
156
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
157
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
158
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
159
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
160
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
161
|
+
}
|
|
162
|
+
function _ts_generator(thisArg, body) {
|
|
163
|
+
var f, y, t, _ = {
|
|
164
|
+
label: 0,
|
|
165
|
+
sent: function() {
|
|
166
|
+
if (t[0] & 1) throw t[1];
|
|
167
|
+
return t[1];
|
|
168
|
+
},
|
|
169
|
+
trys: [],
|
|
170
|
+
ops: []
|
|
171
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
172
|
+
return d(g, "next", {
|
|
173
|
+
value: verb(0)
|
|
174
|
+
}), d(g, "throw", {
|
|
175
|
+
value: verb(1)
|
|
176
|
+
}), d(g, "return", {
|
|
177
|
+
value: verb(2)
|
|
178
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
179
|
+
value: function() {
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
}), g;
|
|
183
|
+
function verb(n) {
|
|
184
|
+
return function(v) {
|
|
185
|
+
return step([
|
|
186
|
+
n,
|
|
187
|
+
v
|
|
188
|
+
]);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function step(op) {
|
|
192
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
193
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
194
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
195
|
+
if (y = 0, t) op = [
|
|
196
|
+
op[0] & 2,
|
|
197
|
+
t.value
|
|
198
|
+
];
|
|
199
|
+
switch(op[0]){
|
|
200
|
+
case 0:
|
|
201
|
+
case 1:
|
|
202
|
+
t = op;
|
|
203
|
+
break;
|
|
204
|
+
case 4:
|
|
205
|
+
_.label++;
|
|
206
|
+
return {
|
|
207
|
+
value: op[1],
|
|
208
|
+
done: false
|
|
209
|
+
};
|
|
210
|
+
case 5:
|
|
211
|
+
_.label++;
|
|
212
|
+
y = op[1];
|
|
213
|
+
op = [
|
|
214
|
+
0
|
|
215
|
+
];
|
|
216
|
+
continue;
|
|
217
|
+
case 7:
|
|
218
|
+
op = _.ops.pop();
|
|
219
|
+
_.trys.pop();
|
|
220
|
+
continue;
|
|
221
|
+
default:
|
|
222
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
223
|
+
_ = 0;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
227
|
+
_.label = op[1];
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
231
|
+
_.label = t[1];
|
|
232
|
+
t = op;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
if (t && _.label < t[2]) {
|
|
236
|
+
_.label = t[2];
|
|
237
|
+
_.ops.push(op);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
if (t[2]) _.ops.pop();
|
|
241
|
+
_.trys.pop();
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
op = body.call(thisArg, _);
|
|
245
|
+
} catch (e) {
|
|
246
|
+
op = [
|
|
247
|
+
6,
|
|
248
|
+
e
|
|
249
|
+
];
|
|
250
|
+
y = 0;
|
|
251
|
+
} finally{
|
|
252
|
+
f = t = 0;
|
|
253
|
+
}
|
|
254
|
+
if (op[0] & 5) throw op[1];
|
|
255
|
+
return {
|
|
256
|
+
value: op[0] ? op[1] : void 0,
|
|
257
|
+
done: true
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Normalize environment variables by merging with process.env and filtering undefined values.
|
|
263
|
+
*/ function normalizeEnv(env) {
|
|
264
|
+
var merged = _object_spread({}, _process.env, env || {});
|
|
265
|
+
var result = {};
|
|
266
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
267
|
+
try {
|
|
268
|
+
for(var _iterator = Object.entries(merged)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
269
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
270
|
+
if (value !== undefined) {
|
|
271
|
+
result[key] = value;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
} catch (err) {
|
|
275
|
+
_didIteratorError = true;
|
|
276
|
+
_iteratorError = err;
|
|
277
|
+
} finally{
|
|
278
|
+
try {
|
|
279
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
280
|
+
_iterator.return();
|
|
281
|
+
}
|
|
282
|
+
} finally{
|
|
283
|
+
if (_didIteratorError) {
|
|
284
|
+
throw _iteratorError;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
function spawnProcess(opts) {
|
|
291
|
+
var _opts_cwd, _opts_stdio, _opts_shell;
|
|
292
|
+
var name = opts.name;
|
|
293
|
+
var command = opts.command;
|
|
294
|
+
var cwd = (_opts_cwd = opts.cwd) !== null && _opts_cwd !== void 0 ? _opts_cwd : _process.cwd();
|
|
295
|
+
var stdio = (_opts_stdio = opts.stdio) !== null && _opts_stdio !== void 0 ? _opts_stdio : 'inherit';
|
|
296
|
+
var shell = (_opts_shell = opts.shell) !== null && _opts_shell !== void 0 ? _opts_shell : _process.platform === 'win32';
|
|
297
|
+
// Resolve paths in args relative to the working directory
|
|
298
|
+
var args = opts.args ? (0, _pathutilsts.resolveArgsPaths)(opts.args, cwd) : [];
|
|
299
|
+
// Merge environment variables
|
|
300
|
+
var env = normalizeEnv(opts.env);
|
|
301
|
+
// Create resolved config for return value
|
|
302
|
+
var resolvedConfig = {
|
|
303
|
+
name: name,
|
|
304
|
+
command: command,
|
|
305
|
+
args: args,
|
|
306
|
+
cwd: cwd,
|
|
307
|
+
env: env,
|
|
308
|
+
stdio: stdio,
|
|
309
|
+
shell: shell
|
|
310
|
+
};
|
|
311
|
+
// Log spawn operation
|
|
312
|
+
_loggerts.logger.info("[".concat(name, "] → ").concat(command, " ").concat(args.join(' ')));
|
|
313
|
+
// Spawn the process
|
|
314
|
+
var spawnOpts = {
|
|
315
|
+
cwd: cwd,
|
|
316
|
+
env: env,
|
|
317
|
+
stdio: stdio,
|
|
318
|
+
shell: shell
|
|
319
|
+
};
|
|
320
|
+
var child = (0, _child_process.spawn)(command, args, spawnOpts);
|
|
321
|
+
// Attach lifecycle logging
|
|
322
|
+
child.on('exit', function(code, sig) {
|
|
323
|
+
return _loggerts.logger.info("[".concat(name, "] exited (code=").concat(code, ", signal=").concat(sig || 'none', ")"));
|
|
324
|
+
});
|
|
325
|
+
child.on('error', function(err) {
|
|
326
|
+
return _loggerts.logger.info("[".concat(name, "] process error: ").concat(err.message));
|
|
327
|
+
});
|
|
328
|
+
// Create stop function with graceful shutdown
|
|
329
|
+
var stop = function() {
|
|
330
|
+
var signal = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 'SIGINT', _$opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
331
|
+
return _async_to_generator(function() {
|
|
332
|
+
var _opts_timeoutMs, timeoutMs, closePromise;
|
|
333
|
+
return _ts_generator(this, function(_state) {
|
|
334
|
+
// If already exited, return immediately
|
|
335
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
336
|
+
return [
|
|
337
|
+
2,
|
|
338
|
+
{
|
|
339
|
+
timedOut: false,
|
|
340
|
+
killed: false
|
|
341
|
+
}
|
|
342
|
+
];
|
|
343
|
+
}
|
|
344
|
+
timeoutMs = (_opts_timeoutMs = _$opts.timeoutMs) !== null && _opts_timeoutMs !== void 0 ? _opts_timeoutMs : 500;
|
|
345
|
+
// Wait for 'close' event (process exit + stdio streams closed)
|
|
346
|
+
// This is better than 'exit' because it ensures stdio is fully cleaned up
|
|
347
|
+
closePromise = new Promise(function(resolve) {
|
|
348
|
+
var isResolved = false;
|
|
349
|
+
var wasKilled = false;
|
|
350
|
+
var resolveOnce = function(timedOut) {
|
|
351
|
+
if (isResolved) return;
|
|
352
|
+
isResolved = true;
|
|
353
|
+
clearTimeout(timeout);
|
|
354
|
+
resolve({
|
|
355
|
+
timedOut: timedOut,
|
|
356
|
+
killed: wasKilled
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
// Set timeout for forceful kill
|
|
360
|
+
var timeout = setTimeout(function() {
|
|
361
|
+
try {
|
|
362
|
+
// Check again before SIGKILL
|
|
363
|
+
if (child.exitCode === null && !child.killed) {
|
|
364
|
+
child.kill('SIGKILL');
|
|
365
|
+
wasKilled = true;
|
|
366
|
+
}
|
|
367
|
+
} catch (_) {}
|
|
368
|
+
// Even if kill fails, resolve
|
|
369
|
+
resolveOnce(true);
|
|
370
|
+
}, timeoutMs);
|
|
371
|
+
// Listen for 'close' event (not 'exit') to wait for stdio close
|
|
372
|
+
child.once('close', function() {
|
|
373
|
+
resolveOnce(false);
|
|
374
|
+
});
|
|
375
|
+
// Also listen for 'error' event in case spawn failed
|
|
376
|
+
// This prevents promise from hanging forever if process never started
|
|
377
|
+
child.once('error', function() {
|
|
378
|
+
resolveOnce(false);
|
|
379
|
+
});
|
|
380
|
+
// Send graceful shutdown signal
|
|
381
|
+
try {
|
|
382
|
+
// Check one more time before killing
|
|
383
|
+
if (child.exitCode !== null) {
|
|
384
|
+
resolveOnce(false);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
var killed = child.kill(signal);
|
|
388
|
+
// If kill returned false, process already exited
|
|
389
|
+
if (!killed) {
|
|
390
|
+
resolveOnce(false);
|
|
391
|
+
}
|
|
392
|
+
} catch (_err) {
|
|
393
|
+
// If kill throws, process is gone or unreachable
|
|
394
|
+
resolveOnce(false);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
return [
|
|
398
|
+
2,
|
|
399
|
+
closePromise
|
|
400
|
+
];
|
|
401
|
+
});
|
|
402
|
+
})();
|
|
403
|
+
};
|
|
404
|
+
return {
|
|
405
|
+
config: resolvedConfig,
|
|
406
|
+
process: child,
|
|
407
|
+
close: stop
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/libs/client/src/spawn/spawn-server.ts"],"sourcesContent":["/**\n * Low-level single server spawning utilities.\n * Provides core process spawning with path resolution, environment management, and lifecycle control.\n */\n\nimport { type ChildProcess, type SpawnOptions, type StdioOptions, spawn } from 'child_process';\nimport * as process from 'process';\nimport { logger } from '../utils/logger.ts';\nimport { resolveArgsPaths } from '../utils/path-utils.ts';\n\n/**\n * Options for spawning a single server process.\n * @internal\n */\nexport interface SpawnProcessOptions {\n /** Server name for logging */\n name: string;\n /** Command to execute (e.g., 'node', 'npx') */\n command: string;\n /** Command arguments (paths will be resolved relative to cwd) */\n args?: string[];\n /** Working directory (must be absolute path) */\n cwd?: string;\n /** Additional environment variables (merged with process.env) */\n env?: Record<string, string>;\n /** Standard I/O configuration */\n stdio?: StdioOptions;\n /** Use shell for command execution (default: false, true on Windows) */\n shell?: boolean;\n}\n\n/**\n * Handle to a spawned server process.\n * Provides access to the process, resolved config, and lifecycle control.\n * @hidden\n */\nexport interface ServerProcess {\n /**\n * The resolved server configuration that was actually used.\n * Useful for debugging and understanding what was spawned.\n */\n config: {\n name: string;\n command: string;\n args: string[];\n cwd: string;\n env: Record<string, string>;\n stdio: StdioOptions;\n shell: boolean;\n };\n\n /**\n * The spawned child process.\n */\n process: ChildProcess;\n\n /**\n * Close the server gracefully.\n * Sends the specified signal (default: SIGINT), then SIGKILL after timeout.\n *\n * @param signal - Signal to send (default: SIGINT)\n * @param opts - Options including timeout\n * @returns Promise resolving to whether the process timed out and was force-killed\n */\n close: (signal?: NodeJS.Signals, opts?: { timeoutMs?: number }) => Promise<{ timedOut: boolean; killed: boolean }>;\n}\n\n/**\n * Normalize environment variables by merging with process.env and filtering undefined values.\n */\nfunction normalizeEnv(env?: Record<string, string>): Record<string, string> {\n const merged = { ...process.env, ...(env || {}) };\n const result: Record<string, string> = {};\n for (const [key, value] of Object.entries(merged)) {\n if (value !== undefined) {\n result[key] = value;\n }\n }\n return result;\n}\n\n/**\n * Spawn a single server process with path resolution and environment management.\n *\n * @internal\n * @param opts - Server spawn options\n * @returns ServerProcess handle with resolved config, process, and stop function\n *\n * @example\n * const handle = spawnProcess({\n * name: 'echo',\n * command: 'node',\n * args: ['./bin/server.js', '--port', '3000'],\n * cwd: '/home/user/project/test/lib/servers/echo',\n * env: { LOG_LEVEL: 'error' }\n * });\n *\n * // Later...\n * await handle.close();\n */\nexport function spawnProcess(opts: SpawnProcessOptions): ServerProcess {\n const name = opts.name;\n const command = opts.command;\n const cwd = opts.cwd ?? process.cwd();\n const stdio = opts.stdio ?? 'inherit';\n const shell = opts.shell ?? process.platform === 'win32';\n\n // Resolve paths in args relative to the working directory\n const args = opts.args ? resolveArgsPaths(opts.args, cwd) : [];\n\n // Merge environment variables\n const env = normalizeEnv(opts.env);\n\n // Create resolved config for return value\n const resolvedConfig = {\n name,\n command,\n args,\n cwd,\n env,\n stdio,\n shell,\n };\n\n // Log spawn operation\n logger.info(`[${name}] → ${command} ${args.join(' ')}`);\n\n // Spawn the process\n const spawnOpts: SpawnOptions = { cwd, env, stdio, shell };\n const child = spawn(command, args, spawnOpts);\n\n // Attach lifecycle logging\n child.on('exit', (code, sig) => logger.info(`[${name}] exited (code=${code}, signal=${sig || 'none'})`));\n child.on('error', (err) => logger.info(`[${name}] process error: ${err.message}`));\n\n // Create stop function with graceful shutdown\n const stop = async (signal: NodeJS.Signals = 'SIGINT', opts: { timeoutMs?: number } = {}): Promise<{ timedOut: boolean; killed: boolean }> => {\n // If already exited, return immediately\n if (child.exitCode !== null || child.signalCode !== null) {\n return { timedOut: false, killed: false };\n }\n\n const timeoutMs = opts.timeoutMs ?? 500;\n\n // Wait for 'close' event (process exit + stdio streams closed)\n // This is better than 'exit' because it ensures stdio is fully cleaned up\n const closePromise = new Promise<{ timedOut: boolean; killed: boolean }>((resolve) => {\n let isResolved = false;\n let wasKilled = false;\n\n const resolveOnce = (timedOut: boolean) => {\n if (isResolved) return;\n isResolved = true;\n clearTimeout(timeout);\n resolve({ timedOut, killed: wasKilled });\n };\n\n // Set timeout for forceful kill\n const timeout = setTimeout(() => {\n try {\n // Check again before SIGKILL\n if (child.exitCode === null && !child.killed) {\n child.kill('SIGKILL');\n wasKilled = true;\n }\n } catch (_) {}\n // Even if kill fails, resolve\n resolveOnce(true);\n }, timeoutMs);\n\n // Listen for 'close' event (not 'exit') to wait for stdio close\n child.once('close', () => {\n resolveOnce(false);\n });\n\n // Also listen for 'error' event in case spawn failed\n // This prevents promise from hanging forever if process never started\n child.once('error', () => {\n resolveOnce(false);\n });\n\n // Send graceful shutdown signal\n try {\n // Check one more time before killing\n if (child.exitCode !== null) {\n resolveOnce(false);\n return;\n }\n\n const killed = child.kill(signal);\n // If kill returned false, process already exited\n if (!killed) {\n resolveOnce(false);\n }\n } catch (_err) {\n // If kill throws, process is gone or unreachable\n resolveOnce(false);\n }\n });\n\n return closePromise;\n };\n\n return {\n config: resolvedConfig,\n process: child,\n close: stop,\n };\n}\n"],"names":["spawnProcess","normalizeEnv","env","merged","process","result","Object","entries","key","value","undefined","opts","name","command","cwd","stdio","shell","platform","args","resolveArgsPaths","resolvedConfig","logger","info","join","spawnOpts","child","spawn","on","code","sig","err","message","stop","signal","timeoutMs","closePromise","exitCode","signalCode","timedOut","killed","Promise","resolve","isResolved","wasKilled","resolveOnce","clearTimeout","timeout","setTimeout","kill","_","once","_err","config","close"],"mappings":"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"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level multi-server registry management.
|
|
3
|
+
* Starts multiple servers from a servers configuration object.
|
|
4
|
+
* Supports stdio, http, and ws transports.
|
|
5
|
+
* Implements Claude Code-compatible configuration with start extension support.
|
|
6
|
+
*/
|
|
7
|
+
import { type ManagedClient } from '../client-helpers.js';
|
|
8
|
+
import { connectMcpClient } from '../connection/connect-client.js';
|
|
9
|
+
import { type SearchOptions, type SearchResponse } from '../search/index.js';
|
|
10
|
+
import type { McpServerEntry } from '../types.js';
|
|
11
|
+
import { type ServerProcess } from './spawn-server.js';
|
|
12
|
+
/**
|
|
13
|
+
* Servers configuration type - a map of server names to their configurations.
|
|
14
|
+
*/
|
|
15
|
+
export type ServersConfig = Record<string, McpServerEntry>;
|
|
16
|
+
/**
|
|
17
|
+
* Dialect for server spawning.
|
|
18
|
+
*
|
|
19
|
+
* - 'servers': Spawn stdio servers (Claude Code compatible)
|
|
20
|
+
* - 'start': Spawn HTTP servers with start blocks
|
|
21
|
+
*/
|
|
22
|
+
export type Dialect = 'servers' | 'start';
|
|
23
|
+
/**
|
|
24
|
+
* Options for creating a server registry.
|
|
25
|
+
*/
|
|
26
|
+
export interface CreateServerRegistryOptions {
|
|
27
|
+
/** Working directory for spawned processes (default: process.cwd()) */
|
|
28
|
+
cwd?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Base environment for all servers.
|
|
31
|
+
* If provided, process.env is NOT included (caller has full control).
|
|
32
|
+
* If omitted, process.env is used as the base (default behavior).
|
|
33
|
+
*/
|
|
34
|
+
env?: Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Dialects controlling which servers to spawn.
|
|
37
|
+
* - ['servers']: Spawn stdio servers only (default, Claude Code compatible)
|
|
38
|
+
* - ['start']: Only spawn servers with start blocks (HTTP servers)
|
|
39
|
+
* - ['servers', 'start']: Spawn both stdio servers and start blocks
|
|
40
|
+
* @default ['servers']
|
|
41
|
+
*/
|
|
42
|
+
dialects?: Dialect[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Result of closing the registry.
|
|
46
|
+
*/
|
|
47
|
+
export interface CloseResult {
|
|
48
|
+
/** Whether any process timed out during shutdown */
|
|
49
|
+
timedOut: boolean;
|
|
50
|
+
/** Number of processes that were force-killed */
|
|
51
|
+
killedCount: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A registry of spawned MCP servers with connection management.
|
|
55
|
+
* Provides access to individual server handles, connection management, and collection-wide close.
|
|
56
|
+
*/
|
|
57
|
+
type RegistryConnectOptions = Parameters<typeof connectMcpClient>[2];
|
|
58
|
+
export interface ServerRegistry {
|
|
59
|
+
/**
|
|
60
|
+
* The resolved servers configuration that was used.
|
|
61
|
+
* Useful for debugging and understanding what was started.
|
|
62
|
+
*/
|
|
63
|
+
config: ServersConfig;
|
|
64
|
+
/**
|
|
65
|
+
* Map of server name to server process handle.
|
|
66
|
+
* @hidden
|
|
67
|
+
*/
|
|
68
|
+
servers: Map<string, ServerProcess>;
|
|
69
|
+
/**
|
|
70
|
+
* Set of connected clients tracked by this registry.
|
|
71
|
+
* Automatically populated when using registry.connect().
|
|
72
|
+
*/
|
|
73
|
+
clients: Set<ManagedClient>;
|
|
74
|
+
/**
|
|
75
|
+
* Connect to a server by name.
|
|
76
|
+
* The connected client is automatically tracked for close.
|
|
77
|
+
*
|
|
78
|
+
* @param name - Server name from configuration
|
|
79
|
+
* @returns Connected MCP SDK Client
|
|
80
|
+
*/
|
|
81
|
+
connect: (name: string, options?: RegistryConnectOptions) => Promise<ManagedClient>;
|
|
82
|
+
/**
|
|
83
|
+
* Close all clients and servers gracefully.
|
|
84
|
+
* First closes all tracked clients, then sends the specified signal to all server processes.
|
|
85
|
+
*
|
|
86
|
+
* @param signal - Signal to send to processes (default: SIGINT)
|
|
87
|
+
* @param opts - Options including timeout
|
|
88
|
+
* @returns Promise resolving to whether any process timed out and how many were force-killed
|
|
89
|
+
*/
|
|
90
|
+
close: (signal?: NodeJS.Signals, opts?: {
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
}) => Promise<CloseResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Search indexed capabilities across all currently connected clients.
|
|
95
|
+
* Requires at least one connected client; respects SearchOptions filters.
|
|
96
|
+
*/
|
|
97
|
+
searchCapabilities: (query: string, options?: SearchOptions) => Promise<SearchResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* Support for `await using` pattern (automatic close).
|
|
100
|
+
*/
|
|
101
|
+
[Symbol.asyncDispose]: () => Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a registry of MCP servers from configuration.
|
|
105
|
+
*
|
|
106
|
+
* **Fast start**: Returns immediately after processes are created.
|
|
107
|
+
* Use `registry.connect()` for lazy MCP connection.
|
|
108
|
+
*
|
|
109
|
+
* @param serversConfig - Map of server names to their configurations
|
|
110
|
+
* @param options - Options for registry creation
|
|
111
|
+
* @param options.cwd - Working directory for spawned processes (default: process.cwd())
|
|
112
|
+
* @param options.env - Base environment for all servers. If provided, process.env is NOT included.
|
|
113
|
+
* If omitted, process.env is used as the base (default behavior).
|
|
114
|
+
* @param options.dialects - Dialects controlling which servers to spawn (default: ['servers'])
|
|
115
|
+
* - ['servers']: Spawn stdio servers only (Claude Code compatible)
|
|
116
|
+
* - ['start']: Only spawn servers with start blocks (HTTP servers)
|
|
117
|
+
* - ['servers', 'start']: Spawn both stdio servers and start blocks
|
|
118
|
+
* @returns ServerRegistry instance with config, server map, connect method, and close function
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Fast server start (does NOT wait for readiness)
|
|
122
|
+
* const registry = createServerRegistry({
|
|
123
|
+
* 'echo': { command: 'node', args: ['server.ts'] },
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* // Connect when needed (waits for MCP handshake)
|
|
127
|
+
* const client = await registry.connect('echo');
|
|
128
|
+
*
|
|
129
|
+
* // Cleanup (closes all clients AND processes)
|
|
130
|
+
* await registry.close();
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* // Start HTTP servers with start blocks
|
|
134
|
+
* const registry = createServerRegistry(
|
|
135
|
+
* {
|
|
136
|
+
* 'http-server': {
|
|
137
|
+
* url: 'http://localhost:8080/mcp',
|
|
138
|
+
* start: { command: 'node', args: ['http.ts', '--port', '8080'] }
|
|
139
|
+
* },
|
|
140
|
+
* },
|
|
141
|
+
* { dialects: ['start'] }
|
|
142
|
+
* );
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* // Using await using for automatic close
|
|
146
|
+
* await using registry = createServerRegistry(config);
|
|
147
|
+
* const client = await registry.connect('server');
|
|
148
|
+
* // Auto-disposed when scope exits
|
|
149
|
+
*/
|
|
150
|
+
export declare function createServerRegistry(serversConfig: ServersConfig, options?: CreateServerRegistryOptions): ServerRegistry;
|
|
151
|
+
export {};
|