@andre.buzeli/git-mcp 16.0.8 → 16.1.3

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.
@@ -11,7 +11,7 @@ export function createGitConfigTool(git) {
11
11
  properties: {
12
12
  projectPath: {
13
13
  type: "string",
14
- description: "Caminho absoluto do diretório do projeto"
14
+ 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."
15
15
  },
16
16
  action: {
17
17
  type: "string",
@@ -40,7 +40,11 @@ export function createGitConfigTool(git) {
40
40
  additionalProperties: false
41
41
  };
42
42
 
43
- const description = `Gerenciamento de configurações Git.
43
+ const description = `IMPORTANTE projectPath:
44
+ Informe o caminho absoluto do projeto aberto no IDE. O servidor MCP não tem acesso ao
45
+ contexto do IDE e não consegue detectar automaticamente qual projeto está sendo trabalhado.
46
+
47
+ Gerenciamento de configurações Git.
44
48
 
45
49
  CONFIGURAÇÕES COMUNS:
46
50
  - user.name: Nome do autor dos commits
@@ -90,5 +94,11 @@ EXEMPLOS:
90
94
  }
91
95
  }
92
96
 
93
- return { name: "git-config", description, inputSchema, handle };
97
+ return {
98
+ name: "git-config",
99
+ description,
100
+ inputSchema,
101
+ handle,
102
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true }
103
+ };
94
104
  }
