@j0hanz/code-review-analyst-mcp 1.2.1 → 1.4.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.
Files changed (55) hide show
  1. package/dist/index.js +12 -3
  2. package/dist/lib/context-budget.d.ts +2 -2
  3. package/dist/lib/context-budget.js +12 -6
  4. package/dist/lib/diff-budget.js +6 -2
  5. package/dist/lib/diff-cleaner.d.ts +12 -0
  6. package/dist/lib/diff-cleaner.js +51 -0
  7. package/dist/lib/diff-parser.js +31 -36
  8. package/dist/lib/diff-store.d.ts +22 -0
  9. package/dist/lib/diff-store.js +28 -0
  10. package/dist/lib/env-config.d.ts +1 -0
  11. package/dist/lib/env-config.js +9 -3
  12. package/dist/lib/errors.d.ts +1 -0
  13. package/dist/lib/errors.js +5 -5
  14. package/dist/lib/gemini-schema.js +2 -1
  15. package/dist/lib/gemini.js +135 -67
  16. package/dist/lib/model-config.d.ts +14 -2
  17. package/dist/lib/model-config.js +30 -6
  18. package/dist/lib/tool-contracts.d.ts +222 -0
  19. package/dist/lib/tool-contracts.js +289 -0
  20. package/dist/lib/tool-factory.d.ts +5 -1
  21. package/dist/lib/tool-factory.js +48 -54
  22. package/dist/lib/tool-response.js +10 -12
  23. package/dist/lib/types.d.ts +3 -3
  24. package/dist/prompts/index.js +47 -41
  25. package/dist/resources/index.d.ts +1 -1
  26. package/dist/resources/index.js +99 -18
  27. package/dist/resources/instructions.d.ts +1 -0
  28. package/dist/resources/instructions.js +69 -0
  29. package/dist/resources/server-config.d.ts +1 -0
  30. package/dist/resources/server-config.js +71 -0
  31. package/dist/resources/tool-catalog.d.ts +1 -0
  32. package/dist/resources/tool-catalog.js +39 -0
  33. package/dist/resources/tool-info.d.ts +5 -0
  34. package/dist/resources/tool-info.js +122 -0
  35. package/dist/resources/workflows.d.ts +1 -0
  36. package/dist/resources/workflows.js +72 -0
  37. package/dist/schemas/inputs.d.ts +6 -5
  38. package/dist/schemas/inputs.js +17 -29
  39. package/dist/schemas/outputs.d.ts +17 -1
  40. package/dist/schemas/outputs.js +84 -52
  41. package/dist/server.js +28 -27
  42. package/dist/tools/analyze-complexity.d.ts +2 -0
  43. package/dist/tools/analyze-complexity.js +51 -0
  44. package/dist/tools/analyze-pr-impact.js +32 -20
  45. package/dist/tools/detect-api-breaking.d.ts +2 -0
  46. package/dist/tools/detect-api-breaking.js +48 -0
  47. package/dist/tools/generate-diff.d.ts +2 -0
  48. package/dist/tools/generate-diff.js +71 -0
  49. package/dist/tools/generate-review-summary.js +34 -29
  50. package/dist/tools/generate-test-plan.js +38 -28
  51. package/dist/tools/index.js +11 -2
  52. package/dist/tools/inspect-code-quality.js +47 -36
  53. package/dist/tools/suggest-search-replace.js +34 -20
  54. package/package.json +1 -2
  55. package/dist/instructions.md +0 -149
