Skip to main content
Glama
code-alchemist01

Development Tools MCP Server

format_code

Format code files automatically using Prettier to ensure consistent styling and improve readability in development workflows.

Instructions

Format code files using Prettier

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesYesFile paths to format
optionsNoPrettier options

Implementation Reference

  • Core handler function that executes the formatting logic using Prettier for a single file, returning original and formatted content.
    async formatCode(filePath: string, options?: prettier.Options): Promise<FormatResult> {
      try {
        const content = readFileSync(filePath, 'utf-8');
        const formatted = await prettier.format(content, {
          filepath: filePath,
          ...options,
        });
    
        return {
          file: filePath,
          formatted: content !== formatted,
          original: content,
          formattedContent: formatted,
        };
      } catch (error) {
        // If Prettier fails, return unformatted
        const content = readFileSync(filePath, 'utf-8');
        return {
          file: filePath,
          formatted: false,
          original: content,
          formattedContent: content,
        };
      }
    }
  • Tool dispatcher handler case for 'format_code' that handles multiple files by mapping over them and calling the formatCode utility.
    case 'format_code': {
      const files = params.files as string[];
      const options = params.options as Record<string, unknown>;
      const results = await Promise.all(
        files.map((file) => lintingUtils.formatCode(file, options))
      );
      return results;
    }
  • Input schema defining the expected parameters for the format_code tool: array of file paths (required) and optional Prettier options.
    inputSchema: {
      type: 'object',
      properties: {
        files: {
          type: 'array',
          items: { type: 'string' },
          description: 'File paths to format',
        },
        options: {
          type: 'object',
          description: 'Prettier options',
        },
      },
      required: ['files'],
    },
  • Registration of the 'format_code' tool in the lintingTools array, including name, description, and schema.
    {
      name: 'format_code',
      description: 'Format code files using Prettier',
      inputSchema: {
        type: 'object',
        properties: {
          files: {
            type: 'array',
            items: { type: 'string' },
            description: 'File paths to format',
          },
          options: {
            type: 'object',
            description: 'Prettier options',
          },
        },
        required: ['files'],
      },
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool formats code files using Prettier, implying a mutation operation that modifies files. However, it doesn't disclose critical behaviors: whether formatting is in-place or creates new files, what happens on errors, if it requires write permissions, or any rate limits. For a mutation tool with zero annotation coverage, this is a significant gap.

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 a single, efficient sentence: 'Format code files using Prettier'. It is front-loaded with the core purpose, has zero wasted words, and is appropriately sized for a tool with clear parameters and context. Every part of the sentence earns its place by specifying the action, resource, and method.

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

Completeness3/5

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

Given the complexity (a mutation tool with 2 parameters, no output schema, and no annotations), the description is minimally complete. It states what the tool does but lacks details on behavior, usage context, or output. Without annotations or output schema, it should provide more guidance on results or errors, but it's adequate as a basic overview, leaving gaps in practical application.

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?

Schema description coverage is 100%, with both parameters ('files' and 'options') fully described in the schema. The description adds no additional meaning beyond what the schema provides, such as examples of file paths or common Prettier options. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, but the description doesn't compensate or enhance parameter understanding.

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 action ('format') and resource ('code files'), specifying the tool as 'Format code files using Prettier'. It distinguishes from sibling tools like 'fix_lint_issues' or 'validate_syntax' by focusing on formatting rather than fixing or validating. However, it doesn't explicitly differentiate from 'format_scraped_data', which is a formatting tool for different content.

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 choose it over 'lint_code' (which might include formatting) or 'format_scraped_data', nor does it specify prerequisites like needing Prettier installed or appropriate file types. Usage is implied by the name and description but not explicitly stated.

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/code-alchemist01/development-tools-mcp-Server'

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