Skip to main content
Glama

format_code

Automatically format code files by specifying the file path and programming language, ensuring consistent style and readability.

Instructions

Format code in a file

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "language": { "description": "Language of the code (e.g., javascript, python, rust)", "type": "string" }, "path": { "description": "Path to the file to format", "type": "string" } }, "required": [ "path" ], "type": "object" }

Implementation Reference

  • Core handler for 'format_code' tool: creates an edit session and delegates formatting to EditInstanceManager
    case 'format_code': return this.editInstanceManager.executeEditCommand(sessionId, { type: 'edit', params: { action: 'format', language: operation.params.language } });
  • Executes the 'edit' command (used for format_code) by sending formatted command to the spawned external edit process
    result = await instance.executeCommand(`edit ${JSON.stringify(command.params)}`); return { success: true, message: result };
  • src/index.ts:246-269 (registration)
    Registers the 'format_code' tool with the MCP server including input schema 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 } });
  • Input schema definition for format_code tool
    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']
  • Categorizes 'format_code' as a complex operation requiring 'edit' executor
    const complexOperations = [ 'interactive_edit_session', 'format_code', 'complex_find_replace', 'merge_conflicts_resolution', 'bulk_edit_operation', 'edit_with_context_awareness' ];

Other Tools

Related 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