@mcp-z/client 2.2.4 → 2.3.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 (107) hide show
  1. package/README.md +12 -1
  2. package/dist/cjs/auth/capability-discovery.d.cts +3 -1
  3. package/dist/cjs/auth/capability-discovery.d.ts +3 -1
  4. package/dist/cjs/auth/capability-discovery.js +46 -32
  5. package/dist/cjs/auth/capability-discovery.js.map +1 -1
  6. package/dist/cjs/auth/discovery-fetch.d.cts +2 -0
  7. package/dist/cjs/auth/discovery-fetch.d.ts +2 -0
  8. package/dist/cjs/auth/discovery-fetch.js +85 -31
  9. package/dist/cjs/auth/discovery-fetch.js.map +1 -1
  10. package/dist/cjs/auth/interactive-oauth-flow.d.cts +1 -1
  11. package/dist/cjs/auth/interactive-oauth-flow.d.ts +1 -1
  12. package/dist/cjs/auth/interactive-oauth-flow.js +13 -6
  13. package/dist/cjs/auth/interactive-oauth-flow.js.map +1 -1
  14. package/dist/cjs/auth/oauth-callback-listener.d.cts +1 -1
  15. package/dist/cjs/auth/oauth-callback-listener.d.ts +1 -1
  16. package/dist/cjs/auth/oauth-callback-listener.js +38 -2
  17. package/dist/cjs/auth/oauth-callback-listener.js.map +1 -1
  18. package/dist/cjs/auth/rfc9728-discovery.d.cts +7 -2
  19. package/dist/cjs/auth/rfc9728-discovery.d.ts +7 -2
  20. package/dist/cjs/auth/rfc9728-discovery.js +120 -88
  21. package/dist/cjs/auth/rfc9728-discovery.js.map +1 -1
  22. package/dist/cjs/auth/types.d.cts +4 -0
  23. package/dist/cjs/auth/types.d.ts +4 -0
  24. package/dist/cjs/auth/types.js.map +1 -1
  25. package/dist/cjs/connection/connect-client.d.cts +9 -1
  26. package/dist/cjs/connection/connect-client.d.ts +9 -1
  27. package/dist/cjs/connection/connect-client.js +282 -75
  28. package/dist/cjs/connection/connect-client.js.map +1 -1
  29. package/dist/cjs/connection/existing-process-transport.d.cts +18 -18
  30. package/dist/cjs/connection/existing-process-transport.d.ts +18 -18
  31. package/dist/cjs/connection/existing-process-transport.js +187 -82
  32. package/dist/cjs/connection/existing-process-transport.js.map +1 -1
  33. package/dist/cjs/connection/wait-for-http-ready.d.cts +1 -1
  34. package/dist/cjs/connection/wait-for-http-ready.d.ts +1 -1
  35. package/dist/cjs/connection/wait-for-http-ready.js +30 -5
  36. package/dist/cjs/connection/wait-for-http-ready.js.map +1 -1
  37. package/dist/cjs/dcr/dcr-authenticator.d.cts +1 -1
  38. package/dist/cjs/dcr/dcr-authenticator.d.ts +1 -1
  39. package/dist/cjs/dcr/dcr-authenticator.js +29 -18
  40. package/dist/cjs/dcr/dcr-authenticator.js.map +1 -1
  41. package/dist/cjs/dcr/dynamic-client-registrar.js +2 -1
  42. package/dist/cjs/dcr/dynamic-client-registrar.js.map +1 -1
  43. package/dist/cjs/index.d.cts +1 -1
  44. package/dist/cjs/index.d.ts +1 -1
  45. package/dist/cjs/index.js.map +1 -1
  46. package/dist/cjs/spawn/owned-process-tree.d.cts +12 -0
  47. package/dist/cjs/spawn/owned-process-tree.d.ts +12 -0
  48. package/dist/cjs/spawn/owned-process-tree.js +93 -0
  49. package/dist/cjs/spawn/owned-process-tree.js.map +1 -0
  50. package/dist/cjs/spawn/spawn-server.d.cts +8 -32
  51. package/dist/cjs/spawn/spawn-server.d.ts +8 -32
  52. package/dist/cjs/spawn/spawn-server.js +398 -212
  53. package/dist/cjs/spawn/spawn-server.js.map +1 -1
  54. package/dist/cjs/spawn/spawn-servers.d.cts +18 -8
  55. package/dist/cjs/spawn/spawn-servers.d.ts +18 -8
  56. package/dist/cjs/spawn/spawn-servers.js +342 -113
  57. package/dist/cjs/spawn/spawn-servers.js.map +1 -1
  58. package/dist/cjs/types.d.cts +1 -1
  59. package/dist/cjs/types.d.ts +1 -1
  60. package/dist/cjs/types.js.map +1 -1
  61. package/dist/esm/auth/capability-discovery.d.ts +3 -1
  62. package/dist/esm/auth/capability-discovery.js +21 -11
  63. package/dist/esm/auth/capability-discovery.js.map +1 -1
  64. package/dist/esm/auth/discovery-fetch.d.ts +2 -0
  65. package/dist/esm/auth/discovery-fetch.js +64 -23
  66. package/dist/esm/auth/discovery-fetch.js.map +1 -1
  67. package/dist/esm/auth/interactive-oauth-flow.d.ts +1 -1
  68. package/dist/esm/auth/interactive-oauth-flow.js +13 -6
  69. package/dist/esm/auth/interactive-oauth-flow.js.map +1 -1
  70. package/dist/esm/auth/oauth-callback-listener.d.ts +1 -1
  71. package/dist/esm/auth/oauth-callback-listener.js +32 -2
  72. package/dist/esm/auth/oauth-callback-listener.js.map +1 -1
  73. package/dist/esm/auth/rfc9728-discovery.d.ts +7 -2
  74. package/dist/esm/auth/rfc9728-discovery.js +40 -16
  75. package/dist/esm/auth/rfc9728-discovery.js.map +1 -1
  76. package/dist/esm/auth/types.d.ts +4 -0
  77. package/dist/esm/auth/types.js.map +1 -1
  78. package/dist/esm/connection/connect-client.d.ts +9 -1
  79. package/dist/esm/connection/connect-client.js +97 -35
  80. package/dist/esm/connection/connect-client.js.map +1 -1
  81. package/dist/esm/connection/existing-process-transport.d.ts +18 -18
  82. package/dist/esm/connection/existing-process-transport.js +132 -70
  83. package/dist/esm/connection/existing-process-transport.js.map +1 -1
  84. package/dist/esm/connection/wait-for-http-ready.d.ts +1 -1
  85. package/dist/esm/connection/wait-for-http-ready.js +19 -4
  86. package/dist/esm/connection/wait-for-http-ready.js.map +1 -1
  87. package/dist/esm/dcr/dcr-authenticator.d.ts +1 -1
  88. package/dist/esm/dcr/dcr-authenticator.js +26 -15
  89. package/dist/esm/dcr/dcr-authenticator.js.map +1 -1
  90. package/dist/esm/dcr/dynamic-client-registrar.js +2 -1
  91. package/dist/esm/dcr/dynamic-client-registrar.js.map +1 -1
  92. package/dist/esm/index.d.ts +1 -1
  93. package/dist/esm/index.js.map +1 -1
  94. package/dist/esm/spawn/owned-process-tree.d.ts +12 -0
  95. package/dist/esm/spawn/owned-process-tree.js +39 -0
  96. package/dist/esm/spawn/owned-process-tree.js.map +1 -0
  97. package/dist/esm/spawn/spawn-server.d.ts +8 -32
  98. package/dist/esm/spawn/spawn-server.js +224 -130
  99. package/dist/esm/spawn/spawn-server.js.map +1 -1
  100. package/dist/esm/spawn/spawn-servers.d.ts +18 -8
  101. package/dist/esm/spawn/spawn-servers.js +180 -55
  102. package/dist/esm/spawn/spawn-servers.js.map +1 -1
  103. package/dist/esm/types.d.ts +1 -1
  104. package/dist/esm/types.js.map +1 -1
  105. package/package.json +8 -5
  106. package/schemas/servers.d.ts +24 -0
  107. package/schemas/servers.schema.json +31 -0
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "OwnedProcessTree", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return OwnedProcessTree;
9
+ }
10
+ });
11
+ var _process = /*#__PURE__*/ _interop_require_wildcard(require("process"));
12
+ function _class_call_check(instance, Constructor) {
13
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
14
+ }
15
+ function _instanceof(left, right) {
16
+ "@swc/helpers - instanceof";
17
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
18
+ return !!right[Symbol.hasInstance](left);
19
+ } else return left instanceof right;
20
+ }
21
+ function _getRequireWildcardCache(nodeInterop) {
22
+ if (typeof WeakMap !== "function") return null;
23
+ var cacheBabelInterop = new WeakMap();
24
+ var cacheNodeInterop = new WeakMap();
25
+ return (_getRequireWildcardCache = function(nodeInterop) {
26
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
27
+ })(nodeInterop);
28
+ }
29
+ function _interop_require_wildcard(obj, nodeInterop) {
30
+ if (!nodeInterop && obj && obj.__esModule) return obj;
31
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") return {
32
+ default: obj
33
+ };
34
+ var cache = _getRequireWildcardCache(nodeInterop);
35
+ if (cache && cache.has(obj)) return cache.get(obj);
36
+ var newObj = {
37
+ __proto__: null
38
+ };
39
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
40
+ for(var key in obj){
41
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
42
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
43
+ if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
44
+ else newObj[key] = obj[key];
45
+ }
46
+ }
47
+ newObj.default = obj;
48
+ if (cache) cache.set(obj, newObj);
49
+ return newObj;
50
+ }
51
+ var OwnedProcessTree = /*#__PURE__*/ function() {
52
+ "use strict";
53
+ function OwnedProcessTree(rootPid) {
54
+ _class_call_check(this, OwnedProcessTree);
55
+ if (_process.platform === 'win32') throw new Error('Owned process groups are not available on Windows');
56
+ this._rootPid = rootPid;
57
+ }
58
+ var _proto = OwnedProcessTree.prototype;
59
+ _proto.isEmpty = function isEmpty() {
60
+ try {
61
+ _process.kill(-this._rootPid, 0);
62
+ return false;
63
+ } catch (error) {
64
+ if (isErrno(error, 'ESRCH')) return true;
65
+ if (isErrno(error, 'EPERM')) return false;
66
+ throw toError(error);
67
+ }
68
+ };
69
+ _proto.terminate = function terminate() {
70
+ try {
71
+ _process.kill(-this._rootPid, 'SIGKILL');
72
+ return {
73
+ killed: true
74
+ };
75
+ } catch (error) {
76
+ if (isErrno(error, 'ESRCH')) return {
77
+ killed: false
78
+ };
79
+ return {
80
+ killed: false,
81
+ error: toError(error)
82
+ };
83
+ }
84
+ };
85
+ return OwnedProcessTree;
86
+ }();
87
+ function isErrno(error, code) {
88
+ return _instanceof(error, Error) && 'code' in error && error.code === code;
89
+ }
90
+ function toError(error) {
91
+ return _instanceof(error, Error) ? error : new Error(String(error));
92
+ }
93
+ /* 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/OpenSource/ai/mcp-z/client/src/spawn/owned-process-tree.ts"],"sourcesContent":["import * as process from 'process';\n\ninterface TerminationResult {\n killed: boolean;\n error?: Error;\n}\n\n/** Tracks the detached process group used for owned processes on POSIX. */\nexport class OwnedProcessTree {\n private readonly _rootPid: number;\n\n constructor(rootPid: number) {\n if (process.platform === 'win32') throw new Error('Owned process groups are not available on Windows');\n this._rootPid = rootPid;\n }\n\n isEmpty(): boolean {\n try {\n process.kill(-this._rootPid, 0);\n return false;\n } catch (error) {\n if (isErrno(error, 'ESRCH')) return true;\n if (isErrno(error, 'EPERM')) return false;\n throw toError(error);\n }\n }\n\n terminate(): TerminationResult {\n try {\n process.kill(-this._rootPid, 'SIGKILL');\n return { killed: true };\n } catch (error) {\n if (isErrno(error, 'ESRCH')) return { killed: false };\n return { killed: false, error: toError(error) };\n }\n }\n}\n\nfunction isErrno(error: unknown, code: string): boolean {\n return error instanceof Error && 'code' in error && error.code === code;\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n"],"names":["OwnedProcessTree","rootPid","process","platform","Error","_rootPid","isEmpty","kill","error","isErrno","toError","terminate","killed","code","String"],"mappings":";;;;+BAQaA;;;eAAAA;;;+DARY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQlB,IAAA,AAAMA,iCAAN;;aAAMA,iBAGCC,OAAe;gCAHhBD;QAIT,IAAIE,SAAQC,QAAQ,KAAK,SAAS,MAAM,IAAIC,MAAM;QAClD,IAAI,CAACC,QAAQ,GAAGJ;;iBALPD;IAQXM,OAAAA,OASC,GATDA,SAAAA;QACE,IAAI;YACFJ,SAAQK,IAAI,CAAC,CAAC,IAAI,CAACF,QAAQ,EAAE;YAC7B,OAAO;QACT,EAAE,OAAOG,OAAO;YACd,IAAIC,QAAQD,OAAO,UAAU,OAAO;YACpC,IAAIC,QAAQD,OAAO,UAAU,OAAO;YACpC,MAAME,QAAQF;QAChB;IACF;IAEAG,OAAAA,SAQC,GARDA,SAAAA;QACE,IAAI;YACFT,SAAQK,IAAI,CAAC,CAAC,IAAI,CAACF,QAAQ,EAAE;YAC7B,OAAO;gBAAEO,QAAQ;YAAK;QACxB,EAAE,OAAOJ,OAAO;YACd,IAAIC,QAAQD,OAAO,UAAU,OAAO;gBAAEI,QAAQ;YAAM;YACpD,OAAO;gBAAEA,QAAQ;gBAAOJ,OAAOE,QAAQF;YAAO;QAChD;IACF;WA3BWR;;AA8Bb,SAASS,QAAQD,KAAc,EAAEK,IAAY;IAC3C,OAAOL,AAAK,YAALA,OAAiBJ,UAAS,UAAUI,SAASA,MAAMK,IAAI,KAAKA;AACrE;AAEA,SAASH,QAAQF,KAAc;IAC7B,OAAOA,AAAK,YAALA,OAAiBJ,SAAQI,QAAQ,IAAIJ,MAAMU,OAAON;AAC3D"}
@@ -2,7 +2,8 @@
2
2
  * Low-level single server spawning utilities.
3
3
  * Provides core process spawning with path resolution, environment management, and lifecycle control.
4
4
  */
5
- import { type ChildProcess, type StdioOptions } from 'child_process';
5
+ import type { ChildProcess, StdioOptions } from 'child_process';
6
+ import type { StopCommandConfig } from '../types.js';
6
7
  /**
7
8
  * Options for spawning a single server process.
8
9
  * @internal
@@ -18,10 +19,12 @@ export interface SpawnProcessOptions {
18
19
  cwd?: string;
19
20
  /** Additional environment variables (merged with process.env) */
20
21
  env?: Record<string, string>;
22
+ /** Whether to add process.env to env; registry callers provide a pre-merged environment */
23
+ inheritEnv?: boolean;
21
24
  /** Standard I/O configuration */
22
25
  stdio?: StdioOptions;
23
- /** Use shell for command execution (default: false, true on Windows) */
24
- shell?: boolean;
26
+ /** Application-specific shutdown command for an owned HTTP server */
27
+ stop?: StopCommandConfig;
25
28
  }
