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

Method getDevcontainerInfo

src/node/services/workspaceService.ts:4279–4323  ·  view source on GitHub ↗

* Get devcontainer info for deep link generation. * Returns null if not a devcontainer workspace or container is not running. * * This queries Docker for the container name (on-demand discovery) and * calls ensureReady to get the container workspace path.

(workspaceId: string)

Source from the content-addressed store, hash-verified

4277 * calls ensureReady to get the container workspace path.
4278 */
4279 async getDevcontainerInfo(workspaceId: string): Promise<{
4280 containerName: string;
4281 containerWorkspacePath: string;
4282 hostWorkspacePath: string;
4283 } | null> {
4284 const metadata = await this.getInfo(workspaceId);
4285 if (metadata?.runtimeConfig?.type !== "devcontainer") {
4286 return null;
4287 }
4288
4289 const workspace = this.config.findWorkspace(workspaceId);
4290 if (!workspace) {
4291 return null;
4292 }
4293
4294 const runtimeConfig = metadata.runtimeConfig;
4295 const runtime = createRuntime(runtimeConfig, {
4296 projectPath: metadata.projectPath,
4297 workspaceName: metadata.name,
4298 workspacePath: workspace.workspacePath,
4299 });
4300
4301 const hostWorkspacePath = workspace.workspacePath;
4302
4303 // Query Docker for container name (on-demand discovery)
4304 const containerName = await getDevcontainerContainerName(hostWorkspacePath);
4305 if (!containerName) {
4306 return null; // Container not running
4307 }
4308
4309 // Get container workspace path via ensureReady (idempotent if already running)
4310 const readyResult = await runtime.ensureReady();
4311 if (!readyResult.ready) {
4312 return null;
4313 }
4314
4315 // Access the cached remoteWorkspaceFolder from DevcontainerRuntime
4316 const devRuntime = runtime as DevcontainerRuntime;
4317 const containerWorkspacePath = devRuntime.getRemoteWorkspaceFolder();
4318 if (!containerWorkspacePath) {
4319 return null;
4320 }
4321
4322 return { containerName, containerWorkspacePath, hostWorkspacePath };
4323 }
4324 async getInfo(workspaceId: string): Promise<FrontendWorkspaceMetadata | null> {
4325 const allMetadata = await this.config.getAllWorkspaceMetadata();
4326 const found = allMetadata.find((metadata) => metadata.id === workspaceId) ?? null;

Callers 2

openInEditorFunction · 0.80
routerFunction · 0.80

Calls 6

getInfoMethod · 0.95
createRuntimeFunction · 0.90
findWorkspaceMethod · 0.80
ensureReadyMethod · 0.65

Tested by

no test coverage detected