Skip to main content
Glama

js.beautify

Format JavaScript code for readability and analysis during security testing, helping identify vulnerabilities by standardizing code structure.

Instructions

Beautify and format JavaScript source code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYesJavaScript source code
indentSizeNoIndentation size

Implementation Reference

  • The asynchronous handler function for the 'js.beautify' tool. It takes JavaScript source code and optional indent size, uses the 'js-beautify' library to format it, and returns the beautified code along with length information or an error.
    async ({ source, indentSize = 2 }: any): Promise<ToolResult> => {
      try {
        const beautified = beautify.js(source, {
          indent_size: indentSize,
          space_in_empty_paren: true,
          preserve_newlines: true,
        });
    
        return formatToolResult(true, {
          beautified,
          originalLength: source.length,
          beautifiedLength: beautified.length,
        });
      } catch (error: any) {
        return formatToolResult(false, null, error.message);
      }
    }
  • Input schema definition for the 'js.beautify' tool, specifying required 'source' parameter and optional 'indentSize'.
    description: 'Beautify and format JavaScript source code',
    inputSchema: {
      type: 'object',
      properties: {
        source: { type: 'string', description: 'JavaScript source code' },
        indentSize: { type: 'number', description: 'Indentation size', default: 2 },
      },
      required: ['source'],
    },
  • src/tools/js.ts:47-76 (registration)
    Registration of the 'js.beautify' tool using server.tool(), including schema and handler function.
      'js.beautify',
      {
        description: 'Beautify and format JavaScript source code',
        inputSchema: {
          type: 'object',
          properties: {
            source: { type: 'string', description: 'JavaScript source code' },
            indentSize: { type: 'number', description: 'Indentation size', default: 2 },
          },
          required: ['source'],
        },
      },
      async ({ source, indentSize = 2 }: any): Promise<ToolResult> => {
        try {
          const beautified = beautify.js(source, {
            indent_size: indentSize,
            space_in_empty_paren: true,
            preserve_newlines: true,
          });
    
          return formatToolResult(true, {
            beautified,
            originalLength: source.length,
            beautifiedLength: beautified.length,
          });
        } catch (error: any) {
          return formatToolResult(false, null, error.message);
        }
      }
    );
  • Import of the 'js-beautify' library, which is used as the core formatting utility in the tool handler.
    import beautify from 'js-beautify';
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. It states the tool 'beautifies and formats' code, implying a read-only transformation, but doesn't clarify if it modifies the original source, handles errors, or has any side effects. It lacks details on output format, performance characteristics, or limitations.

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—a single, clear sentence that front-loads the core purpose without unnecessary words. Every part of the sentence earns its place by directly communicating the tool's function.

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 tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the formatted output looks like, whether it preserves comments, handles different JavaScript versions, or has any error handling. Given the complexity of code formatting and lack of structured data, more context is needed.

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?

The description adds no parameter-specific information beyond what's in the schema, which has 100% coverage. It doesn't explain what 'beautify' entails in terms of the source parameter or provide context for indentSize values. Since the schema fully documents parameters, the baseline score of 3 is appropriate.

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

Purpose4/5

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

The description clearly states the tool's purpose with a specific verb ('beautify and format') and resource ('JavaScript source code'), making it immediately understandable. However, it doesn't differentiate from sibling tools like js.analyze or render.execute_js, which might also process JavaScript code in different ways.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer js.beautify over js.analyze for formatting needs, or when to use it in conjunction with other tools like js.extract_secrets. There's no context about prerequisites or typical workflows.

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/telmon95/VulneraMCP'

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