Skip to main content
Glama
rodhayl
by rodhayl

refactor_helper

Provides naming suggestions and extraction hints for selected code to improve readability and maintainability.

Instructions

Naming suggestions and extraction hints for selected code.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction: suggest_names (better variable/function names), extract_function (suggest function extraction)
codeYesCode snippet to process
languageNoProgramming language (optional)
styleNoFor suggest_names: naming convention (default: auto)
selectionNoFor extract_function: specific code portion to extract (optional)

Implementation Reference

  • The 'refactor_helper' tool is implemented within the 'CodeAssistanceTools' class, specifically using LLM wrappers for 'suggestNames' (lines 520-576) and 'extractFunction' (lines 582-651). Both functions call 'this.llmWrapper.callToolLlm' with the identifier 'refactor_helper'.
      /**
       * Suggest better names for code identifiers
       */
      async suggestNames(
        code: string,
        options?: {
          language?: string;
          focusIdentifiers?: string[];
          style?: 'camelCase' | 'snake_case' | 'PascalCase';
        }
      ): Promise<SuggestNamesResult> {
        const language = options?.language ?? 'code';
        const style = options?.style ?? 'camelCase';
    
        const prompt = `You are an expert at naming things in code. Analyze this ${language} code and suggest better, more descriptive names for variables, functions, and classes.
    
    Naming style: ${style}
    ${options?.focusIdentifiers ? `Focus on these identifiers: ${options.focusIdentifiers.join(', ')}` : 'Analyze all identifiers that could be improved'}
    
    Provide your response as JSON:
    {
      "suggestions": [
        {
          "original": "Current name",
          "suggested": ["Better name 1", "Better name 2"],
          "reasoning": "Why these names are better",
          "type": "variable|function|class|parameter"
        }
      ]
    }`;
    
        try {
          const responseText = await this.llmWrapper.callToolLlm(
            'refactor_helper',
            [
              { role: 'system', content: prompt },
              { role: 'user', content: `\`\`\`${language}\n${code}\n\`\`\`` },
            ],
            { type: 'suggest_names', language, style }
          );
    
          const parsed = this.parseJsonResponse(responseText, {
            suggestions: [],
          });
    
          return {
            success: true,
            suggestions: parsed.suggestions || [],
          };
        } catch (error) {
          return {
            success: false,
            suggestions: [],
            error: error instanceof Error ? error.message : 'Unknown error',
          };
        }
      }

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/rodhayl/mcpLocalHelper'

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