devcontainer_run_user_commands
Execute user-defined setup and initialization scripts in a development container for a specified workspace folder, ensuring required commands run after the container starts.
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
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outputFilePath | No | ||
| workspaceFolder | Yes |
Implementation Reference
- src/devcontainer.ts:48-53 (handler)Core handler function that executes the devcontainer CLI 'run-user-commands' subcommand by spawning the binary with workspace folder argument and handling stdout.export async function runUserCommands(options: DevContainerRunUserCommandsOptions): Promise<number> { return runCommand( ['run-user-commands', '--workspace-folder', options.workspaceFolder], createStdoutStream(options) ); }
- src/server.ts:32-53 (registration)Registers the MCP tool 'devcontainer_run_user_commands' with name, description, Zod input schema, and thin async wrapper that calls the core 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/server.ts:37-40 (schema)Zod validation schema for tool parameters used in MCP tool registration.{ workspaceFolder: z.string(), outputFilePath: z.string().optional(), },
- src/devcontainer.ts:22-24 (schema)TypeScript interface defining input options for the runUserCommands handler.interface DevContainerRunUserCommandsOptions extends DevcontainerOptions { workspaceFolder: string; }
- src/devcontainer.ts:65-83 (helper)Shared helper function for spawning devcontainer CLI processes, piping stdout, and resolving/rejecting based on exit code.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}`)); } }); }); }