Skip to main content
Glama

format_code

Idempotent

Format code files to improve readability and maintain consistency by automatically adjusting indentation, spacing, and structure based on the programming language.

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' MCP tool including its input schema, description, and annotations.
    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
      }
    });
  • Executes the 'format_code' tool by invoking an 'edit' command with 'format' action on the EditInstanceManager for the specified language.
    case 'format_code':
      return this.editInstanceManager.executeEditCommand(sessionId, {
        type: 'edit',
        params: {
          action: 'format',
          language: operation.params.language
        }
      });
  • Implements the generic 'edit' command sent to the Edit process, which handles the 'format' action for format_code tool.
    // This is a simplified approach; in a real implementation, we would need
    // to handle different types of edits (insert, delete, replace, etc.)
    result = await instance.executeCommand(`edit ${JSON.stringify(command.params)}`);
    return { success: true, message: result };
  • Classifies 'format_code' as a complex operation for routing decisions.
    const complexOperations = [
      'interactive_edit_session',
      'format_code',
      'complex_find_replace',
      'merge_conflicts_resolution',
      'bulk_edit_operation',
      'edit_with_context_awareness'
    ];
  • Provides a REST API endpoint (/api/format) that calls the 'format_code' MCP tool.
    this.app.post('/api/format', async (req, res) => {
      try {
        const formatRequest = parseMessage({
          jsonrpc: '2.0',
          method: 'tools/call',
          params: {
            name: 'format_code',
            arguments: {
              path: req.body.path,
              language: req.body.language
            }
          },
          id: 'rest-' + Date.now()
        });
        const response = await this.mcpServer.handleMessage(formatRequest);
        res.json(response);
      } catch (error: any) {
        res.status(500).json({ error: error.message });
      }
    });
Behavior3/5

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

Annotations indicate idempotentHint=true and destructiveHint=false, suggesting safe, repeatable operations. The description adds minimal context by implying it modifies file content (formatting), but doesn't disclose behavioral traits like formatting rules, error handling, or side effects. It doesn't contradict annotations, but adds little beyond them.

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 with zero waste. It's front-loaded and appropriately sized for a simple tool, making it easy to parse quickly without unnecessary details.

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), lack of output schema, and rich annotations, the description is minimally adequate. It states the action but omits details like formatting standards, return values, or error cases. With annotations covering safety, it's complete enough for basic use but has clear gaps.

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 'path' and 'language'. The description doesn't add meaning beyond the schema, such as explaining how formatting varies by language or path constraints. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't detract.

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 'Format code in a file' clearly states the verb ('format') and resource ('code in a file'), but it's vague about what formatting entails (e.g., style rules, indentation) and doesn't distinguish it from siblings like 'smart_refactor' or 'write_file'. It provides a basic purpose but lacks specificity.

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. It doesn't mention prerequisites (e.g., file must exist), exclusions (e.g., not for binary files), or comparisons to siblings like 'write_file' for editing or 'smart_refactor' for structural changes. The description offers no usage context.

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

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