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

NameRequiredDescriptionDefault
codeYesThe code to lint
languageYesProgramming language
rulesNoSpecific rules to check

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "code": { "description": "The code to lint", "type": "string" }, "language": { "description": "Programming language", "type": "string" }, "rules": { "description": "Specific rules to check", "items": { "type": "string" }, "type": "array" } }, "required": [ "code", "language" ], "type": "object" }

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 }],

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