format_code
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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file to format | |
| language | No | Language 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 } });
- src/router/operation-router.ts:446-453 (handler)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'; }
- src/index.ts:249-269 (schema)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 } });