@mcp-z/cli 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.
Files changed (126) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +166 -0
  3. package/bin/cli.js +5 -0
  4. package/dist/cjs/cli.d.cts +1 -0
  5. package/dist/cjs/cli.d.ts +1 -0
  6. package/dist/cjs/cli.js +576 -0
  7. package/dist/cjs/cli.js.map +1 -0
  8. package/dist/cjs/commands/call-tool.d.cts +26 -0
  9. package/dist/cjs/commands/call-tool.d.ts +26 -0
  10. package/dist/cjs/commands/call-tool.js +362 -0
  11. package/dist/cjs/commands/call-tool.js.map +1 -0
  12. package/dist/cjs/commands/get-prompt.d.cts +26 -0
  13. package/dist/cjs/commands/get-prompt.d.ts +26 -0
  14. package/dist/cjs/commands/get-prompt.js +335 -0
  15. package/dist/cjs/commands/get-prompt.js.map +1 -0
  16. package/dist/cjs/commands/inspect.d.cts +35 -0
  17. package/dist/cjs/commands/inspect.d.ts +35 -0
  18. package/dist/cjs/commands/inspect.js +896 -0
  19. package/dist/cjs/commands/inspect.js.map +1 -0
  20. package/dist/cjs/commands/manifest/env-prompting.d.cts +21 -0
  21. package/dist/cjs/commands/manifest/env-prompting.d.ts +21 -0
  22. package/dist/cjs/commands/manifest/env-prompting.js +657 -0
  23. package/dist/cjs/commands/manifest/env-prompting.js.map +1 -0
  24. package/dist/cjs/commands/manifest/generate.d.cts +124 -0
  25. package/dist/cjs/commands/manifest/generate.d.ts +124 -0
  26. package/dist/cjs/commands/manifest/generate.js +2541 -0
  27. package/dist/cjs/commands/manifest/generate.js.map +1 -0
  28. package/dist/cjs/commands/manifest/index.d.cts +2 -0
  29. package/dist/cjs/commands/manifest/index.d.ts +2 -0
  30. package/dist/cjs/commands/manifest/index.js +229 -0
  31. package/dist/cjs/commands/manifest/index.js.map +1 -0
  32. package/dist/cjs/commands/manifest/metadata-reader.d.cts +71 -0
  33. package/dist/cjs/commands/manifest/metadata-reader.d.ts +71 -0
  34. package/dist/cjs/commands/manifest/metadata-reader.js +441 -0
  35. package/dist/cjs/commands/manifest/metadata-reader.js.map +1 -0
  36. package/dist/cjs/commands/manifest/validate.d.cts +1 -0
  37. package/dist/cjs/commands/manifest/validate.d.ts +1 -0
  38. package/dist/cjs/commands/manifest/validate.js +525 -0
  39. package/dist/cjs/commands/manifest/validate.js.map +1 -0
  40. package/dist/cjs/commands/read-resource.d.cts +24 -0
  41. package/dist/cjs/commands/read-resource.d.ts +24 -0
  42. package/dist/cjs/commands/read-resource.js +311 -0
  43. package/dist/cjs/commands/read-resource.js.map +1 -0
  44. package/dist/cjs/commands/search.d.cts +31 -0
  45. package/dist/cjs/commands/search.d.ts +31 -0
  46. package/dist/cjs/commands/search.js +464 -0
  47. package/dist/cjs/commands/search.js.map +1 -0
  48. package/dist/cjs/commands/up.d.cts +49 -0
  49. package/dist/cjs/commands/up.d.ts +49 -0
  50. package/dist/cjs/commands/up.js +235 -0
  51. package/dist/cjs/commands/up.js.map +1 -0
  52. package/dist/cjs/index.d.cts +7 -0
  53. package/dist/cjs/index.d.ts +7 -0
  54. package/dist/cjs/index.js +85 -0
  55. package/dist/cjs/index.js.map +1 -0
  56. package/dist/cjs/lib/find-config.d.cts +14 -0
  57. package/dist/cjs/lib/find-config.d.ts +14 -0
  58. package/dist/cjs/lib/find-config.js +93 -0
  59. package/dist/cjs/lib/find-config.js.map +1 -0
  60. package/dist/cjs/lib/json-schema.d.cts +18 -0
  61. package/dist/cjs/lib/json-schema.d.ts +18 -0
  62. package/dist/cjs/lib/json-schema.js +306 -0
  63. package/dist/cjs/lib/json-schema.js.map +1 -0
  64. package/dist/cjs/lib/resolve-server-config.d.cts +50 -0
  65. package/dist/cjs/lib/resolve-server-config.d.ts +50 -0
  66. package/dist/cjs/lib/resolve-server-config.js +214 -0
  67. package/dist/cjs/lib/resolve-server-config.js.map +1 -0
  68. package/dist/cjs/package.json +1 -0
  69. package/dist/cjs/types.d.cts +21 -0
  70. package/dist/cjs/types.d.ts +21 -0
  71. package/dist/cjs/types.js +32 -0
  72. package/dist/cjs/types.js.map +1 -0
  73. package/dist/esm/cli.d.ts +1 -0
  74. package/dist/esm/cli.js +129 -0
  75. package/dist/esm/cli.js.map +1 -0
  76. package/dist/esm/commands/call-tool.d.ts +26 -0
  77. package/dist/esm/commands/call-tool.js +151 -0
  78. package/dist/esm/commands/call-tool.js.map +1 -0
  79. package/dist/esm/commands/get-prompt.d.ts +26 -0
  80. package/dist/esm/commands/get-prompt.js +118 -0
  81. package/dist/esm/commands/get-prompt.js.map +1 -0
  82. package/dist/esm/commands/inspect.d.ts +35 -0
  83. package/dist/esm/commands/inspect.js +438 -0
  84. package/dist/esm/commands/inspect.js.map +1 -0
  85. package/dist/esm/commands/manifest/env-prompting.d.ts +21 -0
  86. package/dist/esm/commands/manifest/env-prompting.js +213 -0
  87. package/dist/esm/commands/manifest/env-prompting.js.map +1 -0
  88. package/dist/esm/commands/manifest/generate.d.ts +124 -0
  89. package/dist/esm/commands/manifest/generate.js +1087 -0
  90. package/dist/esm/commands/manifest/generate.js.map +1 -0
  91. package/dist/esm/commands/manifest/index.d.ts +2 -0
  92. package/dist/esm/commands/manifest/index.js +23 -0
  93. package/dist/esm/commands/manifest/index.js.map +1 -0
  94. package/dist/esm/commands/manifest/metadata-reader.d.ts +71 -0
  95. package/dist/esm/commands/manifest/metadata-reader.js +143 -0
  96. package/dist/esm/commands/manifest/metadata-reader.js.map +1 -0
  97. package/dist/esm/commands/manifest/validate.d.ts +1 -0
  98. package/dist/esm/commands/manifest/validate.js +167 -0
  99. package/dist/esm/commands/manifest/validate.js.map +1 -0
  100. package/dist/esm/commands/read-resource.d.ts +24 -0
  101. package/dist/esm/commands/read-resource.js +95 -0
  102. package/dist/esm/commands/read-resource.js.map +1 -0
  103. package/dist/esm/commands/search.d.ts +31 -0
  104. package/dist/esm/commands/search.js +145 -0
  105. package/dist/esm/commands/search.js.map +1 -0
  106. package/dist/esm/commands/up.d.ts +49 -0
  107. package/dist/esm/commands/up.js +74 -0
  108. package/dist/esm/commands/up.js.map +1 -0
  109. package/dist/esm/index.d.ts +7 -0
  110. package/dist/esm/index.js +11 -0
  111. package/dist/esm/index.js.map +1 -0
  112. package/dist/esm/lib/find-config.d.ts +14 -0
  113. package/dist/esm/lib/find-config.js +42 -0
  114. package/dist/esm/lib/find-config.js.map +1 -0
  115. package/dist/esm/lib/json-schema.d.ts +18 -0
  116. package/dist/esm/lib/json-schema.js +66 -0
  117. package/dist/esm/lib/json-schema.js.map +1 -0
  118. package/dist/esm/lib/resolve-server-config.d.ts +50 -0
  119. package/dist/esm/lib/resolve-server-config.js +154 -0
  120. package/dist/esm/lib/resolve-server-config.js.map +1 -0
  121. package/dist/esm/package.json +1 -0
  122. package/dist/esm/types.d.ts +21 -0
  123. package/dist/esm/types.js +11 -0
  124. package/dist/esm/types.js.map +1 -0
  125. package/package.json +99 -0
  126. package/schemas/server.schema.json +489 -0
