@andrebuzeli/git-mcp 5.5.0 → 5.5.2

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.
Files changed (224) hide show
  1. package/README.md +25 -0
  2. package/dist/config.d.ts +5 -131
  3. package/dist/config.js +28 -430
  4. package/dist/index.d.ts +1 -21
  5. package/dist/index.js +66 -144
  6. package/dist/providers/giteaProvider.d.ts +3 -0
  7. package/dist/providers/giteaProvider.js +12 -0
  8. package/dist/providers/githubProvider.d.ts +2 -0
  9. package/dist/providers/githubProvider.js +7 -0
  10. package/dist/providers/providerManager.d.ts +11 -0
  11. package/dist/providers/providerManager.js +48 -0
  12. package/dist/server.d.ts +6 -40
  13. package/dist/server.js +30 -700
  14. package/dist/tools/gitAnalytics.d.ts +29 -0
  15. package/dist/tools/gitAnalytics.js +72 -0
  16. package/dist/tools/gitArchive.d.ts +6 -0
  17. package/dist/tools/gitArchive.js +27 -0
  18. package/dist/tools/gitBackup.d.ts +10 -0
  19. package/dist/tools/gitBackup.js +44 -0
  20. package/dist/tools/gitBranches.d.ts +72 -0
  21. package/dist/tools/gitBranches.js +97 -0
  22. package/dist/tools/gitConfig.d.ts +34 -0
  23. package/dist/tools/gitConfig.js +73 -0
  24. package/dist/tools/gitFiles.d.ts +24 -0
  25. package/dist/tools/gitFiles.js +53 -0
  26. package/dist/tools/gitIssues.d.ts +21 -0
  27. package/dist/tools/gitIssues.js +193 -0
  28. package/dist/tools/gitMonitor.d.ts +51 -0
  29. package/dist/tools/gitMonitor.js +102 -0
  30. package/dist/tools/gitPackages.d.ts +6 -0
  31. package/dist/tools/gitPackages.js +28 -0
  32. package/dist/tools/gitPulls.d.ts +74 -0
  33. package/dist/tools/gitPulls.js +190 -0
  34. package/dist/tools/gitRelease.d.ts +34 -0
  35. package/dist/tools/gitRelease.js +99 -0
  36. package/dist/tools/gitRemote.d.ts +51 -0
  37. package/dist/tools/gitRemote.js +68 -0
  38. package/dist/tools/gitReset.d.ts +34 -0
  39. package/dist/tools/gitReset.js +64 -0
  40. package/dist/tools/gitStash.d.ts +41 -0
  41. package/dist/tools/gitStash.js +67 -0
  42. package/dist/tools/gitSync.d.ts +25 -0
  43. package/dist/tools/gitSync.js +51 -0
  44. package/dist/tools/gitTags.d.ts +30 -0
  45. package/dist/tools/gitTags.js +69 -0
  46. package/dist/tools/gitWorkflow.d.ts +69 -0
  47. package/dist/tools/gitWorkflow.js +129 -0
  48. package/dist/types.d.ts +10 -0
  49. package/dist/types.js +2 -0
  50. package/dist/utils/errors.d.ts +13 -0
  51. package/dist/utils/errors.js +22 -0
  52. package/dist/utils/safetyController.d.ts +1 -0
  53. package/dist/utils/safetyController.js +15 -0
  54. package/package.json +7 -2
  55. package/dist/config.d.ts.map +0 -1
  56. package/dist/config.js.map +0 -1
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/providers/base-provider.d.ts +0 -66
  60. package/dist/providers/base-provider.d.ts.map +0 -1
  61. package/dist/providers/base-provider.js +0 -65
  62. package/dist/providers/base-provider.js.map +0 -1
  63. package/dist/providers/gitea-provider.d.ts +0 -79
  64. package/dist/providers/gitea-provider.d.ts.map +0 -1
  65. package/dist/providers/gitea-provider.js +0 -576
  66. package/dist/providers/gitea-provider.js.map +0 -1
  67. package/dist/providers/github-provider.d.ts +0 -74
  68. package/dist/providers/github-provider.d.ts.map +0 -1
  69. package/dist/providers/github-provider.js +0 -683
  70. package/dist/providers/github-provider.js.map +0 -1
  71. package/dist/providers/index.d.ts +0 -13
  72. package/dist/providers/index.d.ts.map +0 -1
  73. package/dist/providers/index.js +0 -35
  74. package/dist/providers/index.js.map +0 -1
  75. package/dist/providers/provider-factory.d.ts +0 -49
  76. package/dist/providers/provider-factory.d.ts.map +0 -1
  77. package/dist/providers/provider-factory.js +0 -193
  78. package/dist/providers/provider-factory.js.map +0 -1
  79. package/dist/providers/provider-operation-handler.d.ts +0 -115
  80. package/dist/providers/provider-operation-handler.d.ts.map +0 -1
  81. package/dist/providers/provider-operation-handler.js +0 -449
  82. package/dist/providers/provider-operation-handler.js.map +0 -1
  83. package/dist/providers/types.d.ts +0 -200
  84. package/dist/providers/types.d.ts.map +0 -1
  85. package/dist/providers/types.js +0 -8
  86. package/dist/providers/types.js.map +0 -1
  87. package/dist/server.d.ts.map +0 -1
  88. package/dist/server.js.map +0 -1
  89. package/dist/tools/git-analytics.d.ts +0 -237
  90. package/dist/tools/git-analytics.d.ts.map +0 -1
  91. package/dist/tools/git-analytics.js +0 -828
  92. package/dist/tools/git-analytics.js.map +0 -1
  93. package/dist/tools/git-archive.d.ts +0 -113
  94. package/dist/tools/git-archive.d.ts.map +0 -1
  95. package/dist/tools/git-archive.js +0 -466
  96. package/dist/tools/git-archive.js.map +0 -1
  97. package/dist/tools/git-auto-monitor.d.ts +0 -180
  98. package/dist/tools/git-auto-monitor.d.ts.map +0 -1
  99. package/dist/tools/git-auto-monitor.js +0 -522
  100. package/dist/tools/git-auto-monitor.js.map +0 -1
  101. package/dist/tools/git-backup.d.ts +0 -105
  102. package/dist/tools/git-backup.d.ts.map +0 -1
  103. package/dist/tools/git-backup.js +0 -414
  104. package/dist/tools/git-backup.js.map +0 -1
  105. package/dist/tools/git-branches.d.ts +0 -183
  106. package/dist/tools/git-branches.d.ts.map +0 -1
  107. package/dist/tools/git-branches.js +0 -507
  108. package/dist/tools/git-branches.js.map +0 -1
  109. package/dist/tools/git-config.d.ts +0 -119
  110. package/dist/tools/git-config.d.ts.map +0 -1
  111. package/dist/tools/git-config.js +0 -449
  112. package/dist/tools/git-config.js.map +0 -1
  113. package/dist/tools/git-files.d.ts +0 -150
  114. package/dist/tools/git-files.d.ts.map +0 -1
  115. package/dist/tools/git-files.js +0 -536
  116. package/dist/tools/git-files.js.map +0 -1
  117. package/dist/tools/git-history.d.ts +0 -253
  118. package/dist/tools/git-history.d.ts.map +0 -1
  119. package/dist/tools/git-history.js +0 -824
  120. package/dist/tools/git-history.js.map +0 -1
  121. package/dist/tools/git-issues.d.ts +0 -164
  122. package/dist/tools/git-issues.d.ts.map +0 -1
  123. package/dist/tools/git-issues.js +0 -349
  124. package/dist/tools/git-issues.js.map +0 -1
  125. package/dist/tools/git-monitor.d.ts +0 -154
  126. package/dist/tools/git-monitor.d.ts.map +0 -1
  127. package/dist/tools/git-monitor.js +0 -531
  128. package/dist/tools/git-monitor.js.map +0 -1
  129. package/dist/tools/git-packages.d.ts +0 -157
  130. package/dist/tools/git-packages.d.ts.map +0 -1
  131. package/dist/tools/git-packages.js +0 -534
  132. package/dist/tools/git-packages.js.map +0 -1
  133. package/dist/tools/git-pulls.d.ts +0 -180
  134. package/dist/tools/git-pulls.d.ts.map +0 -1
  135. package/dist/tools/git-pulls.js +0 -378
  136. package/dist/tools/git-pulls.js.map +0 -1
  137. package/dist/tools/git-release.d.ts +0 -161
  138. package/dist/tools/git-release.d.ts.map +0 -1
  139. package/dist/tools/git-release.js +0 -466
  140. package/dist/tools/git-release.js.map +0 -1
  141. package/dist/tools/git-remote.d.ts +0 -128
  142. package/dist/tools/git-remote.d.ts.map +0 -1
  143. package/dist/tools/git-remote.js +0 -542
  144. package/dist/tools/git-remote.js.map +0 -1
  145. package/dist/tools/git-reset.d.ts +0 -120
  146. package/dist/tools/git-reset.d.ts.map +0 -1
  147. package/dist/tools/git-reset.js +0 -479
  148. package/dist/tools/git-reset.js.map +0 -1
  149. package/dist/tools/git-stash.d.ts +0 -124
  150. package/dist/tools/git-stash.d.ts.map +0 -1
  151. package/dist/tools/git-stash.js +0 -506
  152. package/dist/tools/git-stash.js.map +0 -1
  153. package/dist/tools/git-sync.d.ts +0 -154
  154. package/dist/tools/git-sync.d.ts.map +0 -1
  155. package/dist/tools/git-sync.js +0 -479
  156. package/dist/tools/git-sync.js.map +0 -1
  157. package/dist/tools/git-tags.d.ts +0 -136
  158. package/dist/tools/git-tags.d.ts.map +0 -1
  159. package/dist/tools/git-tags.js +0 -470
  160. package/dist/tools/git-tags.js.map +0 -1
  161. package/dist/tools/git-update.d.ts +0 -224
  162. package/dist/tools/git-update.d.ts.map +0 -1
  163. package/dist/tools/git-update.js +0 -948
  164. package/dist/tools/git-update.js.map +0 -1
  165. package/dist/tools/git-workflow.d.ts +0 -189
  166. package/dist/tools/git-workflow.d.ts.map +0 -1
  167. package/dist/tools/git-workflow.js +0 -551
  168. package/dist/tools/git-workflow.js.map +0 -1
  169. package/dist/utils/credential-manager.d.ts +0 -119
  170. package/dist/utils/credential-manager.d.ts.map +0 -1
  171. package/dist/utils/credential-manager.js +0 -450
  172. package/dist/utils/credential-manager.js.map +0 -1
  173. package/dist/utils/data-merger.d.ts +0 -49
  174. package/dist/utils/data-merger.d.ts.map +0 -1
  175. package/dist/utils/data-merger.js +0 -233
  176. package/dist/utils/data-merger.js.map +0 -1
  177. package/dist/utils/git-command-executor.d.ts +0 -330
  178. package/dist/utils/git-command-executor.d.ts.map +0 -1
  179. package/dist/utils/git-command-executor.js +0 -901
  180. package/dist/utils/git-command-executor.js.map +0 -1
  181. package/dist/utils/logger.d.ts +0 -143
  182. package/dist/utils/logger.d.ts.map +0 -1
  183. package/dist/utils/logger.js +0 -473
  184. package/dist/utils/logger.js.map +0 -1
  185. package/dist/utils/operation-error-handler.d.ts +0 -97
  186. package/dist/utils/operation-error-handler.d.ts.map +0 -1
  187. package/dist/utils/operation-error-handler.js +0 -367
  188. package/dist/utils/operation-error-handler.js.map +0 -1
  189. package/dist/utils/parameter-validator.d.ts +0 -49
  190. package/dist/utils/parameter-validator.d.ts.map +0 -1
  191. package/dist/utils/parameter-validator.js +0 -647
  192. package/dist/utils/parameter-validator.js.map +0 -1
  193. package/dist/utils/repository-checker.d.ts +0 -46
  194. package/dist/utils/repository-checker.d.ts.map +0 -1
  195. package/dist/utils/repository-checker.js +0 -151
  196. package/dist/utils/repository-checker.js.map +0 -1
  197. package/dist/utils/repository-detector.d.ts +0 -128
  198. package/dist/utils/repository-detector.d.ts.map +0 -1
  199. package/dist/utils/repository-detector.js +0 -422
  200. package/dist/utils/repository-detector.js.map +0 -1
  201. package/dist/utils/repository-sync.d.ts +0 -67
  202. package/dist/utils/repository-sync.d.ts.map +0 -1
  203. package/dist/utils/repository-sync.js +0 -344
  204. package/dist/utils/repository-sync.js.map +0 -1
  205. package/dist/utils/response-formatter.d.ts +0 -146
  206. package/dist/utils/response-formatter.d.ts.map +0 -1
  207. package/dist/utils/response-formatter.js +0 -378
  208. package/dist/utils/response-formatter.js.map +0 -1
  209. package/dist/utils/retry.d.ts +0 -12
  210. package/dist/utils/retry.d.ts.map +0 -1
  211. package/dist/utils/retry.js +0 -28
  212. package/dist/utils/retry.js.map +0 -1
  213. package/dist/utils/safety-warnings.d.ts +0 -56
  214. package/dist/utils/safety-warnings.d.ts.map +0 -1
  215. package/dist/utils/safety-warnings.js +0 -330
  216. package/dist/utils/safety-warnings.js.map +0 -1
  217. package/dist/utils/terminal-controller.d.ts +0 -79
  218. package/dist/utils/terminal-controller.d.ts.map +0 -1
  219. package/dist/utils/terminal-controller.js +0 -291
  220. package/dist/utils/terminal-controller.js.map +0 -1
  221. package/dist/utils/user-friendly-formatter.d.ts +0 -45
  222. package/dist/utils/user-friendly-formatter.d.ts.map +0 -1
  223. package/dist/utils/user-friendly-formatter.js +0 -175
  224. package/dist/utils/user-friendly-formatter.js.map +0 -1
package/README.md CHANGED
@@ -44,6 +44,13 @@ export GITEA_TOKEN="your_gitea_token"
44
44
  export GITEA_USERNAME="your_username"
45
45
  ```
46
46
 
47
+ PowerShell (Windows) example - session only:
48
+ ```powershell
49
+ $env:GITEA_URL = 'https://your-gitea-instance.com'
50
+ $env:GITEA_TOKEN = 'your_gitea_token'
51
+ $env:GITEA_USERNAME = 'your_username'
52
+ ```
53
+
47
54
  #### Multi-Provider Support
48
55
  Configure both GitHub and Gitea to use `provider="both"` in tool calls.
49
56
 
@@ -277,6 +284,24 @@ The server automatically validates credentials on startup:
277
284
  npx @andrebuzeli/git-mcp@latest
278
285
  ```
279
286
 
287
+ Optional: use a local `mcp.json` (NOT committed) to keep credentials for local testing.
288
+
289
+ 1. Create `mcp.json` next to package.json with this shape (use the `.example` as a starting point):
290
+
291
+ ```json
292
+ {
293
+ "env": {
294
+ "GITEA_URL": "http://nas-ubuntu:3000",
295
+ "GITEA_TOKEN": "<GITEA_TOKEN>",
296
+ "GITEA_USERNAME": "<GITEA_USERNAME>",
297
+ "GITHUB_TOKEN": "<GITHUB_TOKEN>",
298
+ "GITHUB_USERNAME": "<GITHUB_USERNAME>"
299
+ }
300
+ }
301
+ ```
302
+
303
+ Security note: do NOT commit `mcp.json` with real tokens. The repository's `.gitignore` includes `mcp.json` to help avoid leaks.
304
+
280
305
  ## Troubleshooting
