devcontainer_run_user_commands
Execute user-defined postCreateCommand and postStartCommand scripts in a devcontainer for a given workspace folder to automate setup or initialization after container start.
Instructions
Run the user-defined postCreateCommand and postStartCommand scripts in the devcontainerfor the specified workspace folder. Use this to execute setup or initialization commandsafter the devcontainer starts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspaceFolder | Yes | ||
| outputFilePath | No |
Implementation Reference
- src/server.ts:32-53 (registration)MCP server registration for tool 'devcontainer_run_user_commands' using server.tool() with Zod schema and async handler.
server.tool( "devcontainer_run_user_commands", "Run the user-defined postCreateCommand and postStartCommand scripts in the devcontainer" + "for the specified workspace folder. Use this to execute setup or initialization commands" + "after the devcontainer starts.", { workspaceFolder: z.string(), outputFilePath: z.string().optional(), }, async ({ workspaceFolder, outputFilePath }) => { await devcontainers.runUserCommands({ workspaceFolder, stdioFilePath: outputFilePath }); return { content: [ { type: "text", text: `User commands run in ${workspaceFolder}`, } ] } } ); - src/devcontainer.ts:22-24 (schema)TypeScript interface DevContainerRunUserCommandsOptions defining input schema (workspaceFolder, optional stdioFilePath).
interface DevContainerRunUserCommandsOptions extends DevcontainerOptions { workspaceFolder: string; } - src/devcontainer.ts:48-53 (handler)Core handler function runUserCommands() that calls runCommand with 'run-user-commands' subcommand and workspace folder.
export async function runUserCommands(options: DevContainerRunUserCommandsOptions): Promise<number> { return runCommand( ['run-user-commands', '--workspace-folder', options.workspaceFolder], createStdoutStream(options) ); } - src/server.ts:41-52 (registration)Inline async handler in server.tool() registration that delegates to devcontainers.runUserCommands() and returns success message.
async ({ workspaceFolder, outputFilePath }) => { await devcontainers.runUserCommands({ workspaceFolder, stdioFilePath: outputFilePath }); return { content: [ { type: "text", text: `User commands run in ${workspaceFolder}`, } ] } } - src/devcontainer.ts:65-83 (helper)Helper runCommand() that spawns the devcontainer CLI process with provided args and pipes stdout.
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}`)); } }); }); }