Skip to main content
Glama

list-quality-rules

Retrieve code quality rules for analysis and improvement from the CodeAnalysis MCP Server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The inline handler for the 'list-quality-rules' tool. It calls getQualityRules() to fetch the rules and returns them as JSON-formatted text content. Handles errors gracefully.
    server.tool( "list-quality-rules", {}, async () => { try { const rules = getQualityRules(); return { content: [{ type: "text", text: JSON.stringify(rules, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error retrieving quality rules: ${(error as Error).message}` }], isError: true }; } } );
  • Helper function called by the tool handler to retrieve all registered quality rules from the ruleRegistry.
    export function getQualityRules(): QualityRule[] { return [...ruleRegistry]; }
  • Type schema/definition for the QualityRule objects returned by the list-quality-rules tool.
    interface QualityRule { id: string; name: string; description: string; languages: string[]; severity: 'error' | 'warning' | 'info'; analyze: (content: string, filePath: string, lineIndex?: number) => QualityIssue[]; }
  • The ruleRegistry array containing all quality rule definitions that are listed by the 'list-quality-rules' tool.
    const ruleRegistry: QualityRule[] = [ // JavaScript/TypeScript rules { id: 'no-console', name: 'No Console Statements', description: 'Avoid console statements in production code', languages: ['js', 'jsx', 'ts', 'tsx'], severity: 'warning', analyze: (content, filePath) => { const issues: QualityIssue[] = []; const lines = content.split('\n'); lines.forEach((line, i) => { if (/console\.(log|warn|error|info|debug)\(/.test(line)) { issues.push({ type: 'quality', severity: 'warning', file: filePath, line: i + 1, message: 'Console statement should be removed in production code', rule: 'no-console', context: line.trim() }); } }); return issues; } }, { id: 'max-line-length', name: 'Maximum Line Length', description: 'Lines should not exceed 100 characters', languages: ['js', 'jsx', 'ts', 'tsx', 'py', 'java', 'go', 'rb'], severity: 'info', analyze: (content, filePath) => { const issues: QualityIssue[] = []; const lines = content.split('\n'); lines.forEach((line, i) => { if (line.length > 100) { issues.push({ type: 'style', severity: 'info', file: filePath, line: i + 1, message: 'Line exceeds 100 characters', rule: 'max-line-length' }); } }); return issues; } }, { id: 'no-empty-catch', name: 'No Empty Catch Blocks', description: 'Catch blocks should not be empty', languages: ['js', 'jsx', 'ts', 'tsx', 'java'], severity: 'warning', analyze: (content, filePath) => { const issues: QualityIssue[] = []; const lines = content.split('\n'); for (let i = 0; i < lines.length; i++) { if (/catch\s*\([^)]*\)\s*{/.test(lines[i])) { // Look for empty catch block let j = i + 1; let isEmpty = true; while (j < lines.length && !lines[j].includes('}')) { const trimmed = lines[j].trim(); if (trimmed !== '' && !trimmed.startsWith('//')) { isEmpty = false; break; } j++; } if (isEmpty) { issues.push({ type: 'error-handling', severity: 'warning', file: filePath, line: i + 1, message: 'Empty catch block', rule: 'no-empty-catch', context: lines[i].trim() }); } } } return issues; } }, // Generic rules for all languages { id: 'no-todo-comments', name: 'No TODO Comments', description: 'TODO comments should be addressed', languages: ['*'], severity: 'info', analyze: (content, filePath) => { const issues: QualityIssue[] = []; const lines = content.split('\n'); lines.forEach((line, i) => { if (/(?:\/\/|\/\*|#|<!--)\s*(?:TODO|FIXME|XXX)/.test(line)) { issues.push({ type: 'documentation', severity: 'info', file: filePath, line: i + 1, message: 'TODO comment found', rule: 'no-todo-comments', context: line.trim() }); } }); return issues; } } ];
  • Registers the 'list-quality-rules' tool on the MCP server within the code quality feature.
    // Register the list-quality-rules tool server.tool( "list-quality-rules", {}, async () => { try { const rules = getQualityRules(); return { content: [{ type: "text", text: JSON.stringify(rules, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error retrieving quality rules: ${(error as Error).message}` }], isError: true }; } } );

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/0xjcf/MCP_CodeAnalysis'

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