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
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | Language of the code (e.g., javascript, python, rust) | |
| path | Yes | Path 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
- src/router/operation-router.ts:446-453 (handler)Core handler for 'format_code' tool: creates an edit session and delegates formatting to EditInstanceManagercase '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 processresult = 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 annotationsmcpServer.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/index.ts:249-261 (schema)Input schema definition for format_code toolinputSchema: { 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' executorconst complexOperations = [ 'interactive_edit_session', 'format_code', 'complex_find_replace', 'merge_conflicts_resolution', 'bulk_edit_operation', 'edit_with_context_awareness' ];