Skip to main content
Glama
tarnover
by tarnover

aws_cloudformation

Manage AWS CloudFormation stacks using Ansible MCP Server. Perform actions like create, update, delete, or list stacks, configure templates, parameters, and tags, and automate AWS infrastructure deployment.

Instructions

Manage AWS CloudFormation stacks

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYes
capabilitiesNo
parametersNo
regionYes
stackNameNo
tagsNo
templateBodyNo
templateUrlNo

Implementation Reference

  • Registers the 'aws_cloudformation' tool in the toolDefinitions map, linking it to its description, input schema, and handler function.
    aws_cloudformation: {
      description: 'Manage AWS CloudFormation stacks',
      schema: aws.CloudFormationSchema,
      handler: aws.cloudFormationOperations,
    },
  • Handler function for 'aws_cloudformation' tool. Validates input, generates an Ansible playbook dynamically for actions like list/create/update/delete CloudFormation stacks, handles template files, and executes via Ansible.
    export async function cloudFormationOperations(args: CloudFormationOptions): Promise<string> {
      await verifyAwsCredentials();
    
      const { action, region, stackName, templateBody, templateUrl, parameters, capabilities, tags } = args;
    
      const tempFiles: { filename: string, content: string }[] = [];
      let templateParam = '';
    
      if (templateBody) {
        // Prepare template body to be written to a temp file
        tempFiles.push({ filename: 'template.cfn', content: templateBody });
        templateParam = 'template: "template.cfn"'; // Reference the temp file name
      } else if (templateUrl) {
        templateParam = `template_url: "${templateUrl}"`;
      } else if (action === 'create' || action === 'update') {
        // Template is required for create/update
        throw new AnsibleError('Either templateBody or templateUrl must be provided for CloudFormation create/update actions.');
      }
    
      let playbookContent = `---
    - name: AWS CloudFormation ${action} operation
      hosts: localhost
      connection: local
      gather_facts: no
      tasks:`;
      
      switch (action) {
        case 'list':
          playbookContent += `
        - name: List CloudFormation stacks
          amazon.aws.cloudformation_info:
            region: "${region}"
          register: cfn_info
        
        - name: Display stacks
          debug:
            var: cfn_info.stacks`;
          break;
          
        case 'create':
        case 'update':
          playbookContent += `
        - name: ${action === 'create' ? 'Create' : 'Update'} CloudFormation stack
          amazon.aws.cloudformation:
            region: "${region}"
            stack_name: "${stackName}"
            state: present
            ${templateParam} # Use the determined template parameter
    ${formatYamlParams({
      template_parameters: parameters,
      capabilities,
      tags
    })}
          register: cfn_result
        
        - name: Display stack outputs/result
          debug:
            var: cfn_result`;
          break;
          
        case 'delete':
          playbookContent += `
        - name: Delete CloudFormation stack
          amazon.aws.cloudformation:
            region: "${region}"
            stack_name: "${stackName}"
            state: absent
          register: cfn_delete
          
        - name: Display deletion result
          debug:
            var: cfn_delete`;
          break;
          
        default:
          throw new AnsibleError(`Unsupported CloudFormation action: ${action}`);
      }
      
      // Execute the generated playbook, passing template body if needed
      return executeAwsPlaybook(`cloudformation-${action}`, playbookContent, '', tempFiles);
    }
  • Defines the input schema (CloudFormationSchema) and action enum for validating tool arguments, including required region and optional parameters for CloudFormation operations.
    export const CloudFormationActionEnum = z.enum(['list', 'create', 'update', 'delete']);
    export type CloudFormationAction = z.infer<typeof CloudFormationActionEnum>;
    
    export const IAMActionEnum = z.enum(['list_roles', 'list_policies', 'create_role', 'create_policy', 'delete_role', 'delete_policy']);
    export type IAMAction = z.infer<typeof IAMActionEnum>;
    
    export const RDSActionEnum = z.enum(['list', 'create', 'delete', 'start', 'stop']);
    export type RDSAction = z.infer<typeof RDSActionEnum>;
    
    export const Route53ActionEnum = z.enum(['list_zones', 'list_records', 'create_zone', 'create_record', 'delete_record', 'delete_zone']);
    export type Route53Action = z.infer<typeof Route53ActionEnum>;
    
    export const ELBActionEnum = z.enum(['list', 'create', 'delete']);
    export type ELBAction = z.infer<typeof ELBActionEnum>;
    
    export const LambdaActionEnum = z.enum(['list', 'create', 'update', 'delete', 'invoke']);
    export type LambdaAction = z.infer<typeof LambdaActionEnum>;
    
    // AWS EC2 Schema
    export const EC2InstanceSchema = z.object({
      action: EC2InstanceActionEnum,
      region: z.string().min(1, 'AWS region is required'),
      instanceIds: z.array(z.string()).optional(),
      filters: z.record(z.any()).optional(),
      instanceType: z.string().optional(),
      imageId: z.string().optional(),
      keyName: z.string().optional(),
      securityGroups: z.array(z.string()).optional(),
      userData: z.string().optional(),
      count: z.number().optional(),
      tags: z.record(z.string()).optional(),
      waitForCompletion: z.boolean().optional().default(true),
      terminationProtection: z.boolean().optional()
    });
    
    export type EC2InstanceOptions = z.infer<typeof EC2InstanceSchema>;
    
    // AWS S3 Schema
    export const S3Schema = z.object({
      action: S3ActionEnum,
      region: z.string().min(1, 'AWS region is required'),
      bucket: z.string().optional(),
      objectKey: z.string().optional(),
      localPath: z.string().optional(),
      acl: z.string().optional(),
      tags: z.record(z.string()).optional(),
      metadata: z.record(z.string()).optional(),
      contentType: z.string().optional()
    });
    
    export type S3Options = z.infer<typeof S3Schema>;
    
    // AWS VPC Schema
    export const VPCSchema = z.object({
      action: VPCActionEnum,
      region: z.string().min(1, 'AWS region is required'),
      vpcId: z.string().optional(),
      cidrBlock: z.string().optional(),
      name: z.string().optional(),
      dnsSupport: z.boolean().optional(),
      dnsHostnames: z.boolean().optional(),
      tags: z.record(z.string()).optional(),
      subnets: z.array(z.object({
        cidr: z.string(),
        az: z.string().optional(),
        tags: z.record(z.string()).optional()
      })).optional()
    });
    
    export type VPCOptions = z.infer<typeof VPCSchema>;
    
    // AWS CloudFormation Schema
    export const CloudFormationSchema = z.object({
      action: CloudFormationActionEnum,
      region: z.string().min(1, 'AWS region is required'),
      stackName: z.string().optional(),
      templateBody: z.string().optional(),
      templateUrl: z.string().optional(),
      parameters: z.record(z.any()).optional(),
      capabilities: z.array(z.string()).optional(),
      tags: z.record(z.string()).optional()
    });
    
    export type CloudFormationOptions = z.infer<typeof CloudFormationSchema>;
  • Helper function used by AWS tool handlers (including CloudFormation) to create temp directories, write playbooks/templates, execute ansible-playbook, and clean up.
    async function executeAwsPlaybook(
      operationName: string, 
      playbookContent: string, 
      extraParams: string = '',
      tempFiles: { filename: string, content: string }[] = [] // For additional files like templates, policies
    ): Promise<string> {
      let tempDir: string | undefined;
      try {
        // Create a unique temporary directory
        tempDir = await createTempDirectory(`ansible-aws-${operationName}`);
        
        // Write the main playbook file
        const playbookPath = await writeTempFile(tempDir, 'playbook.yml', playbookContent);
        
        // Write any additional temporary files
        for (const file of tempFiles) {
          await writeTempFile(tempDir, file.filename, file.content);
        }
    
        // Build the command
        const command = `ansible-playbook ${playbookPath} ${extraParams}`;
        console.error(`Executing: ${command}`);
    
        // Execute the playbook asynchronously
        const { stdout, stderr } = await execAsync(command);
        
        // Return stdout, or a success message if stdout is empty
        return stdout || `${operationName} completed successfully (no output).`;
    
      } catch (error: any) {
        // Handle execution errors
        const errorMessage = error.stderr || error.message || 'Unknown error';
        throw new AnsibleExecutionError(`Ansible execution failed for ${operationName}: ${errorMessage}`, error.stderr);
      } finally {
        // Ensure cleanup happens even if errors occur
        if (tempDir) {
          await cleanupTempDirectory(tempDir);
        }
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Manage' implies both read and write operations, but there's no information about permissions required, whether operations are destructive, rate limits, error handling, or what 'manage' actually does behaviorally. The description doesn't explain what happens during create/update/delete actions or any side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just three words, with zero wasted language. It's front-loaded with the core purpose and contains no unnecessary elaboration. While this conciseness comes at the cost of completeness, the structure itself is optimal for its length.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 8 parameters, 0% schema coverage, no annotations, and no output schema, the description is severely incomplete. It doesn't provide enough information for an agent to understand what the tool actually does, how to use it properly, or what to expect from it. The three-word description is inadequate given the tool's complexity and lack of supporting documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for 8 parameters, the description provides no parameter semantics whatsoever. It doesn't explain what 'action' values mean, what 'capabilities' are for, how 'parameters' and 'tags' should be structured, or the relationship between 'templateBody' and 'templateUrl'. The description fails to compensate for the complete lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Manage AWS CloudFormation stacks' states the general purpose (verb+resource) but is vague about what 'manage' entails. It doesn't distinguish this tool from its many AWS siblings (like aws_ec2, aws_s3) beyond mentioning CloudFormation specifically. The description is functional but lacks specificity about the scope of management operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. There's no mention of when to choose CloudFormation over sibling tools like terraform or run_playbook, nor any context about prerequisites or typical use cases. The description offers no usage boundaries or comparison with other infrastructure-as-code options.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/tarnover/mcp-ansible'

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