devcontainer_exec
Execute arbitrary shell commands within a devcontainer context for a given workspace folder.
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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"workspaceFolder": "<workspaceFolder>",
"command": "<command>"
},
"name": "devcontainer_exec"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspaceFolder | Yes | ||
| command | Yes | ||
| outputFilePath | No |
Implementation Reference
- src/server.ts:55-75 (registration)Registration of the devcontainer_exec MCP tool via server.tool(), defining input schema and the handler callback.
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/server.ts:59-62 (schema)Zod schema for the devcontainer_exec tool: workspaceFolder (string), command (array of strings), and optional outputFilePath (string).
{ workspaceFolder: z.string(), command: z.array(z.string()), outputFilePath: z.string().optional(), - src/devcontainer.ts:58-63 (handler)Core handler that executes a command inside the devcontainer by spawning the devcontainer CLI with 'exec' subcommand.
export async function exec(options: DevContainerExecOptions): Promise<number> { return runCommand( ['exec', '--workspace-folder', options.workspaceFolder, ...options.command], createStdoutStream(options) ); } - src/devcontainer.ts:29-32 (schema)TypeScript interface defining the options for the exec function: workspaceFolder and command array.
interface DevContainerExecOptions extends DevcontainerOptions { workspaceFolder: string; command: string[]; } - src/devcontainer.ts:65-83 (helper)Helper function that spawns the devcontainer CLI process, pipes stdout to a stream, and resolves/rejects based on the 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}`)); } }); }); }