Skip to main content
Glama
rodhayl
by rodhayl

code_helper

Explain, optimize, or simplify code snippets to improve understanding, performance, or readability using local AI processing.

Instructions

Explain, optimize, or simplify code snippets.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction: explain (code explanation), optimize (performance suggestions), simplify (reduce complexity)
codeYesCode snippet to process
languageNoProgramming language (optional, auto-detected)
levelNoFor explain: detail level (default: intermediate)
focusNoFor optimize: focus area (default: all)
preserveNoFor simplify: features to preserve (optional)

Implementation Reference

  • One of the methods (explainCode) in CodeAssistanceTools that uses 'code_helper' as a tool identifier to the LLM.
      async explainCode(
        code: string,
        options?: {
          language?: string;
          depth?: 'brief' | 'detailed' | 'comprehensive';
          focusOn?: string;
        }
      ): Promise<ExplainCodeResult> {
        const depth = options?.depth ?? 'detailed';
        const language = options?.language ?? 'code';
    
        const prompt = `You are an expert code explainer. Explain the following ${language} code in plain English.
    
    Depth level: ${depth}
    ${options?.focusOn ? `Focus specifically on: ${options.focusOn}` : ''}
    
    Provide your response as JSON with these fields:
    {
      "explanation": "Clear explanation of what the code does",
      "keyPoints": ["Key point 1", "Key point 2"],
      "complexity": "Brief complexity assessment",
      "potentialIssues": ["Any potential issues or edge cases"]
    }`;
    
        try {
          const responseText = await this.llmWrapper.callToolLlm(
            'code_helper',
            [
              { role: 'system', content: prompt },
              { role: 'user', content: `\`\`\`${language}\n${code}\n\`\`\`` },
            ],
            { type: 'explain_code', language }
          );
    
          const parsed = this.parseJsonResponse(responseText, {
            explanation: responseText,
            keyPoints: [],
          });
    
          return {
            success: true,
            explanation: parsed.explanation || responseText,
            keyPoints: parsed.keyPoints || [],
            complexity: parsed.complexity,
            potentialIssues: parsed.potentialIssues,
          };
        } catch (error) {
          return {
            success: false,
            explanation: '',
            keyPoints: [],
            error: error instanceof Error ? error.message : 'Unknown error',
          };
        }
      }
  • Another method in CodeAssistanceTools (suggestOptimizations) that uses 'code_helper'.
      async suggestOptimizations(
        code: string,
        options?: {
          language?: string;
          focusAreas?: Array<'performance' | 'memory' | 'readability' | 'algorithm'>;
        }
      ): Promise<SuggestOptimizationsResult> {
        const language = options?.language ?? 'code';
        const focusAreas = options?.focusAreas ?? ['performance', 'memory', 'readability', 'algorithm'];
    
        const prompt = `You are an expert code optimizer. Analyze the following ${language} code and suggest optimizations.
    
    Focus on: ${focusAreas.join(', ')}
    
    Constraints:
    - Preserve semantics (same outputs for all inputs). Do NOT propose behavior-changing edits.
    - Call out edge cases (e.g., empty arrays/strings, null/undefined, error handling) and keep them correct.
    - If an optimization depends on assumptions, state them explicitly.
    
    Provide your response as JSON:
    {
      "suggestions": [
        {
          "type": "performance|memory|readability|algorithm",
          "description": "What to optimize",
          "impact": "high|medium|low",
          "before": "Original code snippet (optional)",
          "after": "Optimized code snippet (optional)"
        }
      ],
      "summary": "Overall assessment"
    }`;
    
        try {
          const responseText = await this.llmWrapper.callToolLlm(
            'code_helper',
            [
              { role: 'system', content: prompt },
              { role: 'user', content: `\`\`\`${language}\n${code}\n\`\`\`` },
            ],
            { type: 'optimize_code', language }
          );
    
          const parsed = this.parseJsonResponse(responseText, {
            suggestions: [],
            summary: responseText,
          });
    
          return {
            success: true,
            suggestions: parsed.suggestions || [],
            summary: parsed.summary || '',
          };
        } catch (error) {
          return {
            success: false,
            suggestions: [],
            summary: '',
            error: error instanceof Error ? error.message : 'Unknown error',
          };
        }
      }
  • Another method in CodeAssistanceTools (simplifyCode) that uses 'code_helper'.
      async simplifyCode(
        code: string,
        options?: {
          language?: string;
          preserveComments?: boolean;
        }
      ): Promise<SimplifyCodeResult> {
        const language = options?.language ?? 'code';
    
        const prompt = `You are an expert at simplifying code. Rewrite this ${language} code to be cleaner, more readable, and easier to maintain while preserving its functionality.
    
    ${options?.preserveComments ? 'Preserve existing comments.' : ''}
    
    Provide your response as JSON:
    {
      "originalComplexity": "Brief assessment of original complexity",
      "simplifiedCode": "The simplified code",
      "simplifiedComplexity": "Brief assessment of new complexity",
      "changes": ["Description of each simplification made"]
    }`;
    
        try {
          const responseText = await this.llmWrapper.callToolLlm(
            'code_helper',
            [
              { role: 'system', content: prompt },
              { role: 'user', content: `\`\`\`${language}\n${code}\n\`\`\`` },
            ],
            { type: 'simplify_code', language }
          );
    
          const parsed = this.parseJsonResponse(responseText, {
            originalComplexity: '',
            simplifiedCode: code,
            simplifiedComplexity: '',
            changes: [],
          });
    
          return {
            success: true,
            originalComplexity: parsed.originalComplexity || '',
            simplifiedCode: parsed.simplifiedCode || code,
            simplifiedComplexity: parsed.simplifiedComplexity || '',
            changes: parsed.changes || [],
          };
        } catch (error) {
          return {
            success: false,
            originalComplexity: '',
            simplifiedCode: '',
            simplifiedComplexity: '',
            changes: [],
            error: error instanceof Error ? error.message : 'Unknown error',
          };
        }
      }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full disclosure burden. Unclear whether this returns analysis text (read-only) or modifies files (destructive), and whether 'optimize'/'simplify' actions generate new code or just suggestions. Missing safety and scope disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Extremely terse at seven words. While no words are wasted, the brevity comes at the cost of critical missing information (parameter conditionality, behavioral traits) given the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Missing crucial documentation that parameters are conditional on the action value (level only for 'explain', focus only for 'optimize', preserve only for 'simplify'). No output schema means description should explain return format, which it doesn't.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema has 100% description coverage with clear enum documentation. Description merely repeats the three action types without adding syntax guidance, parameter interdependencies, or usage examples beyond what the schema already provides. Baseline score applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States three specific verbs (explain, optimize, simplify) and the resource (code snippets) clearly. However, it fails to differentiate from numerous sibling code tools like refactor_helper, suggest_refactoring, and local_code_review that likely overlap in functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides no guidance on when to select this tool versus alternatives like refactor_helper or analyze_file. No prerequisites, contextual triggers, or exclusion criteria provided despite the crowded tool namespace.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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