281
306
 
282
307
  ### Common Issues
package/dist/config.d.ts CHANGED
@@ -1,131 +1,5 @@
1
- /**
2
- * Configuration Management
3
- *
4
- * Handles environment variable configuration for GitHub and Gitea providers.
5
- * Provides validation and auto-detection utilities.
6
- */
7
- export type GitMCPMode = 'normal' | 'universal';
8
- export interface GitMCPConfig {
9
- mode: GitMCPMode;
10
- github?: {
11
- token: string;
12
- username: string;
13
- };
14
- gitea?: {
15
- url: string;
16
- token: string;
17
- username: string;
18
- };
19
- }
20
- export interface ProjectContext {
21
- projectPath: string;
22
- repositoryName: string;
23
- isGitRepository: boolean;
24
- remoteOrigin?: string;
25
- currentBranch?: string;
26
- detectedProvider?: string;
27
- }
28
- export interface ConfigValidationResult {
29
- isValid: boolean;
30
- errors: string[];
31
- warnings: string[];
32
- missingEnvVars: string[];
33
- configurationGuide?: {
34
- requiredEnvVars: string[];
35
- exampleConfig: Record<string, string>;
36
- };
37
- }
38
- export interface DetailedValidationResult {
39
- isValid: boolean;
40
- providerResults: {
41
- github?: ProviderValidationResult;
42
- gitea?: ProviderValidationResult;
43
- };
44
- summary: {
45
- totalProviders: number;
46
- validProviders: number;
47
- errors: string[];
48
- warnings: string[];
49
- };
50
- }
51
- export interface ProviderValidationResult {
52
- provider: 'github' | 'gitea';
53
- isValid: boolean;
54
- isConfigured: boolean;
55
- credentialStatus: 'valid' | 'invalid' | 'missing' | 'network_error';
56
- errorDetails?: string;
57
- userInfo?: {
58
- username: string;
59
- displayName?: string;
60
- email?: string;
61
- };
62
- permissions?: string[];
63
- rateLimit?: {
64
- limit: number;
65
- remaining: number;
66
- reset: Date;
67
- };
68
- }
69
- export declare class ConfigManager {
70
- private config;
71
- constructor();
72
- private loadConfiguration;
73
- getConfig(): GitMCPConfig;
74
- isGitHubConfigured(): boolean;
75
- isGiteaConfigured(): boolean;
76
- getConfigurationStatus(): Record<string, string>;
77
- /**
78
- * Gets the current operation mode
79
- */
80
- getMode(): GitMCPMode;
81
- /**
82
- * Checks if universal mode is enabled
83
- */
84
- isUniversalMode(): boolean;
85
- /**
86
- * Validates GitHub and Gitea credentials
87
- */
88
- validateCredentials(): ConfigValidationResult;
89
- /**
90
- * Auto-detects project context from projectPath
91
- */
92
- detectProjectContext(projectPath: string): ProjectContext;
93
- /**
94
- * Auto-detects username/owner from environment variables
95
- */
96
- autoDetectUsername(provider: 'github' | 'gitea'): string | undefined;
97
- /**
98
- * Gets provider configuration for a specific provider
99
- */
100
- getProviderConfig(provider: 'github' | 'gitea'): {
101
- token: string;
102
- username: string;
103
- } | undefined;
104
- /**
105
- * Checks if a provider is supported for operations
106
- */
107
- isProviderSupported(provider: 'github' | 'gitea' | 'both'): boolean;
108
- /**
109
- * Validates credentials with detailed testing of API connectivity
110
- */
111
- validateCredentialsDetailed(): Promise<DetailedValidationResult>;
112
- /**
113
- * Validates GitHub credentials with API test
114
- */
115
- private validateGitHubCredentials;
116
- /**
117
- * Validates Gitea credentials with API test
118
- */
119
- private validateGiteaCredentials;
120
- /**
121
- * Gets configuration guidance for missing setup
122
- */
123
- getConfigurationGuidance(): {
124
- requiredEnvVars: string[];
125
- exampleConfig: Record<string, string>;
126
- setupInstructions: string[];
127
- };
128
- }
129
- export declare const configManager: ConfigManager;
130
- export declare function getProviderConfig(): GitMCPConfig;
131
- //# sourceMappingURL=config.d.ts.map
1
+ export type MCPConfig = {
2
+ env?: Record<string, string>;
3
+ [k: string]: any;
4
+ };
5
+ export declare function loadMCPConfig(configPath?: string): MCPConfig | null;
package/dist/config.js CHANGED
@@ -1,441 +1,39 @@
1
1
  "use strict";
