@codacy/codacy-mcp 0.3.9 → 0.4.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.
- package/README.md +22 -5
- package/dist/index.js +4 -0
- 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/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,10 @@ 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
|
+
- Windsurf: edit the `.codeium/windsurf/mcp_config.json` file to add the following
|
|
77
|
+
- Claude Desktop: edit the `claude_desktop_config.json` file to add the following
|
|
65
78
|
|
|
66
79
|
### NPX
|
|
67
80
|
|
|
@@ -81,7 +94,7 @@ Depending on what are you connecting the MCP Server to, you can use the followin
|
|
|
81
94
|
|
|
82
95
|
### Node (when using NVM)
|
|
83
96
|
|
|
84
|
-
When using NVM with Claude Desktop, NPX won't work. You should first install the MCP Server globally, and
|
|
97
|
+
When using NVM with Claude Desktop, NPX won't work. You should first install the MCP Server globally, and then use Node directly:
|
|
85
98
|
|
|
86
99
|
```bash
|
|
87
100
|
npm install -g @codacy/codacy-mcp
|
|
@@ -111,6 +124,10 @@ npm run update-api
|
|
|
111
124
|
npm run build
|
|
112
125
|
```
|
|
113
126
|
|
|
127
|
+
## Codacy-CLI Support (WIP)
|
|
128
|
+
|
|
129
|
+
In order to use the [Codacy-CLI](https://github.com/codacy/codacy-cli-v2), it needs to be installed.
|
|
130
|
+
|
|
114
131
|
## License
|
|
115
132
|
|
|
116
133
|
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
|
@@ -120,6 +120,10 @@ const toolDefinitions = {
|
|
|
120
120
|
tool: Tools.listOrganizationsTool,
|
|
121
121
|
handler: Handlers.listOrganizationsHandler,
|
|
122
122
|
},
|
|
123
|
+
codacy_cli_analyze: {
|
|
124
|
+
tool: Tools.cliAnalyzeTool,
|
|
125
|
+
handler: Handlers.cliAnalyzeHandler,
|
|
126
|
+
},
|
|
123
127
|
};
|
|
124
128
|
// Register tools
|
|
125
129
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
@@ -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