@codacy/codacy-mcp 0.2.3 → 0.3.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.
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
- import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
5
  import { OpenAPI } from './src/api/client/index.js';
6
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';
7
+ import { getFileCoverageHandler, getFileIssuesHandler, getPullRequestGitDiffHandler, getRepositoryPullRequestFilesCoverageHandler, listFilesHandler, listPullRequestIssuesHandler, listRepositoryPullRequestsHandler, searchRepositoryIssuesHandler, searchSecurityItemsHandler, listOrganizationRepositoriesHandler, getRepositoryWithAnalysisHandler, getFileWithAnalysisHandler, } from './src/handlers/index.js';
8
+ import { getRepositoryWithAnalysisTool } from './src/tools/getRepositoryWithAnalysisTool.js';
9
+ import { getFileWithAnalysisTool } from './src/tools/getFileWithAnalysisTool.js';
8
10
  OpenAPI.BASE = 'https://app.codacy.com/api/v3';
9
11
  OpenAPI.HEADERS = {
10
12
  'api-token': process.env.CODACY_ACCOUNT_TOKEN || '',
@@ -17,93 +19,61 @@ const server = new Server({
17
19
  tools: {},
18
20
  },
19
21
  });
22
+ const toolDefinitions = {
23
+ codacy_list_organization_repositories: {
24
+ tool: listOrganizationRepositoriesTool,
25
+ handler: listOrganizationRepositoriesHandler,
26
+ },
27
+ codacy_list_srm_items: { tool: searchSecurityItemsTool, handler: searchSecurityItemsHandler },
28
+ codacy_list_repository_issues: {
29
+ tool: searchRepositoryIssuesTool,
30
+ handler: searchRepositoryIssuesHandler,
31
+ },
32
+ codacy_list_repository_pull_requests: {
33
+ tool: listRepositoryPullRequestsTool,
34
+ handler: listRepositoryPullRequestsHandler,
35
+ },
36
+ codacy_list_files: { tool: listFilesTool, handler: listFilesHandler },
37
+ codacy_get_file_issues: { tool: listFileIssuesTool, handler: getFileIssuesHandler },
38
+ codacy_get_file_coverage: { tool: getFileCoverageTool, handler: getFileCoverageHandler },
39
+ codacy_get_repository_pull_request_files_coverage: {
40
+ tool: getRepositoryPullRequestFilesCoverageTool,
41
+ handler: getRepositoryPullRequestFilesCoverageHandler,
42
+ },
43
+ codacy_get_pull_request_git_diff: {
44
+ tool: getPullRequestGitDiffTool,
45
+ handler: getPullRequestGitDiffHandler,
46
+ },
47
+ codacy_list_pull_request_issues: {
48
+ tool: listPullRequestIssuesTool,
49
+ handler: listPullRequestIssuesHandler,
50
+ },
51
+ codacy_get_repository_with_analysis: {
52
+ tool: getRepositoryWithAnalysisTool,
53
+ handler: getRepositoryWithAnalysisHandler,
54
+ },
55
+ codacy_get_file_with_analysis: {
56
+ tool: getFileWithAnalysisTool,
57
+ handler: getFileWithAnalysisHandler,
58
+ },
59
+ };
20
60
  // Register tools
21
- server.setRequestHandler(ListToolsRequestSchema, async () => {
22
- return {
23
- tools: [
24
- listOrganizationRepositoriesTool,
25
- searchRepositoryIssuesTool,
26
- listFilesTool,
27
- listFileIssuesTool,
28
- getFileCoverageTool,
29
- searchSecurityItemsTool,
30
- listRepositoryPullRequestsTool,
31
- listPullRequestIssuesTool,
32
- getRepositoryPullRequestFilesCoverageTool,
33
- getPullRequestGitDiffTool,
34
- ],
35
- };
36
- });
61
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
62
+ tools: Object.values(toolDefinitions).map(({ tool }) => tool),
63
+ }));
37
64
  // Register request handlers
