@andre.buzeli/git-mcp 16.0.8 → 16.1.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.
- package/package.json +32 -29
- package/src/index.js +159 -147
- package/src/tools/git-branches.js +13 -3
- package/src/tools/git-clone.js +48 -85
- package/src/tools/git-config.js +13 -3
- package/src/tools/git-diff.js +121 -137
- package/src/tools/git-files.js +13 -3
- package/src/tools/git-help.js +322 -284
- package/src/tools/git-history.js +13 -3
- package/src/tools/git-ignore.js +13 -3
- package/src/tools/git-issues.js +13 -3
- package/src/tools/git-merge.js +13 -3
- package/src/tools/git-pulls.js +14 -4
- package/src/tools/git-remote.js +503 -492
- package/src/tools/git-reset.js +23 -4
- package/src/tools/git-stash.js +13 -3
- package/src/tools/git-sync.js +13 -3
- package/src/tools/git-tags.js +13 -3
- package/src/tools/git-workflow.js +599 -456
- package/src/tools/git-worktree.js +180 -0
- package/src/utils/errors.js +434 -433
- package/src/utils/gitAdapter.js +118 -6
- package/src/utils/mcpNotify.js +45 -0
- package/src/utils/repoHelpers.js +5 -31
- package/src/utils/hooks.js +0 -255
- package/src/utils/metrics.js +0 -198
package/src/tools/git-diff.js
CHANGED
|
@@ -1,137 +1,121 @@
|
|
|
1
|
-
import Ajv from "ajv";
|
|
2
|
-
import { asToolError, asToolResult, errorToResponse } from "../utils/errors.js";
|
|
3
|
-
import { validateProjectPath
|
|
4
|
-
|
|
5
|
-
const ajv = new Ajv({ allErrors: true });
|
|
6
|
-
|
|
7
|
-
export function createGitDiffTool(git) {
|
|
8
|
-
const inputSchema = {
|
|
9
|
-
type: "object",
|
|
10
|
-
properties: {
|
|
11
|
-
projectPath: {
|
|
12
|
-
type: "string",
|
|
13
|
-
description: "Caminho absoluto do diretório do projeto"
|
|
14
|
-
},
|
|
15
|
-
action: {
|
|
16
|
-
type: "string",
|
|
17
|
-
enum: ["show", "compare", "stat"],
|
|
18
|
-
description: `Ação a executar:
|
|
19
|
-
- show: Mostra
|
|
20
|
-
- compare: Compara
|
|
21
|
-
- stat: Mostra estatísticas (arquivos alterados,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
type: "string",
|
|
29
|
-
description: "
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
type: "
|
|
33
|
-
description: "
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
to: toParam || "working directory",
|
|
123
|
-
...stats,
|
|
124
|
-
message: `${stats.filesChanged} arquivo(s), +${stats.insertions} -${stats.deletions}`
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return asToolError("VALIDATION_ERROR", `Ação '${action}' não suportada`, {
|
|
129
|
-
availableActions: ["show", "compare", "stat"]
|
|
130
|
-
});
|
|
131
|
-
} catch (e) {
|
|
132
|
-
return errorToResponse(e);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return { name: "git-diff", description, inputSchema, handle };
|
|
137
|
-
}
|
|
1
|
+
import Ajv from "ajv";
|
|
2
|
+
import { asToolError, asToolResult, errorToResponse } from "../utils/errors.js";
|
|
3
|
+
import { validateProjectPath } from "../utils/repoHelpers.js";
|
|
4
|
+
|
|
5
|
+
const ajv = new Ajv({ allErrors: true });
|
|
6
|
+
|
|
7
|
+
export function createGitDiffTool(git) {
|
|
8
|
+
const inputSchema = {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
projectPath: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Caminho absoluto do diretório do projeto no IDE (ex: '/home/user/meu-projeto' ou 'C:/Users/user/meu-projeto'). IMPORTANTE: este valor não pode ser inferido automaticamente pelo servidor — o agente deve fornecer o path real do projeto sendo trabalhado, não o diretório home do usuário."
|
|
14
|
+
},
|
|
15
|
+
action: {
|
|
16
|
+
type: "string",
|
|
17
|
+
enum: ["show", "compare", "stat"],
|
|
18
|
+
description: `Ação a executar:
|
|
19
|
+
- show: Mostra diferenças não commitadas (working tree vs index/HEAD)
|
|
20
|
+
- compare: Compara duas referências (branch vs branch, commit vs commit)
|
|
21
|
+
- stat: Mostra estatísticas resumidas (arquivos alterados, inserções, deleções)`
|
|
22
|
+
},
|
|
23
|
+
target: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Alvo da comparação (para action='compare'). Ex: 'HEAD', 'main', 'develop', 'abc1234'"
|
|
26
|
+
},
|
|
27
|
+
source: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Origem da comparação (para action='compare'). Default: HEAD atual"
|
|
30
|
+
},
|
|
31
|
+
staged: {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
description: "Para action='show': comparar staged vs HEAD (em vez de working vs index). Default: false"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
required: ["projectPath", "action"],
|
|
37
|
+
additionalProperties: false
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const description = `IMPORTANTE — projectPath:
|
|
41
|
+
Informe o caminho absoluto do projeto aberto no IDE. O servidor MCP não tem acesso ao
|
|
42
|
+
contexto do IDE e não consegue detectar automaticamente qual projeto está sendo trabalhado.
|
|
43
|
+
|
|
44
|
+
Visualização de diferenças (diff) no Git.
|
|
45
|
+
|
|
46
|
+
QUANDO USAR:
|
|
47
|
+
- Revisar mudanças antes de commitar (action='show')
|
|
48
|
+
- Comparar branches antes de merge (action='compare')
|
|
49
|
+
- Ver o que mudou entre versões
|
|
50
|
+
|
|
51
|
+
EXEMPLOS:
|
|
52
|
+
- Ver mudanças não commitadas: action='show'
|
|
53
|
+
- Ver mudanças staged: action='show' staged=true
|
|
54
|
+
- Comparar branch atual com main: action='compare' target='main'
|
|
55
|
+
- Estatísticas de mudança: action='stat' target='HEAD~1'`;
|
|
56
|
+
|
|
57
|
+
async function handle(args) {
|
|
58
|
+
const validate = ajv.compile(inputSchema);
|
|
59
|
+
if (!validate(args || {})) return asToolError("VALIDATION_ERROR", "Parâmetros inválidos", validate.errors);
|
|
60
|
+
const { projectPath, action } = args;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
validateProjectPath(projectPath);
|
|
64
|
+
|
|
65
|
+
if (action === "show") {
|
|
66
|
+
const diff = await git.diff(projectPath, { staged: args.staged });
|
|
67
|
+
return asToolResult({
|
|
68
|
+
diff: diff || "Nenhuma diferença encontrada",
|
|
69
|
+
staged: !!args.staged
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (action === "compare") {
|
|
74
|
+
if (!args.target) return asToolError("MISSING_PARAMETER", "target é obrigatório para compare", { parameter: "target", example: "main" });
|
|
75
|
+
const diff = await git.diff(projectPath, { target: args.target, source: args.source });
|
|
76
|
+
return asToolResult({
|
|
77
|
+
diff: diff || "Nenhuma diferença encontrada",
|
|
78
|
+
target: args.target,
|
|
79
|
+
source: args.source || "HEAD"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (action === "stat") {
|
|
84
|
+
// Implementação simplificada de diff --stat via git log ou diff
|
|
85
|
+
// Se target fornecido, compara HEAD com target. Se não, compara working com HEAD
|
|
86
|
+
// gitAdapter.diff já retorna texto. Para stat, precisaríamos parsear ou usar flag.
|
|
87
|
+
// O adaptador atual talvez não suporte --stat diretamente.
|
|
88
|
+
// Vamos retornar o diff normal com uma nota, ou tentar implementar se suportado.
|
|
89
|
+
// Assumindo que git.diff suporta options string ou object.
|
|
90
|
+
|
|
91
|
+
// Se o adaptador não suportar stat nativamente, retornamos o diff normal
|
|
92
|
+
const diff = await git.diff(projectPath, { target: args.target, source: args.source });
|
|
93
|
+
|
|
94
|
+
// Tentar gerar estatísticas simples do diff text
|
|
95
|
+
const filesChanged = (diff.match(/^diff --git/gm) || []).length;
|
|
96
|
+
const insertions = (diff.match(/^\+/gm) || []).length;
|
|
97
|
+
const deletions = (diff.match(/^-/gm) || []).length;
|
|
98
|
+
|
|
99
|
+
return asToolResult({
|
|
100
|
+
summary: `${filesChanged} arquivos alterados, ${insertions} inserções(+), ${deletions} deleções(-)`,
|
|
101
|
+
filesChanged,
|
|
102
|
+
insertions,
|
|
103
|
+
deletions,
|
|
104
|
+
target: args.target
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return asToolError("VALIDATION_ERROR", `Ação '${action}' não suportada`, { availableActions: ["show", "compare", "stat"] });
|
|
109
|
+
} catch (e) {
|
|
110
|
+
return errorToResponse(e);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
name: "git-diff",
|
|
116
|
+
description,
|
|
117
|
+
inputSchema,
|
|
118
|
+
handle,
|
|
119
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
120
|
+
};
|
|
121
|
+
}
|
package/src/tools/git-files.js
CHANGED
|
@@ -10,7 +10,7 @@ export function createGitFilesTool(git) {
|
|
|
10
10
|
properties: {
|
|
11
11
|
projectPath: {
|
|
12
12
|
type: "string",
|
|
13
|
-
description: "Caminho absoluto do diretório do projeto"
|
|
13
|
+
description: "Caminho absoluto do diretório do projeto no IDE (ex: '/home/user/meu-projeto' ou 'C:/Users/user/meu-projeto'). IMPORTANTE: este valor não pode ser inferido automaticamente pelo servidor — o agente deve fornecer o path real do projeto sendo trabalhado, não o diretório home do usuário."
|
|
14
14
|
},
|
|
15
15
|
action: {
|
|
16
16
|
type: "string",
|
|
@@ -32,7 +32,11 @@ export function createGitFilesTool(git) {
|
|
|
32
32
|
additionalProperties: false
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
const description = `
|
|
35
|
+
const description = `IMPORTANTE — projectPath:
|
|
36
|
+
Informe o caminho absoluto do projeto aberto no IDE. O servidor MCP não tem acesso ao
|
|
37
|
+
contexto do IDE e não consegue detectar automaticamente qual projeto está sendo trabalhado.
|
|
38
|
+
|
|
39
|
+
Leitura de arquivos do repositório Git.
|
|
36
40
|
|
|
37
41
|
QUANDO USAR:
|
|
38
42
|
- Ver arquivos de um commit antigo
|
|
@@ -78,5 +82,11 @@ NOTA: Esta tool lê arquivos do histórico Git, não do sistema de arquivos.`;
|
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
return {
|
|
85
|
+
return {
|
|
86
|
+
name: "git-files",
|
|
87
|
+
description,
|
|
88
|
+
inputSchema,
|
|
89
|
+
handle,
|
|
90
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
|
|
91
|
+
};
|
|
82
92
|
}
|