@codacy/codacy-mcp 0.3.4 → 0.3.6

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
@@ -3,8 +3,9 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
4
  import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
5
  import { OpenAPI } from './src/api/client/index.js';
6
- import { getFileCoverageTool, listFileIssuesTool, getPullRequestGitDiffTool, getRepositoryPullRequestFilesCoverageTool, listFilesTool, listOrganizationRepositoriesTool, listPullRequestIssuesTool, listRepositoryPullRequestsTool, searchRepositoryIssuesTool, searchSecurityItemsTool, getRepositoryWithAnalysisTool, getFileWithAnalysisTool, listRepositoryToolsTool, listToolsTool, listRepositoryToolPatternsTool, getPatternTool, getIssueTool, getRepositoryPullRequestTool, } from './src/tools/index.js';
7
- import { getFileCoverageHandler, getFileIssuesHandler, getPullRequestGitDiffHandler, getRepositoryPullRequestFilesCoverageHandler, listFilesHandler, listPullRequestIssuesHandler, listRepositoryPullRequestsHandler, searchRepositoryIssuesHandler, searchSecurityItemsHandler, listOrganizationRepositoriesHandler, getRepositoryWithAnalysisHandler, getFileWithAnalysisHandler, getRepositoryPullRequestHandler, getIssueHandler, listRepositoryToolPatternsHandler, listRepositoryToolsHandler, listToolsHandler, getPatternHandler, } from './src/handlers/index.js';
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
+ 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 || '',
@@ -106,6 +107,10 @@ const toolDefinitions = {
106
107
  tool: listRepositoryToolsTool,
107
108
  handler: listRepositoryToolsHandler,
108
109
  },
110
+ codacy_list_organization: {
111
+ tool: listOrganizationsTool,
112
+ handler: listOrganizationsHandler,
113
+ },
109
114
  };
110
115
  // Register tools
111
116
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
@@ -120,6 +125,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
120
125
  const toolDefinition = toolDefinitions[request.params.name];
121
126
  if (!toolDefinition)
122
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
+ }
123
132
  const result = await toolDefinition.handler(request.params.arguments);
124
133
  return {
125
134
  content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
@@ -0,0 +1,5 @@
1
+ import { AccountService } from '../api/client/index.js';
2
+ export const listOrganizationsHandler = async (args) => {
3
+ const { provider, cursor, limit } = args;
4
+ return await AccountService.listOrganizations(provider, cursor, limit);
5
+ };
@@ -4,3 +4,4 @@ export * from './analysis.js';
4
4
  export * from './organization.js';
5
5
  export * from './security.js';
6
6
  export * from './tools.js';
7
+ export * from './account.js';
@@ -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
+ };
@@ -16,3 +16,4 @@ export * from './getRepositoryPullRequestTool.js';
16
16
  export * from './listRepositoryToolPatternsTool.js';
17
17
  export * from './listRepositoryToolsTool.js';
18
18
  export * from './listToolsTool.js';
19
+ export * from './listOrganizationsTool.js';
@@ -0,0 +1,12 @@
1
+ import { defaultPagination, organizationSchema } from './utils.js';
2
+ export const listOrganizationsTool = {
3
+ name: 'codacy_list_organizations',
4
+ description: 'List organizations with pagination',
5
+ inputSchema: {
6
+ type: 'object',
7
+ properties: {
8
+ provider: organizationSchema.provider,
9
+ ...defaultPagination,
10
+ },
11
+ },
12
+ };
@@ -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.4",
3
+ "version": "0.3.6",
4
4
  "description": "Codacy MCP server",
5
5
  "license": "MIT",
6
6
  "author": "Codacy",