Skip to main content
Glama

code_review

Analyze code for bugs, style issues, performance problems, and security vulnerabilities to improve code quality and reliability.

Instructions

Provides a code review for a given file or code snippet, focusing on potential bugs, style issues, performance bottlenecks, and security vulnerabilities.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathNoThe full path to the local file containing the code to review
languageNoThe programming language of the code
code_snippetNoOptional small code snippet for quick reviews (alternative to file_path)

Implementation Reference

  • Main handler function for the code_review tool. Validates arguments, reads file or code snippet, sanitizes inputs, generates prompt using template and system prompt, calls Deepseek API for review, handles errors, and returns ToolResponse.
    export async function handler(args: unknown): Promise<ToolResponse> {
      // Validate arguments
      if (!checkRateLimit()) {
        return {
          content: [
            {
              type: 'text',
              text: 'Rate limit exceeded. Please try again later.',
            },
          ],
          isError: true,
        };
      }
    
      if (!args || typeof args !== 'object') {
        return {
          content: [
            {
              type: 'text',
              text: 'Invalid arguments provided.',
            },
          ],
          isError: true,
        };
      }
    
      // Type guard for CodeReviewArgs
      if (!('language' in args) || typeof args.language !== 'string') {
        return {
          content: [
            {
              type: 'text',
              text: 'Language parameter is required and must be a string.',
            },
          ],
          isError: true,
        };
      }
    
      try {
        let codeToReview: string;
        const typedArgs = args as CodeReviewArgs;
    
        // Get code from either file or snippet
        if (typedArgs.file_path) {
          try {
            codeToReview = await readFileContent(typedArgs.file_path);
          } catch (error) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Error reading file: ${error instanceof Error ? error.message : 'Unknown error'}`,
                },
              ],
              isError: true,
            };
          }
        } else if (typedArgs.code_snippet) {
          codeToReview = typedArgs.code_snippet;
        } else {
          return {
            content: [
              {
                type: 'text',
                text: 'Either file_path or code_snippet must be provided.',
              },
            ],
            isError: true,
          };
        }
    
        // Sanitize inputs
        const sanitizedCode = sanitizeInput(codeToReview);
        const sanitizedLanguage = sanitizeInput(typedArgs.language);
    
        // Create the complete prompt
        const prompt = createPrompt(PROMPT_TEMPLATE, {
          language: sanitizedLanguage,
          code: sanitizedCode,
        });
    
        // Make the API call
        const response = await makeDeepseekAPICall(prompt, SYSTEM_PROMPT);
    
        if (response.isError) {
          return {
            content: [
              {
                type: 'text',
                text: `Error generating code review: ${response.errorMessage || 'Unknown error'}`,
              },
            ],
            isError: true,
          };
        }
    
        // Return the formatted response
        return {
          content: [
            {
              type: 'text',
              text: response.text,
            },
          ],
        };
      } catch (error) {
        console.error('Code review tool error:', error);
        return {
          content: [
            {
              type: 'text',
              text: `Error processing code review: ${error instanceof Error ? error.message : 'Unknown error'}`,
            },
          ],
          isError: true,
        };
      }
    }
  • ToolDefinition object defining the name, description, and inputSchema (with properties file_path, language, code_snippet and oneOf requirements for either file or snippet with language).
    export const definition: ToolDefinition = {
      name: 'code_review',
      description: 'Provides a code review for a given file or code snippet, focusing on potential bugs, style issues, performance bottlenecks, and security vulnerabilities.',
      inputSchema: {
        type: 'object',
        properties: {
          file_path: {
            type: 'string',
            description: 'The full path to the local file containing the code to review',
          },
          language: {
            type: 'string',
            description: 'The programming language of the code',
          },
          code_snippet: {
            type: 'string',
            description: 'Optional small code snippet for quick reviews (alternative to file_path)',
          },
        },
        oneOf: [
          { required: ['file_path', 'language'] },
          { required: ['code_snippet', 'language'] },
        ],
      },
    };
  • src/server.ts:56-64 (registration)
    Registration of code_review tool in the ListToolsRequestSchema handler by including codeReview.definition in the tools array.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        secondOpinion.definition,
        codeReview.definition,
        designCritique.definition,
        writingFeedback.definition,
        brainstormEnhancements.definition,
      ],
    }));
  • src/server.ts:92-100 (registration)
    Registration of code_review tool in the CallToolRequestSchema switch case: validates args with isCodeReviewArgs and calls codeReview.handler(args).
    case "code_review": {
      if (!isCodeReviewArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Invalid parameters for code review"
        );
      }
      response = await codeReview.handler(args);
      break;
  • Type guard function isCodeReviewArgs used to validate arguments before calling the handler.
    export function isCodeReviewArgs(args: unknown): args is CodeReviewArgs {
      if (!args || typeof args !== 'object') return false;
      const a = args as Record<string, unknown>;
      
      // Must have either file_path or code_snippet
      const hasFilePath = 'file_path' in a && (typeof a.file_path === 'string' || a.file_path === undefined);
      const hasCodeSnippet = 'code_snippet' in a && (typeof a.code_snippet === 'string' || a.code_snippet === undefined);
      const hasLanguage = 'language' in a && typeof a.language === 'string';
      
      return hasLanguage && (hasFilePath || hasCodeSnippet);
    }
  • TypeScript interface defining the shape of CodeReviewArgs.
    export interface CodeReviewArgs {
      file_path?: string;
      language: string;
      code_snippet?: string;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions what the review focuses on (bugs, style, performance, security) but doesn't describe the output format, depth of analysis, whether it modifies code, authentication needs, rate limits, or error handling. For a tool with no annotations, 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 a single, efficient sentence that front-loads the core purpose and lists key focus areas. Every word earns its place with zero redundancy or wasted text. It's appropriately sized for this 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?

Given no annotations and no output schema, the description is incomplete for this tool's complexity. It doesn't explain what the review output looks like (structured report? list of issues?), depth of analysis, or limitations. For a code review tool with 3 parameters and no structured output documentation, the description should provide more contextual information.

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 three parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain trade-offs between file_path vs code_snippet, or language-specific considerations). Baseline 3 is appropriate when schema does the heavy lifting.

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?

The description clearly states the tool's purpose: 'Provides a code review' with specific focus areas (bugs, style, performance, security). It uses a specific verb ('Provides') and resource ('code review'), but doesn't explicitly differentiate from sibling tools like 'design_critique' or 'second_opinion' which might overlap in scope.

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. It doesn't mention when to choose 'code_review' over 'design_critique' or 'second_opinion', nor does it specify prerequisites or exclusions. The agent must infer usage from the tool name 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/cyanheads/mentor-mcp-server'

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