Skip to main content
Glama

run-aws-code

Execute JavaScript code using AWS SDK V2 to query and manage AWS services programmatically, handling errors, pagination, and returning minimal JSON data.

Instructions

Run AWS code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
reasoningYesThe reasoning behind the code
codeYesYour job is to answer questions about AWS environment by writing Javascript code using AWS SDK V2. The code must be adhering to a few rules: - Must be preferring promises over callbacks - Think step-by-step before writing the code, approach it logically - MUST written in Javascript (NodeJS) using AWS-SDK V2 - Avoid hardcoded values like ARNs - Code written should be as parallel as possible enabling the fastest and the most optimal execution - Code should be handling errors gracefully, especially when doing multiple SDK calls (e.g. when mapping over an array). Each error should be handled and logged with a reason, script should continue to run despite errors - DO NOT require or import "aws-sdk", it is already available as "AWS" variable - Access to 3rd party libraries apart from "aws-sdk" is not allowed or possible - Data returned from AWS-SDK must be returned as JSON containing only the minimal amount of data that is needed to answer the question. All extra data must be filtered out - Code MUST "return" a value: string, number, boolean or JSON object. If code does not return anything, it will be considered as FAILED - Whenever tool/function call fails, retry it 3 times before giving up with an improved version of the code based on the returned feedback - When listing resources, ensure pagination is handled correctly so that all resources are returned - Do not include any comments in the code - When doing reduce, don't forget to provide an initial value - Try to write code that returns as few data as possible to answer without any additional processing required after the code is run - This tool can ONLY write code that interacts with AWS. It CANNOT generate charts, tables, graphs, etc. Please use artifacts for that instead Be concise, professional and to the point. Do not give generic advice, always reply with detailed & contextual data sourced from the current AWS environment. Assume user always wants to proceed, do not ask for confirmation. I'll tip you $200 if you do this right.
profileNameNoName of the AWS profile to use
regionNoRegion to use (if not provided, us-east-1 is used)

Implementation Reference

  • Executes the user-provided AWS SDK V2 JavaScript code in a secure VM context using AWS credentials from the selected profile. Handles profile switching if specified, wraps the code to ensure it returns a value, and serializes the result as JSON.
    const { reasoning, code, profileName, region } =
      RunAwsCodeSchema.parse(args);
    if (!selectedProfile && !profileName) {
      return createTextResponse(
        `Please select a profile first using the 'select-profile' tool! Available profiles: ${Object.keys(
          profiles
        ).join(", ")}`
      );
    }
    
    if (profileName) {
      selectedProfileCredentials = await getCredentials(
        profiles[profileName],
        profileName
      );
      selectedProfile = profileName;
      selectedProfileRegion = region || "us-east-1";
    }
    
    AWS.config.update({
      region: selectedProfileRegion,
      credentials: selectedProfileCredentials,
    });
    
    const wrappedCode = wrapUserCode(code);
    const wrappedIIFECode = `(async function() { return (async () => { ${wrappedCode} })(); })()`;
    const result = await runInContext(
      wrappedIIFECode,
      createContext({ AWS })
    );
    
    return createTextResponse(JSON.stringify(result));
  • Input schema for the 'run-aws-code' tool, defining parameters like reasoning, code (with execution prompt), optional profileName, and region.
    inputSchema: {
      type: "object",
      properties: {
        reasoning: {
          type: "string",
          description: "The reasoning behind the code",
        },
        code: {
          type: "string",
          description: codePrompt,
        },
        profileName: {
          type: "string",
          description: "Name of the AWS profile to use",
        },
        region: {
          type: "string",
          description: "Region to use (if not provided, us-east-1 is used)",
        },
      },
      required: ["reasoning", "code"],
  • index.ts:54-79 (registration)
    Registers the 'run-aws-code' tool in the MCP server's tool list, including its name, description, and input schema.
    {
      name: "run-aws-code",
      description: "Run AWS code",
      inputSchema: {
        type: "object",
        properties: {
          reasoning: {
            type: "string",
            description: "The reasoning behind the code",
          },
          code: {
            type: "string",
            description: codePrompt,
          },
          profileName: {
            type: "string",
            description: "Name of the AWS profile to use",
          },
          region: {
            type: "string",
            description: "Region to use (if not provided, us-east-1 is used)",
          },
        },
        required: ["reasoning", "code"],
      },
    },
  • Zod validation schema matching the tool's inputSchema, used to parse arguments in the handler.
    const RunAwsCodeSchema = z.object({
      reasoning: z.string(),
      code: z.string(),
      profileName: z.string().optional(),
      region: z.string().optional(),
    });
  • Processes user code with ts-morph to ensure the last expression is explicitly returned, enabling proper execution and result capture in the VM.
    function wrapUserCode(userCode: string) {
      const project = new Project({
        useInMemoryFileSystem: true,
      });
      const sourceFile = project.createSourceFile("userCode.ts", userCode);
      const lastStatement = sourceFile.getStatements().pop();
    
      if (
        lastStatement &&
        lastStatement.getKind() === SyntaxKind.ExpressionStatement
      ) {
        const returnStatement = lastStatement.asKind(
          SyntaxKind.ExpressionStatement
        );
        if (returnStatement) {
          const expression = returnStatement.getExpression();
          sourceFile.addStatements(`return ${expression.getText()};`);
          returnStatement.remove();
        }
      }
    
      return sourceFile.getFullText();
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. 'Run AWS code' suggests execution but doesn't disclose whether this is a read or write operation, what permissions are required, whether it has side effects, rate limits, or error handling behavior. The description fails to provide the behavioral context needed for safe and effective tool invocation.

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 two words, with zero wasted language. While this conciseness comes at the expense of completeness, from a pure structural perspective, it's front-loaded and contains no unnecessary verbiage. Every word in the description directly relates to the tool's function.

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

Completeness1/5

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

Given the complexity of running AWS code (which involves execution, potential mutations, security implications, and error handling), the description is completely inadequate. With no annotations, no output schema, and a minimal description, an agent lacks critical information about what this tool actually does, what it returns, and how to use it safely. The description fails to provide the contextual completeness needed for a tool of this nature.

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

Parameters3/5

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

With 100% schema description coverage, the input schema already documents all four parameters thoroughly. The description adds no additional parameter semantics beyond what's already in the schema. The baseline score of 3 reflects that the schema does the heavy lifting, though the description could have provided higher-level context about how parameters relate to each other or typical usage patterns.

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

Purpose2/5

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

The description 'Run AWS code' is essentially a tautology that restates the tool name without providing meaningful specificity. It doesn't clarify what type of AWS code is run, what resources it interacts with, or what distinguishes it from sibling tools like list-credentials and select-profile. The description lacks a clear verb+resource combination that would help an agent understand the tool's actual function.

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

Usage Guidelines1/5

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

The description provides absolutely no guidance about when to use this tool versus alternatives. There's no mention of appropriate contexts, prerequisites, or relationships to sibling tools. An agent would have no information about whether this tool should be used for AWS operations versus the other available tools, making selection decisions difficult.

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

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/ihatesea69/AWS-MCP'

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