list-quality-rules
Retrieve code quality rules for analysis and improvement from the CodeAnalysis MCP Server.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list-quality-rules"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/features/code-quality/index.ts:47-69 (handler)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; } } ]; - src/features/code-quality/index.ts:46-69 (registration)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 }; } } );