@@ -1,137 +1,122 @@
1
- import Ajv from "ajv";
2
- import { asToolError, asToolResult, errorToResponse } from "../utils/errors.js";
3
- import { validateProjectPath, withRetry } 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"
14
- },
15
- action: {
16
- type: "string",
17
- enum: ["show", "compare", "stat"],
18
- description: `Ação a executar:
19
- - show: Mostra diff do working directory (arquivos não commitados)
20
- - compare: Compara dois commits/branches/tags
21
- - stat: Mostra estatísticas (arquivos alterados, linhas +/-)`
22
- },
23
- from: {
24
- type: "string",
25
- description: "Ref inicial para comparação (commit SHA, branch, tag). Default: HEAD"
26
- },
27
- fromRef: {
28
- type: "string",
29
- description: "Alias para 'from'. Ref inicial para comparação"
30
- },
31
- to: {
32
- type: "string",
33
- description: "Ref final para comparação. Se não fornecido, compara com working directory"
34
- },
35
- toRef: {
36
- type: "string",
37
- description: "Alias para 'to'. Ref final para comparação"
38
- },
39
- file: {
40
- type: "string",
41
- description: "Arquivo específico para ver diff. Se não fornecido, mostra todos"
42
- },
43
- filepath: {
44
- type: "string",
45
- description: "Alias para 'file'. Arquivo específico para ver diff"
46
- },
47
- context: {
48
- type: "number",
49
- description: "Número de linhas de contexto ao redor das mudanças. Default: 3"
50
- }
51
- },
52
- required: ["projectPath", "action"],
53
- additionalProperties: false
54
- };
55
-
56
- const description = `Ver diferenças entre commits, branches ou arquivos.
57
-
58
- QUANDO USAR:
59
- - Ver o que mudou antes de commitar (action='show')
60
- - Comparar branches antes de merge (action='compare')
61
- - Ver estatísticas de mudanças (action='stat')
62
-
63
- EXEMPLOS:
64
- - Ver mudanças não commitadas: action='show'
65
- - Ver mudanças de um arquivo: action='show' file='src/index.js'
66
- - Comparar com último commit: action='compare' from='HEAD~1'
67
- - Comparar branches: action='compare' from='main' to='feature/x'
68
- - Ver stats: action='stat' from='main' to='develop'`;
69
-
70
- async function handle(args) {
71
- const validate = ajv.compile(inputSchema);
72
- if (!validate(args || {})) return asToolError("VALIDATION_ERROR", "Parâmetros inválidos", validate.errors);
73
- const { projectPath, action } = args;
74
-
75
- // Support aliases: fromRef -> from, toRef -> to, filepath -> file
76
- const fromParam = args.from || args.fromRef || "HEAD";
77
- const toParam = args.to || args.toRef;
78
- const fileParam = args.file || args.filepath;
79
-
80
- try {
81
- validateProjectPath(projectPath);
82
- if (action === "show") {
83
- const diff = await withRetry(() => git.diff(projectPath, {
84
- file: fileParam,
85
- context: args.context || 3
86
- }), 3, "diff-show");
87
-
88
- if (!diff || diff.length === 0) {
89
- return asToolResult({
90
- changes: [],
91
- message: "Nenhuma mudança detectada no working directory"
92
- });
93
- }
94
-
95
- return asToolResult({
96
- changes: diff,
97
- totalFiles: diff.length,
98
- message: `${diff.length} arquivo(s) com mudanças`
99
- });
100
- }
101
-
102
- if (action === "compare") {
103
- const diff = await withRetry(() => git.diffCommits(projectPath, fromParam, toParam, {
104
- file: fileParam,
105
- context: args.context || 3
106
- }), 3, "diff-compare");
107
-
108
- return asToolResult({
109
- from: fromParam,
110
- to: toParam || "working directory",
111
- changes: diff,
112
- totalFiles: diff.length,
113
- message: `Comparando ${fromParam} com ${toParam || 'working directory'}: ${diff.length} arquivo(s)`
114
- });
115
- }
116
-
117
- if (action === "stat") {
118
- const stats = await withRetry(() => git.diffStats(projectPath, fromParam, toParam), 3, "diff-stat");
119
-
120
- return asToolResult({
121
- from: fromParam,
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
+ default: false,
34
+ description: "Para action='show': comparar staged vs HEAD (em vez de working vs index). Default: false"
35
+ }
36
+ },
37
+ required: ["projectPath", "action"],
38
+ additionalProperties: false
39
+ };
40
+
41
+ const description = `IMPORTANTE projectPath:
42
+ Informe o caminho absoluto do projeto aberto no IDE. O servidor MCP não tem acesso ao
43
+ contexto do IDE e não consegue detectar automaticamente qual projeto está sendo trabalhado.
44
+
45
+ Visualização de diferenças (diff) no Git.
46
+
47
+ QUANDO USAR:
48
+ - Revisar mudanças antes de commitar (action='show')
49
+ - Comparar branches antes de merge (action='compare')
50
+ - Ver o que mudou entre versões
51
+
52
+ EXEMPLOS:
53
+ - Ver mudanças não commitadas: action='show'
54
+ - Ver mudanças staged: action='show' staged=true
55
+ - Comparar branch atual com main: action='compare' target='main'
56
+ - Estatísticas de mudança: action='stat' target='HEAD~1'`;
57
+
58
+ async function handle(args) {
59
+ const validate = ajv.compile(inputSchema);
60
+ if (!validate(args || {})) return asToolError("VALIDATION_ERROR", "Parâmetros inválidos", validate.errors);
61
+ const { projectPath, action } = args;
62
+
63
+ try {
64
+ validateProjectPath(projectPath);
65
+
66
+ if (action === "show") {
67
+ const diff = await git.diff(projectPath, { staged: args.staged });
68
+ return asToolResult({
69
+ diff: diff || "Nenhuma diferença encontrada",
70
+ staged: !!args.staged
71
+ });
72
+ }
73
+
74
+ if (action === "compare") {
75
+ if (!args.target) return asToolError("MISSING_PARAMETER", "target é obrigatório para compare", { parameter: "target", example: "main" });
76
+ const diff = await git.diff(projectPath, { target: args.target, source: args.source });
77
+ return asToolResult({
78
+ diff: diff || "Nenhuma diferença encontrada",
79
+ target: args.target,
80
+ source: args.source || "HEAD"
81
+ });
82
+ }
83
+
84
+ if (action === "stat") {
85
+ // Implementação simplificada de diff --stat via git log ou diff
86
+ // Se target fornecido, compara HEAD com target. Se não, compara working com HEAD
87
+ // gitAdapter.diff já retorna texto. Para stat, precisaríamos parsear ou usar flag.
88
+ // O adaptador atual talvez não suporte --stat diretamente.
89
+ // Vamos retornar o diff normal com uma nota, ou tentar implementar se suportado.
90
+ // Assumindo que git.diff suporta options string ou object.
91
+
92
+ // Se o adaptador não suportar stat nativamente, retornamos o diff normal
93
+ const diff = await git.diff(projectPath, { target: args.target, source: args.source });
94
+
95
+ // Tentar gerar estatísticas simples do diff text
96
+ const filesChanged = (diff.match(/^diff --git/gm) || []).length;
97
+ const insertions = (diff.match(/^\+/gm) || []).length;
98
+ const deletions = (diff.match(/^-/gm) || []).length;
99
+
100
+ return asToolResult({
101
+ summary: `${filesChanged} arquivos alterados, ${insertions} inserções(+), ${deletions} deleções(-)`,
102
+ filesChanged,
103
+ insertions,
104
+ deletions,
105
+ target: args.target
106
+ });
107
+ }
108
+
109
+ return asToolError("VALIDATION_ERROR", `Ação '${action}' não suportada`, { availableActions: ["show", "compare", "stat"] });
110
+ } catch (e) {
111
+ return errorToResponse(e);
112
+ }
113
+ }
114
+
115
+ return {
116
+ name: "git-diff",
117
+ description,
118
+ inputSchema,
119
+ handle,
120
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
121
+ };
122
+ }
@@ -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 = `Leitura de arquivos do repositório Git.
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 { name: "git-files", description, inputSchema, handle };
85
+ return {
86
+ name: "git-files",
87
+ description,
88
+ inputSchema,
89
+ handle,
90
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
91
+ };
82
92
  }