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

Method workspaceExists

src/node/services/coderService.ts:963–984  ·  view source on GitHub ↗

* Check if a Coder workspace exists by name. * * Uses `coder list --search name: ` so we don't have to fetch all workspaces. * Note: Coder's `--search` is prefix-based server-side, so we must exact-match locally.

(workspaceName: string)

Source from the content-addressed store, hash-verified

961 * Note: Coder's `--search` is prefix-based server-side, so we must exact-match locally.
962 */
963 async workspaceExists(workspaceName: string): Promise<boolean> {
964 try {
965 const stdout = await this.runCoderJsonCommand([
966 "list",
967 "--search",
968 `name:${workspaceName}`,
969 "--output=json",
970 ]);
971
972 if (!stdout.trim()) {
973 return false;
974 }
975
976 const workspaces = JSON.parse(stdout) as Array<{ name: string }>;
977 return workspaces.some((w) => w.name === workspaceName);
978 } catch (error) {
979 // Best-effort: if Coder isn't configured/logged in, treat as "doesn't exist" so we
980 // don't block creation (later steps will fail with a more actionable error).
981 log.debug("Failed to check if Coder workspace exists", { workspaceName, error });
982 return false;
983 }
984 }
985
986 /**
987 * List Coder workspaces (all statuses).

Callers 2

validateBeforePersistMethod · 0.80

Calls 3

runCoderJsonCommandMethod · 0.95
debugMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected