transform_code
Apply code transformations to modernize, migrate frameworks, improve structure, or convert syntax while preserving logic and comments.
Instructions
๐ง Apply code transformations including syntax changes, structural reorganization, framework migration, and modernization. Combines syntax-level and structural changes.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Source code to transform | |
| transformations | Yes | List of transformations to apply | |
| language | Yes | Programming language of the code | |
| target_language | No | Target language (for language conversion) | |
| target_framework | No | Target framework (for framework migration) | |
| options | No |
Implementation Reference
- src/tools/consolidated.ts:519-593 (schema)Tool schema definition for 'transform_code' including input validation schema{ name: 'transform_code', description: '๐ง Apply code transformations including syntax changes, structural reorganization, framework migration, and modernization. Combines syntax-level and structural changes.', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Source code to transform', }, transformations: { type: 'array', items: { type: 'object', properties: { type: { type: 'string', enum: ['naming', 'modernize', 'framework', 'performance', 'security', 'structure', 'migration'], description: 'Type of transformation', }, options: { type: 'object', description: 'Transformation-specific options', }, }, required: ['type'], }, description: 'List of transformations to apply', }, language: { type: 'string', description: 'Programming language of the code', }, target_language: { type: 'string', description: 'Target language (for language conversion)', }, target_framework: { type: 'string', description: 'Target framework (for framework migration)', }, options: { type: 'object', properties: { preserve_comments: { type: 'boolean', description: 'Preserve code comments', default: true, }, preserve_logic: { type: 'boolean', description: 'Preserve business logic during transformation', default: true, }, update_imports: { type: 'boolean', description: 'Update import paths automatically', default: true, }, include_instructions: { type: 'boolean', description: 'Include transformation instructions', default: true, }, validate_syntax: { type: 'boolean', description: 'Validate syntax after transformation', default: true, }, }, }, }, required: ['code', 'transformations', 'language'], }, },
- src/index.ts:236-240 (registration)Registration of all tools including 'transform_code' via consolidatedTools in ListToolsRequestSchema handlerserver.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: consolidatedTools, }; });
- src/index.ts:559-577 (handler)MCP tool handler for 'transform_code' that extracts arguments and delegates to RefactorService.transformCodeasync function handleTransformCode(args: any) { try { const { code, transformations, language, target_language, options = {} } = args; const result = await refactorService.transformCode( code, transformations, language, target_language, options ); const response = createResponse(result); return formatToolResponse(response); } catch (error) { const response = createResponse(null, error); return formatToolResponse(response); } }
- src/services/refactor.ts:1086-1119 (handler)Core implementation of code transformation logic in RefactorService, applying specified transformationsasync transformCode(code: string, transformations: any[], language: string, target_language?: string, options: any = {}): Promise<any> { let transformedCode = code; const changes = []; const warnings = []; for (const transformation of transformations) { switch (transformation.type) { case 'naming': const namingResult = await this.transformNamingConvention(transformedCode, transformation.options); transformedCode = namingResult.code; changes.push(...namingResult.changes); break; case 'modernize': const modernizeResult = await this.modernizeCode(transformedCode, language); transformedCode = modernizeResult.refactoredCode; changes.push(...modernizeResult.changes); break; case 'performance': warnings.push('Performance optimization not implemented'); break; case 'security': warnings.push('Security transformation not implemented'); break; } } return { originalCode: code, transformedCode, changes, warnings, instructions: ['Review transformed code for correctness'], }; }
- src/index.ts:285-287 (registration)Dispatch routing in CallToolRequestSchema handler for 'transform_code' toolcase 'transform_code': result = await handleTransformCode(args); break;