pulumi-cli-stack-output
Retrieve specific output values from a Pulumi stack by specifying the working directory and optional stack or output name.
Instructions
Get the output value(s) of a given stack
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outputName | No | The specific stack output name to retrieve. | |
| stackName | No | The associated stack name. Defaults to 'dev'. | |
| workDir | Yes | The working directory of the program. |
Implementation Reference
- src/pulumi/cli.ts:105-161 (handler)The core implementation of the 'stack-output' command, including schema validation with Zod and the handler function that executes Pulumi automation to retrieve stack outputs. This is used as the basis for the 'pulumi-cli-stack-output' tool.'stack-output': { description: 'Get the output value(s) of a given stack', schema: { workDir: z.string().describe('The working directory of the program.'), stackName: z.string().optional().describe("The associated stack name. Defaults to 'dev'."), outputName: z.string().optional().describe('The specific stack output name to retrieve.') }, handler: async (args: { workDir: string; stackName?: string; outputName?: string }) => { const stackArgs: automation.LocalProgramArgs = { stackName: args.stackName ?? 'dev', workDir: args.workDir }; const stack = await automation.LocalWorkspace.selectStack(stackArgs); // Get stack outputs const outputs = await stack.outputs(); let description: string; let outputContent: string; if (args.outputName) { // Return a specific output const specificOutput = outputs[args.outputName]; if (specificOutput) { description = `Pulumi Stack Output: ${args.outputName}`; outputContent = `${args.outputName}: ${JSON.stringify(specificOutput.value)}`; } else { description = `Pulumi Stack Output: ${args.outputName}`; outputContent = `Output '${args.outputName}' not found.`; } } else { // Return all outputs description = 'Pulumi Stack Outputs'; outputContent = Object.entries(outputs) .map(([key, value]) => `${key}: ${JSON.stringify(value.value)}`) .join('\\n'); if (!outputContent) { outputContent = 'No outputs found'; } } return { description: description, content: [ { type: 'text' as const, text: ` Stack: ${stack.name} ${outputContent} ` } ] }; } },
- src/server/server.ts:69-79 (registration)Registration of all CLI commands as MCP tools, dynamically naming them 'pulumi-cli-{commandName}', including 'pulumi-cli-stack-output', by wrapping the handler from cliCommands with error handling.Object.entries(cliCommands).forEach(([commandName, command]) => { const toolName = `pulumi-cli-${commandName}`; // eslint-disable-next-line @typescript-eslint/no-explicit-any this.tool(toolName, command.description, command.schema, async (args: any) => { try { return await command.handler(args); } catch (error) { return handleError(error, toolName); } }); });
- src/pulumi/cli.ts:107-111 (schema)Zod schema defining the input parameters for the pulumi-cli-stack-output tool: workDir (required), stackName (optional, defaults to 'dev'), outputName (optional).schema: { workDir: z.string().describe('The working directory of the program.'), stackName: z.string().optional().describe("The associated stack name. Defaults to 'dev'."), outputName: z.string().optional().describe('The specific stack output name to retrieve.') },