@codacy/codacy-mcp 0.6.10 → 0.6.12

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
@@ -5,7 +5,6 @@ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextpro
5
5
  import { OpenAPI } from './src/api/client/index.js';
6
6
  import * as Tools from './src/tools/index.js';
7
7
  import * as Handlers from './src/handlers/index.js';
8
- import { validateOrganization } from './src/middleware/validation.js';
9
8
  // Check for API key
10
9
  const CODACY_ACCOUNT_TOKEN = process.env.CODACY_ACCOUNT_TOKEN;
11
10
  OpenAPI.BASE = 'https://app.codacy.com/api/v3';
@@ -161,10 +160,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
161
160
  const toolDefinition = toolDefinitions[request.params.name];
162
161
  if (!toolDefinition)
163
162
  throw new Error(`Unknown tool: ${request.params.name}`);
164
- // Validate organization if the tool requires it
165
- if (request.params.arguments.organization) {
166
- request.params.arguments = validateOrganization(request.params.arguments);
167
- }
163
+ // Validate required arguments
164
+ const requiredArguments = (toolDefinition.tool.inputSchema.required || []);
165
+ requiredArguments.forEach(required => {
166
+ if (!request.params.arguments?.[required]) {
167
+ throw new Error(`Argument ${required} is required`);
168
+ }
169
+ });
168
170
  const result = await toolDefinition.handler(request.params.arguments);
169
171
  return {
170
172
  content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
@@ -32,7 +32,6 @@ export class CodacyCli {
32
32
  .join(' ');
33
33
  // Add the args to the command and remove any shell metacharacters
34
34
  const cmd = `${command} ${argsString}`.trim().replace(/[;&|`$]/g, '');
35
- // Add the CODACY_CLI_VERSION to the command
36
35
  return new Promise((resolve, reject) => {
37
36
  exec(cmd, {
38
37
  cwd: this.rootPath,
@@ -11,13 +11,13 @@ export class MacCodacyCli extends CodacyCli {
11
11
  const localPath = path.join(CODACY_FOLDER_NAME, 'cli.sh');
12
12
  const fullPath = path.join(this.rootPath, localPath);
13
13
  if (fs.existsSync(fullPath)) {
14
- this.setCliCommand(this._cliVersion ? `CODACY_CLI_VERSION=${this._cliVersion} ${localPath}` : localPath);
14
+ this.setCliCommand(this._cliVersion ? `CODACY_CLI_V2_VERSION=${this._cliVersion} ${localPath}` : localPath);
15
15
  return;
16
16
  }
17
17
  // check if codacy-cli is installed globally
18
18
  try {
19
19
  // first set the command for the getCliCommand to do the right thing when called
20
- this.setCliCommand(this._cliVersion ? `CODACY_CLI_VERSION=${this._cliVersion} codacy-cli` : 'codacy-cli');
20
+ this.setCliCommand(this._cliVersion ? `CODACY_CLI_V2_VERSION=${this._cliVersion} codacy-cli` : 'codacy-cli');
21
21
  await this.execAsync(`${this.getCliCommand()} --help`);
22
22
  return;
23
23
  }
@@ -50,7 +50,7 @@ export class MacCodacyCli extends CodacyCli {
50
50
  await this.execAsync(`curl -Ls -o "${execPath}" https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh`);
51
51
  await this.execAsync(`chmod +x "${execPath}"`);
52
52
  this.setCliCommand(this._cliVersion
53
- ? `CODACY_CLI_VERSION=${this._cliVersion} ${codacyCliPath}`
53
+ ? `CODACY_CLI_V2_VERSION=${this._cliVersion} ${codacyCliPath}`
54
54
  : codacyCliPath);
55
55
  }
56
56
  }
@@ -19,13 +19,17 @@ const rules = `
19
19
  ${generalOrganizationMistakes}
20
20
  ${generalRepositoryMistakes}
21
21
  `;
22
+ const optionalRepositorySchema = JSON.parse(JSON.stringify(repositorySchema));
23
+ optionalRepositorySchema.provider.description = `Optional. ${repositorySchema.provider.description}`;
24
+ optionalRepositorySchema.organization.description = `Optional. ${repositorySchema.organization.description}`;
25
+ optionalRepositorySchema.repository.description = `Optional. ${repositorySchema.repository.description}`;
22
26
  export const cliAnalyzeTool = {
23
27
  name: toolNames.CODACY_CLI_ANALYZE,
24
28
  description: `Run quality analysis locally using Codacy CLI. \n ${rules}`,
25
29
  inputSchema: {
26
30
  type: 'object',
27
31
  properties: {
28
- ...repositorySchema,
32
+ ...optionalRepositorySchema,
29
33
  rootPath: {
30
34
  type: 'string',
31
35
  description: '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.',
package/dist/src/utils.js CHANGED
@@ -91,21 +91,6 @@ export const organizationSecurityScanTypes = {
91
91
  DAST: 'Dynamic Application Security Testing',
92
92
  PenTesting: 'Penetration testing',
93
93
  };
94
- export const extractOrganizationFromUrl = (url) => {
95
- const patterns = [
96
- /git@github\.com:([^/]+)\/[^/]+\.git$/,
97
- /https:\/\/github\.com\/([^/]+)\/[^/]+\.git$/,
98
- /https:\/\/gitlab\.com\/([^/]+)\/[^/]+\.git$/,
99
- /https:\/\/bitbucket\.org\/([^/]+)\/[^/]+\.git$/,
100
- ];
101
- for (const pattern of patterns) {
102
- const match = pattern.exec(url);
103
- if (match?.[1]) {
104
- return match[1];
105
- }
106
- }
107
- return null;
108
- };
109
94
  // Helper function to parse URI based on template
110
95
  export const parseUri = (uri, template) => {
111
96
  const templateParts = template.split('/');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/codacy-mcp",
3
- "version": "0.6.10",
3
+ "version": "0.6.12",
4
4
  "description": "Codacy MCP server",
5
5
  "license": "MIT",
6
6
  "author": "Codacy",
@@ -1,27 +0,0 @@
1
- import { extractOrganizationFromUrl } from '../utils.js';
2
- export class ValidationError extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = 'ValidationError';
6
- }
7
- }
8
- export const validateOrganization = (args) => {
9
- if (!args.organization) {
10
- throw new ValidationError('Organization name is required');
11
- }
12
- if (!args.provider) {
13
- throw new ValidationError('Provider is required');
14
- }
15
- // Validate provider
16
- if (!['gh', 'gl', 'bb'].includes(args.provider)) {
17
- throw new ValidationError('Invalid provider. Must be one of: gh, gl, bb');
18
- }
19
- // If a git URL is provided, validate organization matches
20
- if (args.gitUrl) {
21
- const extractedOrg = extractOrganizationFromUrl(args.gitUrl);
22
- if (extractedOrg && extractedOrg !== args.organization) {
23
- throw new ValidationError(`Organization name '${args.organization}' does not match the organization in the git URL: '${extractedOrg}'`);
24
- }
25
- }
26
- return args;
27
- };