analyze_results
Identify security vulnerabilities and code quality issues by analyzing Semgrep scan results from a JSON file.
Instructions
Analyzes scan results
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| results_file | Yes | Absolute path to JSON results file (must be within an allowed workspace root) |
Implementation Reference
- src/index.ts:476-510 (handler)Handler function for analyze_results tool. Reads a Semgrep JSON results file, parses it, and produces a summary with total findings, breakdown by severity, and breakdown by rule.
private async handleAnalyzeResults(args: any) { if (!args.results_file) { throw new McpError(ErrorCode.InvalidParams, 'Results file is required'); } const resultsFile = validateAbsolutePath(args.results_file, 'results_file'); try { const fileContent = await readFile(resultsFile, 'utf-8'); const results = parseSemgrepResults(fileContent); const findings = getSemgrepFindings(results); const summary = { total_findings: findings.length, by_severity: {} as Record<string, number>, by_rule: {} as Record<string, number> }; for (const finding of findings) { const severity = finding.extra?.severity || 'unknown'; const rule = finding.check_id || 'unknown'; summary.by_severity[severity] = (summary.by_severity[severity] || 0) + 1; summary.by_rule[rule] = (summary.by_rule[rule] || 0) + 1; } return { content: [{ type: 'text', text: JSON.stringify(summary, null, 2) }] }; } catch (error: any) { return { content: [{ type: 'text', text: `Error analyzing results: ${error.message}` }], isError: true }; } } - src/index.ts:286-297 (schema)Schema/registration for analyze_results tool. Defines the input schema requiring a 'results_file' string property.
name: 'analyze_results', description: 'Analyzes scan results', inputSchema: { type: 'object', properties: { results_file: { type: 'string', description: 'Absolute path to JSON results file (must be within an allowed workspace root)' } }, required: ['results_file'] } - src/index.ts:379-380 (registration)Tool handler dispatch - routes 'analyze_results' tool calls to handleAnalyzeResults method.
case 'analyze_results': return await this.handleAnalyzeResults(request.params.arguments); - src/index.ts:92-100 (helper)Helper used by handleAnalyzeResults to parse the JSON file content into SemgrepResults object.
export function parseSemgrepResults(fileContent: string): SemgrepResults { const parsedContent = JSON.parse(fileContent); if (!parsedContent || typeof parsedContent !== 'object' || Array.isArray(parsedContent)) { return {}; } return parsedContent as SemgrepResults; } - src/index.ts:102-104 (helper)Helper used by handleAnalyzeResults to extract the findings array from parsed results.
function getSemgrepFindings(results: SemgrepResults): SemgrepFinding[] { return Array.isArray(results.results) ? results.results : []; }