@@ -0,0 +1,441 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "MetadataReader", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MetadataReader;
9
+ }
10
+ });
11
+ var _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
12
+ var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
13
+ var _jsonschemats = require("../../lib/json-schema.js");
14
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
15
+ try {
16
+ var info = gen[key](arg);
17
+ var value = info.value;
18
+ } catch (error) {
19
+ reject(error);
20
+ return;
21
+ }
22
+ if (info.done) {
23
+ resolve(value);
24
+ } else {
25
+ Promise.resolve(value).then(_next, _throw);
26
+ }
27
+ }
28
+ function _async_to_generator(fn) {
29
+ return function() {
30
+ var self = this, args = arguments;
31
+ return new Promise(function(resolve, reject) {
32
+ var gen = fn.apply(self, args);
33
+ function _next(value) {
34
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
+ }
36
+ function _throw(err) {
37
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
38
+ }
39
+ _next(undefined);
40
+ });
41
+ };
42
+ }
43
+ function _class_call_check(instance, Constructor) {
44
+ if (!(instance instanceof Constructor)) {
45
+ throw new TypeError("Cannot call a class as a function");
46
+ }
47
+ }
48
+ function _instanceof(left, right) {
49
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
50
+ return !!right[Symbol.hasInstance](left);
51
+ } else {
52
+ return left instanceof right;
53
+ }
54
+ }
55
+ function _getRequireWildcardCache(nodeInterop) {
56
+ if (typeof WeakMap !== "function") return null;
57
+ var cacheBabelInterop = new WeakMap();
58
+ var cacheNodeInterop = new WeakMap();
59
+ return (_getRequireWildcardCache = function(nodeInterop) {
60
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
61
+ })(nodeInterop);
62
+ }
63
+ function _interop_require_wildcard(obj, nodeInterop) {
64
+ if (!nodeInterop && obj && obj.__esModule) {
65
+ return obj;
66
+ }
67
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
68
+ return {
69
+ default: obj
70
+ };
71
+ }
72
+ var cache = _getRequireWildcardCache(nodeInterop);
73
+ if (cache && cache.has(obj)) {
74
+ return cache.get(obj);
75
+ }
76
+ var newObj = {
77
+ __proto__: null
78
+ };
79
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
80
+ for(var key in obj){
81
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
82
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
83
+ if (desc && (desc.get || desc.set)) {
84
+ Object.defineProperty(newObj, key, desc);
85
+ } else {
86
+ newObj[key] = obj[key];
87
+ }
88
+ }
89
+ }
90
+ newObj.default = obj;
91
+ if (cache) {
92
+ cache.set(obj, newObj);
93
+ }
94
+ return newObj;
95
+ }
96
+ function _ts_generator(thisArg, body) {
97
+ var f, y, t, _ = {
98
+ label: 0,
99
+ sent: function() {
100
+ if (t[0] & 1) throw t[1];
101
+ return t[1];
102
+ },
103
+ trys: [],
104
+ ops: []
105
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
106
+ return d(g, "next", {
107
+ value: verb(0)
108
+ }), d(g, "throw", {
109
+ value: verb(1)
110
+ }), d(g, "return", {
111
+ value: verb(2)
112
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
113
+ value: function() {
114
+ return this;
115
+ }
116
+ }), g;
117
+ function verb(n) {
118
+ return function(v) {
119
+ return step([
120
+ n,
121
+ v
122
+ ]);
123
+ };
124
+ }
125
+ function step(op) {
126
+ if (f) throw new TypeError("Generator is already executing.");
127
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
128
+ 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;
129
+ if (y = 0, t) op = [
130
+ op[0] & 2,
131
+ t.value
132
+ ];
133
+ switch(op[0]){
134
+ case 0:
135
+ case 1:
136
+ t = op;
137
+ break;
138
+ case 4:
139
+ _.label++;
140
+ return {
141
+ value: op[1],
142
+ done: false
143
+ };
144
+ case 5:
145
+ _.label++;
146
+ y = op[1];
147
+ op = [
148
+ 0
149
+ ];
150
+ continue;
151
+ case 7:
152
+ op = _.ops.pop();
153
+ _.trys.pop();
154
+ continue;
155
+ default:
156
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
157
+ _ = 0;
158
+ continue;
159
+ }
160
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
161
+ _.label = op[1];
162
+ break;
163
+ }
164
+ if (op[0] === 6 && _.label < t[1]) {
165
+ _.label = t[1];
166
+ t = op;
167
+ break;
168
+ }
169
+ if (t && _.label < t[2]) {
170
+ _.label = t[2];
171
+ _.ops.push(op);
172
+ break;
173
+ }
174
+ if (t[2]) _.ops.pop();
175
+ _.trys.pop();
176
+ continue;
177
+ }
178
+ op = body.call(thisArg, _);
179
+ } catch (e) {
180
+ op = [
181
+ 6,
182
+ e
183
+ ];
184
+ y = 0;
185
+ } finally{
186
+ f = t = 0;
187
+ }
188
+ if (op[0] & 5) throw op[1];
189
+ return {
190
+ value: op[0] ? op[1] : void 0,
191
+ done: true
192
+ };
193
+ }
194
+ }
195
+ var MetadataReader = /*#__PURE__*/ function() {
196
+ "use strict";
197
+ function MetadataReader() {
198
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
199
+ _class_call_check(this, MetadataReader);
200
+ this.options = options;
201
+ }
202
+ var _proto = MetadataReader.prototype;
203
+ /**
204
+ * Read server.json metadata from local directory or node_modules
205
+ * Validates against MCP schema before returning
206
+ *
207
+ * @param serverName - Can be:
208
+ * - Full package name: "@org/package-name"
209
+ * - Short name: "drive" (will search node_modules for packages with server.json)
210
+ */ _proto.readServerMetadata = function readServerMetadata(serverName) {
211
+ return _async_to_generator(function() {
212
+ var _this_options_moduleResolutionPaths, content, sourcePath, resolutionPaths, packagePath, discovered, match, metadata, error, message;
213
+ return _ts_generator(this, function(_state) {
214
+ switch(_state.label){
215
+ case 0:
216
+ // If it's a scoped package name, try to resolve directly
217
+ resolutionPaths = (_this_options_moduleResolutionPaths = this.options.moduleResolutionPaths) !== null && _this_options_moduleResolutionPaths !== void 0 ? _this_options_moduleResolutionPaths : [
218
+ process.cwd()
219
+ ];
220
+ if (!serverName.startsWith('@')) return [
221
+ 3,
222
+ 1
223
+ ];
224
+ try {
225
+ packagePath = require.resolve("".concat(serverName, "/server.json"), {
226
+ paths: resolutionPaths
227
+ });
228
+ content = _fs.readFileSync(packagePath, 'utf8');
229
+ sourcePath = packagePath;
230
+ } catch (unused) {
231
+ throw new Error("Server '".concat(serverName, "' not found in node_modules"));
232
+ }
233
+ return [
234
+ 3,
235
+ 3
236
+ ];
237
+ case 1:
238
+ return [
239
+ 4,
240
+ this.discoverInstalledServers()
241
+ ];
242
+ case 2:
243
+ discovered = _state.sent();
244
+ match = discovered.find(function(s) {
245
+ return s.shortName === serverName;
246
+ });
247
+ if (match) {
248
+ content = _fs.readFileSync(match.serverJsonPath, 'utf8');
249
+ sourcePath = match.serverJsonPath;
250
+ } else {
251
+ throw new Error("Server '".concat(serverName, "' not found. Run 'mcpz config list --available' to see installed servers."));
252
+ }
253
+ _state.label = 3;
254
+ case 3:
255
+ metadata = JSON.parse(content);
256
+ if (!!this.options.skipSchemaValidation) return [
257
+ 3,
258
+ 7
259
+ ];
260
+ _state.label = 4;
261
+ case 4:
262
+ _state.trys.push([
263
+ 4,
264
+ 6,
265
+ ,
266
+ 7
267
+ ]);
268
+ return [
269
+ 4,
270
+ (0, _jsonschemats.validateSchema)(metadata, serverName)
271
+ ];
272
+ case 5:
273
+ _state.sent();
274
+ return [
275
+ 3,
276
+ 7
277
+ ];
278
+ case 6:
279
+ error = _state.sent();
280
+ message = _instanceof(error, Error) ? error.message : String(error);
281
+ throw new Error("".concat(message, "\n\nSource: ").concat(sourcePath));
282
+ case 7:
283
+ return [
284
+ 2,
285
+ metadata
286
+ ];
287
+ }
288
+ });
289
+ }).call(this);
290
+ };
291
+ /**
292
+ * Get package config for specific transport type
293
+ */ _proto.getPackageForTransport = function getPackageForTransport(metadata, transport) {
294
+ return metadata.packages.find(function(p) {
295
+ return p.transport.type === transport;
296
+ });
297
+ };
298
+ /**
299
+ * Discover installed servers from:
300
+ * 1. ../servers/ directory (for monorepo development)
301
+ * 2. node_modules (any package with server.json)
302
+ */ _proto.discoverInstalledServers = function discoverInstalledServers() {
303
+ return _async_to_generator(function() {
304
+ var _ref, _this_options_monorepoPath, _this_options_nodeModulesPath, _this_options_moduleResolutionPaths, servers, seen, basePath, monorepoPath, entries, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, entry, serverJsonPath, shortName, nodeModulesPath, entries1, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, entry1, scopePath, scopedPackages, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, pkg, serverJsonPath1, shortName1, serverJsonPath2, shortName2;
305
+ return _ts_generator(this, function(_state) {
306
+ servers = [];
307
+ seen = new Set();
308
+ basePath = (_ref = (_this_options_moduleResolutionPaths = this.options.moduleResolutionPaths) === null || _this_options_moduleResolutionPaths === void 0 ? void 0 : _this_options_moduleResolutionPaths[0]) !== null && _ref !== void 0 ? _ref : process.cwd();
309
+ // Check ../servers/ for monorepo development (packages named server-*)
310
+ monorepoPath = (_this_options_monorepoPath = this.options.monorepoPath) !== null && _this_options_monorepoPath !== void 0 ? _this_options_monorepoPath : _path.join(basePath, '..', 'servers');
311
+ if (_fs.existsSync(monorepoPath)) {
312
+ try {
313
+ entries = _fs.readdirSync(monorepoPath);
314
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
315
+ try {
316
+ for(_iterator = entries[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
317
+ entry = _step.value;
318
+ serverJsonPath = _path.join(monorepoPath, entry, 'server.json');
319
+ if (_fs.existsSync(serverJsonPath)) {
320
+ // Extract short name (e.g., "gmail" from "mcp-gmail")
321
+ shortName = entry.startsWith('server-') ? entry.replace('server-', '') : entry;
322
+ if (!seen.has(shortName)) {
323
+ seen.add(shortName);
324
+ servers.push({
325
+ shortName: shortName,
326
+ packageName: entry,
327
+ serverJsonPath: serverJsonPath
328
+ });
329
+ }
330
+ }
331
+ }
332
+ } catch (err) {
333
+ _didIteratorError = true;
334
+ _iteratorError = err;
335
+ } finally{
336
+ try {
337
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
338
+ _iterator.return();
339
+ }
340
+ } finally{
341
+ if (_didIteratorError) {
342
+ throw _iteratorError;
343
+ }
344
+ }
345
+ }
346
+ } catch (unused) {
347
+ // Ignore errors reading monorepo path
348
+ }
349
+ }
350
+ // Check node_modules for any package with server.json
351
+ nodeModulesPath = (_this_options_nodeModulesPath = this.options.nodeModulesPath) !== null && _this_options_nodeModulesPath !== void 0 ? _this_options_nodeModulesPath : _path.join(basePath, 'node_modules');
352
+ if (_fs.existsSync(nodeModulesPath)) {
353
+ try {
354
+ entries1 = _fs.readdirSync(nodeModulesPath);
355
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
356
+ try {
357
+ for(_iterator1 = entries1[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
358
+ entry1 = _step1.value;
359
+ if (entry1.startsWith('@')) {
360
+ // Scoped package - check all packages in scope
361
+ scopePath = _path.join(nodeModulesPath, entry1);
362
+ if (_fs.statSync(scopePath).isDirectory()) {
363
+ scopedPackages = _fs.readdirSync(scopePath);
364
+ _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
365
+ try {
366
+ for(_iterator2 = scopedPackages[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
367
+ pkg = _step2.value;
368
+ serverJsonPath1 = _path.join(scopePath, pkg, 'server.json');
369
+ if (_fs.existsSync(serverJsonPath1)) {
370
+ shortName1 = pkg.startsWith('server-') ? pkg.replace('server-', '') : pkg;
371
+ if (!seen.has(shortName1)) {
372
+ seen.add(shortName1);
373
+ servers.push({
374
+ shortName: shortName1,
375
+ packageName: "".concat(entry1, "/").concat(pkg),
376
+ serverJsonPath: serverJsonPath1
377
+ });
378
+ }
379
+ }
380
+ }
381
+ } catch (err) {
382
+ _didIteratorError2 = true;
383
+ _iteratorError2 = err;
384
+ } finally{
385
+ try {
386
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
387
+ _iterator2.return();
388
+ }
389
+ } finally{
390
+ if (_didIteratorError2) {
391
+ throw _iteratorError2;
392
+ }
393
+ }
394
+ }
395
+ }
396
+ } else {
397
+ // Unscoped package - check for server.json
398
+ serverJsonPath2 = _path.join(nodeModulesPath, entry1, 'server.json');
399
+ if (_fs.existsSync(serverJsonPath2)) {
400
+ shortName2 = entry1.startsWith('server-') ? entry1.replace('server-', '') : entry1;
401
+ if (!seen.has(shortName2)) {
402
+ seen.add(shortName2);
403
+ servers.push({
404
+ shortName: shortName2,
405
+ packageName: entry1,
406
+ serverJsonPath: serverJsonPath2
407
+ });
408
+ }
409
+ }
410
+ }
411
+ }
412
+ } catch (err) {
413
+ _didIteratorError1 = true;
414
+ _iteratorError1 = err;
415
+ } finally{
416
+ try {
417
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
418
+ _iterator1.return();
419
+ }
420
+ } finally{
421
+ if (_didIteratorError1) {
422
+ throw _iteratorError1;
423
+ }
424
+ }
425
+ }
426
+ } catch (unused) {
427
+ // Ignore errors reading node_modules
428
+ }
429
+ }
430
+ return [
431
+ 2,
432
+ servers.sort(function(a, b) {
433
+ return a.shortName.localeCompare(b.shortName);
434
+ })
435
+ ];
436
+ });
437
+ }).call(this);
438
+ };
439
+ return MetadataReader;
440
+ }();
441
+ /* 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/cli/src/commands/manifest/metadata-reader.ts"],"sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { validateSchema } from '../../lib/json-schema.ts';\n\nexport interface ServerMetadata {\n name: string;\n description: string;\n version: string;\n title: string;\n packages: PackageConfig[];\n}\n\nexport interface PackageConfig {\n registryType: string;\n identifier: string;\n transport: {\n type: 'stdio' | 'streamable-http';\n url?: string;\n };\n runtimeHint?: string;\n runtimeArguments?: CliArgMetadata[];\n environmentVariables: EnvVarMetadata[];\n packageArguments: CliArgMetadata[];\n}\n\nexport interface EnvVarMetadata {\n name: string;\n value?: string;\n default?: string; // Default value (MCP schema standard field)\n description: string;\n placeholder?: string;\n choices?: string[];\n isRequired?: boolean;\n isSecret: boolean;\n isMandatoryForMatrix?: boolean; // Include in test matrix? (default: true for vars with choices)\n dependsOn?: Record<string, string[]>; // Conditional: only prompt when dependency has specific value(s)\n}\n\nexport interface CliArgMetadata {\n type: 'named';\n name: string;\n value?: string;\n description?: string;\n choices?: string[];\n}\n\nexport interface MetadataReaderOptions {\n monorepoPath?: string;\n nodeModulesPath?: string;\n moduleResolutionPaths?: string[];\n skipSchemaValidation?: boolean;\n}\n\nexport class MetadataReader {\n private readonly options: MetadataReaderOptions;\n\n constructor(options: MetadataReaderOptions = {}) {\n this.options = options;\n }\n\n /**\n * Read server.json metadata from local directory or node_modules\n * Validates against MCP schema before returning\n *\n * @param serverName - Can be:\n * - Full package name: \"@org/package-name\"\n * - Short name: \"drive\" (will search node_modules for packages with server.json)\n */\n async readServerMetadata(serverName: string): Promise<ServerMetadata> {\n let content: string;\n let sourcePath: string;\n\n // If it's a scoped package name, try to resolve directly\n const resolutionPaths = this.options.moduleResolutionPaths ?? [process.cwd()];\n\n if (serverName.startsWith('@')) {\n try {\n const packagePath = require.resolve(`${serverName}/server.json`, {\n paths: resolutionPaths,\n });\n content = fs.readFileSync(packagePath, 'utf8');\n sourcePath = packagePath;\n } catch {\n throw new Error(`Server '${serverName}' not found in node_modules`);\n }\n } else {\n // Short name - search for matching package\n const discovered = await this.discoverInstalledServers();\n const match = discovered.find((s) => s.shortName === serverName);\n\n if (match) {\n content = fs.readFileSync(match.serverJsonPath, 'utf8');\n sourcePath = match.serverJsonPath;\n } else {\n throw new Error(`Server '${serverName}' not found. Run 'mcpz config list --available' to see installed servers.`);\n }\n }\n\n const metadata = JSON.parse(content);\n\n // Validate against MCP schema\n if (!this.options.skipSchemaValidation) {\n try {\n await validateSchema(metadata, serverName);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`${message}\\n\\nSource: ${sourcePath}`);\n }\n }\n\n return metadata;\n }\n\n /**\n * Get package config for specific transport type\n */\n getPackageForTransport(metadata: ServerMetadata, transport: 'stdio' | 'streamable-http'): PackageConfig | undefined {\n return metadata.packages.find((p) => p.transport.type === transport);\n }\n\n /**\n * Discover installed servers from:\n * 1. ../servers/ directory (for monorepo development)\n * 2. node_modules (any package with server.json)\n */\n async discoverInstalledServers(): Promise<Array<{ shortName: string; packageName: string; serverJsonPath: string }>> {\n const servers: Array<{ shortName: string; packageName: string; serverJsonPath: string }> = [];\n const seen = new Set<string>();\n\n const basePath = this.options.moduleResolutionPaths?.[0] ?? process.cwd();\n\n // Check ../servers/ for monorepo development (packages named server-*)\n const monorepoPath = this.options.monorepoPath ?? path.join(basePath, '..', 'servers');\n if (fs.existsSync(monorepoPath)) {\n try {\n const entries = fs.readdirSync(monorepoPath);\n for (const entry of entries) {\n const serverJsonPath = path.join(monorepoPath, entry, 'server.json');\n if (fs.existsSync(serverJsonPath)) {\n // Extract short name (e.g., \"gmail\" from \"mcp-gmail\")\n const shortName = entry.startsWith('server-') ? entry.replace('server-', '') : entry;\n if (!seen.has(shortName)) {\n seen.add(shortName);\n servers.push({\n shortName,\n packageName: entry, // Use directory name as package name for monorepo\n serverJsonPath,\n });\n }\n }\n }\n } catch {\n // Ignore errors reading monorepo path\n }\n }\n\n // Check node_modules for any package with server.json\n const nodeModulesPath = this.options.nodeModulesPath ?? path.join(basePath, 'node_modules');\n if (fs.existsSync(nodeModulesPath)) {\n try {\n const entries = fs.readdirSync(nodeModulesPath);\n\n for (const entry of entries) {\n if (entry.startsWith('@')) {\n // Scoped package - check all packages in scope\n const scopePath = path.join(nodeModulesPath, entry);\n if (fs.statSync(scopePath).isDirectory()) {\n const scopedPackages = fs.readdirSync(scopePath);\n for (const pkg of scopedPackages) {\n const serverJsonPath = path.join(scopePath, pkg, 'server.json');\n if (fs.existsSync(serverJsonPath)) {\n const shortName = pkg.startsWith('server-') ? pkg.replace('server-', '') : pkg;\n if (!seen.has(shortName)) {\n seen.add(shortName);\n servers.push({\n shortName,\n packageName: `${entry}/${pkg}`,\n serverJsonPath,\n });\n }\n }\n }\n }\n } else {\n // Unscoped package - check for server.json\n const serverJsonPath = path.join(nodeModulesPath, entry, 'server.json');\n if (fs.existsSync(serverJsonPath)) {\n const shortName = entry.startsWith('server-') ? entry.replace('server-', '') : entry;\n if (!seen.has(shortName)) {\n seen.add(shortName);\n servers.push({\n shortName,\n packageName: entry,\n serverJsonPath,\n });\n }\n }\n }\n }\n } catch {\n // Ignore errors reading node_modules\n }\n }\n\n return servers.sort((a, b) => a.shortName.localeCompare(b.shortName));\n }\n}\n"],"names":["MetadataReader","options","readServerMetadata","serverName","content","sourcePath","resolutionPaths","packagePath","discovered","match","metadata","error","message","moduleResolutionPaths","process","cwd","startsWith","require","resolve","paths","fs","readFileSync","Error","discoverInstalledServers","find","s","shortName","serverJsonPath","JSON","parse","skipSchemaValidation","validateSchema","String","getPackageForTransport","transport","packages","p","type","servers","seen","basePath","monorepoPath","entries","entry","nodeModulesPath","scopePath","scopedPackages","pkg","Set","path","join","existsSync","readdirSync","replace","has","add","push","packageName","statSync","isDirectory","sort","a","b","localeCompare"],"mappings":";;;;+BAqDaA;;;eAAAA;;;0DArDO;4DACE;4BACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDxB,IAAA,AAAMA,+BAAN;;aAAMA;YAGCC,UAAAA,iEAAiC,CAAC;gCAHnCD;QAIT,IAAI,CAACC,OAAO,GAAGA;;iBAJND;IAOX;;;;;;;GAOC,GACD,OAAME,kBA2CL,GA3CD,SAAMA,mBAAmBC,UAAkB;;gBAKjB,qCAJpBC,S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AAiBD,QAAO;oCACzD,IAAIvB,IAAG+B,UAAU,CAACxB,kBAAiB;wCAC3BD,aAAYiB,OAAM3B,UAAU,CAAC,aAAa2B,OAAMU,OAAO,CAAC,WAAW,MAAMV;wCAC/E,IAAI,CAACJ,KAAKe,GAAG,CAAC5B,aAAY;4CACxBa,KAAKgB,GAAG,CAAC7B;4CACTY,QAAQkB,IAAI,CAAC;gDACX9B,WAAAA;gDACA+B,aAAad;gDACbhB,gBAAAA;4CACF;wCACF;oCACF;gCACF;4BACF;;4BApCK;4BAAA;;;qCAAA,8BAAA;oCAAA;;;oCAAA;0CAAA;;;;oBAqCP,EAAE,eAAM;oBACN,qCAAqC;oBACvC;gBACF;gBAEA;;oBAAOW,QAAQsB,IAAI,CAAC,SAACC,GAAGC;+BAAMD,EAAEnC,SAAS,CAACqC,aAAa,CAACD,EAAEpC,SAAS;;;;QACrE;;WAxJW1B"}
@@ -0,0 +1 @@
1
+ export declare function validateCommand(filePath: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function validateCommand(filePath: string): Promise<void>;