38
65
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
39
66
  try {
40
67
  if (!request.params.arguments) {
41
68
  throw new Error('Arguments are required');
42
69
  }
43
- switch (request.params.name) {
44
- case 'codacy_list_repositories': {
45
- const result = await listOrganizationRepositoriesHandler(request.params.arguments);
46
- return {
47
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
48
- };
49
- }
50
- case 'codacy_list_files': {
51
- const result = await listFilesHandler(request.params.arguments);
52
- return {
53
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
54
- };
55
- }
56
- case 'codacy_get_file_issues': {
57
- const result = await getFileIssuesHandler(request.params.arguments);
58
- return {
59
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
60
- };
61
- }
62
- case 'codacy_get_file_coverage': {
63
- const result = await getFileCoverageHandler(request.params.arguments);
64
- return {
65
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
66
- };
67
- }
68
- case 'codacy_list_repository_issues': {
69
- const result = await searchRepositoryIssuesHandler(request.params.arguments);
70
- return {
71
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
72
- };
73
- }
74
- case 'codacy_list_repository_pull_requests': {
75
- const result = await listRepositoryPullRequestsHandler(request.params.arguments);
76
- return {
77
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
78
- };
79
- }
80
- case 'codacy_list_srm_items': {
81
- const result = await searchSecurityItemsHandler(request.params.arguments);
82
- return {
83
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
84
- };
85
- }
86
- case 'codacy_list_pull_request_issues': {
87
- const result = await listPullRequestIssuesHandler(request.params.arguments);
88
- return {
89
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
90
- };
91
- }
92
- case 'codacy_get_repository_pull_request_files_coverage': {
93
- const result = await getRepositoryPullRequestFilesCoverageHandler(request.params.arguments);
94
- return {
95
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
96
- };
97
- }
98
- case 'codacy_get_pull_request_git_diff': {
99
- const result = await getPullRequestGitDiffHandler(request.params.arguments);
100
- return {
101
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
102
- };
103
- }
104
- default:
105
- throw new Error(`Unknown tool: ${request.params.name}`);
106
- }
70
+ const toolDefinition = toolDefinitions[request.params.name];
71
+ if (!toolDefinition)
72
+ throw new Error(`Unknown tool: ${request.params.name}`);
73
+ const result = await toolDefinition.handler(request.params.arguments);
74
+ return {
75
+ content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
76
+ };
107
77
  }
108
78
  catch (error) {
109
79
  console.error(error);
@@ -11,3 +11,7 @@ export const searchRepositoryIssuesHandler = async (args) => {
11
11
  const { provider, organization, repository, limit, cursor, body } = args;
12
12
  return await AnalysisService.searchRepositoryIssues(provider, organization, repository, cursor, limit, body);
13
13
  };
14
+ export const getRepositoryWithAnalysisHandler = async (args) => {
15
+ const { provider, organization, repository, branch } = args;
16
+ return await AnalysisService.getRepositoryWithAnalysis(provider, organization, repository, branch);
17
+ };
@@ -1,4 +1,12 @@
1
1
  import { RepositoryService } from '../api/client/index.js';
2
+ export const getFileWithAnalysisHandler = async (args) => {
3
+ const { provider, organization, repository, fileId } = args;
4
+ return await RepositoryService.getFileWithAnalysis(provider, organization, repository, fileId);
5
+ };
6
+ export const listFilesHandler = async (args) => {
7
+ const { provider, organization, repository, branch, search, sort, direction, cursor, limit } = args;
8
+ return await RepositoryService.listFiles(provider, organization, repository, branch, search, sort, direction, cursor, limit);
9
+ };
2
10
  export const getFileCoverageHandler = async (args) => {
3
11
  const { provider, organization, repository, fileId } = args;
4
12
  return await RepositoryService.getFileCoverage(provider, organization, repository, fileId);
@@ -7,7 +15,3 @@ export const getFileIssuesHandler = async (args) => {
7
15
  const { provider, organization, repository, fileId, limit, cursor } = args;
8
16
  return await RepositoryService.getFileIssues(provider, organization, repository, fileId, cursor, limit);
9
17
  };
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
- };
@@ -1,15 +1,11 @@
1
- import { repositorySchema } from './utils.js';
1
+ import { fileSchema } from './utils.js';
2
2
  export const getFileCoverageTool = {
3
3
  name: 'codacy_get_file_coverage',
4
4
  description: 'Get coverage information for a file in the head commit of a repository branch.',
5
5
  inputSchema: {
6
6
  type: 'object',
7
7
  properties: {
8
- ...repositorySchema,
9
- fileId: {
10
- type: 'string',
11
- description: 'Identifier of a file in a specific commit',
12
- },
8
+ ...fileSchema,
13
9
  },
14
10
  },
15
11
  };
@@ -0,0 +1,11 @@
1
+ import { fileSchema } from './utils.js';
2
+ export const getFileWithAnalysisTool = {
3
+ name: 'codacy_get_file_with_analysis',
4
+ description: "Get file information and it's analysis information and coverage metrics. A file that is ignored is not analyzed by Codacy. Here you will find results for five metrics: Grade, Issues, Duplication, Complexity and Coverage.",
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...fileSchema,
9
+ },
10
+ },
11
+ };
@@ -0,0 +1,12 @@
1
+ import { branchSchema, repositorySchema } from './utils.js';
2
+ export const getRepositoryWithAnalysisTool = {
3
+ name: 'codacy_get_repository_with_analysis',
4
+ description: 'Get repository with analysis information. Here you will find results for five metrics: Grade, Issues, Duplication, Complexity and Coverage. LoC stands for Lines of Code, and Codacy prefers to show the Issues metric as /kLoC (issues per thousand lines of code).',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ ...repositorySchema,
9
+ ...branchSchema,
10
+ },
11
+ },
12
+ };
@@ -1,16 +1,12 @@
1
- import { defaultPagination, repositorySchema } from './utils.js';
1
+ import { defaultPagination, fileSchema } from './utils.js';
2
2
  export const listFileIssuesTool = {
3
3
  name: 'codacy_get_file_issues',
4
4
  description: 'Get the issue list for a file in a repository',
5
5
  inputSchema: {
6
6
  type: 'object',
7
7
  properties: {
8
- ...repositorySchema,
8
+ ...fileSchema,
9
9
  ...defaultPagination,
10
- fileId: {
11
- type: 'string',
12
- description: 'Identifier of a file in a specific commit',
13
- },
14
10
  },
15
11
  },
16
12
  };
