@codacy/codacy-mcp 0.6.9 → 0.6.11

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) }],
@@ -93,21 +93,17 @@ export class MacCodacyCli extends CodacyCli {
93
93
  }
94
94
  }
95
95
  if (needsInitialization) {
96
- const apiToken = this._accountToken
97
- ? { 'api-token': this._accountToken }
98
- : {};
99
- // Repository params are required for the "api-token" flag to work; it only works all together
100
- const repositoryAccess = this.repository && this.provider && this.organization
96
+ const initParams = (this._accountToken && this.repository && this.provider && this.organization
101
97
  ? {
102
98
  provider: this.provider,
103
99
  organization: this.organization,
104
100
  repository: this.repository,
105
- ...apiToken,
101
+ 'api-token': this._accountToken,
106
102
  }
107
- : {};
103
+ : {});
108
104
  try {
109
105
  // initialize codacy-cli
110
- await this.execAsync(`${this.getCliCommand()} init`, { ...repositoryAccess });
106
+ await this.execAsync(`${this.getCliCommand()} init`, initParams);
111
107
  }
112
108
  catch (error) {
113
109
  throw new Error(`Failed to initialize CLI: ${error}`);
@@ -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.9",
3
+ "version": "0.6.11",
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
- };