26
29
  /**
27
30
  * Handle to a spawned server process.
@@ -29,10 +32,6 @@ export interface SpawnProcessOptions {
29
32
  * @hidden
30
33
  */
31
34
  export interface ServerProcess {
32
- /**
33
- * The resolved server configuration that was actually used.
34
- * Useful for debugging and understanding what was spawned.
35
- */
36
35
  config: {
37
36
  name: string;
38
37
  command: string;
@@ -40,20 +39,9 @@ export interface ServerProcess {
40
39
  cwd: string;
41
40
  env: Record<string, string>;
42
41
  stdio: StdioOptions;
43
- shell: boolean;
42
+ shell: false;
44
43
  };
45
- /**
46
- * The spawned child process.
47
- */
48
44
  process: ChildProcess;
49
- /**
50
- * Close the server gracefully, terminating its process tree on Windows.
51
- * Sends the specified signal (default: SIGINT), then force-kills after timeout.
52
- *
53
- * @param signal - Signal to send (default: SIGINT)
54
- * @param opts - Options including timeout
55
- * @returns Promise resolving to whether the process timed out and was force-killed
56
- */
57
45
  close: (signal?: NodeJS.Signals, opts?: {
58
46
  timeoutMs?: number;
59
47
  }) => Promise<{
@@ -66,18 +54,6 @@ export interface ServerProcess {
66
54
  *
67
55
  * @internal
68
56
  * @param opts - Server spawn options
69
- * @returns ServerProcess handle with resolved config, process, and stop function
70
- *
71
- * @example
72
- * const handle = spawnProcess({
73
- * name: 'echo',
74
- * command: 'node',
75
- * args: ['./bin/server.js', '--port', '3000'],
76
- * cwd: '/home/user/project/test/lib/servers/echo',
77
- * env: { LOG_LEVEL: 'error' }
78
- * });
79
- *
80
- * // Later...
81
- * await handle.close();
57
+ * @returns ServerProcess handle with resolved config and lifecycle control
82
58
  */
83
59
  export declare function spawnProcess(opts: SpawnProcessOptions): ServerProcess;
@@ -2,7 +2,8 @@
2
2
  * Low-level single server spawning utilities.
3
3
  * Provides core process spawning with path resolution, environment management, and lifecycle control.
4
4
  */
5
- import { type ChildProcess, type StdioOptions } from 'child_process';
5
+ import type { ChildProcess, StdioOptions } from 'child_process';
6
+ import type { StopCommandConfig } from '../types.js';
6
7
  /**
7
8
  * Options for spawning a single server process.
8
9
  * @internal
@@ -18,10 +19,12 @@ export interface SpawnProcessOptions {
18
19
  cwd?: string;
19
20
  /** Additional environment variables (merged with process.env) */
20
21
  env?: Record<string, string>;
22
+ /** Whether to add process.env to env; registry callers provide a pre-merged environment */
23
+ inheritEnv?: boolean;
21
24
  /** Standard I/O configuration */
22
25
  stdio?: StdioOptions;
23
- /** Use shell for command execution (default: false, true on Windows) */
24
- shell?: boolean;
26
+ /** Application-specific shutdown command for an owned HTTP server */
27
+ stop?: StopCommandConfig;
25
28
  }
26
29
  /**
27
30
  * Handle to a spawned server process.
@@ -29,10 +32,6 @@ export interface SpawnProcessOptions {
29
32
  * @hidden
30
33
  */
31
34
  export interface ServerProcess {
32
- /**
33
- * The resolved server configuration that was actually used.
34
- * Useful for debugging and understanding what was spawned.
35
- */
36
35
  config: {
37
36
  name: string;
38
37
  command: string;
@@ -40,20 +39,9 @@ export interface ServerProcess {
40
39
  cwd: string;
41
40
  env: Record<string, string>;
42
41
  stdio: StdioOptions;
43
- shell: boolean;
42
+ shell: false;
44
43
  };
45
- /**
46
- * The spawned child process.
47
- */
48
44
  process: ChildProcess;
49
- /**
50
- * Close the server gracefully, terminating its process tree on Windows.
51
- * Sends the specified signal (default: SIGINT), then force-kills after timeout.
52
- *
53
- * @param signal - Signal to send (default: SIGINT)
54
- * @param opts - Options including timeout
55
- * @returns Promise resolving to whether the process timed out and was force-killed
56
- */
57
45
  close: (signal?: NodeJS.Signals, opts?: {
58
46
  timeoutMs?: number;
59
47
  }) => Promise<{
@@ -66,18 +54,6 @@ export interface ServerProcess {
66
54
  *
67
55
  * @internal
68
56
  * @param opts - Server spawn options
69
- * @returns ServerProcess handle with resolved config, process, and stop function
70
- *
71
- * @example
72
- * const handle = spawnProcess({
73
- * name: 'echo',
74
- * command: 'node',
75
- * args: ['./bin/server.js', '--port', '3000'],
76
- * cwd: '/home/user/project/test/lib/servers/echo',
77
- * env: { LOG_LEVEL: 'error' }
78
- * });
79
- *
80
- * // Later...
81
- * await handle.close();
57
+ * @returns ServerProcess handle with resolved config and lifecycle control
82
58
  */
83
59
  export declare function spawnProcess(opts: SpawnProcessOptions): ServerProcess;