2
- /**
3
- * Configuration Management
4
- *
5
- * Handles environment variable configuration for GitHub and Gitea providers.
6
- * Provides validation and auto-detection utilities.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
42
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
43
4
  };
44
5
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.configManager = exports.ConfigManager = void 0;
46
- exports.getProviderConfig = getProviderConfig;
47
- const path = __importStar(require("path"));
48
- const fs = __importStar(require("fs"));
49
- const rest_1 = require("@octokit/rest");
50
- const axios_1 = __importDefault(require("axios"));
51
- class ConfigManager {
52
- config;
53
- constructor() {
54
- this.config = this.loadConfiguration();
55
- }
56
- loadConfiguration() {
57
- const config = {
58
- mode: process.env.GIT_MCP_MODE || 'normal'
59
- };
60
- // GitHub configuration
61
- if (process.env.GITHUB_TOKEN && process.env.GITHUB_USERNAME) {
62
- config.github = {
63
- token: process.env.GITHUB_TOKEN,
64
- username: process.env.GITHUB_USERNAME,
65
- };
66
- }
67
- // Gitea configuration
68
- if (process.env.GITEA_URL && process.env.GITEA_TOKEN && process.env.GITEA_USERNAME) {
69
- config.gitea = {
70
- url: process.env.GITEA_URL,
71
- token: process.env.GITEA_TOKEN,
72
- username: process.env.GITEA_USERNAME,
73
- };
74
- }
75
- return config;
76
- }
77
- getConfig() {
78
- return this.config;
79
- }
80
- isGitHubConfigured() {
81
- return !!this.config.github;
82
- }
83
- isGiteaConfigured() {
84
- return !!this.config.gitea;
85
- }
86
- getConfigurationStatus() {
87
- return {
88
- github: this.isGitHubConfigured() ? 'configured' : 'not configured',
89
- gitea: this.isGiteaConfigured() ? 'configured' : 'not configured',
90
- };
91
- }
92
- /**
93
- * Gets the current operation mode
94
- */
95
- getMode() {
96
- return this.config.mode;
97
- }
98
- /**
99
- * Checks if universal mode is enabled
100
- */
101
- isUniversalMode() {
102
- return this.config.mode === 'universal';
103
- }
104
- /**
105
- * Validates GitHub and Gitea credentials
106
- */
107
- validateCredentials() {
108
- const result = {
109
- isValid: true,
110
- errors: [],
111
- warnings: [],
112
- missingEnvVars: [],
113
- };
114
- // Check GitHub configuration
115
- if (process.env.GITHUB_TOKEN && !process.env.GITHUB_USERNAME) {
116
- result.errors.push('GITHUB_TOKEN is set but GITHUB_USERNAME is missing');
117
- result.missingEnvVars.push('GITHUB_USERNAME');
118
- result.isValid = false;
119
- }
120
- if (process.env.GITHUB_USERNAME && !process.env.GITHUB_TOKEN) {
121
- result.errors.push('GITHUB_USERNAME is set but GITHUB_TOKEN is missing');
122
- result.missingEnvVars.push('GITHUB_TOKEN');
123
- result.isValid = false;
124
- }
125
- // Check Gitea configuration
126
- const giteaVars = ['GITEA_URL', 'GITEA_TOKEN', 'GITEA_USERNAME'];
127
- const setGiteaVars = giteaVars.filter(varName => !!process.env[varName]);
128
- if (setGiteaVars.length > 0 && setGiteaVars.length < 3) {
129
- const missingGiteaVars = giteaVars.filter(varName => !process.env[varName]);
130
- result.errors.push(`Partial Gitea configuration detected. Missing: ${missingGiteaVars.join(', ')}`);
131
- result.missingEnvVars.push(...missingGiteaVars);
132
- result.isValid = false;
133
- }
134
- // Validate Gitea URL format
135
- if (process.env.GITEA_URL) {
136
- try {
137
- new URL(process.env.GITEA_URL);
138
- }
139
- catch (error) {
140
- result.errors.push('GITEA_URL is not a valid URL format');
141
- result.isValid = false;
142
- }
143
- }
144
- // Check if at least one provider is configured
145
- if (!this.isGitHubConfigured() && !this.isGiteaConfigured()) {
146
- result.warnings.push('No providers are configured. At least one provider (GitHub or Gitea) should be configured for remote operations.');
147
- result.configurationGuide = {
148
- requiredEnvVars: ['GITHUB_TOKEN', 'GITHUB_USERNAME', 'GITEA_URL', 'GITEA_TOKEN', 'GITEA_USERNAME'],
149
- exampleConfig: {
150
- 'GITHUB_TOKEN': 'ghp_xxxxxxxxxxxxxxxxxxxx',
151
- 'GITHUB_USERNAME': 'your-github-username',
152
- 'GITEA_URL': 'https://gitea.example.com',
153
- 'GITEA_TOKEN': 'your-gitea-token',
154
- 'GITEA_USERNAME': 'your-gitea-username'
155
- }
156
- };
157
- }
158
- // Validate universal mode requirements
159
- if (this.config.mode === 'universal') {
160
- if (!this.isGitHubConfigured() || !this.isGiteaConfigured()) {
161
- result.errors.push('Universal mode requires both GitHub and Gitea to be configured');
162
- result.isValid = false;
163
- result.missingEnvVars.push(...(!this.isGitHubConfigured() ? ['GITHUB_TOKEN', 'GITHUB_USERNAME'] : []));
164
- result.missingEnvVars.push(...(!this.isGiteaConfigured() ? ['GITEA_URL', 'GITEA_TOKEN', 'GITEA_USERNAME'] : []));
165
- }
166
- }
167
- return result;
168
- }
169
- /**
170
- * Auto-detects project context from projectPath
171
- */
172
- detectProjectContext(projectPath) {
173
- const context = {
174
- projectPath,
175
- repositoryName: path.basename(projectPath),
176
- isGitRepository: false,
177
- };
178
- try {
179
- // Check if it's a Git repository
180
- const gitDir = path.join(projectPath, '.git');
181
- context.isGitRepository = fs.existsSync(gitDir);
182
- if (context.isGitRepository) {
183
- // Try to detect remote origin
184
- const gitConfigPath = path.join(gitDir, 'config');
185
- if (fs.existsSync(gitConfigPath)) {
186
- const gitConfig = fs.readFileSync(gitConfigPath, 'utf8');
187
- const remoteMatch = gitConfig.match(/\[remote "origin"\][\s\S]*?url = (.+)/);
188
- if (remoteMatch) {
189
- context.remoteOrigin = remoteMatch[1].trim();
190
- // Detect provider from remote URL
191
- if (context.remoteOrigin.includes('github.com')) {
192
- context.detectedProvider = 'github';
193
- }
194
- else if (context.remoteOrigin.includes('gitea') ||
195
- (this.config.gitea && context.remoteOrigin.includes(new URL(this.config.gitea.url).hostname))) {
196
- context.detectedProvider = 'gitea';
197
- }
198
- }
199
- }
200
- // Try to detect current branch
201
- const headPath = path.join(gitDir, 'HEAD');
202
- if (fs.existsSync(headPath)) {
203
- const headContent = fs.readFileSync(headPath, 'utf8').trim();
204
- const branchMatch = headContent.match(/ref: refs\/heads\/(.+)/);
205
- if (branchMatch) {
206
- context.currentBranch = branchMatch[1];
207
- }
6
+ exports.loadMCPConfig = loadMCPConfig;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ function maskSecret(value) {
10
+ if (!value)
11
+ return 'undefined';
12
+ if (value.length <= 8)
13
+ return '****';
14
+ return `${value.slice(0, 4)}...${value.slice(-4)}`;
15
+ }
16
+ function loadMCPConfig(configPath) {
17
+ const cfgPath = path_1.default.resolve(process.cwd(), configPath ?? 'mcp.json');
18
+ if (!fs_1.default.existsSync(cfgPath))
19
+ return null;
20
+ try {
21
+ const raw = fs_1.default.readFileSync(cfgPath, 'utf8');
22
+ const cfg = JSON.parse(raw);
23
+ if (cfg.env) {
24
+ for (const [k, v] of Object.entries(cfg.env)) {
25
+ // Only set if not already present in process.env
26
+ if (process.env[k] == null) {
27
+ process.env[k] = v;
208
28
  }
29
+ // Log presence (masked) but never print raw tokens
30
+ console.log(`MCP config: env.${k}=${maskSecret(process.env[k])}`);
209
31
  }
210
32
  }
211
- catch (error) {
212
- // Silently handle errors in detection
213
- }
214
- return context;
215
- }
216
- /**
217
- * Auto-detects username/owner from environment variables
218
- */
219
- autoDetectUsername(provider) {
220
- if (provider === 'github' && this.config.github) {
221
- return this.config.github.username;
222
- }
223
- if (provider === 'gitea' && this.config.gitea) {
224
- return this.config.gitea.username;
225
- }
226
- return undefined;
227
- }
228
- /**
229
- * Gets provider configuration for a specific provider
230
- */
231
- getProviderConfig(provider) {
232
- return provider === 'github' ? this.config.github : this.config.gitea;
233
- }
234
- /**
235
- * Checks if a provider is supported for operations
236
- */
237
- isProviderSupported(provider) {
238
- if (provider === 'both') {
239
- return this.isGitHubConfigured() && this.isGiteaConfigured();
240
- }
241
- return provider === 'github' ? this.isGitHubConfigured() : this.isGiteaConfigured();
242
- }
243
- /**
244
- * Validates credentials with detailed testing of API connectivity
245
- */
246
- async validateCredentialsDetailed() {
247
- const result = {
248
- isValid: false,
249
- providerResults: {},
250
- summary: {
251
- totalProviders: 0,
252
- validProviders: 0,
253
- errors: [],
254
- warnings: []
255
- }
256
- };
257
- // Validate GitHub credentials
258
- if (this.isGitHubConfigured()) {
259
- result.summary.totalProviders++;
260
- result.providerResults.github = await this.validateGitHubCredentials();
261
- if (result.providerResults.github.isValid) {
262
- result.summary.validProviders++;
263
- }
264
- else {
265
- result.summary.errors.push(`GitHub: ${result.providerResults.github.errorDetails || 'Validation failed'}`);
266
- }
267
- }
268
- // Validate Gitea credentials
269
- if (this.isGiteaConfigured()) {
270
- result.summary.totalProviders++;
271
- result.providerResults.gitea = await this.validateGiteaCredentials();
272
- if (result.providerResults.gitea.isValid) {
273
- result.summary.validProviders++;
274
- }
275
- else {
276
- result.summary.errors.push(`Gitea: ${result.providerResults.gitea.errorDetails || 'Validation failed'}`);
277
- }
278
- }
279
- result.isValid = result.summary.validProviders > 0;
280
- // Add warnings for partial configuration
281
- if (result.summary.totalProviders > 0 && result.summary.validProviders < result.summary.totalProviders) {
282
- result.summary.warnings.push('Some providers failed validation. Check credentials and network connectivity.');
283
- }
284
- if (result.summary.totalProviders === 0) {
285
- result.summary.errors.push('No providers are configured. Set up GitHub or Gitea credentials.');
286
- }
287
- // Add warning for universal mode with partial configuration
288
- if (this.config.mode === 'universal' && result.summary.totalProviders === 1) {
289
- result.summary.warnings.push('Universal mode is enabled but only one provider is configured. Both GitHub and Gitea are required for universal mode.');
290
- }
291
- return result;
33
+ return cfg;
292
34
  }
293
- /**
294
- * Validates GitHub credentials with API test
295
- */
296
- async validateGitHubCredentials() {
297
- const result = {
298
- provider: 'github',
299
- isValid: false,
300
- isConfigured: true,
301
- credentialStatus: 'invalid'
302
- };
303
- if (!this.config.github?.token) {
304
- result.credentialStatus = 'missing';
305
- result.errorDetails = 'GitHub token is not configured';
306
- return result;
307
- }
308
- try {
309
- const octokit = new rest_1.Octokit({
310
- auth: this.config.github.token
311
- });
312
- // Test authentication by getting user info
313
- const userResponse = await octokit.rest.users.getAuthenticated();
314
- result.isValid = true;
315
- result.credentialStatus = 'valid';
316
- result.userInfo = {
317
- username: userResponse.data.login,
318
- displayName: userResponse.data.name || undefined,
319
- email: userResponse.data.email || undefined
320
- };
321
- // Get rate limit info
322
- try {
323
- const rateLimitResponse = await octokit.rest.rateLimit.get();
324
- result.rateLimit = {
325
- limit: rateLimitResponse.data.rate.limit,
326
- remaining: rateLimitResponse.data.rate.remaining,
327
- reset: new Date(rateLimitResponse.data.rate.reset * 1000)
328
- };
329
- }
330
- catch (rateLimitError) {
331
- // Rate limit check failed, but auth is still valid
332
- }
333
- }
334
- catch (error) {
335
- if (error.status === 401) {
336
- result.credentialStatus = 'invalid';
337
- result.errorDetails = 'Invalid GitHub token or insufficient permissions';
338
- }
339
- else if (error.status === 403) {
340
- result.credentialStatus = 'invalid';
341
- result.errorDetails = 'GitHub token is valid but lacks required permissions';
342
- }
343
- else if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED') {
344
- result.credentialStatus = 'network_error';
345
- result.errorDetails = 'Network error: Cannot reach GitHub API';
346
- }
347
- else {
348
- result.credentialStatus = 'invalid';
349
- result.errorDetails = `GitHub API error: ${error.message}`;
350
- }
351
- }
352
- return result;
35
+ catch (err) {
36
+ console.error('Failed to parse mcp.json:', err.message ?? String(err));
37
+ return null;
353
38
  }
354
- /**
355
- * Validates Gitea credentials with API test
356
- */
357
- async validateGiteaCredentials() {
358
- const result = {
359
- provider: 'gitea',
360
- isValid: false,
361
- isConfigured: true,
362
- credentialStatus: 'invalid'
363
- };
364
- if (!this.config.gitea?.url || !this.config.gitea?.token) {
365
- result.credentialStatus = 'missing';
366
- result.errorDetails = 'Gitea URL or token is not configured';
367
- return result;
368
- }
369
- try {
370
- // Test authentication by getting user info
371
- const response = await axios_1.default.get(`${this.config.gitea.url}/api/v1/user`, {
372
- headers: {
373
- 'Authorization': `token ${this.config.gitea.token}`,
374
- 'Accept': 'application/json'
375
- },
376
- timeout: 10000
377
- });
378
- result.isValid = true;
379
- result.credentialStatus = 'valid';
380
- result.userInfo = {
381
- username: response.data.login,
382
- displayName: response.data.full_name || undefined,
383
- email: response.data.email || undefined
384
- };
385
- }
386
- catch (error) {
387
- if (error.response?.status === 401) {
388
- result.credentialStatus = 'invalid';
389
- result.errorDetails = 'Invalid Gitea token';
390
- }
391
- else if (error.response?.status === 403) {
392
- result.credentialStatus = 'invalid';
393
- result.errorDetails = 'Gitea token is valid but lacks required permissions';
394
- }
395
- else if (error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED') {
396
- result.credentialStatus = 'network_error';
397
- result.errorDetails = `Network error: Cannot reach Gitea at ${this.config.gitea.url}`;
398
- }
399
- else if (error.response?.status >= 500) {
400
- result.credentialStatus = 'network_error';
401
- result.errorDetails = `Gitea server error: ${error.response.status}`;
402
- }
403
- else {
404
- result.credentialStatus = 'invalid';
405
- result.errorDetails = `Gitea API error: ${error.message}`;
406
- }
407
- }
408
- return result;
409
- }
410
- /**
411
- * Gets configuration guidance for missing setup
412
- */
413
- getConfigurationGuidance() {
414
- return {
415
- requiredEnvVars: [
416
- 'GITHUB_TOKEN', 'GITHUB_USERNAME',
417
- 'GITEA_URL', 'GITEA_TOKEN', 'GITEA_USERNAME'
418
- ],
419
- exampleConfig: {
420
- 'GITHUB_TOKEN': 'ghp_xxxxxxxxxxxxxxxxxxxx',
421
- 'GITHUB_USERNAME': 'your-github-username',
422
- 'GITEA_URL': 'https://gitea.example.com',
423
- 'GITEA_TOKEN': 'your-gitea-token',
424
- 'GITEA_USERNAME': 'your-gitea-username'
425
- },
426
- setupInstructions: [
427
- '1. For GitHub: Create a personal access token at https://github.com/settings/tokens',
428
- '2. For Gitea: Create an access token in your Gitea instance settings',
429
- '3. Set the environment variables before running the MCP server',
430
- '4. At least one provider (GitHub or Gitea) must be configured for remote operations'
431
- ]
432
- };
433
- }
434
- }
435
- exports.ConfigManager = ConfigManager;
436
- // Export singleton instance and convenience functions
437
- exports.configManager = new ConfigManager();
438
- function getProviderConfig() {
439
- return exports.configManager.getConfig();
440
39
  }
441
- //# sourceMappingURL=config.js.map
package/dist/index.d.ts CHANGED
@@ -1,22 +1,2 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * GIT MCP Server - Entry Point
4
- *
5
- * Professional MCP server for Git operations with multi-provider support.
6
- * Supports GitHub and Gitea providers with unified interface.
7
- *
8
- * Usage:
9
- * - Local development: node dist/index.js
10
- * - NPM package: npx @andrebuzeli/git-mcp@latest
11
- * - Direct execution: git-mcp (after npm install -g)
12
- *
13
- * Environment Variables:
14
- * - GITHUB_TOKEN: GitHub personal access token
15
- * - GITHUB_USERNAME: GitHub username
16
- * - GITEA_URL: Gitea instance URL
17
- * - GITEA_TOKEN: Gitea access token
18
- * - GITEA_USERNAME: Gitea username
19
- */
20
- export { GitMCPServer } from './server.js';
21
- export { getProviderConfig } from './config.js';
22
- //# sourceMappingURL=index.d.ts.map
2
+ export {};