Skip to main content
Glama

reflect_on_code

Analyze code for quality, security, performance, and maintainability issues. Receive structured critiques with specific improvement suggestions to enhance your programming projects.

Instructions

Provides a structured critique of code, analyzing quality, security, performance, and maintainability. Returns specific improvement suggestions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe code to analyze
languageYesProgramming language of the code
focusNoAreas to focus analysis on

Implementation Reference

  • The handler function that implements the core logic of the 'reflect_on_code' tool. It takes code, language, and optional focus areas, then generates a structured markdown report analyzing quality, security, performance, and maintainability.
    export function reflectOnCodeHandler(args: any) {
        const { code, language, focus = ["all"] } = args;
        const lines = code.split("\n").length;
    
        const reflection = `# Code Reflection: ${language}
    
    ## Overview
    - **Lines of Code**: ${lines}
    - **Language**: ${language}
    - **Focus Areas**: ${focus.join(", ")}
    
    ## Quality Analysis
    ${focus.includes("quality") || focus.includes("all") ? `
    ### Strengths
    - Code structure appears organized
    - Follows basic conventions
    
    ### Improvements Needed
    - Consider adding more descriptive variable names
    - Add JSDoc/docstrings for public functions
    - Break down functions longer than 20 lines
    ` : "Not analyzed"}
    
    ## Security Analysis
    ${focus.includes("security") || focus.includes("all") ? `
    ### Checklist
    - [ ] Input validation present?
    - [ ] No hardcoded secrets?
    - [ ] Proper error handling?
    - [ ] SQL injection prevention?
    - [ ] XSS prevention?
    
    ### Recommendations
    - Validate all user inputs
    - Use parameterized queries
    - Sanitize output appropriately
    ` : "Not analyzed"}
    
    ## Performance Analysis
    ${focus.includes("performance") || focus.includes("all") ? `
    ### Considerations
    - Check for O(n²) or worse algorithms
    - Look for unnecessary iterations
    - Consider caching opportunities
    - Avoid blocking operations
    
    ### Recommendations
    - Profile before optimizing
    - Use appropriate data structures
    - Consider lazy evaluation
    ` : "Not analyzed"}
    
    ## Maintainability Analysis
    ${focus.includes("maintainability") || focus.includes("all") ? `
    ### Metrics
    - Single Responsibility: Review needed
    - DRY Principle: Check for duplication
    - Coupling: Assess dependencies
    
    ### Recommendations
    - Add comprehensive tests
    - Document complex logic
    - Use consistent naming
    ` : "Not analyzed"}
    
    ## Action Items
    1. Address security concerns first
    2. Add missing documentation
    3. Implement suggested improvements
    4. Add/improve tests
    `;
    
        return {
            content: [{ type: "text", text: reflection }]
        };
    }
  • The schema definition for the 'reflect_on_code' tool, including name, description, and Zod input schema for validation.
    export const reflectOnCodeSchema = {
        name: "reflect_on_code",
        description: "Provides a structured critique of code, analyzing quality, security, performance, and maintainability. Returns specific improvement suggestions.",
        inputSchema: z.object({
            code: z.string().describe("The code to analyze"),
            language: z.string().describe("Programming language of the code"),
            focus: z.array(z.enum(["quality", "security", "performance", "maintainability", "all"])).optional().describe("Areas to focus analysis on")
        })
    };
  • src/index.ts:80-80 (registration)
    Registration of the 'reflect_on_code' tool in the main tool registry Map used by the stdio server.
    ["reflect_on_code", { schema: reflectOnCodeSchema, handler: reflectOnCodeHandler }],
  • src/server.ts:90-90 (registration)
    Registration of the 'reflect_on_code' tool in the HTTP server's tool registry Map.
    ["reflect_on_code", { schema: reflectOnCodeSchema, handler: reflectOnCodeHandler }],
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool provides a 'structured critique' and 'returns specific improvement suggestions', but lacks details on response format, depth of analysis, computational cost, or any limitations. For a tool with 3 parameters and no output schema, this leaves significant behavioral gaps.

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

Conciseness5/5

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

The description is efficiently structured in two sentences: the first states the core function, and the second specifies the return value. Every word earns its place with no redundancy or fluff, making it easy to parse and understand quickly.

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

Completeness3/5

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

Given 3 parameters with full schema coverage but no annotations or output schema, the description adequately covers the tool's purpose and return type. However, it lacks details on behavioral aspects like analysis depth, response structure, or error handling, which would be helpful for a tool performing complex code analysis without structured output documentation.

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 description coverage is 100%, so the schema already documents all parameters thoroughly. The description mentions 'analyzing quality, security, performance, and maintainability', which aligns with the 'focus' parameter's enum values, but adds no additional semantic context beyond what the schema provides. This meets the baseline for high schema coverage.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('provides a structured critique', 'analyzing') and resources ('code'), covering quality, security, performance, and maintainability. It distinguishes from siblings like 'lint_code' or 'validate_code' by emphasizing comprehensive analysis and improvement suggestions rather than just validation or formatting.

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?

The description provides no guidance on when to use this tool versus alternatives like 'lint_code', 'validate_code', or 'explain_code'. It mentions analysis areas but doesn't specify contexts where this tool is preferred over siblings, leaving the agent to infer usage based on tool names alone.

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/millsydotdev/Code-MCP'

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