@codacy/codacy-mcp 0.3.5 → 0.3.7

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,6 +5,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextpro
5
5
  import { OpenAPI } from './src/api/client/index.js';
6
6
  import { getFileCoverageTool, listFileIssuesTool, getPullRequestGitDiffTool, getRepositoryPullRequestFilesCoverageTool, listFilesTool, listOrganizationRepositoriesTool, listPullRequestIssuesTool, listRepositoryPullRequestsTool, searchRepositoryIssuesTool, searchSecurityItemsTool, getRepositoryWithAnalysisTool, getFileWithAnalysisTool, listRepositoryToolsTool, listToolsTool, listRepositoryToolPatternsTool, getPatternTool, getIssueTool, getRepositoryPullRequestTool, listOrganizationsTool, } from './src/tools/index.js';
7
7
  import { getFileCoverageHandler, getFileIssuesHandler, getPullRequestGitDiffHandler, getRepositoryPullRequestFilesCoverageHandler, listFilesHandler, listPullRequestIssuesHandler, listRepositoryPullRequestsHandler, searchRepositoryIssuesHandler, searchSecurityItemsHandler, listOrganizationRepositoriesHandler, getRepositoryWithAnalysisHandler, getFileWithAnalysisHandler, getRepositoryPullRequestHandler, getIssueHandler, listRepositoryToolPatternsHandler, listRepositoryToolsHandler, listToolsHandler, getPatternHandler, listOrganizationsHandler, } from './src/handlers/index.js';
8
+ import { validateOrganization } from './src/middleware/validation.js';
8
9
  OpenAPI.BASE = 'https://app.codacy.com/api/v3';
9
10
  OpenAPI.HEADERS = {
10
11
  'api-token': process.env.CODACY_ACCOUNT_TOKEN || '',
@@ -124,6 +125,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
124
125
  const toolDefinition = toolDefinitions[request.params.name];
125
126
  if (!toolDefinition)
126
127
  throw new Error(`Unknown tool: ${request.params.name}`);
128
+ // Validate organization if the tool requires it
129
+ if (request.params.arguments.organization) {
130
+ request.params.arguments = validateOrganization(request.params.arguments);
131
+ }
127
132
  const result = await toolDefinition.handler(request.params.arguments);
128
133
  return {
129
134
  content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
@@ -0,0 +1,27 @@
1
+ import { extractOrganizationFromUrl } from '../tools/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
+ };
@@ -1,7 +1,7 @@
1
1
  import { getPaginationWithSorting, organizationSchema, securityCategories, securityScanTypes, securityStatuses, } from './utils.js';
2
2
  export const searchSecurityItemsTool = {
3
3
  name: 'codacy_list_srm_items',
4
- description: `Primary tool to list security items/issues/vulnerabilities/findings, results are related to the organization security and risk management (SRM) dashboard on Codacy. This tool contains pagination. Returns comprehensive security analysis including ${Object.keys(securityScanTypes).join(', ')} security issues. Provides advanced filtering by security categories, priorities, and scan types. Use this as the first tool when investigating security or compliance concerns. Map the results statuses as open issues: ${securityStatuses.Open.join(', ')}; and closed issues: ${securityStatuses.Closed.join(', ')}. Prioritize the open issues as the most important ones in the results. To get the SRM items for a specific repository, use the repository name in body object.`,
4
+ description: `Primary tool to list security items/issues/vulnerabilities/findings, results are related to the organization security and risk management (SRM) dashboard on Codacy. This tool contains pagination. Returns comprehensive security analysis including ${Object.keys(securityScanTypes).join(', ')} security issues. Provides advanced filtering by security categories, priorities, and scan types. Use this as the first tool when investigating security or compliance concerns. Always add the current repository name in the repositories filter, unless specified otherwise. Map the results statuses as open issues: ${securityStatuses.Open.join(', ')}; and closed issues: ${securityStatuses.Closed.join(', ')}. Prioritize the open issues as the most important ones in the results. To get the SRM items for a specific repository, use the repository name in body object.`,
5
5
  inputSchema: {
6
6
  type: 'object',
7
7
  properties: {
@@ -89,13 +89,22 @@ export const securityScanTypes = {
89
89
  PenTesting: 'Penetration testing',
90
90
  };
91
91
  export const organizationSchema = {
92
+ gitUrl: {
93
+ type: 'string',
94
+ description: "Git URL of the repository. Get the git url using 'git remote -v'",
95
+ },
92
96
  provider: {
93
97
  type: 'string',
94
98
  description: "Organization's git provider: GitHub (gh), GitLab (gl) or BitBucket (bb). Accepted values: gh, gl, bb. In case a repository is given, use that repository's Git provider. ",
95
99
  },
96
100
  organization: {
97
101
  type: 'string',
98
- description: "Organization name on the Git provider. In case a repository is given, use that repository's owner (could be an organization name or username), to find the repository's owner check the repository git remote url, it should be something like this 'git@github.com:<owner>/<repository>.git' or for gh:'https://github.com/<owner>/<repository>.git' for gl:'https://gitlab.com/<owner>/<repository>.git' for bb:'https://bitbucket.org/<owner>/<repository>.git'.",
102
+ description: "Organization name or username that owns the repository on the Git provider. This should only be extracted from the repository's git remote URL using these patterns:\n" +
103
+ "- SSH format: 'git@github.com:{organization}/{repository}.git'\n" +
104
+ "- HTTPS GitHub: 'https://github.com/{organization}/{repository}.git'\n" +
105
+ "- HTTPS GitLab: 'https://gitlab.com/{organization}/{repository}.git'\n" +
106
+ "- HTTPS BitBucket: 'https://bitbucket.org/{organization}/{repository}.git'\n" +
107
+ 'Do not use the README file to extract the organization name.',
99
108
  },
100
109
  };
101
110
  export const repositorySchema = {
@@ -140,3 +149,18 @@ export const fileSchema = {
140
149
  description: "Codacy's identifier of a file in a specific commit",
141
150
  },
142
151
  };
152
+ export const extractOrganizationFromUrl = (url) => {
153
+ const patterns = [
154
+ /git@github\.com:([^/]+)\/[^/]+\.git$/,
155
+ /https:\/\/github\.com\/([^/]+)\/[^/]+\.git$/,
156
+ /https:\/\/gitlab\.com\/([^/]+)\/[^/]+\.git$/,
157
+ /https:\/\/bitbucket\.org\/([^/]+)\/[^/]+\.git$/,
158
+ ];
159
+ for (const pattern of patterns) {
160
+ const match = url.match(pattern);
161
+ if (match && match[1]) {
162
+ return match[1];
163
+ }
164
+ }
165
+ return null;
166
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/codacy-mcp",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Codacy MCP server",
5
5
  "license": "MIT",
6
6
  "author": "Codacy",