sonarqube-issue-mcp 0.0.1

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.
@@ -0,0 +1,207 @@
1
+ /**
2
+ * 控制返回结果是否补充规则说明等重字段。
3
+ *
4
+ * @remarks
5
+ * - `standard`: 只返回常规排查字段
6
+ * - `full`: 额外返回规则描述、修复建议等扩展字段
7
+ */
8
+ export type DetailLevel = "standard" | "full";
9
+ /**
10
+ * MCP 详情查询目前支持的实体类型。
11
+ *
12
+ * @remarks
13
+ * `issue` 对应 SonarQube 的常规 issue,`hotspot` 对应 Security Hotspot。
14
+ */
15
+ export type FindingKind = "issue" | "hotspot";
16
+ /**
17
+ * 将 SonarQube 原始问题重新映射为 MCP 输出侧的稳定分类。
18
+ *
19
+ * @remarks
20
+ * 这里不沿用 SonarQube 的所有类型,而是只暴露本项目当前关心的三类:
21
+ * Security、Reliability、Security Hotspot。
22
+ */
23
+ export type FindingCategory = "security" | "reliability" | "security-hotspot";
24
+ /**
25
+ * 从 SonarQube dashboard URL 中解析出的项目定位信息。
26
+ *
27
+ * @remarks
28
+ * 这是后续所有 SonarQube API 请求共享的上下文载体。
29
+ */
30
+ export interface ProjectRef {
31
+ /** SonarQube 服务根地址,例如 `https://sonarqube.example.com`。 */
32
+ origin: string;
33
+ /** 项目标识,对应 dashboard URL 中的 `id` 参数。 */
34
+ projectKey: string;
35
+ /** 可选分支名;community 版通常为空。 */
36
+ branch: string | null;
37
+ /** 可选 PR 编号;community 版通常为空。 */
38
+ pullRequest: string | null;
39
+ /** 用户原始传入的 dashboard URL。 */
40
+ dashboardUrl: string;
41
+ }
42
+ /**
43
+ * SonarQube 返回的行列范围信息。
44
+ *
45
+ * @remarks
46
+ * 与编辑器中的高亮区间或 Sonar 页面中的定位区域一一对应。
47
+ */
48
+ export interface TextRange {
49
+ /** 高亮区域起始行号。 */
50
+ startLine: number;
51
+ /** 高亮区域结束行号。 */
52
+ endLine: number;
53
+ /** 起始列偏移。 */
54
+ startOffset: number;
55
+ /** 结束列偏移。 */
56
+ endOffset: number;
57
+ }
58
+ /**
59
+ * SonarQube 新版 issue impacts 字段中的单条影响描述。
60
+ *
61
+ * @remarks
62
+ * 新版规则/问题模型会用 `softwareQuality + severity` 组合表达影响级别。
63
+ */
64
+ export interface FindingImpact {
65
+ /** 受影响的软件质量维度,例如 `SECURITY`。 */
66
+ softwareQuality: string;
67
+ /** 该质量维度下的严重程度。 */
68
+ severity: string;
69
+ }
70
+ /**
71
+ * 项目级基础信息,供 MCP 汇总和详情接口复用。
72
+ *
73
+ * @remarks
74
+ * 这部分字段被设计成稳定结构,方便客户端直接缓存或展示。
75
+ */
76
+ export interface ProjectInfo {
77
+ /** 项目 key。 */
78
+ key: string;
79
+ /** 项目名称。 */
80
+ name: string;
81
+ /** SonarQube 组件限定符,例如 `TRK`。 */
82
+ qualifier: string | null;
83
+ /** 当前查询绑定的分支。 */
84
+ branch: string | null;
85
+ /** 当前查询绑定的 PR。 */
86
+ pullRequest: string | null;
87
+ /** 用户原始传入的 dashboard URL。 */
88
+ dashboardUrl: string;
89
+ /** 标准化后的项目浏览链接。 */
90
+ browseUrl: string;
91
+ /** SonarQube 服务版本。 */
92
+ serverVersion: string;
93
+ }
94
+ /**
95
+ * MCP 对单条问题的统一摘要结构。
96
+ *
97
+ * @remarks
98
+ * 这里刻意把 issue 与 hotspot 归一成一套字段,方便上层 LLM 或客户端统一消费。
99
+ */
100
+ export interface FindingSummary {
101
+ /** 问题唯一 key。 */
102
+ key: string;
103
+ /** 底层实体类型。 */
104
+ kind: FindingKind;
105
+ /** MCP 归一化后的业务分类。 */
106
+ category: FindingCategory;
107
+ /** SonarQube 规则 key。 */
108
+ ruleKey: string;
109
+ /** 规则展示名。 */
110
+ ruleName: string | null;
111
+ /** 问题主消息。 */
112
+ message: string;
113
+ /** 当前状态。 */
114
+ status: string;
115
+ /** 当前处理结论;未设置时为空。 */
116
+ resolution: string | null;
117
+ /** 统一后的严重度。 */
118
+ severity: string | null;
119
+ /** Hotspot 风险概率。 */
120
+ vulnerabilityProbability: string | null;
121
+ /** 新版质量模型 impacts 列表。 */
122
+ impacts: FindingImpact[];
123
+ /** Clean Code 属性。 */
124
+ cleanCodeAttribute: string | null;
125
+ /** 相对文件路径。 */
126
+ file: string | null;
127
+ /** 问题所在行号。 */
128
+ line: number | null;
129
+ /** 更精细的文本范围。 */
130
+ textRange: TextRange | null;
131
+ /** 作者信息。 */
132
+ author: string | null;
133
+ /** 负责人信息。 */
134
+ assignee: string | null;
135
+ /** 规则或问题标签。 */
136
+ tags: string[];
137
+ /** 创建时间。 */
138
+ createdAt: string;
139
+ /** 最后更新时间。 */
140
+ updatedAt: string;
141
+ /** 指向 SonarQube 页面的深链。 */
142
+ sonarUrl: string;
143
+ /** 规则描述文本。 */
144
+ ruleDescription: string | null;
145
+ /** Hotspot 风险说明。 */
146
+ riskDescription: string | null;
147
+ /** Hotspot 修复建议。 */
148
+ fixRecommendations: string | null;
149
+ /** Hotspot 漏洞说明。 */
150
+ vulnerabilityDescription: string | null;
151
+ }
152
+ /**
153
+ * 项目级汇总统计信息。
154
+ *
155
+ * @remarks
156
+ * 所有计数都基于当前 MCP 固定查询口径计算,而不是 Sonar 页面的全部历史数据。
157
+ */
158
+ export interface ProjectFindingsSummary {
159
+ /** Security 问题数量。 */
160
+ securityIssueCount: number;
161
+ /** Reliability 问题数量。 */
162
+ reliabilityIssueCount: number;
163
+ /** Security Hotspots 数量。 */
164
+ securityHotspotCount: number;
165
+ /** 三类问题总数。 */
166
+ totalFindings: number;
167
+ /** 当前结果生成时使用的详情级别。 */
168
+ detailLevel: DetailLevel;
169
+ }
170
+ /**
171
+ * `sonarqube_get_project_findings` 的结构化返回体。
172
+ *
173
+ * @remarks
174
+ * 三个数组已按服务层预定义规则完成排序,可直接展示或继续追问。
175
+ */
176
+ export interface ProjectFindingsResult {
177
+ /** 项目基础信息。 */
178
+ project: ProjectInfo;
179
+ /** 数量汇总。 */
180
+ summary: ProjectFindingsSummary;
181
+ /** Security 问题列表。 */
182
+ securityIssues: FindingSummary[];
183
+ /** Reliability 问题列表。 */
184
+ reliabilityIssues: FindingSummary[];
185
+ /** Security Hotspot 列表。 */
186
+ securityHotspots: FindingSummary[];
187
+ }
188
+ /**
189
+ * `sonarqube_get_finding_detail` 的结构化返回体。
190
+ *
191
+ * @remarks
192
+ * `raw` 保留底层 SonarQube 返回,便于出现歧义时做问题排查。
193
+ */
194
+ export interface FindingDetail {
195
+ /** 项目基础信息。 */
196
+ project: ProjectInfo;
197
+ /** 统一摘要。 */
198
+ summary: FindingSummary;
199
+ /** 问题评论;issue 与 hotspot 的原始结构不同,因此保留为原始数组。 */
200
+ comments: unknown[];
201
+ /** issue/hotspot 的历史变更记录。 */
202
+ changelog: unknown[];
203
+ /** SonarQube 提供的 execution/data flow。 */
204
+ flows: unknown[];
205
+ /** 调试与追查问题时使用的原始 API 返回。 */
206
+ raw: unknown;
207
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "sonarqube-issue-mcp",
3
+ "version": "0.0.1",
4
+ "description": "基于 SonarQube 项目链接查询 Security、Reliability 和 Security Hotspots 问题的 MCP 服务。",
5
+ "type": "module",
6
+ "bin": {
7
+ "sonarqube-issue-mcp": "./bin/sonarqube-issue-mcp.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=20.0.0"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "dev": "tsx watch src/index.ts",
20
+ "prepack": "pnpm build",
21
+ "prepublishOnly": "pnpm test && pnpm build",
22
+ "start": "node dist/index.js",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest"
25
+ },
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "1.27.1",
28
+ "undici": "7.24.4",
29
+ "zod": "4.3.6"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "25.5.0",
33
+ "tsx": "4.21.0",
34
+ "typescript": "5.9.3",
35
+ "vitest": "4.1.0"
36
+ }
37
+ }