@theronap/cortex-mcp 0.4.0 → 0.4.2

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.
@@ -16,7 +16,7 @@
16
16
  * Get your token from the Cortex console → Connect your AI.
17
17
  */
18
18
 
19
- const VERSION = '0.4.0'
19
+ const VERSION = '0.4.2'
20
20
  const cmd = process.argv[2]
21
21
  const rest = process.argv.slice(3)
22
22
 
@@ -42,23 +42,30 @@ if (cmd === '--help' || cmd === '-h' || cmd === 'help') {
42
42
  process.exit(0)
43
43
  }
44
44
 
45
+ // The network-using subcommands do their work, release the global fetch (undici) sockets, then
46
+ // let the process exit NATURALLY — no process.exit(). Forcing exit on Windows tears libuv down
47
+ // abruptly and, if a threadpool/pipe handle is mid-flight (DNS, the stdout flush), trips an
48
+ // assertion (`!(handle->flags & UV_HANDLE_CLOSING)`, src\win\async.c) AFTER the real output.
49
+ // A graceful drain lets libuv finish those handles first, so the assertion never fires. The MCP
50
+ // server (default branch) runs forever and never reaches an exit path. if/else so the CLI
51
+ // commands don't fall through into the server.
45
52
  if (cmd === 'setup') {
46
53
  const { runSetup } = await import('../lib/setup.mjs')
47
54
  await runSetup(rest)
48
- process.exit(0)
49
- }
50
-
51
- if (cmd === 'doctor') {
55
+ const { closeFetch } = await import('../lib/diagnose.mjs')
56
+ await closeFetch()
57
+ } else if (cmd === 'doctor') {
52
58
  const { runDoctor } = await import('../lib/doctor.mjs')
53
- process.exit(await runDoctor())
54
- }
55
-
56
- if (cmd === 'capture') {
59
+ process.exitCode = await runDoctor()
60
+ const { closeFetch } = await import('../lib/diagnose.mjs')
61
+ await closeFetch()
62
+ } else if (cmd === 'capture') {
57
63
  const { runCapture } = await import('../lib/capture.mjs')
58
64
  await runCapture()
59
- process.exit(0)
65
+ const { closeFetch } = await import('../lib/diagnose.mjs')
66
+ await closeFetch()
67
+ } else {
68
+ // Default: run the MCP server (stays alive; never exits).
69
+ const { runServer } = await import('../lib/server.mjs')
70
+ await runServer(VERSION)
60
71
  }
61
-
62
- // Default: run the MCP server.
63
- const { runServer } = await import('../lib/server.mjs')
64
- await runServer(VERSION)
package/lib/diagnose.mjs CHANGED
@@ -108,3 +108,14 @@ export async function checkToken(token, base) {
108
108
  } catch { /* context shape changed — non-fatal for a health check */ }
109
109
  return { ok: true, status: 200, projectCount, requestId }
110
110
  }
111
+
112
+ // Release the keep-alive sockets the global fetch (undici) holds, so a short-lived CLI command
113
+ // can tear down cleanly. Without this, calling process.exit() right after a fetch can race a
114
+ // lingering socket handle and trip a libuv assertion on Windows
115
+ // (`!(handle->flags & UV_HANDLE_CLOSING)`, src\win\async.c). Best-effort + never throws.
116
+ export async function closeFetch() {
117
+ try {
118
+ const dispatcher = globalThis[Symbol.for('undici.globalDispatcher.1')]
119
+ if (dispatcher && typeof dispatcher.close === 'function') await dispatcher.close()
120
+ } catch { /* cleanup must never break the caller */ }
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theronap/cortex-mcp",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Connect your AI assistant to Cortex — your org's projects, activity, gaps, and directives, scoped to you.",
5
5
  "type": "module",
6
6
  "bin": {