MCPcopy Create free account
hub / github.com/tiann/hapi / shouldAutoStartServer

Function shouldAutoStartServer

cli/src/utils/autoStartServer.ts:92–122  ·  view source on GitHub ↗

* Determine if hub should be auto-started

()

Source from the content-addressed store, hash-verified

90 * Determine if hub should be auto-started
91 */
92async function shouldAutoStartServer(): Promise<boolean> {
93 // Condition 1: HAPI_API_URL not set (using default localhost:3006)
94 if (process.env.HAPI_API_URL) {
95 logger.debug('[AUTO-START] HAPI_API_URL is set, skipping auto-start')
96 return false
97 }
98
99 // Condition 2: Check settings.json
100 const settings = await readSettings()
101
102 // 2a: apiUrl is set in settings.json (user configured a specific hub)
103 if (settings.apiUrl || settings.serverUrl) {
104 logger.debug('[AUTO-START] apiUrl is set in settings.json, skipping auto-start')
105 return false
106 }
107
108 // 2b: cliApiToken exists in settings.json (hub was previously started)
109 if (!settings.cliApiToken) {
110 logger.debug('[AUTO-START] No cliApiToken in settings, skipping auto-start')
111 return false
112 }
113
114 // Condition 3: Port 3006 is not currently listening
115 const isListening = await checkPortListening(DEFAULT_SERVER_PORT)
116 if (isListening) {
117 logger.debug('[AUTO-START] Port 3006 already in use, skipping auto-start')
118 return false
119 }
120
121 return true
122}
123
124/**
125 * Start hub as a child process (will exit when CLI exits)

Callers 1

maybeAutoStartServerFunction · 0.85

Calls 3

readSettingsFunction · 0.90
checkPortListeningFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected