Skip to main content
Glama
pulumi

@pulumi/mcp-server

Official
by pulumi

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
NameRequiredDescriptionDefault
outputNameNoThe specific stack output name to retrieve.
stackNameNoThe associated stack name. Defaults to 'dev'.
workDirYesThe working directory of the program.

Implementation Reference

  • 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}
    `
              }
            ]
          };
        }
      },
  • 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);
        }
      });
    });
  • 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.')
    },
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pulumi/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server