format_code
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
| 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' 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 } });
- src/router/operation-router.ts:446-453 (handler)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' ];
- src/http/http-server.ts:257-276 (helper)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 }); } });