@@ -1,7 +1,7 @@
1
1
  import { getPaginationWithSorting, repositorySchema } from './utils.js';
2
2
  export const listFilesTool = {
3
3
  name: 'codacy_list_files',
4
- description: 'List files in a repository with pagination',
4
+ description: "List files in a repository with pagination. Supports sorting by various metrics (coverage, grade, issues, etc.) and filtering. Use sort='coverage' and direction='desc' to efficiently find files with high coverage, or sort='grade' for code quality analysis. Use search to filter files by name. ",
5
5
  inputSchema: {
6
6
  type: 'object',
7
7
  properties: {
@@ -1,6 +1,6 @@
1
1
  import { defaultPagination, organizationSchema } from './utils.js';
2
2
  export const listOrganizationRepositoriesTool = {
3
- name: 'codacy_list_repositories',
3
+ name: 'codacy_list_organization_repositories',
4
4
  description: 'List repositories in an organization with pagination',
5
5
  inputSchema: {
6
6
  type: 'object',
@@ -1,4 +1,4 @@
1
- import { codacyLanguages, defaultPagination, issueCategories, repositorySchema } from './utils.js';
1
+ import { branchSchema, codacyLanguages, defaultPagination, issueCategories, repositorySchema, } from './utils.js';
2
2
  export const searchRepositoryIssuesTool = {
3
3
  name: 'codacy_list_repository_issues',
4
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',
@@ -11,10 +11,7 @@ export const searchRepositoryIssuesTool = {
11
11
  type: 'object',
12
12
  description: 'Search parameters to filter the list of issues in a repository',
13
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
- },
14
+ ...branchSchema,
18
15
  patternIds: {
19
16
  type: 'array',
20
17
  description: 'Set of code pattern identifiers',
@@ -120,10 +120,23 @@ export const getPaginationWithSorting = (sortDescription) => ({
120
120
  ...defaultPagination,
121
121
  direction: {
122
122
  type: 'string',
123
- description: 'Sort direction (ascending or descending). Accepted values: asc, desc',
123
+ description: "Sort direction (ascending or descending). Use 'desc' to see highest values first, 'asc' for lowest values first.",
124
124
  },
125
125
  sort: {
126
126
  type: 'string',
127
127
  description: sortDescription,
128
128
  },
129
129
  });
130
+ export const branchSchema = {
131
+ branchName: {
132
+ type: 'string',
133
+ description: 'Branch name, by default the main/default branch defined on the Codacy repository settings is used',
134
+ },
135
+ };
136
+ export const fileSchema = {
137
+ ...repositorySchema,
138
+ fileId: {
139
+ type: 'string',
140
+ description: "Codacy's identifier of a file in a specific commit",
141
+ },
142
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/codacy-mcp",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Codacy MCP server",
5
5
  "license": "MIT",
6
6
  "author": "Codacy",