@codacy/codacy-mcp 0.5.8 → 0.6.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 +30 -28
- package/dist/index.js +4 -0
- package/dist/src/handlers/cliAnalyze.js +2 -1
- package/dist/src/handlers/index.js +1 -0
- package/dist/src/handlers/setupRepository.js +135 -0
- package/dist/src/schemas.js +1 -0
- package/dist/src/tools/index.js +1 -0
- package/dist/src/tools/setupRepositoryTool.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,13 +45,13 @@ The following tools are available through the Codacy MCP Server:
|
|
|
45
45
|
|
|
46
46
|
Both tools provide comprehensive security analysis including:
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
- SAST (Code scanning)
|
|
49
|
+
- Secrets (Secret scanning)
|
|
50
|
+
- SCA (Dependency scanning)
|
|
51
|
+
- IaC (Infrastructure-as-code scanning)
|
|
52
|
+
- CICD (CI/CD scanning)
|
|
53
|
+
- DAST (Dynamic Application Security Testing)
|
|
54
|
+
- PenTesting (Penetration testing)
|
|
55
55
|
|
|
56
56
|
### Pull Request Analysis
|
|
57
57
|
|
|
@@ -82,9 +82,10 @@ Both tools provide comprehensive security analysis including:
|
|
|
82
82
|
### Requirements
|
|
83
83
|
|
|
84
84
|
Ensure your machine has the following tools installed:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
|
|
86
|
+
- git
|
|
87
|
+
- node.js
|
|
88
|
+
- ensure that the `npx` command runs without issues.
|
|
88
89
|
|
|
89
90
|
### Personal API Access Token
|
|
90
91
|
|
|
@@ -105,7 +106,7 @@ Depending on what you are connecting the MCP Server to, you can use the followin
|
|
|
105
106
|
- Cursor: edit the `.cursor/mcp.json` file to add the following
|
|
106
107
|
- Windsurf: edit the `.codeium/windsurf/mcp_config.json` file to add the following
|
|
107
108
|
- Claude Desktop: edit the `claude_desktop_config.json` file to add the following
|
|
108
|
-
|
|
109
|
+
|
|
109
110
|
```json
|
|
110
111
|
{
|
|
111
112
|
"mcpServers": {
|
|
@@ -113,7 +114,8 @@ Depending on what you are connecting the MCP Server to, you can use the followin
|
|
|
113
114
|
"command": "npx",
|
|
114
115
|
"args": ["-y", "@codacy/codacy-mcp"],
|
|
115
116
|
"env": {
|
|
116
|
-
"CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>"
|
|
117
|
+
"CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>",
|
|
118
|
+
"CODACY_CLI_VERSION": "<VERSION>"
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
}
|
|
@@ -126,23 +128,22 @@ Depending on what you are connecting the MCP Server to, you can use the followin
|
|
|
126
128
|
|
|
127
129
|
```json
|
|
128
130
|
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
"env": {
|
|
139
|
-
"CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>"
|
|
140
|
-
}
|
|
141
|
-
}
|
|
131
|
+
"mcp": {
|
|
132
|
+
"inputs": [],
|
|
133
|
+
"servers": {
|
|
134
|
+
"codacy": {
|
|
135
|
+
"command": "npx",
|
|
136
|
+
"args": ["-y", "@codacy/codacy-mcp"],
|
|
137
|
+
"env": {
|
|
138
|
+
"CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>",
|
|
139
|
+
"CODACY_CLI_VERSION": "<VERSION>"
|
|
142
140
|
}
|
|
141
|
+
}
|
|
143
142
|
}
|
|
143
|
+
}
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
|
+
|
|
146
147
|
You can open the user settings.json file in:
|
|
147
148
|
|
|
148
149
|
`View > Command Palette > Preferences: Open User Settings (JSON)`
|
|
@@ -153,7 +154,7 @@ Or open the general settings.json file directly, which according to your OS shou
|
|
|
153
154
|
- for Windows: `%APPDATA%\Code\User\settings.json`
|
|
154
155
|
- for Linux: `~/.config/Code/User/settings.json`
|
|
155
156
|
|
|
156
|
-
Don't forget to update the value of `CODACY_ACCOUNT_TOKEN` with your token.
|
|
157
|
+
Don't forget to update the value of `CODACY_ACCOUNT_TOKEN` with your token.
|
|
157
158
|
|
|
158
159
|
2. Make sure you have Agent mode enabled: [vscode://settings/chat.agent.enabled](vscode://settings/chat.agent.enabled)
|
|
159
160
|
|
|
@@ -178,7 +179,8 @@ npm install -g @codacy/codacy-mcp
|
|
|
178
179
|
"command": "/Users/yourusername/.nvm/versions/node/vXX.X.X/bin/node",
|
|
179
180
|
"args": ["/path-to/codacy-mcp/dist/index.js"],
|
|
180
181
|
"env": {
|
|
181
|
-
"CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>"
|
|
182
|
+
"CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>",
|
|
183
|
+
"CODACY_CLI_VERSION": "<VERSION>"
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
186
|
}
|
|
@@ -197,7 +199,7 @@ npm run build
|
|
|
197
199
|
|
|
198
200
|
## Codacy-CLI Support (WIP)
|
|
199
201
|
|
|
200
|
-
In order to use the [Codacy-CLI](https://github.com/codacy/codacy-cli-v2), it needs to be installed.
|
|
202
|
+
In order to use the [Codacy-CLI](https://github.com/codacy/codacy-cli-v2), it needs to be installed. Note that the `CODACY_CLI_VERSION` variable is optional, in case you want to use a specific version of our CLI.
|
|
201
203
|
|
|
202
204
|
## License
|
|
203
205
|
|
package/dist/index.js
CHANGED
|
@@ -139,6 +139,10 @@ const toolDefinitions = {
|
|
|
139
139
|
tool: Tools.cliAnalyzeTool,
|
|
140
140
|
handler: Handlers.cliAnalyzeHandler,
|
|
141
141
|
},
|
|
142
|
+
codacy_setup_repository: {
|
|
143
|
+
tool: Tools.setupRepositoryTool,
|
|
144
|
+
handler: Handlers.setupRepositoryHandler,
|
|
145
|
+
},
|
|
142
146
|
};
|
|
143
147
|
// Register tools
|
|
144
148
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
@@ -2,6 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { exec } from 'child_process';
|
|
4
4
|
const CODACY_ACCOUNT_TOKEN = process.env.CODACY_ACCOUNT_TOKEN;
|
|
5
|
+
const CODACY_CLI_VERSION = process.env.CODACY_CLI_VERSION;
|
|
5
6
|
const CLI_FILE_NAME = 'cli.sh';
|
|
6
7
|
const CLI_FOLDER_NAME = '.codacy';
|
|
7
8
|
const CLI_LOCAL_COMMAND = `${CLI_FOLDER_NAME}/${CLI_FILE_NAME}`;
|
|
@@ -10,7 +11,7 @@ const CLI_GLOBAL_COMMAND = 'codacy-cli';
|
|
|
10
11
|
const MAX_BUFFER_SIZE = 1024 * 1024 * 10;
|
|
11
12
|
const execAsync = (command, options) => {
|
|
12
13
|
return new Promise((resolve, reject) => {
|
|
13
|
-
exec(command
|
|
14
|
+
exec(`${CODACY_CLI_VERSION ? `CODACY_CLI_V2_VERSION=${CODACY_CLI_VERSION} ` : ''}${command}`, {
|
|
14
15
|
cwd: options.rootPath,
|
|
15
16
|
maxBuffer: MAX_BUFFER_SIZE, // To solve: stdout maxBuffer exceeded
|
|
16
17
|
}, (error, stdout, stderr) => {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { AccountService, OrganizationService, RepositoryService } from '../api/client/index.js';
|
|
2
|
+
const findOrganization = async (provider, organization, cursor) => {
|
|
3
|
+
try {
|
|
4
|
+
const { data: orgs, pagination } = await AccountService.listOrganizations(provider, cursor, 100);
|
|
5
|
+
const existingOrg = orgs.find(org => org.name === organization && org.provider === provider);
|
|
6
|
+
if (!existingOrg) {
|
|
7
|
+
if (pagination?.cursor === null) {
|
|
8
|
+
return {
|
|
9
|
+
success: false,
|
|
10
|
+
message: 'Organization not found',
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return findOrganization(provider, organization, pagination?.cursor);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
success: true,
|
|
17
|
+
organization: existingOrg,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
message: `Failed to find organization: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const addOrganization = async (args) => {
|
|
28
|
+
const { provider, organization } = args;
|
|
29
|
+
const findOrgResult = await findOrganization(provider, organization);
|
|
30
|
+
if (!findOrgResult.success) {
|
|
31
|
+
return findOrgResult;
|
|
32
|
+
}
|
|
33
|
+
const { organization: existingOrg } = findOrgResult;
|
|
34
|
+
if (existingOrg?.joinStatus === 'member') {
|
|
35
|
+
return {
|
|
36
|
+
success: true,
|
|
37
|
+
message: `Organization already added to Codacy: ${JSON.stringify(existingOrg)}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (existingOrg?.joinStatus === 'pendingMember') {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
message: 'Waiting for join request to be approved',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (existingOrg?.joinStatus === 'remoteMember') {
|
|
47
|
+
if (existingOrg.identifier) {
|
|
48
|
+
try {
|
|
49
|
+
await OrganizationService.joinOrganization(provider, organization);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
message: `Failed to join organization: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
await OrganizationService.addOrganization({
|
|
60
|
+
provider,
|
|
61
|
+
remoteIdentifier: existingOrg.remoteIdentifier,
|
|
62
|
+
name: organization,
|
|
63
|
+
type: existingOrg.type,
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
success: true,
|
|
67
|
+
message: 'Organization added to Codacy',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
message: 'Organization not found',
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export const setupRepositoryHandler = async (args) => {
|
|
77
|
+
const { provider, organization, repository } = args;
|
|
78
|
+
const repositoryFullPath = `${organization}/${repository}`;
|
|
79
|
+
const addOrgResult = await addOrganization({ provider, organization });
|
|
80
|
+
if (!addOrgResult.success) {
|
|
81
|
+
return addOrgResult;
|
|
82
|
+
}
|
|
83
|
+
const { data: orgData } = await OrganizationService.getOrganization(provider, organization);
|
|
84
|
+
const isAdmin = orgData.membership.userRole === 'admin';
|
|
85
|
+
const { data } = await OrganizationService.listOrganizationRepositories(provider, organization, undefined, 10, repository, 'NotSynced');
|
|
86
|
+
const remoteRepository = data.find(repo => repo.fullPath === repositoryFullPath);
|
|
87
|
+
if (!remoteRepository) {
|
|
88
|
+
return {
|
|
89
|
+
success: false,
|
|
90
|
+
message: `Repository not found`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (remoteRepository?.addedState === 'Added') {
|
|
94
|
+
if (!isAdmin) {
|
|
95
|
+
try {
|
|
96
|
+
await RepositoryService.followAddedRepository(provider, organization, repository);
|
|
97
|
+
return {
|
|
98
|
+
success: true,
|
|
99
|
+
message: 'Repository followed',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
error: error,
|
|
106
|
+
message: `Failed to follow repository: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
success: true,
|
|
112
|
+
message: 'Repository is already added to Codacy',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (remoteRepository?.addedState === 'Following') {
|
|
116
|
+
return {
|
|
117
|
+
success: true,
|
|
118
|
+
message: 'Repository is already being followed',
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await RepositoryService.addRepository({ provider, repositoryFullPath });
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
message: 'Repository added to Codacy',
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
return {
|
|
130
|
+
success: false,
|
|
131
|
+
error: error,
|
|
132
|
+
message: `Failed to add repository: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
};
|
package/dist/src/schemas.js
CHANGED
|
@@ -21,6 +21,7 @@ export const toolNames = {
|
|
|
21
21
|
CODACY_GET_PATTERN: 'codacy_get_pattern',
|
|
22
22
|
CODACY_CLI_ANALYZE: 'codacy_cli_analyze',
|
|
23
23
|
CODACY_GET_FILE_CLONES: 'codacy_get_file_clones',
|
|
24
|
+
CODACY_SETUP_REPOSITORY: 'codacy_setup_repository',
|
|
24
25
|
};
|
|
25
26
|
export const organizationSchema = {
|
|
26
27
|
provider: {
|
package/dist/src/tools/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { repositorySchema, toolNames } from '../schemas.js';
|
|
2
|
+
export const setupRepositoryTool = {
|
|
3
|
+
name: toolNames.CODACY_SETUP_REPOSITORY,
|
|
4
|
+
description: 'Use this tool to setup a repository. If the organization the repository belongs to is not added, this tool will add the organization and then add the repository to the organization. If the repository is not added and the user is an admin, this tool will add the repository to the organization. If the repository is already added and the user is not an admin, this tool will follow the repository.',
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
...repositorySchema,
|
|
9
|
+
},
|
|
10
|
+
required: ['provider', 'organization', 'repository'],
|
|
11
|
+
},
|
|
12
|
+
};
|