@@ -1,149 +0,0 @@
1
- # CODE REVIEW ANALYST MCP INSTRUCTIONS
2
-
3
- These instructions are available as a resource (internal://instructions) or prompt (get-help). Load them when unsure about tool usage.
4
-
5
- ---
6
-
7
- ## CORE CAPABILITY
8
-
9
- - Domain: Gemini-powered code review analysis — accepts unified diffs and returns structured findings, impact assessments, test plans, and search/replace fixes.
10
- - Primary Resources: Unified diff text, structured JSON review results, impact assessments, test plans.
11
- - Tools: READ: `analyze_pr_impact`, `generate_review_summary`, `inspect_code_quality`, `suggest_search_replace`, `generate_test_plan`. WRITE: none.
12
-
13
- ---
14
-
15
- ## PROMPTS
16
-
17
- - `get-help`: Returns these instructions for quick recall.
18
- - `review-guide`: Guided workflow for a specific tool and focus area. Accepts `tool` and `focusArea` arguments with auto-completion.
19
-
20
- ---
21
-
22
- ## RESOURCES & RESOURCE LINKS
23
-
24
- - `internal://instructions`: This document.
25
-
26
- ---
27
-
28
- ## PROGRESS & TASKS
29
-
30
- - Include `_meta.progressToken` in requests to receive `notifications/progress` updates during Gemini processing.
31
- - Task-augmented tool calls are supported for all five tools:
32
- - Send `tools/call` with `task` to get a task id.
33
- - Poll `tasks/get` and fetch results via `tasks/result`.
34
- - Use `tasks/cancel` to abort.
35
- - Progress reports 4 steps: start → input validated → prompt prepared → model response received → completed.
36
- - Task data is stored in memory (30-minute TTL) and cleared on restart.
37
-
38
- ---
39
-
40
- ## THE "GOLDEN PATH" WORKFLOWS (CRITICAL)
41
-
42
- ### WORKFLOW A: FULL PR REVIEW
43
-
44
- 1. Call `generate_review_summary` with `diff` and `repository` to get a high-level summary, risk rating, and merge recommendation.
45
- 2. Call `inspect_code_quality` with the same `diff`, `repository`, and optionally `files` for context-aware deep review.
46
- 3. For each actionable finding, call `suggest_search_replace` with the `diff`, `findingTitle`, and `findingDetails` from step 2.
47
- NOTE: Keep `suggest_search_replace` scoped to one finding per call. Pre-check diff size < 120,000 chars before any call.
48
-
49
- ### WORKFLOW B: IMPACT ASSESSMENT
50
-
51
- 1. Call `analyze_pr_impact` with `diff` and `repository` to get severity, categories, breaking changes, and rollback complexity.
52
- 2. Call `generate_review_summary` with the same `diff` for a complementary merge recommendation.
53
- NOTE: Use `analyze_pr_impact` when you need categorization (breaking_change, api_change, etc.) and rollback assessment.
54
-
55
- ### WORKFLOW C: PATCH FROM FINDING
56
-
57
- 1. Call `inspect_code_quality` with `diff`, `repository`, and `focusAreas` to identify specific findings.
58
- 2. Pick one finding. Call `suggest_search_replace` with the same `diff`, plus `findingTitle` and `findingDetails` from that finding.
59
- 3. Validate the returned `blocks[]` before applying — `search` text must match file content exactly.
60
- NOTE: Never batch multiple findings into one `suggest_search_replace` call.
61
-
62
- ### WORKFLOW D: TEST COVERAGE
63
-
64
- 1. Call `generate_test_plan` with `diff`, `repository`, and optionally `testFramework` and `maxTestCases`.
65
- 2. Review `testCases[]` ordered by priority: `must_have` → `should_have` → `nice_to_have`.
66
- NOTE: Combine with `inspect_code_quality` when you need finding-aware test targeting.
67
-
68
- ---
69
-
70
- ## TOOL NUANCES & GOTCHAS
71
-
72
- `analyze_pr_impact`
73
-
74
- - Purpose: Assess impact severity, categories, breaking changes, and rollback complexity for a PR diff.
75
- - Input: `diff` (required), `repository` (required), `language` (optional, defaults to auto-detect).
76
- - Output: `severity`, `categories[]`, `breakingChanges[]`, `affectedAreas[]`, `rollbackComplexity`.
77
- - Side effects: Calls external Gemini API (Flash model); does not mutate local state.
78
-
79
- `generate_review_summary`
80
-
81
- - Purpose: Produce a concise PR summary with risk rating, key changes, and merge recommendation.
82
- - Input: `diff` (required), `repository` (required), `language` (optional).
83
- - Output: `summary`, `overallRisk`, `keyChanges[]`, `recommendation`, `stats` (computed locally from diff, not by Gemini).
84
- - Gotcha: `stats` (filesChanged, linesAdded, linesRemoved) are computed from diff parsing before the Gemini call — they are always accurate.
85
-
86
- `inspect_code_quality`
87
-
88
- - Purpose: Deep code review with optional full file context for cross-reference analysis.
89
- - Input: `diff` (required), `repository` (required), `language` (optional), `focusAreas` (optional, 1–12 items), `maxFindings` (optional, 1–25), `files` (optional, 1–20 files with `path` and `content`).
90
- - Output: `summary`, `overallRisk`, `findings[]`, `testsNeeded[]`, `contextualInsights[]`, `totalFindings`.
91
- - Gotcha: Uses Pro model with thinking — slower but higher quality than Flash-based tools. Timeout is 120 seconds.
92
- - Gotcha: Combined diff + file context must stay under `MAX_CONTEXT_CHARS` (default 500,000). Provide only relevant files.
93
- - Gotcha: `maxFindings` caps results AFTER Gemini returns. `totalFindings` shows the pre-cap count.
94
- - Limits: Max 20 files, each max 100,000 chars content.
95
-
96
- `suggest_search_replace`
97
-
98
- - Purpose: Generate verbatim search-and-replace blocks to fix one specific finding.
99
- - Input: `diff` (required), `findingTitle` (3–160 chars), `findingDetails` (10–3,000 chars).
100
- - Output: `summary`, `blocks[]` (each with `file`, `search`, `replace`, `explanation`), `validationChecklist[]`.
101
- - Gotcha: Uses Pro model with thinking (120s timeout). `search` blocks must match exact verbatim text in the file.
102
- - Gotcha: Scope each call to one finding. Multi-finding calls produce mixed patch intent.
103
-
104
- `generate_test_plan`
105
-
106
- - Purpose: Create an actionable test plan with pseudocode covering changes in the diff.
107
- - Input: `diff` (required), `repository` (required), `language` (optional), `testFramework` (optional, defaults to auto-detect), `maxTestCases` (optional, 1–30).
108
- - Output: `summary`, `testCases[]` (each with `name`, `type`, `file`, `description`, `pseudoCode`, `priority`), `coverageSummary`.
109
- - Gotcha: `maxTestCases` caps results AFTER Gemini returns. Uses Flash model with thinking budget.
110
-
111
- ---
112
-
113
- ## CROSS-FEATURE RELATIONSHIPS
114
-
115
- - Use `inspect_code_quality` findings (`title` + `explanation`) as `findingTitle` + `findingDetails` for `suggest_search_replace`.
116
- - Use `generate_review_summary` for quick triage before committing to the slower `inspect_code_quality`.
117
- - All tools share the same diff budget guard, Gemini client, retry policy, and concurrency limiter.
118
- - `inspect_code_quality` is the only tool that accepts `files` for full file context — all others analyze diff only.
119
- - All tool responses include both `structuredContent` and JSON-string `content` for client compatibility.
120
-
121
- ---
122
-
123
- ## CONSTRAINTS & LIMITATIONS
124
-
125
- - Transport: stdio only.
126
- - API credentials: Require `GEMINI_API_KEY` or `GOOGLE_API_KEY` environment variable.
127
- - Model selection: `GEMINI_MODEL` env var overrides the default (gemini-2.5-flash). Pro model tools (`inspect_code_quality`, `suggest_search_replace`) always use gemini-2.5-pro regardless.
128
- - Diff size: Runtime limit defaults to 120,000 chars (`MAX_DIFF_CHARS` env override).
129
- - Context size: Combined diff + files limit defaults to 500,000 chars (`MAX_CONTEXT_CHARS` env override). Only applies to `inspect_code_quality`.
130
- - Timeout: 60 seconds default (Flash tools), 120 seconds for Pro tools. Retry count: 1 with exponential backoff.
131
- - Max output tokens: 16,384 per Gemini call.
132
- - Concurrency: `MAX_CONCURRENT_CALLS` defaults to 10. Excess calls wait up to `MAX_CONCURRENT_CALLS_WAIT_MS` (default 2,000ms).
133
- - Safety: Gemini safety thresholds default to `BLOCK_NONE`. Override with `GEMINI_HARM_BLOCK_THRESHOLD` (`BLOCK_NONE`, `BLOCK_ONLY_HIGH`, `BLOCK_MEDIUM_AND_ABOVE`, `BLOCK_LOW_AND_ABOVE`).
134
- - Task TTL: 30 minutes. Task data is in-memory and lost on process restart.
135
-
136
- ---
137
-
138
- ## ERROR HANDLING STRATEGY
139
-
140
- - `E_INPUT_TOO_LARGE`: Diff or combined context exceeded budget. → Split the diff into smaller chunks or reduce the number of `files`. Not retryable.
141
- - `E_ANALYZE_IMPACT`: Impact analysis failed. → Check API key env vars, reduce diff size, and retry. Inspect `error.kind` for classification.
142
- - `E_REVIEW_SUMMARY`: Summary generation failed. → Check connectivity/model availability and retry with same diff.
143
- - `E_INSPECT_QUALITY`: Code quality inspection failed. → Reduce diff size or file context, verify API key, and retry.
144
- - `E_SUGGEST_SEARCH_REPLACE`: Search/replace generation failed. → Verify finding inputs are specific and retry with narrower details.
145
- - `E_GENERATE_TEST_PLAN`: Test plan generation failed. → Reduce diff size and retry.
146
- - Error `kind` values: `validation` (bad input, not retryable), `budget` (size exceeded, not retryable), `upstream` (Gemini API error, retryable), `timeout` (exceeded deadline, retryable), `cancelled` (request aborted, not retryable), `internal` (unexpected, not retryable).
147
- - Missing API key: Set `GEMINI_API_KEY` or `GOOGLE_API_KEY` env var and restart.
148
- - Gemini timeout: Reduce diff/context size or increase timeout via tool config.
149
- - Empty model response: Retry — Gemini occasionally returns empty bodies under load.