MCPcopy
hub / github.com/coder/mux / discoverServer

Function discoverServer

src/cli/api.ts:29–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29async function discoverServer(): Promise<ServerDiscovery> {
30 // Priority 1: Explicit env vars override everything
31 if (process.env.MUX_SERVER_URL) {
32 return {
33 baseUrl: process.env.MUX_SERVER_URL,
34 authToken: process.env.MUX_SERVER_AUTH_TOKEN,
35 };
36 }
37
38 // Priority 2: Try lockfile discovery (running Electron or mux server)
39 try {
40 const lockfile = new ServerLockfile(getMuxHome());
41 const data = await lockfile.read();
42 if (data) {
43 return {
44 baseUrl: data.baseUrl,
45 authToken: data.token,
46 };
47 }
48 } catch {
49 // Ignore lockfile errors
50 }
51
52 // Priority 3: Default fallback (standalone server on default port)
53 return {
54 baseUrl: "http://localhost:3000",
55 authToken: process.env.MUX_SERVER_AUTH_TOKEN,
56 };
57}
58
59// Run async discovery then start CLI
60(async () => {

Callers 1

api.tsFile · 0.85

Calls 2

readMethod · 0.95
getMuxHomeFunction · 0.90

Tested by

no test coverage detected