Skip to main content
Glama

lint_code

Analyzes code for style issues, potential bugs, and best practice violations to improve code quality and maintainability.

Instructions

Analyzes code for style issues, potential bugs, and best practice violations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe code to lint
languageYesProgramming language
rulesNoSpecific rules to check

Implementation Reference

  • The core handler function that performs linting analysis on provided code, checking for universal issues like line length, tabs, trailing spaces, and language-specific rules for JavaScript/TypeScript and Python. Generates a formatted report with errors, warnings, and a score.
    export function lintCodeHandler(args: any) {
        const { code, language, rules = [] } = args;
        const lines = code.split("\n");
        const warnings: string[] = [];
        const errors: string[] = [];
    
        lines.forEach((line: string, i: number) => {
            const lineNum = i + 1;
    
            // Universal checks
            if (line.length > 120) {
                warnings.push(`Line ${lineNum}: Line exceeds 120 characters (${line.length})`);
            }
            if (line.includes("\t")) {
                warnings.push(`Line ${lineNum}: Tab character detected - prefer spaces`);
            }
            if (line.endsWith(" ")) {
                warnings.push(`Line ${lineNum}: Trailing whitespace`);
            }
    
            // Language-specific checks
            if (language === "javascript" || language === "typescript") {
                if (line.includes("var ")) {
                    errors.push(`Line ${lineNum}: Use 'let' or 'const' instead of 'var'`);
                }
                if (line.includes("== ") && !line.includes("=== ")) {
                    warnings.push(`Line ${lineNum}: Use strict equality (===) instead of loose equality (==)`);
                }
                if (line.includes("console.log")) {
                    warnings.push(`Line ${lineNum}: console.log found - remove before production`);
                }
                if (line.includes("any")) {
                    warnings.push(`Line ${lineNum}: 'any' type detected - consider using specific type`);
                }
            }
    
            if (language === "python") {
                if (line.includes("except:") && !line.includes("except ")) {
                    errors.push(`Line ${lineNum}: Bare except clause - specify exception type`);
                }
                if (line.includes("print(") && !line.includes("# debug")) {
                    warnings.push(`Line ${lineNum}: print() found - use logging instead`);
                }
            }
        });
    
        const result = `# Lint Report: ${language}
    
    ## Summary
    - **Errors**: ${errors.length}
    - **Warnings**: ${warnings.length}
    - **Lines Analyzed**: ${lines.length}
    
    ## Errors
    ${errors.length > 0 ? errors.map(e => `- ❌ ${e}`).join("\n") : "✅ No errors"}
    
    ## Warnings
    ${warnings.length > 0 ? warnings.map(w => `- ⚠️ ${w}`).join("\n") : "✅ No warnings"}
    
    ## Score
    ${errors.length === 0 && warnings.length < 3 ? "🌟 Excellent!" : errors.length === 0 ? "👍 Good" : "⚠️ Needs improvement"}
    `;
    
        return { content: [{ type: "text", text: result }] };
    }
  • Zod schema definition for the lint_code tool, specifying input parameters: code (string), language (string), and optional rules (array of strings).
    export const lintCodeSchema = {
        name: "lint_code",
        description: "Analyzes code for style issues, potential bugs, and best practice violations.",
        inputSchema: z.object({
            code: z.string().describe("The code to lint"),
            language: z.string().describe("Programming language"),
            rules: z.array(z.string()).optional().describe("Specific rules to check")
        })
    };
  • src/index.ts:104-104 (registration)
    Registration of the lint_code tool in the toolRegistry Map used by the main MCP stdio server.
    ["lint_code", { schema: lintCodeSchema, handler: lintCodeHandler }],
  • src/server.ts:104-104 (registration)
    Registration of the lint_code tool in the toolRegistry Map used by the HTTP server.
    ["lint_code", { schema: lintCodeSchema, handler: lintCodeHandler }],
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'analyzes' implies a read-only operation, it doesn't explicitly state safety aspects like whether it modifies code, requires authentication, has rate limits, or what the output format looks like. For a tool with no annotation coverage, 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 directly states the tool's purpose without unnecessary words. It's appropriately sized for a straightforward analysis tool and front-loads the core functionality. Every word earns its place.

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 the tool has no annotations and no output schema, the description is incomplete for proper agent usage. While it states what the tool does, it lacks crucial context about behavioral traits, output format, and differentiation from similar sibling tools. For a code analysis tool with 3 parameters, this leaves significant gaps in understanding how to effectively invoke and interpret results.

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 ('code', 'language', 'rules') with their descriptions. The tool description adds no additional parameter semantics beyond what's in the schema. According to guidelines, when schema coverage is high (>80%), the baseline score is 3 even with no param info in the description.

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: 'Analyzes code for style issues, potential bugs, and best practice violations.' This specifies the verb ('analyzes') and resource ('code') with concrete analysis targets. However, it doesn't explicitly differentiate from sibling tools like 'validate_code' or 'check_imports', which appear related but may have different scopes.

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. With many sibling tools like 'validate_code', 'check_imports', and 'debug_problem' that might overlap in functionality, there's no indication of this tool's specific context, prerequisites, or exclusions. The agent must infer usage from the purpose 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