@codacy/codacy-mcp 0.2.2 → 0.2.4

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.
package/dist/index.js CHANGED
@@ -2,7 +2,9 @@
2
2
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
4
  import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
- import { OpenAPI, OrganizationService, RepositoryService, AnalysisService, SecurityService, CoverageService, } from './src/api/client/index.js';
5
+ import { OpenAPI } from './src/api/client/index.js';
6
+ import { getFileCoverageTool, listFileIssuesTool, getPullRequestGitDiffTool, getRepositoryPullRequestFilesCoverageTool, listFilesTool, listOrganizationRepositoriesTool, listPullRequestIssuesTool, listRepositoryPullRequestsTool, searchRepositoryIssuesTool, searchSecurityItemsTool, } from './src/tools/index.js';
7
+ import { getFileCoverageHandler, getFileIssuesHandler, getPullRequestGitDiffHandler, getRepositoryPullRequestFilesCoverageHandler, listFilesHandler, listPullRequestIssuesHandler, listRepositoryPullRequestsHandler, searchRepositoryIssuesHandler, searchSecurityItemsHandler, listOrganizationRepositoriesHandler, } from './src/handlers/index.js';
6
8
  OpenAPI.BASE = 'https://app.codacy.com/api/v3';
7
9
  OpenAPI.HEADERS = {
8
10
  'api-token': process.env.CODACY_ACCOUNT_TOKEN || '',
@@ -15,624 +17,53 @@ const server = new Server({
15
17
  tools: {},
16
18
  },
17
19
  });
