@j0hanz/code-review-analyst-mcp 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { validateContextBudget } from '../lib/context-budget.js';
2
2
  import { computeDiffStatsAndSummaryFromFiles } from '../lib/diff-parser.js';
3
- import { requireToolContract } from '../lib/tool-contracts.js';
3
+ import { buildStructuredToolRuntimeOptions, requireToolContract, } from '../lib/tool-contracts.js';
4
4
  import { registerStructuredToolTask } from '../lib/tool-factory.js';
5
5
  import { InspectCodeQualityInputSchema } from '../schemas/inputs.js';
6
6
  import { CodeQualityOutputSchema, CodeQualityResultSchema, } from '../schemas/outputs.js';
@@ -10,12 +10,16 @@ const PATH_ESCAPE_REPLACEMENTS = {
10
10
  '"': '\\"',
11
11
  '\n': ' ',
12
12
  '\r': ' ',
13
+ '<': '&lt;',
14
+ '>': '&gt;',
13
15
  };
14
- const PATH_ESCAPE_PATTERN = /["\n\r]/g;
16
+ const PATH_ESCAPE_PATTERN = /["\n\r<>]/g;
15
17
  const SYSTEM_INSTRUCTION = `
16
- You are a principal engineer performing a deep code review. Identify bugs, security vulnerabilities, performance issues, and maintainability risks from the diff and file context.
17
- Ignore style issues unless they cause runtime risk. Prioritize correctness and failure modes.
18
- Return strict JSON only.
18
+ Principal Engineer Code Review.
19
+ Source: Unified diff (primary), File excerpts (supplementary context).
20
+ Goal: Identify bugs, security, performance, maintainability.
21
+ Ignore style. Prioritize correctness/failure modes.
22
+ Return strict JSON.
19
23
  `;
20
24
  const TOOL_CONTRACT = requireToolContract('inspect_code_quality');
21
25
  export function sanitizePath(path) {
@@ -38,21 +42,20 @@ function formatFileContext(files) {
38
42
  if (!files || files.length === 0) {
39
43
  return '';
40
44
  }
41
- const fileBlocks = [];
42
- for (const file of files) {
43
- fileBlocks.push(`
45
+ return (FILE_CONTEXT_HEADING +
46
+ files
47
+ .map((file) => `
44
48
  <<FILE path="${sanitizePath(file.path)}">>
45
49
  ${sanitizeContent(file.content)}
46
50
  <<END_FILE>>
47
- `);
48
- }
49
- return `${FILE_CONTEXT_HEADING}${fileBlocks.join('\n')}`;
51
+ `)
52
+ .join('\n'));
50
53
  }
51
54
  export function registerInspectCodeQualityTool(server) {
52
55
  registerStructuredToolTask(server, {
53
56
  name: 'inspect_code_quality',
54
57
  title: 'Inspect Code Quality',
55
- description: 'Deep code review. Prerequisite: generate_diff. Auto-infer repo/language/focus. Provide file content for best results.',
58
+ description: 'Deep code review. Prerequisite: generate_diff. Auto-infer repo/language/focus. Operates primarily on the diff; files are optional supplementary excerpts only.',
56
59
  inputSchema: InspectCodeQualityInputSchema,
57
60
  fullInputSchema: InspectCodeQualityInputSchema,
58
61
  resultSchema: CodeQualityOutputSchema,
@@ -61,15 +64,7 @@ export function registerInspectCodeQualityTool(server) {
61
64
  model: TOOL_CONTRACT.model,
62
65
  timeoutMs: TOOL_CONTRACT.timeoutMs,
63
66
  maxOutputTokens: TOOL_CONTRACT.maxOutputTokens,
64
- ...(TOOL_CONTRACT.thinkingLevel !== undefined
65
- ? { thinkingLevel: TOOL_CONTRACT.thinkingLevel }
66
- : undefined),
67
- ...(TOOL_CONTRACT.temperature !== undefined
68
- ? { temperature: TOOL_CONTRACT.temperature }
69
- : undefined),
70
- ...(TOOL_CONTRACT.deterministicJson !== undefined
71
- ? { deterministicJson: TOOL_CONTRACT.deterministicJson }
72
- : undefined),
67
+ ...buildStructuredToolRuntimeOptions(TOOL_CONTRACT),
73
68
  progressContext: (input) => {
74
69
  const fileCount = input.files?.length;
75
70
  return fileCount ? `+${fileCount} files` : '';
@@ -83,10 +78,8 @@ export function registerInspectCodeQualityTool(server) {
83
78
  formatOutput: (result) => {
84
79
  const count = result.findings.length;
85
80
  const total = result.totalFindings ?? count;
86
- const findingsSuffix = count < total
87
- ? `${count} of ${total} findings reported.`
88
- : `${count} findings reported.`;
89
- return `Code Quality Inspection: ${result.summary}\n${findingsSuffix}`;
81
+ const findingsSuffix = count < total ? `${count} of ${total} findings.` : `${count} findings.`;
82
+ return `${result.summary}\n${findingsSuffix}`;
90
83
  },
91
84
  transformResult: (input, result) => {
92
85
  const totalFindings = result.findings.length;
@@ -101,7 +94,7 @@ export function registerInspectCodeQualityTool(server) {
101
94
  const languageLine = formatOptionalLine('Language', input.language);
102
95
  const maxFindingsLine = formatOptionalLine('Max Findings', input.maxFindings);
103
96
  const noFilesNote = !input.files?.length
104
- ? '\nNote: No file context provided. Leave contextualInsights empty.'
97
+ ? '\nNote: No file excerpts provided. Review based on diff only; leave contextualInsights empty.'
105
98
  : '';
106
99
  return {
107
100
  systemInstruction: SYSTEM_INSTRUCTION,
@@ -1,13 +1,14 @@
1
1
  import { extractChangedPathsFromFiles } from '../lib/diff-parser.js';
2
- import { requireToolContract } from '../lib/tool-contracts.js';
2
+ import { buildStructuredToolRuntimeOptions, requireToolContract, } from '../lib/tool-contracts.js';
3
3
  import { registerStructuredToolTask } from '../lib/tool-factory.js';
4
4
  import { SuggestSearchReplaceInputSchema } from '../schemas/inputs.js';
5
5
  import { SearchReplaceResultSchema } from '../schemas/outputs.js';
6
6
  const SYSTEM_INSTRUCTION = `
7
- You are a code remediation expert. Generate minimal search-and-replace blocks to fix exactly the described issue.
8
- CRITICAL: 'search' must be verbatim — character-exact whitespace and indentation.
9
- Never modify code outside the fix scope. If the target cannot be located precisely, omit the block rather than guessing.
10
- Return strict JSON only.
7
+ Code Remediation Expert.
8
+ Generate minimal search/replace blocks for described issue.
9
+ CRITICAL: 'search' must be verbatim (exact whitespace/indentation).
10
+ No out-of-scope changes. Omit if imprecise.
11
+ Return strict JSON.
11
12
  `;
12
13
  const TOOL_CONTRACT = requireToolContract('suggest_search_replace');
13
14
  function formatPatchCount(count) {
@@ -25,21 +26,13 @@ export function registerSuggestSearchReplaceTool(server) {
25
26
  model: TOOL_CONTRACT.model,
26
27
  timeoutMs: TOOL_CONTRACT.timeoutMs,
27
28
  maxOutputTokens: TOOL_CONTRACT.maxOutputTokens,
28
- ...(TOOL_CONTRACT.thinkingLevel !== undefined
29
- ? { thinkingLevel: TOOL_CONTRACT.thinkingLevel }
30
- : undefined),
31
- ...(TOOL_CONTRACT.temperature !== undefined
32
- ? { temperature: TOOL_CONTRACT.temperature }
33
- : undefined),
34
- ...(TOOL_CONTRACT.deterministicJson !== undefined
35
- ? { deterministicJson: TOOL_CONTRACT.deterministicJson }
36
- : undefined),
29
+ ...buildStructuredToolRuntimeOptions(TOOL_CONTRACT),
37
30
  requiresDiff: true,
38
31
  formatOutcome: (result) => formatPatchCount(result.blocks.length),
39
32
  formatOutput: (result) => {
40
33
  const count = result.blocks.length;
41
34
  const patches = formatPatchCount(count);
42
- return `${result.summary}\n${patches} • Checklist: ${result.validationChecklist.join(' | ')}`;
35
+ return `${result.summary}\n${patches} • ${result.validationChecklist.join(' | ')}`;
43
36
  },
44
37
  buildPrompt: (input, ctx) => {
45
38
  const diff = ctx.diffSlot?.diff ?? '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@j0hanz/code-review-analyst-mcp",
3
- "version": "1.5.3",
3
+ "version": "1.6.0",
4
4
  "mcpName": "io.github.j0hanz/code-review-analyst",
5
5
  "description": "Gemini-powered MCP server for code review analysis.",
6
6
  "type": "module",