@codacy/codacy-mcp 0.3.8 → 0.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.
- package/README.md +20 -4
- package/dist/index.js +49 -36
- package/dist/src/handlers/cliAnalyze.js +53 -0
- package/dist/src/handlers/index.js +1 -0
- package/dist/src/tools/cliAnalyzeTool.js +23 -0
- package/dist/src/tools/index.js +1 -0
- package/dist/src/tools/searchRepositoryIssuesTool.js +1 -1
- package/dist/src/tools/utils.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,10 +9,13 @@ MCP Server for the Codacy API, enabling access to repositories, files, quality,
|
|
|
9
9
|
The following tools are available through the Codacy MCP Server:
|
|
10
10
|
|
|
11
11
|
### Repository Management
|
|
12
|
+
|
|
12
13
|
- `codacy_list_repositories`: List repositories in an organization with pagination support.
|
|
13
14
|
|
|
14
15
|
### Code Quality and Analysis
|
|
16
|
+
|
|
15
17
|
- `codacy_list_repository_issues`: 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:
|
|
18
|
+
|
|
16
19
|
- Pagination support for handling large result sets
|
|
17
20
|
- Filtering by multiple criteria including severity, category, and language
|
|
18
21
|
- Author-based filtering for accountability
|
|
@@ -20,6 +23,7 @@ The following tools are available through the Codacy MCP Server:
|
|
|
20
23
|
- Pattern-based searching
|
|
21
24
|
|
|
22
25
|
Common use cases:
|
|
26
|
+
|
|
23
27
|
- Code quality audits
|
|
24
28
|
- Technical debt assessment
|
|
25
29
|
- Style guide compliance checks
|
|
@@ -27,12 +31,15 @@ The following tools are available through the Codacy MCP Server:
|
|
|
27
31
|
- Complexity analysis
|
|
28
32
|
|
|
29
33
|
### File Management
|
|
34
|
+
|
|
30
35
|
- `codacy_list_files`: List files in a repository with pagination support.
|
|
31
36
|
- `codacy_get_file_issues`: Get the issue list for a file in a repository.
|
|
32
37
|
- `codacy_get_file_coverage`: Get coverage information for a file in the head commit of a repository branch.
|
|
33
38
|
|
|
34
39
|
### Security Analysis
|
|
40
|
+
|
|
35
41
|
- `codacy_list_srm_items`: Primary tool to list security items/issues/vulnerabilities/findings. Results are related to the organization security and risk management (SRM) dashboard on Codacy. Provides comprehensive security analysis including:
|
|
42
|
+
|
|
36
43
|
- SAST (Code scanning)
|
|
37
44
|
- Secrets (Secret scanning)
|
|
38
45
|
- SCA (Dependency scanning)
|
|
@@ -40,16 +47,20 @@ The following tools are available through the Codacy MCP Server:
|
|
|
40
47
|
- CICD (CI/CD scanning)
|
|
41
48
|
- DAST (Dynamic Application Security Testing)
|
|
42
49
|
- PenTesting (Penetration testing)
|
|
43
|
-
|
|
50
|
+
|
|
44
51
|
Use this as the first tool when investigating security or compliance concerns.
|
|
45
52
|
|
|
46
53
|
### Pull Request Analysis
|
|
54
|
+
|
|
47
55
|
- `codacy_list_repository_pull_requests`: 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.
|
|
48
56
|
- `codacy_list_pull_request_issues`: Returns a list of issues found in a pull request. We can request either new or fixed issues.
|
|
49
57
|
- `codacy_get_repository_pull_request_files_coverage`: Get coverage information for all files in a pull request.
|
|
50
58
|
- `codacy_get_pull_request_git_diff`: Returns the human-readable Git diff of a pull request.
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
### CLI Analysis
|
|
61
|
+
|
|
62
|
+
- `codacy_cli_analyze`: Uses Codacy's command-line tool to analyze code.
|
|
63
|
+
|
|
53
64
|
|
|
54
65
|
## Setup
|
|
55
66
|
|
|
@@ -60,8 +71,9 @@ Get your Codacy's Account API Token from your [Codacy Account](https://app.codac
|
|
|
60
71
|
### Usage
|
|
61
72
|
|
|
62
73
|
Depending on what are you connecting the MCP Server to, you can use the following methods:
|
|
63
|
-
|
|
64
|
-
-
|
|
74
|
+
|
|
75
|
+
- Cursor: edit the `.cursor/mcp.json` file to add the following
|
|
76
|
+
- Claude Desktop: edit the `claude_desktop_config.json` file to add the following
|
|
65
77
|
|
|
66
78
|
### NPX
|
|
67
79
|
|
|
@@ -111,6 +123,10 @@ npm run update-api
|
|
|
111
123
|
npm run build
|
|
112
124
|
```
|
|
113
125
|
|
|
126
|
+
## Codacy-CLI Support (WIP)
|
|
127
|
+
|
|
128
|
+
In order to use the [Codacy-CLI](https://github.com/codacy/codacy-cli-v2), it needs to be installed.
|
|
129
|
+
|
|
114
130
|
## License
|
|
115
131
|
|
|
116
132
|
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ 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
5
|
import { OpenAPI } from './src/api/client/index.js';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import * as Tools from './src/tools/index.js';
|
|
7
|
+
import * as Handlers from './src/handlers/index.js';
|
|
8
8
|
import { validateOrganization } from './src/middleware/validation.js';
|
|
9
9
|
OpenAPI.BASE = 'https://app.codacy.com/api/v3';
|
|
10
10
|
OpenAPI.HEADERS = {
|
|
@@ -48,68 +48,81 @@ const server = new Server({
|
|
|
48
48
|
});
|
|
49
49
|
const toolDefinitions = {
|
|
50
50
|
codacy_list_organization_repositories: {
|
|
51
|
-
tool: listOrganizationRepositoriesTool,
|
|
52
|
-
handler: listOrganizationRepositoriesHandler,
|
|
51
|
+
tool: Tools.listOrganizationRepositoriesTool,
|
|
52
|
+
handler: Handlers.listOrganizationRepositoriesHandler,
|
|
53
|
+
},
|
|
54
|
+
codacy_list_srm_items: {
|
|
55
|
+
tool: Tools.searchSecurityItemsTool,
|
|
56
|
+
handler: Handlers.searchSecurityItemsHandler,
|
|
53
57
|
},
|
|
54
|
-
codacy_list_srm_items: { tool: searchSecurityItemsTool, handler: searchSecurityItemsHandler },
|
|
55
58
|
codacy_list_repository_issues: {
|
|
56
|
-
tool: searchRepositoryIssuesTool,
|
|
57
|
-
handler: searchRepositoryIssuesHandler,
|
|
59
|
+
tool: Tools.searchRepositoryIssuesTool,
|
|
60
|
+
handler: Handlers.searchRepositoryIssuesHandler,
|
|
58
61
|
},
|
|
59
62
|
codacy_list_repository_pull_requests: {
|
|
60
|
-
tool: listRepositoryPullRequestsTool,
|
|
61
|
-
handler: listRepositoryPullRequestsHandler,
|
|
63
|
+
tool: Tools.listRepositoryPullRequestsTool,
|
|
64
|
+
handler: Handlers.listRepositoryPullRequestsHandler,
|
|
65
|
+
},
|
|
66
|
+
codacy_list_files: { tool: Tools.listFilesTool, handler: Handlers.listFilesHandler },
|
|
67
|
+
codacy_get_file_issues: {
|
|
68
|
+
tool: Tools.listFileIssuesTool,
|
|
69
|
+
handler: Handlers.getFileIssuesHandler,
|
|
70
|
+
},
|
|
71
|
+
codacy_get_file_coverage: {
|
|
72
|
+
tool: Tools.getFileCoverageTool,
|
|
73
|
+
handler: Handlers.getFileCoverageHandler,
|
|
62
74
|
},
|
|
63
|
-
codacy_list_files: { tool: listFilesTool, handler: listFilesHandler },
|
|
64
|
-
codacy_get_file_issues: { tool: listFileIssuesTool, handler: getFileIssuesHandler },
|
|
65
|
-
codacy_get_file_coverage: { tool: getFileCoverageTool, handler: getFileCoverageHandler },
|
|
66
75
|
codacy_get_repository_pull_request_files_coverage: {
|
|
67
|
-
tool: getRepositoryPullRequestFilesCoverageTool,
|
|
68
|
-
handler: getRepositoryPullRequestFilesCoverageHandler,
|
|
76
|
+
tool: Tools.getRepositoryPullRequestFilesCoverageTool,
|
|
77
|
+
handler: Handlers.getRepositoryPullRequestFilesCoverageHandler,
|
|
69
78
|
},
|
|
70
79
|
codacy_get_pull_request_git_diff: {
|
|
71
|
-
tool: getPullRequestGitDiffTool,
|
|
72
|
-
handler: getPullRequestGitDiffHandler,
|
|
80
|
+
tool: Tools.getPullRequestGitDiffTool,
|
|
81
|
+
handler: Handlers.getPullRequestGitDiffHandler,
|
|
73
82
|
},
|
|
74
83
|
codacy_list_pull_request_issues: {
|
|
75
|
-
tool: listPullRequestIssuesTool,
|
|
76
|
-
handler: listPullRequestIssuesHandler,
|
|
84
|
+
tool: Tools.listPullRequestIssuesTool,
|
|
85
|
+
handler: Handlers.listPullRequestIssuesHandler,
|
|
77
86
|
},
|
|
78
87
|
codacy_get_repository_with_analysis: {
|
|
79
|
-
tool: getRepositoryWithAnalysisTool,
|
|
80
|
-
handler: getRepositoryWithAnalysisHandler,
|
|
88
|
+
tool: Tools.getRepositoryWithAnalysisTool,
|
|
89
|
+
handler: Handlers.getRepositoryWithAnalysisHandler,
|
|
81
90
|
},
|
|
82
91
|
codacy_get_file_with_analysis: {
|
|
83
|
-
tool: getFileWithAnalysisTool,
|
|
84
|
-
handler: getFileWithAnalysisHandler,
|
|
92
|
+
tool: Tools.getFileWithAnalysisTool,
|
|
93
|
+
handler: Handlers.getFileWithAnalysisHandler,
|
|
85
94
|
},
|
|
86
95
|
codacy_get_repository_pull_request: {
|
|
87
|
-
tool: getRepositoryPullRequestTool,
|
|
88
|
-
handler: getRepositoryPullRequestHandler,
|
|
96
|
+
tool: Tools.getRepositoryPullRequestTool,
|
|
97
|
+
handler: Handlers.getRepositoryPullRequestHandler,
|
|
89
98
|
},
|
|
90
99
|
codacy_get_issue: {
|
|
91
|
-
tool: getIssueTool,
|
|
92
|
-
handler: getIssueHandler,
|
|
100
|
+
tool: Tools.getIssueTool,
|
|
101
|
+
handler: Handlers.getIssueHandler,
|
|
93
102
|
},
|
|
94
103
|
codacy_get_pattern: {
|
|
95
|
-
tool: getPatternTool,
|
|
96
|
-
handler: getPatternHandler,
|
|
104
|
+
tool: Tools.getPatternTool,
|
|
105
|
+
handler: Handlers.getPatternHandler,
|
|
97
106
|
},
|
|
98
107
|
codacy_list_repository_tool_patterns: {
|
|
99
|
-
tool: listRepositoryToolPatternsTool,
|
|
100
|
-
handler: listRepositoryToolPatternsHandler,
|
|
108
|
+
tool: Tools.listRepositoryToolPatternsTool,
|
|
109
|
+
handler: Handlers.listRepositoryToolPatternsHandler,
|
|
101
110
|
},
|
|
102
111
|
codacy_list_tools: {
|
|
103
|
-
tool: listToolsTool,
|
|
104
|
-
handler: listToolsHandler,
|
|
112
|
+
tool: Tools.listToolsTool,
|
|
113
|
+
handler: Handlers.listToolsHandler,
|
|
105
114
|
},
|
|
106
115
|
codacy_list_repository_tools: {
|
|
107
|
-
tool: listRepositoryToolsTool,
|
|
108
|
-
handler: listRepositoryToolsHandler,
|
|
116
|
+
tool: Tools.listRepositoryToolsTool,
|
|
117
|
+
handler: Handlers.listRepositoryToolsHandler,
|
|
109
118
|
},
|
|
110
119
|
codacy_list_organization: {
|
|
111
|
-
tool: listOrganizationsTool,
|
|
112
|
-
handler: listOrganizationsHandler,
|
|
120
|
+
tool: Tools.listOrganizationsTool,
|
|
121
|
+
handler: Handlers.listOrganizationsHandler,
|
|
122
|
+
},
|
|
123
|
+
codacy_cli_analyze: {
|
|
124
|
+
tool: Tools.cliAnalyzeTool,
|
|
125
|
+
handler: Handlers.cliAnalyzeHandler,
|
|
113
126
|
},
|
|
114
127
|
};
|
|
115
128
|
// Register tools
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import util from 'util';
|
|
2
|
+
import { exec as execChildProcess } from 'child_process';
|
|
3
|
+
import { allowedTools } from '../tools/cliAnalyzeTool.js';
|
|
4
|
+
const exec = util.promisify(execChildProcess);
|
|
5
|
+
// Safeguard: Validate and sanitize command inputs
|
|
6
|
+
const sanitizeCommand = (command) => {
|
|
7
|
+
// Remove any shell metacharacters
|
|
8
|
+
return command?.replace(/[;&|`$]/g, '') || '';
|
|
9
|
+
};
|
|
10
|
+
// Safeguard: Validate tool name
|
|
11
|
+
const validateTool = (tool) => {
|
|
12
|
+
if (!allowedTools.includes(tool)) {
|
|
13
|
+
throw new Error(`Invalid tool: ${tool}. Allowed tools are: ${allowedTools.join(', ')}`);
|
|
14
|
+
}
|
|
15
|
+
return tool;
|
|
16
|
+
};
|
|
17
|
+
export const cliAnalyzeHandler = async (args) => {
|
|
18
|
+
try {
|
|
19
|
+
const safeTool = validateTool(args.tool);
|
|
20
|
+
const safeFile = sanitizeCommand(args.file);
|
|
21
|
+
const command = `codacy-cli analyze --tool ${safeTool} --format sarif ${safeFile}`;
|
|
22
|
+
// Add options object with cwd and increased maxBuffer
|
|
23
|
+
const options = {
|
|
24
|
+
cwd: args.rootPath,
|
|
25
|
+
maxBuffer: 1024 * 1024 * 10, // 10MB buffer size
|
|
26
|
+
};
|
|
27
|
+
const { stdout, stderr } = await exec(command, options);
|
|
28
|
+
// Only treat stderr as an error if:
|
|
29
|
+
// 1. There's no stdout (meaning only errors occurred)
|
|
30
|
+
// 2. stderr contains actual error messages (not just progress logs)
|
|
31
|
+
if (stderr && (!stdout || /error|fail|exception/i.test(stderr))) {
|
|
32
|
+
return {
|
|
33
|
+
success: false,
|
|
34
|
+
errorType: 'stderr',
|
|
35
|
+
output: stderr,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Try to extract JSON from the output if it's embedded in other text
|
|
39
|
+
const jsonMatch = /(\{[\s\S]*\}|\[[\s\S]*\])/.exec(stdout);
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
output: stdout,
|
|
43
|
+
result: jsonMatch ? JSON.parse(jsonMatch[0]) : null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
errorType: 'try-catch',
|
|
50
|
+
output: error instanceof Error ? error.message : 'Unknown error',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const allowedTools = ['eslint'];
|
|
2
|
+
export const cliAnalyzeTool = {
|
|
3
|
+
name: 'codacy_cli_analyze',
|
|
4
|
+
description: 'Run quality analysis using Codacy CLI. Requires the Codacy CLI to be installed and configured.',
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
rootPath: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
description: 'Required. Root path to the project or repository in the local filesystem. This must be filled to ensure permissions are met for the tool to run.',
|
|
11
|
+
},
|
|
12
|
+
tool: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: `Required. Tool to use for analysis (e.g., eslint). Possible values: ${allowedTools.join(', ')}.`,
|
|
15
|
+
},
|
|
16
|
+
file: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'Optional. Absolute path to the file to analyze, or pattern to match files (e.g., "src/**/*.js"). If left empty, the analysis will be executed for the whole project.',
|
|
19
|
+
default: '',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
package/dist/src/tools/index.js
CHANGED
package/dist/src/tools/utils.js
CHANGED
|
@@ -157,8 +157,8 @@ export const extractOrganizationFromUrl = (url) => {
|
|
|
157
157
|
/https:\/\/bitbucket\.org\/([^/]+)\/[^/]+\.git$/,
|
|
158
158
|
];
|
|
159
159
|
for (const pattern of patterns) {
|
|
160
|
-
const match =
|
|
161
|
-
if (match
|
|
160
|
+
const match = pattern.exec(url);
|
|
161
|
+
if (match?.[1]) {
|
|
162
162
|
return match[1];
|
|
163
163
|
}
|
|
164
164
|
}
|