@codacy/codacy-mcp 0.5.8 → 0.5.9

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
@@ -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 () => ({
@@ -6,3 +6,4 @@ export * from './security.js';
6
6
  export * from './tools.js';
7
7
  export * from './account.js';
8
8
  export * from './cliAnalyze.js';
9
+ export * from './setupRepository.js';
@@ -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
+ };
@@ -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: {
@@ -19,3 +19,4 @@ export * from './listToolsTool.js';
19
19
  export * from './listOrganizationsTool.js';
20
20
  export * from './cliAnalyzeTool.js';
21
21
  export * from './getFileClonesTool.js';
22
+ export * from './setupRepositoryTool.js';
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/codacy-mcp",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Codacy MCP server",
5
5
  "license": "MIT",
6
6
  "author": "Codacy",