18
- const codacyLanguages = [
19
- 'C',
20
- 'CPP',
21
- 'CSharp',
22
- 'Java',
23
- 'Go',
24
- 'Kotlin',
25
- 'Ruby',
26
- 'Scala',
27
- 'Dart',
28
- 'Python',
29
- 'TypeScript',
30
- 'Javascript',
31
- 'CoffeeScript',
32
- 'Swift',
33
- 'JSP',
34
- 'VisualBasic',
35
- 'PHP',
36
- 'PLSQL',
37
- 'SQL',
38
- 'TSQL',
39
- 'Crystal',
40
- 'Haskell',
41
- 'Elixir',
42
- 'Groovy',
43
- 'Apex',
44
- 'VisualForce',
45
- 'Velocity',
46
- 'CSS',
47
- 'HTML',
48
- 'LESS',
49
- 'SASS',
50
- 'Dockerfile',
51
- 'Terraform',
52
- 'Shell',
53
- 'Powershell',
54
- 'JSON',
55
- 'XML',
56
- 'YAML',
57
- 'Markdown',
58
- 'Cobol',
59
- 'ABAP',
60
- 'ObjectiveC',
61
- 'Rust',
62
- ];
63
- const issueCategories = [
64
- 'security',
65
- 'errorprone',
66
- 'performance',
67
- 'complexity',
68
- 'unusedcode',
69
- 'comprehensibility',
70
- 'compatibility',
71
- 'bestpractice',
72
- 'codestyle',
73
- 'documentation',
74
- ];
75
- // Tool definitions
76
- const listOrganizationRepositoriesTool = {
77
- name: 'codacy_list_repositories',
78
- description: 'List repositories in an organization with pagination',
79
- inputSchema: {
80
- type: 'object',
81
- properties: {
82
- provider: {
83
- type: 'string',
84
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
85
- },
86
- organization: {
87
- type: 'string',
88
- description: 'Organization name',
89
- },
90
- cursor: {
91
- type: 'string',
92
- description: 'Pagination cursor for next page of results',
93
- },
94
- limit: {
95
- type: 'number',
96
- description: 'Maximum number of results to return (default 100, max 100)',
97
- default: 100,
98
- },
99
- },
20
+ const toolDefinitions = {
21
+ codacy_list_organization_repositories: {
22
+ tool: listOrganizationRepositoriesTool,
23
+ handler: listOrganizationRepositoriesHandler,
100
24
  },
101
- };
102
- const searchRepositoryIssuesTool = {
103
- name: 'codacy_list_repository_issues',
104
- description: 'Lists and filters code quality issues in a repository. This is the primary tool for investigating general code quality concerns (e.g. best practices, performance, complexity, style) but NOT security issues. For security-related issues, use the SRM items tool instead. Features include:\n\n- Pagination support for handling large result sets\n- Filtering by multiple criteria including severity, category, and language\n- Author-based filtering for accountability\n- Branch-specific analysis\n- Pattern-based searching\n\nCommon use cases:\n- Code quality audits\n- Technical debt assessment\n- Style guide compliance checks\n- Performance issue investigation\n- Complexity analysis',
105
- inputSchema: {
106
- type: 'object',
107
- properties: {
108
- provider: {
109
- type: 'string',
110
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
111
- },
112
- organization: {
113
- type: 'string',
114
- description: 'Organization name on the Git provider',
115
- },
116
- repository: {
117
- type: 'string',
118
- description: 'Repository name on the Git provider organization',
119
- },
120
- body: {
121
- type: 'object',
122
- description: 'Search parameters to filter the list of issues in a repository',
123
- properties: {
124
- branchName: {
125
- type: 'string',
126
- description: 'Branch name, by default the main branch defined on the Codacy repository settings is used',
127
- },
128
- patternIds: {
129
- type: 'array',
130
- description: 'Set of code pattern identifiers',
131
- },
132
- languages: {
133
- type: 'array',
134
- description: `Set of language names, without spaces. Accepted values: ${codacyLanguages.join(', ')}`,
135
- },
136
- categories: {
137
- type: 'array',
138
- description: `Set of issue categories. Accepted values: ${issueCategories.join(', ')}`,
139
- },
140
- levels: {
141
- type: 'array',
142
- description: 'Set of issue severity levels. Accepted values: Info, Warning and Error. Codacy maps these values as follows: Info->Minor, Warning->Medium, Error->Critical',
143
- },
144
- authorEmails: {
145
- type: 'array',
146
- description: 'Set of commit author email addresses',
147
- },
148
- },
149
- },
150
- cursor: {
151
- type: 'string',
152
- description: 'Pagination cursor for next page of results',
153
- },
154
- limit: {
155
- type: 'number',
156
- description: 'Maximum number of results to return (default 100, max 100)',
157
- default: 100,
158
- },
159
- },
160
- },
161
- };
162
- const listFilesTool = {
163
- name: 'codacy_list_files',
164
- description: 'List files in a repository with pagination',
165
- inputSchema: {
166
- type: 'object',
167
- properties: {
168
- provider: {
169
- type: 'string',
170
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
171
- },
172
- organization: {
173
- type: 'string',
174
- description: 'Organization name on the Git provider',
175
- },
176
- repository: {
177
- type: 'string',
178
- description: 'Repository name on the Git provider organization',
179
- },
180
- branch: {
181
- type: 'string',
182
- description: 'Name of a repository branch enabled on Codacy',
183
- },
184
- search: {
185
- type: 'string',
186
- description: 'Filter files that include this string anywhere in their relative path',
187
- },
188
- sort: {
189
- type: 'string',
190
- description: "Field used to sort the list of files. The allowed values are 'filename', 'issues', 'grade', 'duplication', 'complexity', and 'coverage'.",
191
- },
192
- direction: {
193
- type: 'string',
194
- description: "Sort direction. Possible values are 'asc' (ascending) or 'desc' (descending).",
195
- },
196
- cursor: {
197
- type: 'string',
198
- description: 'Pagination cursor for next page of results',
199
- },
200
- limit: {
201
- type: 'number',
202
- description: 'Maximum number of results to return (default 100, max 100)',
203
- default: 100,
204
- },
205
- },
206
- },
207
- };
208
- const getFileIssuesTool = {
209
- name: 'codacy_get_file_issues',
210
- description: 'Get the issue list for a file in a repository',
211
- inputSchema: {
212
- type: 'object',
213
- properties: {
214
- provider: {
215
- type: 'string',
216
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
217
- },
218
- organization: {
219
- type: 'string',
220
- description: 'Organization name on the Git provider',
221
- },
222
- repository: {
223
- type: 'string',
224
- description: 'Repository name on the Git provider organization',
225
- },
226
- fileId: {
227
- type: 'string',
228
- description: 'Identifier of a file in a specific commit',
229
- },
230
- cursor: {
231
- type: 'string',
232
- description: 'Pagination cursor for next page of results',
233
- },
234
- limit: {
235
- type: 'number',
236
- description: 'Maximum number of results to return (default 100, max 100)',
237
- default: 100,
238
- },
239
- },
240
- },
241
- };
242
- const getFileCoverageTool = {
243
- name: 'codacy_get_file_coverage',
244
- description: 'Get coverage information for a file in the head commit of a repository branch.',
245
- inputSchema: {
246
- type: 'object',
247
- properties: {
248
- provider: {
249
- type: 'string',
250
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
251
- },
252
- organization: {
253
- type: 'string',
254
- description: 'Organization name on the Git provider',
255
- },
256
- repository: {
257
- type: 'string',
258
- description: 'Repository name on the Git provider organization',
259
- },
260
- fileId: {
261
- type: 'string',
262
- description: 'Identifier of a file in a specific commit',
263
- },
264
- },
25
+ codacy_list_srm_items: { tool: searchSecurityItemsTool, handler: searchSecurityItemsHandler },
26
+ codacy_list_repository_issues: {
27
+ tool: searchRepositoryIssuesTool,
28
+ handler: searchRepositoryIssuesHandler,
265
29
  },
266
- };
267
- const securityStatuses = {
268
- Open: ['OnTrack', 'DueSoon', 'Overdue'],
269
- Closed: ['ClosedOnTime', 'ClosedLate', 'Ignored'],
270
- };
271
- const securityCategories = [
272
- 'Auth',
273
- 'CommandInjection',
274
- 'Cookies',
275
- 'Cryptography',
276
- 'CSRF',
277
- 'DoS',
278
- 'FileAccess',
279
- 'HTTP',
280
- 'InputValidation',
281
- 'InsecureModulesLibraries',
282
- 'InsecureStorage',
283
- 'Other',
284
- 'Regex',
285
- 'SQLInjection',
286
- 'UnexpectedBehaviour',
287
- 'Visibility',
288
- 'XSS',
289
- '_other_',
290
- ];
291
- const securityScanTypes = {
292
- SAST: 'Code scanning',
293
- Secrets: 'Secret scanning',
294
- SCA: 'Dependency scanning',
295
- IaC: 'Infrastructure-as-code scanning',
296
- CICD: 'CI/CD scanning',
297
- DAST: 'Dynamic Application Security Testing',
298
- PenTesting: 'Penetration testing',
299
- };
300
- //PR endpoints
301
- const listRepositoryPullRequestsTool = {
302
- name: 'codacy_list_repository_pull_requests',
303
- description: 'List pull requests from a repository that the user has access to. You can search this endpoint for either last-updated (default), impact or merged',
304
- inputSchema: {
305
- type: 'object',
306
- properties: {
307
- provider: {
308
- type: 'string',
309
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
310
- },
311
- organization: {
312
- type: 'string',
313
- description: 'Organization name on the Git provider',
314
- },
315
- repository: {
316
- type: 'string',
317
- description: 'Repository name on the Git provider organization',
318
- },
319
- includeNotAnalyzed: {
320
- type: 'boolean',
321
- description: 'If true, includes pull requests that have not been analyzed',
322
- },
323
- cursor: {
324
- type: 'string',
325
- description: 'Pagination cursor for next page of results',
326
- },
327
- limit: {
328
- type: 'number',
329
- description: 'Maximum number of results to return (default 100, max 100)',
330
- default: 100,
331
- },
332
- },
30
+ codacy_list_repository_pull_requests: {
31
+ tool: listRepositoryPullRequestsTool,
32
+ handler: listRepositoryPullRequestsHandler,
333
33
  },
334
- };
335
- const listPullRequestIssuesTool = {
336
- name: 'codacy_list_pull_request_issues',
337
- description: 'Returns a list of issues found in a pull request. We can request either new or fixed issues.',
338
- inputSchema: {
339
- type: 'object',
340
- properties: {
341
- provider: {
342
- type: 'string',
343
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
344
- },
345
- organization: {
346
- type: 'string',
347
- description: 'Organization name on the Git provider',
348
- },
349
- repository: {
350
- type: 'string',
351
- description: 'Repository name on the Git provider organization',
352
- },
353
- pullRequestNumber: {
354
- type: 'number',
355
- description: 'Pull request number',
356
- },
357
- status: {
358
- type: 'string',
359
- description: 'Filter issues by status. Accepted values: all, new, fixed.',
360
- },
361
- onlyPotential: {
362
- type: 'boolean',
363
- description: 'If true, retrieves only potential issues',
364
- },
365
- cursor: {
366
- type: 'string',
367
- description: 'Pagination cursor for next page of results',
368
- },
369
- limit: {
370
- type: 'number',
371
- description: 'Maximum number of results to return (default 100, max 100)',
372
- default: 100,
373
- },
374
- },
34
+ codacy_list_files: { tool: listFilesTool, handler: listFilesHandler },
35
+ codacy_get_file_issues: { tool: listFileIssuesTool, handler: getFileIssuesHandler },
36
+ codacy_get_file_coverage: { tool: getFileCoverageTool, handler: getFileCoverageHandler },
37
+ codacy_get_repository_pull_request_files_coverage: {
38
+ tool: getRepositoryPullRequestFilesCoverageTool,
39
+ handler: getRepositoryPullRequestFilesCoverageHandler,
375
40
  },
376
- };
377
- const getRepositoryPullRequestFilesCoverageTool = {
378
- name: 'codacy_get_repository_pull_request_files_coverage',
379
- description: 'Get coverage information for all files in a pull request.',
380
- inputSchema: {
381
- type: 'object',
382
- properties: {
383
- provider: {
384
- type: 'string',
385
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
386
- },
387
- organization: {
388
- type: 'string',
389
- description: 'Organization name on the Git provider',
390
- },
391
- repository: {
392
- type: 'string',
393
- description: 'Repository name on the Git provider organization',
394
- },
395
- pullRequestNumber: {
396
- type: 'number',
397
- description: 'Pull request number',
398
- },
399
- },
41
+ codacy_get_pull_request_git_diff: {
42
+ tool: getPullRequestGitDiffTool,
43
+ handler: getPullRequestGitDiffHandler,
400
44
  },
401
- };
402
- const searchSecurityItemsTool = {
403
- name: 'codacy_list_srm_items',
404
- description: `Primary tool to list security items/issues/vulnerabilities/findings, results are related to the organization security and risk management (SRM) dashboard on Codacy. This tool contains pagination. Returns comprehensive security analysis including ${Object.keys(securityScanTypes).join(', ')} security issues. Provides advanced filtering by security categories, priorities, and scan types. Use this as the first tool when investigating security or compliance concerns. Map the results statuses as open issues: ${securityStatuses.Open.join(', ')}; and closed issues: ${securityStatuses.Closed.join(', ')}. Prioritize the open issues as the most important ones in the results.`,
405
- inputSchema: {
406
- type: 'object',
407
- properties: {
408
- provider: {
409
- type: 'string',
410
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
411
- },
412
- organization: {
413
- type: 'string',
414
- description: 'Organization name',
415
- },
416
- cursor: {
417
- type: 'string',
418
- description: 'Pagination cursor for next page of results',
419
- },
420
- limit: {
421
- type: 'number',
422
- description: 'Maximum number of results to return (default 100, max 100)',
423
- default: 100,
424
- },
425
- sort: {
426
- type: 'string',
427
- description: 'Sort SRM items by. Accepted values: Status, DetectedAt',
428
- },
429
- direction: {
430
- type: 'string',
431
- description: 'Sort direction (ascending or descending). Accepted values: asc, desc',
432
- },
433
- body: {
434
- type: 'object',
435
- description: 'Search parameters to filter the metrics of the security issues dashboard of an organization',
436
- properties: {
437
- repositories: {
438
- type: 'array',
439
- description: 'Repository names',
440
- },
441
- priorities: {
442
- description: 'Array of security issue priorities/severities to filter by.',
443
- type: 'array',
444
- items: {
445
- type: 'string',
446
- enum: ['Low', 'Medium', 'High', 'Critical'],
447
- },
448
- },
449
- statuses: {
450
- type: 'array',
451
- description: 'Array of security issue statuses to filter by. Must be one or more of the following values:\n\nOpen issues:\n- OnTrack\n- DueSoon\n- Overdue\n\nClosed issues:\n- ClosedOnTime\n- ClosedLate\n- Ignored',
452
- items: {
453
- type: 'string',
454
- enum: ['OnTrack', 'DueSoon', 'Overdue', 'ClosedOnTime', 'ClosedLate', 'Ignored'],
455
- },
456
- },
457
- categories: {
458
- description: 'Array of security categories to filter by.',
459
- type: 'array',
460
- items: {
461
- type: 'string',
462
- enum: securityCategories,
463
- },
464
- note: "_other_ can be used to search for issues that don't have a security category",
465
- },
466
- scanTypes: {
467
- description: 'Array of security scan types to filter by.',
468
- type: 'array',
469
- items: {
470
- type: 'string',
471
- enum: Object.keys(securityScanTypes),
472
- },
473
- mapping: securityScanTypes,
474
- },
475
- segments: {
476
- type: 'array',
477
- description: 'Set of segments ids (type number). Segment is a Codacy concept that groups repositories by different criteria',
478
- },
479
- },
480
- },
481
- },
45
+ codacy_list_pull_request_issues: {
46
+ tool: listPullRequestIssuesTool,
47
+ handler: listPullRequestIssuesHandler,
482
48
  },
483
49
  };
484
- const getPullRequestGitDiffTool = {
485
- name: 'codacy_get_pull_request_git_diff',
486
- description: 'Returns the human-readable Git diff of a pull request',
487
- inputSchema: {
488
- type: 'object',
489
- properties: {
490
- provider: {
491
- type: 'string',
492
- description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb.",
493
- },
494
- organization: {
495
- type: 'string',
496
- description: 'Organization name on the Git provider',
497
- },
498
- repository: {
499
- type: 'string',
500
- description: 'Repository name on the Git provider organization',
501
- },
502
- pullRequestNumber: {
503
- type: 'number',
504
- description: 'Pull request number',
505
- },
506
- },
507
- },
508
- };
509
- const listOrganizationRepositoriesHandler = async (args) => {
510
- const { provider, organization, limit, cursor } = args;
511
- return await OrganizationService.listOrganizationRepositories(provider, organization, cursor, limit);
512
- };
513
- const listFilesHandler = async (args) => {
514
- const { provider, organization, repository, branch, search, sort, direction, cursor, limit } = args;
515
- return await RepositoryService.listFiles(provider, organization, repository, branch, search, sort, direction, cursor, limit);
516
- };
517
- const getFileIssuesHandler = async (args) => {
518
- const { provider, organization, repository, fileId, limit, cursor } = args;
519
- return await RepositoryService.getFileIssues(provider, organization, repository, fileId, cursor, limit);
520
- };
521
- const getFileCoverageHandler = async (args) => {
522
- const { provider, organization, repository, fileId } = args;
523
- return await RepositoryService.getFileCoverage(provider, organization, repository, fileId);
524
- };
525
- const searchRepositoryIssuesHandler = async (args) => {
526
- const { provider, organization, repository, limit, cursor, body } = args;
527
- return await AnalysisService.searchRepositoryIssues(provider, organization, repository, cursor, limit, body);
528
- };
529
- const listRepositoryPullRequestsHandler = async (args) => {
530
- const { provider, organization, repository, search, includeNotAnalyzed, cursor, limit } = args;
531
- return await AnalysisService.listRepositoryPullRequests(provider, organization, repository, limit, cursor, search, includeNotAnalyzed);
532
- };
533
- const searchSecurityItemsHandler = async (args) => {
534
- const { provider, organization, cursor, limit, sort, direction, body } = args;
535
- return await SecurityService.searchSecurityItems(provider, organization, cursor, limit, sort, direction, body);
536
- };
537
- const listPullRequestIssuesHandler = async (args) => {
538
- const { provider, organization, repository, pullRequestNumber, status, onlyPotential, cursor, limit, } = args;
539
- return await AnalysisService.listPullRequestIssues(provider, organization, repository, pullRequestNumber, status, onlyPotential, cursor, limit);
540
- };
541
- const getRepositoryPullRequestFilesCoverageHandler = async (args) => {
542
- const { provider, organization, repository, pullRequestNumber } = args;
543
- return await CoverageService.getRepositoryPullRequestFilesCoverage(provider, organization, repository, pullRequestNumber);
544
- };
545
- const getPullRequestGitDiffHandler = async (args) => {
546
- const { provider, organization, repository, pullRequestNumber } = args;
547
- return await CoverageService.getPullRequestGitDiff(provider, organization, repository, pullRequestNumber);
548
- };
549
50
  // Register tools
550
- server.setRequestHandler(ListToolsRequestSchema, async () => {
551
- return {
552
- tools: [
553
- listOrganizationRepositoriesTool,
554
- searchRepositoryIssuesTool,
555
- listFilesTool,
556
- getFileIssuesTool,
557
- getFileCoverageTool,
558
- searchSecurityItemsTool,
559
- listRepositoryPullRequestsTool,
560
- listPullRequestIssuesTool,
561
- getRepositoryPullRequestFilesCoverageTool,
562
- getPullRequestGitDiffTool,
563
- ],
564
- };
565
- });
51
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
52
+ tools: Object.values(toolDefinitions).map(({ tool }) => tool),
53
+ }));
566
54
  // Register request handlers
567
55
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
568
56
  try {
569
57
  if (!request.params.arguments) {
570
58
  throw new Error('Arguments are required');
571
59
  }
572
- switch (request.params.name) {
573
- case 'codacy_list_repositories': {
574
- const result = await listOrganizationRepositoriesHandler(request.params.arguments);
575
- return {
576
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
577
- };
578
- }
579
- case 'codacy_list_files': {
580
- const result = await listFilesHandler(request.params.arguments);
581
- return {
582
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
583
- };
584
- }
585
- case 'codacy_get_file_issues': {
586
- const result = await getFileIssuesHandler(request.params.arguments);
587
- return {
588
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
589
- };
590
- }
591
- case 'codacy_get_file_coverage': {
592
- const result = await getFileCoverageHandler(request.params.arguments);
593
- return {
594
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
595
- };
596
- }
597
- case 'codacy_list_repository_issues': {
598
- const result = await searchRepositoryIssuesHandler(request.params.arguments);
599
- return {
600
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
601
- };
602
- }
603
- case 'codacy_list_repository_pull_requests': {
604
- const result = await listRepositoryPullRequestsHandler(request.params.arguments);
605
- return {
606
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
607
- };
608
- }
609
- case 'codacy_list_srm_items': {
610
- const result = await searchSecurityItemsHandler(request.params.arguments);
611
- return {
612
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
613
- };
614
- }
615
- case 'codacy_list_pull_request_issues': {
616
- const result = await listPullRequestIssuesHandler(request.params.arguments);
617
- return {
618
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
619
- };
620
- }
621
- case 'codacy_get_repository_pull_request_files_coverage': {
622
- const result = await getRepositoryPullRequestFilesCoverageHandler(request.params.arguments);
623
- return {
624
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
625
- };
626
- }
627
- case 'codacy_get_pull_request_git_diff': {
628
- const result = await getPullRequestGitDiffHandler(request.params.arguments);
629
- return {
630
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
631
- };
632
- }
633
- default:
634
- throw new Error(`Unknown tool: ${request.params.name}`);
635
- }
60
+ const toolDefinition = toolDefinitions[request.params.name];
61
+ if (!toolDefinition)
62
+ throw new Error(`Unknown tool: ${request.params.name}`);
63
+ const result = await toolDefinition.handler(request.params.arguments);
64
+ return {
65
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
66
+ };
636
67
  }
637
68
  catch (error) {
638
69
  console.error(error);
@@ -0,0 +1,13 @@
1
+ import { AnalysisService } from '../api/client/index.js';
2
+ export const listPullRequestIssuesHandler = async (args) => {
3
+ const { provider, organization, repository, pullRequestNumber, status, onlyPotential, cursor, limit, } = args;
4
+ return await AnalysisService.listPullRequestIssues(provider, organization, repository, pullRequestNumber, status, onlyPotential, cursor, limit);
5
+ };
6
+ export const listRepositoryPullRequestsHandler = async (args) => {
7
+ const { provider, organization, repository, search, includeNotAnalyzed, cursor, limit } = args;
8
+ return await AnalysisService.listRepositoryPullRequests(provider, organization, repository, limit, cursor, search, includeNotAnalyzed);
9
+ };
10
+ export const searchRepositoryIssuesHandler = async (args) => {
11
+ const { provider, organization, repository, limit, cursor, body } = args;
12
+ return await AnalysisService.searchRepositoryIssues(provider, organization, repository, cursor, limit, body);
13
+ };
@@ -0,0 +1,9 @@
1
+ import { CoverageService } from '../api/client/index.js';
2
+ export const getPullRequestGitDiffHandler = async (args) => {
3
+ const { provider, organization, repository, pullRequestNumber } = args;
4
+ return await CoverageService.getPullRequestGitDiff(provider, organization, repository, pullRequestNumber);
5
+ };
6
+ export const getRepositoryPullRequestFilesCoverageHandler = async (args) => {
7
+ const { provider, organization, repository, pullRequestNumber } = args;
8
+ return await CoverageService.getRepositoryPullRequestFilesCoverage(provider, organization, repository, pullRequestNumber);
9
+ };
@@ -0,0 +1,5 @@
1
+ export * from './coverage.js';
2
+ export * from './repository.js';
3
+ export * from './analysis.js';
4
+ export * from './organization.js';
5
+ export * from './security.js';
@@ -0,0 +1,5 @@
1
+ import { OrganizationService } from '../api/client/index.js';
2
+ export const listOrganizationRepositoriesHandler = async (args) => {
3
+ const { provider, organization, limit, cursor } = args;
4
+ return await OrganizationService.listOrganizationRepositories(provider, organization, cursor, limit);
5
+ };
@@ -0,0 +1,13 @@
1
+ import { RepositoryService } from '../api/client/index.js';
2
+ export const getFileCoverageHandler = async (args) => {
3
+ const { provider, organization, repository, fileId } = args;
4
+ return await RepositoryService.getFileCoverage(provider, organization, repository, fileId);
5
+ };
6
+ export const getFileIssuesHandler = async (args) => {
7
+ const { provider, organization, repository, fileId, limit, cursor } = args;
8
+ return await RepositoryService.getFileIssues(provider, organization, repository, fileId, cursor, limit);
9
+ };
10
+ export const listFilesHandler = async (args) => {
11
+ const { provider, organization, repository, branch, search, sort, direction, cursor, limit } = args;
12
+ return await RepositoryService.listFiles(provider, organization, repository, branch, search, sort, direction, cursor, limit);
13
+ };
@@ -0,0 +1,5 @@
1
+ import { SecurityService } from '../api/client/index.js';
2
+ export const searchSecurityItemsHandler = async (args) => {
3
+ const { provider, organization, cursor, limit, sort, direction, body } = args;
4
+ return await SecurityService.searchSecurityItems(provider, organization, cursor, limit, sort, direction, body);
5
+ };
@@ -0,0 +1,15 @@
1
+ import { repositorySchema } from './utils.js';
2
+ export const getFileCoverageTool = {
3
+ name: 'codacy_get_file_coverage',
4
+ description: 'Get coverage information for a file in the head commit of a repository branch.',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ fileId: {
10
+ type: 'string',
11
+ description: 'Identifier of a file in a specific commit',
12
+ },
13
+ },
14
+ },
15
+ };
@@ -0,0 +1,15 @@
1
+ import { repositorySchema } from './utils.js';
2
+ export const getPullRequestGitDiffTool = {
3
+ name: 'codacy_get_pull_request_git_diff',
4
+ description: 'Returns the human-readable Git diff of a pull request',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ pullRequestNumber: {
10
+ type: 'number',
11
+ description: 'Pull request number',
12
+ },
13
+ },
14
+ },
15
+ };
@@ -0,0 +1,15 @@
1
+ import { repositorySchema } from './utils.js';
2
+ export const getRepositoryPullRequestFilesCoverageTool = {
3
+ name: 'codacy_get_repository_pull_request_files_coverage',
4
+ description: 'Get coverage information for all files in a pull request.',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ pullRequestNumber: {
10
+ type: 'number',
11
+ description: 'Pull request number',
12
+ },
13
+ },
14
+ },
15
+ };
@@ -0,0 +1,10 @@
1
+ export * from './getFileCoverageTool.js';
2
+ export * from './listFileIssuesTool.js';
3
+ export * from './getPullRequestGitDiffTool.js';
4
+ export * from './getRepositoryPullRequestFilesCoverageTool.js';
5
+ export * from './listFilesTool.js';
6
+ export * from './listOrganizationRepositoriesTool.js';
7
+ export * from './listPullRequestIssuesTool.js';
8
+ export * from './listRepositoryPullRequestsTool.js';
9
+ export * from './searchRepositoryIssuesTool.js';
10
+ export * from './searchSecurityItemsTool.js';
@@ -0,0 +1,16 @@
1
+ import { defaultPagination, repositorySchema } from './utils.js';
2
+ export const listFileIssuesTool = {
3
+ name: 'codacy_get_file_issues',
4
+ description: 'Get the issue list for a file in a repository',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ ...defaultPagination,
10
+ fileId: {
11
+ type: 'string',
12
+ description: 'Identifier of a file in a specific commit',
13
+ },
14
+ },
15
+ },
16
+ };
@@ -0,0 +1,20 @@
1
+ import { getPaginationWithSorting, repositorySchema } from './utils.js';
2
+ export const listFilesTool = {
3
+ name: 'codacy_list_files',
4
+ description: 'List files in a repository with pagination',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ ...getPaginationWithSorting("Field used to sort the list of files. The allowed values are 'filename', 'issues', 'grade', 'duplication', 'complexity', and 'coverage'."),
10
+ branch: {
11
+ type: 'string',
12
+ description: 'Name of a repository branch enabled on Codacy',
13
+ },
14
+ search: {
15
+ type: 'string',
16
+ description: 'Filter files that include this string anywhere in their relative path',
17
+ },
18
+ },
19
+ },
20
+ };
@@ -0,0 +1,12 @@
1
+ import { defaultPagination, organizationSchema } from './utils.js';
2
+ export const listOrganizationRepositoriesTool = {
3
+ name: 'codacy_list_organization_repositories',
4
+ description: 'List repositories in an organization with pagination',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...organizationSchema,
9
+ ...defaultPagination,
10
+ },
11
+ },
12
+ };
@@ -0,0 +1,24 @@
1
+ import { defaultPagination, repositorySchema } from './utils.js';
2
+ export const listPullRequestIssuesTool = {
3
+ name: 'codacy_list_pull_request_issues',
4
+ description: 'Returns a list of issues found in a pull request. We can request either new or fixed issues.',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ ...defaultPagination,
10
+ pullRequestNumber: {
11
+ type: 'number',
12
+ description: 'Pull request number',
13
+ },
14
+ status: {
15
+ type: 'string',
16
+ description: 'Filter issues by status. Accepted values: all, new, fixed.',
17
+ },
18
+ onlyPotential: {
19
+ type: 'boolean',
20
+ description: 'If true, retrieves only potential issues',
21
+ },
22
+ },
23
+ },
24
+ };
@@ -0,0 +1,16 @@
1
+ import { defaultPagination, repositorySchema } from './utils.js';
2
+ export const listRepositoryPullRequestsTool = {
3
+ name: 'codacy_list_repository_pull_requests',
4
+ description: 'List pull requests from a repository that the user has access to. You can search this endpoint for either last-updated (default), impact or merged',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ ...defaultPagination,
10
+ includeNotAnalyzed: {
11
+ type: 'boolean',
12
+ description: 'If true, includes pull requests that have not been analyzed',
13
+ },
14
+ },
15
+ },
16
+ };
@@ -0,0 +1,42 @@
1
+ import { codacyLanguages, defaultPagination, issueCategories, repositorySchema } from './utils.js';
2
+ export const searchRepositoryIssuesTool = {
3
+ name: 'codacy_list_repository_issues',
4
+ description: 'Lists and filters code quality issues in a repository. This is the primary tool for investigating general code quality concerns (e.g. best practices, performance, complexity, style) but NOT security issues. For security-related issues, use the SRM items tool instead. Features include:\n\n- Pagination support for handling large result sets\n- Filtering by multiple criteria including severity, category, and language\n- Author-based filtering for accountability\n- Branch-specific analysis\n- Pattern-based searching\n\nCommon use cases:\n- Code quality audits\n- Technical debt assessment\n- Style guide compliance checks\n- Performance issue investigation\n- Complexity analysis',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ ...defaultPagination,
10
+ body: {
11
+ type: 'object',
12
+ description: 'Search parameters to filter the list of issues in a repository',
13
+ properties: {
14
+ branchName: {
15
+ type: 'string',
16
+ description: 'Branch name, by default the main branch defined on the Codacy repository settings is used',
17
+ },
18
+ patternIds: {
19
+ type: 'array',
20
+ description: 'Set of code pattern identifiers',
21
+ },
22
+ languages: {
23
+ type: 'array',
24
+ description: `Set of language names, without spaces. Accepted values: ${codacyLanguages.join(', ')}`,
25
+ },
26
+ categories: {
27
+ type: 'array',
28
+ description: `Set of issue categories. Accepted values: ${issueCategories.join(', ')}`,
29
+ },
30
+ levels: {
31
+ type: 'array',
32
+ description: 'Set of issue severity levels. Accepted values: Info, Warning and Error. Codacy maps these values as follows: Info->Minor, Warning->Medium, Error->Critical',
33
+ },
34
+ authorEmails: {
35
+ type: 'array',
36
+ description: 'Set of commit author email addresses',
37
+ },
38
+ },
39
+ },
40
+ },
41
+ },
42
+ };
@@ -0,0 +1,60 @@
1
+ import { getPaginationWithSorting, organizationSchema, securityCategories, securityScanTypes, securityStatuses, } from './utils.js';
2
+ export const searchSecurityItemsTool = {
3
+ name: 'codacy_list_srm_items',
4
+ description: `Primary tool to list security items/issues/vulnerabilities/findings, results are related to the organization security and risk management (SRM) dashboard on Codacy. This tool contains pagination. Returns comprehensive security analysis including ${Object.keys(securityScanTypes).join(', ')} security issues. Provides advanced filtering by security categories, priorities, and scan types. Use this as the first tool when investigating security or compliance concerns. Map the results statuses as open issues: ${securityStatuses.Open.join(', ')}; and closed issues: ${securityStatuses.Closed.join(', ')}. Prioritize the open issues as the most important ones in the results.`,
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...organizationSchema,
9
+ ...getPaginationWithSorting('Sort SRM items by. Accepted values: Status, DetectedAt'),
10
+ body: {
11
+ type: 'object',
12
+ description: 'Search parameters to filter the metrics of the security issues dashboard of an organization',
13
+ properties: {
14
+ repositories: {
15
+ type: 'array',
16
+ description: 'Repository names',
17
+ },
18
+ priorities: {
19
+ description: 'Array of security issue priorities/severities to filter by.',
20
+ type: 'array',
21
+ items: {
22
+ type: 'string',
23
+ enum: ['Low', 'Medium', 'High', 'Critical'],
24
+ },
25
+ },
26
+ statuses: {
27
+ type: 'array',
28
+ description: 'Array of security issue statuses to filter by. Must be one or more of the following values:\n\nOpen issues:\n- OnTrack\n- DueSoon\n- Overdue\n\nClosed issues:\n- ClosedOnTime\n- ClosedLate\n- Ignored',
29
+ items: {
30
+ type: 'string',
31
+ enum: ['OnTrack', 'DueSoon', 'Overdue', 'ClosedOnTime', 'ClosedLate', 'Ignored'],
32
+ },
33
+ },
34
+ categories: {
35
+ description: 'Array of security categories to filter by.',
36
+ type: 'array',
37
+ items: {
38
+ type: 'string',
39
+ enum: securityCategories,
40
+ },
41
+ note: "_other_ can be used to search for issues that don't have a security category",
42
+ },
43
+ scanTypes: {
44
+ description: 'Array of security scan types to filter by.',
45
+ type: 'array',
46
+ items: {
47
+ type: 'string',
48
+ enum: Object.keys(securityScanTypes),
49
+ },
50
+ mapping: securityScanTypes,
51
+ },
52
+ segments: {
53
+ type: 'array',
54
+ description: 'Set of segments ids (type number). Segment is a Codacy concept that groups repositories by different criteria',
55
+ },
56
+ },
57
+ },
58
+ },
59
+ },
60
+ };
@@ -0,0 +1,129 @@
1
+ export const codacyLanguages = [
2
+ 'C',
3
+ 'CPP',
4
+ 'CSharp',
5
+ 'Java',
6
+ 'Go',
7
+ 'Kotlin',
8
+ 'Ruby',
9
+ 'Scala',
10
+ 'Dart',
11
+ 'Python',
12
+ 'TypeScript',
13
+ 'Javascript',
14
+ 'CoffeeScript',
15
+ 'Swift',
16
+ 'JSP',
17
+ 'VisualBasic',
18
+ 'PHP',
19
+ 'PLSQL',
20
+ 'SQL',
21
+ 'TSQL',
22
+ 'Crystal',
23
+ 'Haskell',
24
+ 'Elixir',
25
+ 'Groovy',
26
+ 'Apex',
27
+ 'VisualForce',
28
+ 'Velocity',
29
+ 'CSS',
30
+ 'HTML',
31
+ 'LESS',
32
+ 'SASS',
33
+ 'Dockerfile',
34
+ 'Terraform',
35
+ 'Shell',
36
+ 'Powershell',
37
+ 'JSON',
38
+ 'XML',
39
+ 'YAML',
40
+ 'Markdown',
41
+ 'Cobol',
42
+ 'ABAP',
43
+ 'ObjectiveC',
44
+ 'Rust',
45
+ ];
46
+ export const issueCategories = [
47
+ 'security',
48
+ 'errorprone',
49
+ 'performance',
50
+ 'complexity',
51
+ 'unusedcode',
52
+ 'comprehensibility',
53
+ 'compatibility',
54
+ 'bestpractice',
55
+ 'codestyle',
56
+ 'documentation',
57
+ ];
58
+ export const securityStatuses = {
59
+ Open: ['OnTrack', 'DueSoon', 'Overdue'],
60
+ Closed: ['ClosedOnTime', 'ClosedLate', 'Ignored'],
61
+ };
62
+ export const securityCategories = [
63
+ 'Auth',
64
+ 'CommandInjection',
65
+ 'Cookies',
66
+ 'Cryptography',
67
+ 'CSRF',
68
+ 'DoS',
69
+ 'FileAccess',
70
+ 'HTTP',
71
+ 'InputValidation',
72
+ 'InsecureModulesLibraries',
73
+ 'InsecureStorage',
74
+ 'Other',
75
+ 'Regex',
76
+ 'SQLInjection',
77
+ 'UnexpectedBehaviour',
78
+ 'Visibility',
79
+ 'XSS',
80
+ '_other_',
81
+ ];
82
+ export const securityScanTypes = {
83
+ SAST: 'Code scanning',
84
+ Secrets: 'Secret scanning',
85
+ SCA: 'Dependency scanning',
86
+ IaC: 'Infrastructure-as-code scanning',
87
+ CICD: 'CI/CD scanning',
88
+ DAST: 'Dynamic Application Security Testing',
89
+ PenTesting: 'Penetration testing',
90
+ };
91
+ export const organizationSchema = {
92
+ provider: {
93
+ type: 'string',
94
+ description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb. In case a repository is given, use that repository's Git provider.",
95
+ },
96
+ organization: {
97
+ type: 'string',
98
+ description: "Organization name on the Git provider. In case a repository is given, use that repository's owner (could be an organization name or username).",
99
+ },
100
+ };
101
+ export const repositorySchema = {
102
+ ...organizationSchema,
103
+ repository: {
104
+ type: 'string',
105
+ description: 'Repository name on the Git provider',
106
+ },
107
+ };
108
+ export const defaultPagination = {
109
+ cursor: {
110
+ type: 'string',
111
+ description: 'Pagination cursor for next page of results',
112
+ },
113
+ limit: {
114
+ type: 'number',
115
+ description: 'Maximum number of results to return (default 100, max 100)',
116
+ default: 100,
117
+ },
118
+ };
119
+ export const getPaginationWithSorting = (sortDescription) => ({
120
+ ...defaultPagination,
121
+ direction: {
122
+ type: 'string',
123
+ description: 'Sort direction (ascending or descending). Accepted values: asc, desc',
124
+ },
125
+ sort: {
126
+ type: 'string',
127
+ description: sortDescription,
128
+ },
129
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/codacy-mcp",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Codacy MCP server",
5
5
  "license": "MIT",
6
6
  "author": "Codacy",