devcontainer_exec
Run custom shell commands or scripts directly within a specified devcontainer workspace folder. Simplify execution of development tasks by leveraging the containerized environment context.
Instructions
Execute an arbitrary shell command inside the devcontainer for the specified workspace folder.Use this to run custom commands or scripts within the devcontainer context.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | ||
| outputFilePath | No | ||
| workspaceFolder | Yes |
Implementation Reference
- src/devcontainer.ts:58-63 (handler)Core implementation of the exec function that runs the devcontainer exec CLI command with the given options.export async function exec(options: DevContainerExecOptions): Promise<number> { return runCommand( ['exec', '--workspace-folder', options.workspaceFolder, ...options.command], createStdoutStream(options) ); }
- src/server.ts:59-63 (schema)Zod schema defining the input parameters for the devcontainer_exec tool: workspaceFolder, command array, and optional outputFilePath.{ workspaceFolder: z.string(), command: z.array(z.string()), outputFilePath: z.string().optional(), },
- src/server.ts:55-75 (registration)Registration of the 'devcontainer_exec' tool in the MCP server, including description, schema, and thin wrapper handler function.server.tool( "devcontainer_exec", "Execute an arbitrary shell command inside the devcontainer for the specified workspace folder." + "Use this to run custom commands or scripts within the devcontainer context.", { workspaceFolder: z.string(), command: z.array(z.string()), outputFilePath: z.string().optional(), }, async ({ workspaceFolder, command, outputFilePath }) => { await devcontainers.exec({ workspaceFolder, command, stdioFilePath: outputFilePath }); return { content: [ { type: "text", text: `Executed command ${command.join(" ")} in ${workspaceFolder}`, } ] } } );
- src/devcontainer.ts:65-83 (helper)Helper function that spawns the devcontainer CLI process using node's spawn and handles stdout piping and exit codes.async function runCommand(args: string[], stdout: fs.WriteStream): Promise<number> { return new Promise((resolve, reject) => { const proc = spawn('node', [devcontainerBinaryPath(), ...args], { stdio: ['ignore', 'pipe', 'inherit'], }); proc.stdout.pipe(stdout); proc.on('close', (code) => { stdout.end(); if (code === 0) { resolve(code); } else { reject(new Error(`devcontainer command ${args.join(' ')} exited with code ${code}`)); } }); }); }
- src/devcontainer.ts:29-32 (schema)TypeScript interface defining the options for the exec function, extending the base DevcontainerOptions.interface DevContainerExecOptions extends DevcontainerOptions { workspaceFolder: string; command: string[]; }