@andrebuzeli/git-mcp 6.0.0 → 6.1.1

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.
@@ -8,6 +8,7 @@ export declare class GitBranchesTool implements Tool {
8
8
  branches?: undefined;
9
9
  current?: undefined;
10
10
  deleted?: undefined;
11
+ currentBranch?: undefined;
11
12
  result?: undefined;
12
13
  baseBranch?: undefined;
13
14
  compareBranch?: undefined;
@@ -19,6 +20,7 @@ export declare class GitBranchesTool implements Tool {
19
20
  success?: undefined;
20
21
  branch?: undefined;
21
22
  deleted?: undefined;
23
+ currentBranch?: undefined;
22
24
  result?: undefined;
23
25
  baseBranch?: undefined;
24
26
  compareBranch?: undefined;
@@ -30,6 +32,7 @@ export declare class GitBranchesTool implements Tool {
30
32
  current: boolean;
31
33
  branches?: undefined;
32
34
  deleted?: undefined;
35
+ currentBranch?: undefined;
33
36
  result?: undefined;
34
37
  baseBranch?: undefined;
35
38
  compareBranch?: undefined;
@@ -38,6 +41,7 @@ export declare class GitBranchesTool implements Tool {
38
41
  } | {
39
42
  success: boolean;
40
43
  deleted: any;
44
+ currentBranch: string;
41
45
  branch?: undefined;
42
46
  branches?: undefined;
43
47
  current?: undefined;
@@ -53,6 +57,7 @@ export declare class GitBranchesTool implements Tool {
53
57
  branches?: undefined;
54
58
  current?: undefined;
55
59
  deleted?: undefined;
60
+ currentBranch?: undefined;
56
61
  baseBranch?: undefined;
57
62
  compareBranch?: undefined;
58
63
  commits?: undefined;
@@ -67,6 +72,7 @@ export declare class GitBranchesTool implements Tool {
67
72
  branches?: undefined;
68
73
  current?: undefined;
69
74
  deleted?: undefined;
75
+ currentBranch?: undefined;
70
76
  result?: undefined;
71
77
  }>;
72
78
  }
@@ -7,6 +7,7 @@ exports.GitBranchesTool = void 0;
7
7
  const simple_git_1 = __importDefault(require("simple-git"));
8
8
  const errors_1 = require("../utils/errors");
9
9
  const safetyController_1 = require("../utils/safetyController");
10
+ const repoHelpers_1 = require("../utils/repoHelpers");
10
11
  class GitBranchesTool {
11
12
  constructor() {
12
13
  this.name = 'git-branches';
@@ -60,8 +61,17 @@ class GitBranchesTool {
60
61
  const branchName = params.branchName;
61
62
  if (!branchName)
62
63
  throw new errors_1.MCPError('VALIDATION_ERROR', 'branchName is required');
64
+ // Safety check: prevent deleting the current active branch
65
+ const currentBranch = (0, repoHelpers_1.getCurrentBranch)(projectPath);
66
+ if (currentBranch && currentBranch === branchName) {
67
+ throw new errors_1.MCPError('SAFETY_ERROR', `Cannot delete the currently active branch '${branchName}'.`, [
68
+ 'Switch to another branch first using git checkout',
69
+ 'Example: git checkout master',
70
+ 'Then retry the delete operation',
71
+ ]);
72
+ }
63
73
  await git.deleteLocalBranch(branchName, params.force);
64
- return { success: true, deleted: branchName };
74
+ return { success: true, deleted: branchName, currentBranch };
65
75
  }
66
76
  case 'merge': {
67
77
  const branchName = params.branchName;
@@ -6,6 +6,7 @@ export declare class GitSyncTool implements Tool {
6
6
  success: boolean;
7
7
  remote: any;
8
8
  branch: any;
9
+ automated: boolean;
9
10
  message: string;
10
11
  status?: undefined;
11
12
  remotes?: undefined;
@@ -20,6 +21,7 @@ export declare class GitSyncTool implements Tool {
20
21
  remotes: import("simple-git").RemoteWithRefs[];
21
22
  remote?: undefined;
22
23
  branch?: undefined;
24
+ automated?: undefined;
23
25
  message?: undefined;
24
26
  }>;
25
27
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.GitSyncTool = void 0;
7
7
  const simple_git_1 = __importDefault(require("simple-git"));
8
8
  const errors_1 = require("../utils/errors");
9
+ const repoHelpers_1 = require("../utils/repoHelpers");
9
10
  class GitSyncTool {
10
11
  constructor() {
11
12
  this.name = 'git-sync';
@@ -21,13 +22,20 @@ class GitSyncTool {
21
22
  switch (action) {
22
23
  case 'sync': {
23
24
  const remote = params.remote || 'origin';
24
- const branch = params.branch;
25
+ // Auto-detect current branch if not provided
26
+ let branch = params.branch;
27
+ if (!branch) {
28
+ branch = (0, repoHelpers_1.getCurrentBranch)(projectPath);
29
+ if (!branch) {
30
+ throw new errors_1.MCPError('VALIDATION_ERROR', 'Could not detect current branch. Please provide branch parameter.');
31
+ }
32
+ }
25
33
  if (branch) {
26
34
  await git.checkout(branch);
27
35
  }
28
36
  await git.fetch(remote);
29
37
  await git.pull(remote, branch);
30
- return { success: true, remote, branch, message: 'Repository synced' };
38
+ return { success: true, remote, branch, automated: !params.branch, message: 'Repository synced' };
31
39
  }
32
40
  case 'status': {
33
41
  const status = await git.status();
@@ -60,7 +60,14 @@ class GitUploadTool {
60
60
  const repoName = params.repoName || (0, repoHelpers_1.getRepoNameFromPath)(projectPath);
61
61
  const description = params.description || `Project uploaded via git-upload at ${new Date().toISOString()}`;
62
62
  const isPrivate = params.private !== undefined ? params.private : true;
63
- const branch = params.branch || 'master';
63
+ // Auto-detect current branch if not provided
64
+ let branch = params.branch;
65
+ if (!branch) {
66
+ branch = (0, repoHelpers_1.getCurrentBranch)(projectPath);
67
+ if (!branch) {
68
+ branch = 'master'; // Ultimate fallback
69
+ }
70
+ }
64
71
  const git = (0, simple_git_1.default)({ baseDir: projectPath });
65
72
  // Resultado com rastreabilidade completa
66
73
  const results = {
@@ -3,9 +3,19 @@
3
3
  */
4
4
  /**
5
5
  * Extract repository name from project path
6
- * Normalizes: spaces to hyphens, lowercase, removes special chars
6
+ * Normalizes: spaces to hyphens, lowercase, keeps alphanumeric and hyphens/underscores
7
7
  */
8
8
  export declare function getRepoNameFromPath(projectPath: string): string;
9
+ /**
10
+ * Get current Git branch from project path
11
+ * Returns empty string if not in a Git repository
12
+ */
13
+ export declare function getCurrentBranch(projectPath: string): string;
14
+ /**
15
+ * Get default branch from Git repository (usually 'main' or 'master')
16
+ * Falls back to 'master' if unable to determine
17
+ */
18
+ export declare function getDefaultBranch(projectPath: string): string;
9
19
  /**
10
20
  * Get GitHub owner from environment
11
21
  */
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getRepoNameFromPath = getRepoNameFromPath;
7
+ exports.getCurrentBranch = getCurrentBranch;
8
+ exports.getDefaultBranch = getDefaultBranch;
7
9
  exports.getGitHubOwner = getGitHubOwner;
8
10
  exports.getGiteaOwner = getGiteaOwner;
9
11
  exports.getGiteaUrl = getGiteaUrl;
@@ -11,18 +13,68 @@ exports.buildGitHubUrl = buildGitHubUrl;
11
13
  exports.buildGiteaUrl = buildGiteaUrl;
12
14
  exports.getRepoInfo = getRepoInfo;
13
15
  const path_1 = __importDefault(require("path"));
16
+ const child_process_1 = require("child_process");
14
17
  /**
15
18
  * Helper functions to extract repository information automatically
16
19
  */
17
20
  /**
18
21
  * Extract repository name from project path
19
- * Normalizes: spaces to hyphens, lowercase, removes special chars
22
+ * Normalizes: spaces to hyphens, lowercase, keeps alphanumeric and hyphens/underscores
20
23
  */
21
24
  function getRepoNameFromPath(projectPath) {
22
25
  return path_1.default.basename(projectPath)
23
26
  .toLowerCase()
24
27
  .replace(/\s+/g, '-')
25
- .replace(/[^a-z0-9-]/g, '');
28
+ .replace(/[^a-z0-9-_]/g, '');
29
+ }
30
+ /**
31
+ * Get current Git branch from project path
32
+ * Returns empty string if not in a Git repository
33
+ */
34
+ function getCurrentBranch(projectPath) {
35
+ try {
36
+ const branchName = (0, child_process_1.execSync)('git rev-parse --abbrev-ref HEAD', {
37
+ cwd: projectPath,
38
+ encoding: 'utf8',
39
+ stdio: ['pipe', 'pipe', 'ignore'], // Suppress stderr
40
+ });
41
+ return branchName.trim();
42
+ }
43
+ catch (error) {
44
+ return '';
45
+ }
46
+ }
47
+ /**
48
+ * Get default branch from Git repository (usually 'main' or 'master')
49
+ * Falls back to 'master' if unable to determine
50
+ */
51
+ function getDefaultBranch(projectPath) {
52
+ try {
53
+ // Try to get default branch from remote
54
+ const defaultBranch = (0, child_process_1.execSync)('git symbolic-ref refs/remotes/origin/HEAD', {
55
+ cwd: projectPath,
56
+ encoding: 'utf8',
57
+ stdio: ['pipe', 'pipe', 'ignore'],
58
+ });
59
+ return defaultBranch.trim().replace('refs/remotes/origin/', '');
60
+ }
61
+ catch (error) {
62
+ // If that fails, try to detect main or master
63
+ try {
64
+ const branches = (0, child_process_1.execSync)('git branch -r', {
65
+ cwd: projectPath,
66
+ encoding: 'utf8',
67
+ stdio: ['pipe', 'pipe', 'ignore'],
68
+ });
69
+ if (branches.includes('origin/main'))
70
+ return 'main';
71
+ if (branches.includes('origin/master'))
72
+ return 'master';
73
+ }
74
+ catch { }
75
+ // Ultimate fallback
76
+ return 'master';
77
+ }
26
78
  }
27
79
  /**
28
80
  * Get GitHub owner from environment
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@andrebuzeli/git-mcp",
3
- "version": "6.0.0",
4
- "description": "Professional MCP server for Git operations - FULLY AUTONOMOUS: each provider uses own username from env, repo name auto-normalized from projectPath (spaces→hyphens, lowercase, safe chars), zero redundant parameters, automatic dual-provider execution (GitHub + Gitea)",
3
+ "version": "6.1.1",
4
+ "description": "Professional MCP server for Git operations - FULLY AUTONOMOUS: auto-detects current branch, default branch, owner from env, repo from path. Zero manual parameters. Intelligent defaults for all operations. Dual-provider execution (GitHub + Gitea)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {