Skip to main content
Glama

format_code

Idempotent

Automatically formats code in files to improve readability and maintain consistency across programming languages like JavaScript, Python, and Rust.

Instructions

Format code in a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to format
languageNoLanguage of the code (e.g., javascript, python, rust)

Implementation Reference

  • src/index.ts:246-269 (registration)
    Registers the 'format_code' tool with the MCP server, including its name, description, input schema (path required, optional language), and annotations indicating it's non-read-only, non-destructive, idempotent.
    mcpServer.registerTool({
      name: 'format_code',
      description: 'Format code in a file',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to format'
          },
          language: {
            type: 'string',
            description: 'Language of the code (e.g., javascript, python, rust)'
          }
        },
        required: ['path']
      },
      annotations: {
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false
      }
    });
  • The handler for the 'format_code' operation within the executeWithEdit method. It creates an edit session and executes an 'edit' command with action 'format' on the EditInstanceManager, passing the language if provided.
    case 'format_code':
      return this.editInstanceManager.executeEditCommand(sessionId, {
        type: 'edit',
        params: {
          action: 'format',
          language: operation.params.language
        }
      });
  • In executeEditCommand, the 'edit' case handles edit commands (including format) by sending the params as JSON to the spawned editor process via executeCommand.
    result = await instance.executeCommand(`edit ${JSON.stringify(command.params)}`);
    return { success: true, message: result };
  • Classifies 'format_code' as a complex operation in analyzeComplexity method.
    const complexOperations = [
      'interactive_edit_session',
      'format_code',
      'complex_find_replace',
      'merge_conflicts_resolution',
      'bulk_edit_operation',
      'edit_with_context_awareness'
    ];
    
    // Hybrid operations
    const hybridOperations = [
      'smart_refactor',
      'validate_and_edit',
      'backup_and_edit',
      'atomic_multi_file_edit'
    ];
    
    if (simpleOperations.includes(operation.type)) {
      return 'simple';
    } else if (complexOperations.includes(operation.type)) {
      return 'complex';
    } else if (hybridOperations.includes(operation.type)) {
      return 'medium';
    }
    
    // If not explicitly categorized, analyze based on method and params
    let complexityScore = 0;
    
    // Analyze based on method
    if (operation.method.includes('edit') || operation.method.includes('format')) {
      complexityScore += 0.5;
    }
    
    // Analyze based on params
    if (operation.params.contextAware || operation.params.advanced) {
      complexityScore += 0.3;
    }
    
    if (operation.params.regex || operation.params.pattern) {
      complexityScore += 0.2;
    }
    
    // Determine complexity level based on score
    if (complexityScore < 0.3) {
      return 'simple';
    } else if (complexityScore < 0.7) {
      return 'medium';
    } else {
      return 'complex';
    }
  • Input schema for format_code tool: requires 'path', optional 'language'.
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to format'
          },
          language: {
            type: 'string',
            description: 'Language of the code (e.g., javascript, python, rust)'
          }
        },
        required: ['path']
      },
      annotations: {
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false
      }
    });
Behavior3/5

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

Annotations cover key behavioral traits: readOnlyHint=false (implies mutation), idempotentHint=true (safe to retry), destructiveHint=false (non-destructive). The description adds minimal context beyond this, only implying it modifies file content. It doesn't disclose additional behaviors like formatting rules, error handling, or side effects (e.g., backup creation). With annotations providing a solid baseline, the description adds some value but lacks depth.

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 four words, front-loading the core purpose without any fluff. Every word earns its place: 'Format' specifies the action, 'code' the target, 'in a file' the scope. It's efficiently structured for quick comprehension, though this brevity contributes to gaps in other dimensions.

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 tool's moderate complexity (formatting code with two parameters), annotations provide good behavioral coverage, but there's no output schema. The description is minimal, lacking details on return values, error conditions, or formatting standards. It's adequate as a starting point but incomplete for confident use, especially without output schema to compensate.

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 clear descriptions for both parameters (path and language). The description adds no parameter-specific information beyond what the schema provides. It implies both parameters are used but doesn't explain their interaction (e.g., language might be inferred from path). Baseline 3 is appropriate given the schema does all the heavy lifting.

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 'Format code in a file' clearly states the action (format) and resource (code in a file), making the purpose immediately understandable. It distinguishes from siblings like 'write_file' or 'smart_refactor' by focusing specifically on formatting rather than writing or refactoring. However, it doesn't explicitly differentiate from all siblings (e.g., 'backup_and_edit' might also involve formatting), keeping it at 4 rather than 5.

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 prerequisites (e.g., file must exist), when-not-to-use scenarios (e.g., for non-code files), or direct alternatives among siblings like 'smart_refactor' for more complex code changes. This leaves the agent with minimal context for tool selection.

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/mixelpixx/edit-mcp'

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