@codacy/codacy-mcp 0.4.6 → 0.4.8
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 +1 -0
- package/dist/index.js +4 -0
- package/dist/src/handlers/cliAnalyze.js +1 -10
- package/dist/src/handlers/repository.js +4 -0
- package/dist/src/schemas.js +1 -0
- package/dist/src/tools/cliAnalyzeTool.js +0 -5
- package/dist/src/tools/getFileClonesTool.js +29 -0
- package/dist/src/tools/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ The following tools are available through the Codacy MCP Server:
|
|
|
35
35
|
- `codacy_list_files`: List files in a repository with pagination support.
|
|
36
36
|
- `codacy_get_file_issues`: Get the issue list for a file in a repository.
|
|
37
37
|
- `codacy_get_file_coverage`: Get coverage information for a file in the head commit of a repository branch.
|
|
38
|
+
- `codacy_get_file_clones`: Get the list of duplication clones (identical or very similar code segments) for a file in a repository. Use this tool to identify potential refactoring opportunities and reduce code duplication.
|
|
38
39
|
|
|
39
40
|
### Security Analysis
|
|
40
41
|
|
package/dist/index.js
CHANGED
|
@@ -103,6 +103,10 @@ const toolDefinitions = {
|
|
|
103
103
|
tool: Tools.getFileWithAnalysisTool,
|
|
104
104
|
handler: Handlers.getFileWithAnalysisHandler,
|
|
105
105
|
},
|
|
106
|
+
codacy_get_file_clones: {
|
|
107
|
+
tool: Tools.getFileClonesTool,
|
|
108
|
+
handler: Handlers.getFileClonesHandler,
|
|
109
|
+
},
|
|
106
110
|
codacy_get_repository_pull_request: {
|
|
107
111
|
tool: Tools.getRepositoryPullRequestTool,
|
|
108
112
|
handler: Handlers.getRepositoryPullRequestHandler,
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import util from 'util';
|
|
2
2
|
import { exec as execChildProcess } from 'child_process';
|
|
3
|
-
import { allowedTools } from '../tools/cliAnalyzeTool.js';
|
|
4
3
|
const exec = util.promisify(execChildProcess);
|
|
5
4
|
// Safeguard: Validate and sanitize command inputs
|
|
6
5
|
const sanitizeCommand = (command) => {
|
|
7
6
|
// Remove any shell metacharacters
|
|
8
7
|
return command?.replace(/[;&|`$]/g, '') || '';
|
|
9
8
|
};
|
|
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
9
|
export const cliAnalyzeHandler = async (args) => {
|
|
18
10
|
try {
|
|
19
|
-
const safeTool = validateTool(args.tool);
|
|
20
11
|
const safeFile = sanitizeCommand(args.file);
|
|
21
|
-
const command = `codacy-cli analyze --
|
|
12
|
+
const command = `codacy-cli analyze --format sarif ${safeFile}`;
|
|
22
13
|
// Add options object with cwd and increased maxBuffer
|
|
23
14
|
const options = {
|
|
24
15
|
cwd: args.rootPath,
|
|
@@ -3,6 +3,10 @@ export const getFileWithAnalysisHandler = async (args) => {
|
|
|
3
3
|
const { provider, organization, repository, fileId } = args;
|
|
4
4
|
return await RepositoryService.getFileWithAnalysis(provider, organization, repository, fileId);
|
|
5
5
|
};
|
|
6
|
+
export const getFileClonesHandler = async (args) => {
|
|
7
|
+
const { provider, organization, repository, fileId } = args;
|
|
8
|
+
return await RepositoryService.getFileClones(provider, organization, repository, fileId);
|
|
9
|
+
};
|
|
6
10
|
export const listFilesHandler = async (args) => {
|
|
7
11
|
const { provider, organization, repository, branch, search, sort, direction, cursor, limit } = args;
|
|
8
12
|
return await RepositoryService.listFiles(provider, organization, repository, branch, search, sort, direction, cursor, limit);
|
package/dist/src/schemas.js
CHANGED
|
@@ -20,6 +20,7 @@ export const toolNames = {
|
|
|
20
20
|
CODACY_GET_ISSUE: 'codacy_get_issue',
|
|
21
21
|
CODACY_GET_PATTERN: 'codacy_get_pattern',
|
|
22
22
|
CODACY_CLI_ANALYZE: 'codacy_cli_analyze',
|
|
23
|
+
CODACY_GET_FILE_CLONES: 'codacy_get_file_clones',
|
|
23
24
|
};
|
|
24
25
|
export const organizationSchema = {
|
|
25
26
|
provider: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { toolNames } from '../schemas.js';
|
|
2
|
-
export const allowedTools = ['eslint'];
|
|
3
2
|
export const cliAnalyzeTool = {
|
|
4
3
|
name: toolNames.CODACY_CLI_ANALYZE,
|
|
5
4
|
description: 'Run quality analysis using Codacy CLI. Requires the Codacy CLI to be installed and configured.',
|
|
@@ -10,10 +9,6 @@ export const cliAnalyzeTool = {
|
|
|
10
9
|
type: 'string',
|
|
11
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.',
|
|
12
11
|
},
|
|
13
|
-
tool: {
|
|
14
|
-
type: 'string',
|
|
15
|
-
description: `Required. Tool to use for analysis (e.g., eslint). Possible values: ${allowedTools.join(', ')}.`,
|
|
16
|
-
},
|
|
17
12
|
file: {
|
|
18
13
|
type: 'string',
|
|
19
14
|
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.',
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { generalOrganizationMistakes, generalRepositoryMistakes } from '../rules.js';
|
|
2
|
+
import { fileSchema, toolNames } from '../schemas.js';
|
|
3
|
+
const rules = `
|
|
4
|
+
Use this tool to list the duplication clones for specific file in a repository.
|
|
5
|
+
Duplication clones are code segments that are identical or very similar to other segments in the codebase.
|
|
6
|
+
|
|
7
|
+
Common use cases:
|
|
8
|
+
- When the user asks for code duplication in a specific file
|
|
9
|
+
- When the user wants to identify repeated code segments
|
|
10
|
+
- When investigating potential refactoring opportunities
|
|
11
|
+
|
|
12
|
+
Common mistakes:
|
|
13
|
+
- Using this tool for listing general code quality issues
|
|
14
|
+
- Using this tool for listing security issues
|
|
15
|
+
- Using this with a wrong fileId (validate the fileId with the codacy_list_files tool)
|
|
16
|
+
${generalOrganizationMistakes}
|
|
17
|
+
${generalRepositoryMistakes}
|
|
18
|
+
`;
|
|
19
|
+
export const getFileClonesTool = {
|
|
20
|
+
name: toolNames.CODACY_GET_FILE_CLONES,
|
|
21
|
+
description: `Get the list of duplication clones for a file in a repository. \n ${rules}`,
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
...fileSchema,
|
|
26
|
+
},
|
|
27
|
+
required: ['provider', 'organization', 'repository'],
|
|
28
|
+
},
|
|
29
|
+
};
|
package/dist/src/tools/index.js
CHANGED