Skip to main content
Glama
TheAlchemist6

CodeCompass MCP

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
NameRequiredDescriptionDefault
codeYesSource code to transform
transformationsYesList of transformations to apply
languageYesProgramming language of the code
target_languageNoTarget language (for language conversion)
target_frameworkNoTarget framework (for framework migration)
optionsNo

Implementation Reference

  • 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 handler
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: consolidatedTools,
      };
    });
  • MCP tool handler for 'transform_code' that extracts arguments and delegates to RefactorService.transformCode
    async 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);
      }
    }
  • Core implementation of code transformation logic in RefactorService, applying specified transformations
    async 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' tool
    case 'transform_code':
      result = await handleTransformCode(args);
      break;

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/TheAlchemist6/codecompass-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server