mcp-server-git 0.3.0__tar.gz → 0.4.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mcp-server-git
3
- Version: 0.3.0
3
+ Version: 0.4.1
4
4
  Summary: A Model Context Protocol server providing tools to read, search, and manipulate Git repositories programmatically via LLMs
5
5
  Author: Anthropic, PBC.
6
6
  Maintainer-email: David Soria Parra <davidsp@anthropic.com>
@@ -20,6 +20,8 @@ Description-Content-Type: text/markdown
20
20
 
21
21
  # mcp-server-git: A git MCP server
22
22
 
23
+ ## Overview
24
+
23
25
  A Model Context Protocol server for Git repository interaction and automation. This server provides tools to read, search, and manipulate Git repositories via Large Language Models.
24
26
 
25
27
  Please note that mcp-server-git is currently in early development. The functionality and available tools are subject to change and expansion as we continue to develop and improve the server.
@@ -28,17 +30,13 @@ Please note that mcp-server-git is currently in early development. The functiona
28
30
 
29
31
  The current list of tools includes:
30
32
 
31
- - `git_read_file`: Read contents of a file at a specific Git reference
32
- - `git_list_files`: List all files in a repository or subdirectory
33
- - `git_file_history`: Get commit history for a specific file
34
- - `git_commit`: Create Git commits with messages and specified files
35
- - `git_search_code`: Search repository content with pattern matching
36
- - `git_get_diff`: View diffs between Git references
37
- - `git_get_repo_structure`: View repository file structure
38
- - `git_list_repos`: List available Git repositories
39
- - `git_log`: Retrieve commit log for the repository
40
- - `git_list_branches`: List all branches in the repository
41
- - `git_list_tags`: List all tags in the repository
33
+ - `git_status`: Shows the working tree status
34
+ - `git_diff_unstaged`: Shows changes in the working directory that are not yet staged
35
+ - `git_diff_staged`: Shows changes that are staged for commit
36
+ - `git_commit`: Records changes to the repository
37
+ - `git_add`: Adds file contents to the staging area
38
+ - `git_reset`: Unstages all staged changes
39
+ - `git_log`: Shows the commit logs
42
40
 
43
41
  This list is expected to grow as we add more functionality to the server. We welcome contributions from the community to expand and enhance the available tools.
44
42
 
@@ -64,10 +62,14 @@ python -m mcp_server_git
64
62
  ```
65
63
 
66
64
  ## Configuration
65
+
67
66
  ### Configure for Claude.app
68
67
 
69
68
  Add to your Claude settings:
70
69
 
70
+ <details>
71
+ <summary>Using uvx</summary>
72
+
71
73
  ```json
72
74
  "mcpServers": {
73
75
  "git": {
@@ -76,8 +78,10 @@ Add to your Claude settings:
76
78
  }
77
79
  }
78
80
  ```
81
+ </details>
79
82
 
80
- Alternatively, if using pip installation:
83
+ <details>
84
+ <summary>Using pip installation</summary>
81
85
 
82
86
  ```json
83
87
  "mcpServers": {
@@ -87,11 +91,15 @@ Alternatively, if using pip installation:
87
91
  }
88
92
  }
89
93
  ```
94
+ </details>
90
95
 
91
96
  ### Configure for Zed
92
97
 
93
98
  Add to your Zed settings.json:
94
99
 
100
+ <details>
101
+ <summary>Using uvx</summary>
102
+
95
103
  ```json
96
104
  "context_servers": [
97
105
  "mcp-server-git": {
@@ -100,18 +108,35 @@ Add to your Zed settings.json:
100
108
  }
101
109
  ],
102
110
  ```
111
+ </details>
103
112
 
104
- Alternatively, if using pip installation:
113
+ <details>
114
+ <summary>Using pip installation</summary>
105
115
 
106
116
  ```json
107
117
  "context_servers": {
108
118
  "mcp-server-git": {
109
119
  "command": "python",
110
- "args": ["-m", "mcp-server-git"]
120
+ "args": ["-m", "mcp_server_git"]
111
121
  }
112
122
  },
113
123
  ```
124
+ </details>
125
+
126
+ ## Debugging
127
+
128
+ You can use the MCP inspector to debug the server. For uvx installations:
129
+
130
+ ```
131
+ npx @modelcontextprotocol/inspector uvx mcp-server-git
132
+ ```
114
133
 
134
+ Or if you've installed the package in a specific directory or are developing on it:
135
+
136
+ ```
137
+ cd path/to/servers/src/git
138
+ npx @modelcontextprotocol/inspector uv run mcp-server-git
139
+ ```
115
140
 
116
141
  ## Contributing
117
142
 
@@ -121,3 +146,7 @@ For examples of other MCP servers and implementation patterns, see:
121
146
  https://github.com/modelcontextprotocol/servers
122
147
 
123
148
  Pull requests are welcome! Feel free to contribute new ideas, bug fixes, or enhancements to make mcp-server-git even more powerful and useful.
149
+
150
+ ## License
151
+
152
+ mcp-server-git is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
@@ -1,5 +1,7 @@
1
1
  # mcp-server-git: A git MCP server
2
2
 
3
+ ## Overview
4
+
3
5
  A Model Context Protocol server for Git repository interaction and automation. This server provides tools to read, search, and manipulate Git repositories via Large Language Models.
4
6
 
5
7
  Please note that mcp-server-git is currently in early development. The functionality and available tools are subject to change and expansion as we continue to develop and improve the server.
@@ -8,17 +10,13 @@ Please note that mcp-server-git is currently in early development. The functiona
8
10
 
9
11
  The current list of tools includes:
10
12
 
11
- - `git_read_file`: Read contents of a file at a specific Git reference
12
- - `git_list_files`: List all files in a repository or subdirectory
13
- - `git_file_history`: Get commit history for a specific file
14
- - `git_commit`: Create Git commits with messages and specified files
15
- - `git_search_code`: Search repository content with pattern matching
16
- - `git_get_diff`: View diffs between Git references
17
- - `git_get_repo_structure`: View repository file structure
18
- - `git_list_repos`: List available Git repositories
19
- - `git_log`: Retrieve commit log for the repository
20
- - `git_list_branches`: List all branches in the repository
21
- - `git_list_tags`: List all tags in the repository
13
+ - `git_status`: Shows the working tree status
14
+ - `git_diff_unstaged`: Shows changes in the working directory that are not yet staged
15
+ - `git_diff_staged`: Shows changes that are staged for commit
16
+ - `git_commit`: Records changes to the repository
17
+ - `git_add`: Adds file contents to the staging area
18
+ - `git_reset`: Unstages all staged changes
19
+ - `git_log`: Shows the commit logs
22
20
 
23
21
  This list is expected to grow as we add more functionality to the server. We welcome contributions from the community to expand and enhance the available tools.
24
22
 
@@ -44,10 +42,14 @@ python -m mcp_server_git
44
42
  ```
45
43
 
46
44
  ## Configuration
45
+
47
46
  ### Configure for Claude.app
48
47
 
49
48
  Add to your Claude settings:
50
49
 
50
+ <details>
51
+ <summary>Using uvx</summary>
52
+
51
53
  ```json
52
54
  "mcpServers": {
53
55
  "git": {
@@ -56,8 +58,10 @@ Add to your Claude settings:
56
58
  }
57
59
  }
58
60
  ```
61
+ </details>
59
62
 
60
- Alternatively, if using pip installation:
63
+ <details>
64
+ <summary>Using pip installation</summary>
61
65
 
62
66
  ```json
63
67
  "mcpServers": {
@@ -67,11 +71,15 @@ Alternatively, if using pip installation:
67
71
  }
68
72
  }
69
73
  ```
74
+ </details>
70
75
 
71
76
  ### Configure for Zed
72
77
 
73
78
  Add to your Zed settings.json:
74
79
 
80
+ <details>
81
+ <summary>Using uvx</summary>
82
+
75
83
  ```json
76
84
  "context_servers": [
77
85
  "mcp-server-git": {
@@ -80,18 +88,35 @@ Add to your Zed settings.json:
80
88
  }
81
89
  ],
82
90
  ```
91
+ </details>
83
92
 
84
- Alternatively, if using pip installation:
93
+ <details>
94
+ <summary>Using pip installation</summary>
85
95
 
86
96
  ```json
87
97
  "context_servers": {
88
98
  "mcp-server-git": {
89
99
  "command": "python",
90
- "args": ["-m", "mcp-server-git"]
100
+ "args": ["-m", "mcp_server_git"]
91
101
  }
92
102
  },
93
103
  ```
104
+ </details>
105
+
106
+ ## Debugging
107
+
108
+ You can use the MCP inspector to debug the server. For uvx installations:
109
+
110
+ ```
111
+ npx @modelcontextprotocol/inspector uvx mcp-server-git
112
+ ```
94
113
 
114
+ Or if you've installed the package in a specific directory or are developing on it:
115
+
116
+ ```
117
+ cd path/to/servers/src/git
118
+ npx @modelcontextprotocol/inspector uv run mcp-server-git
119
+ ```
95
120
 
96
121
  ## Contributing
97
122
 
@@ -101,3 +126,7 @@ For examples of other MCP servers and implementation patterns, see:
101
126
  https://github.com/modelcontextprotocol/servers
102
127
 
103
128
  Pull requests are welcome! Feel free to contribute new ideas, bug fixes, or enhancements to make mcp-server-git even more powerful and useful.
129
+
130
+ ## License
131
+
132
+ mcp-server-git is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
@@ -1,6 +1,6 @@
1
1
  [project]
2
- name = "mcp-server-git"
3
- version = "0.3.0"
2
+ name="mcp-server-git"
3
+ version = "0.4.1"
4
4
  description = "A Model Context Protocol server providing tools to read, search, and manipulate Git repositories programmatically via LLMs"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -0,0 +1,25 @@
1
+ import click
2
+ from functools import partial
3
+ from pathlib import Path
4
+ import logging
5
+ import sys
6
+ from .server import serve
7
+
8
+ @click.command()
9
+ @click.option("--repository", "-r", type=Path, help="Git repository path")
10
+ @click.option("-v", "--verbose", count=True)
11
+ def main(repository: Path | None, verbose: bool) -> None:
12
+ """MCP Git Server - Git functionality for MCP"""
13
+ import asyncio
14
+
15
+ logging_level = logging.WARN
16
+ if verbose == 1:
17
+ logging_level = logging.INFO
18
+ elif verbose >= 2:
19
+ logging_level = logging.DEBUG
20
+
21
+ logging.basicConfig(level=logging_level, stream=sys.stderr)
22
+ asyncio.run(serve(repository))
23
+
24
+ if __name__ == "__main__":
25
+ main()
@@ -0,0 +1,228 @@
1
+ import logging
2
+ import json
3
+ from pathlib import Path
4
+ from typing import Sequence
5
+ from mcp.server import Server
6
+ from mcp.server.session import ServerSession
7
+ from mcp.server.stdio import stdio_server
8
+ from mcp.types import (
9
+ ClientCapabilities,
10
+ TextContent,
11
+ Tool,
12
+ ListRootsResult,
13
+ RootsCapability,
14
+ )
15
+ from enum import Enum
16
+ import git
17
+ from pydantic import BaseModel, Field
18
+ from typing import List, Optional
19
+
20
+ class GitStatus(BaseModel):
21
+ repo_path: str
22
+
23
+ class GitDiffUnstaged(BaseModel):
24
+ repo_path: str
25
+
26
+ class GitDiffStaged(BaseModel):
27
+ repo_path: str
28
+
29
+ class GitCommit(BaseModel):
30
+ repo_path: str
31
+ message: str
32
+
33
+ class GitAdd(BaseModel):
34
+ repo_path: str
35
+ files: List[str]
36
+
37
+ class GitReset(BaseModel):
38
+ repo_path: str
39
+
40
+ class GitLog(BaseModel):
41
+ repo_path: str
42
+ max_count: int = 10
43
+
44
+ class GitTools(str, Enum):
45
+ STATUS = "git_status"
46
+ DIFF_UNSTAGED = "git_diff_unstaged"
47
+ DIFF_STAGED = "git_diff_staged"
48
+ COMMIT = "git_commit"
49
+ ADD = "git_add"
50
+ RESET = "git_reset"
51
+ LOG = "git_log"
52
+
53
+ def git_status(repo: git.Repo) -> str:
54
+ return repo.git.status()
55
+
56
+ def git_diff_unstaged(repo: git.Repo) -> str:
57
+ return repo.git.diff()
58
+
59
+ def git_diff_staged(repo: git.Repo) -> str:
60
+ return repo.git.diff("--cached")
61
+
62
+ def git_commit(repo: git.Repo, message: str) -> str:
63
+ commit = repo.index.commit(message)
64
+ return f"Changes committed successfully with hash {commit.hexsha}"
65
+
66
+ def git_add(repo: git.Repo, files: list[str]) -> str:
67
+ repo.index.add(files)
68
+ return "Files staged successfully"
69
+
70
+ def git_reset(repo: git.Repo) -> str:
71
+ repo.index.reset()
72
+ return "All staged changes reset"
73
+
74
+ def git_log(repo: git.Repo, max_count: int = 10) -> list[str]:
75
+ commits = list(repo.iter_commits(max_count=max_count))
76
+ log = []
77
+ for commit in commits:
78
+ log.append(
79
+ f"Commit: {commit.hexsha}\n"
80
+ f"Author: {commit.author}\n"
81
+ f"Date: {commit.authored_datetime}\n"
82
+ f"Message: {commit.message}\n"
83
+ )
84
+ return log
85
+
86
+ async def serve(repository: Path | None) -> None:
87
+ logger = logging.getLogger(__name__)
88
+
89
+ if repository is not None:
90
+ try:
91
+ git.Repo(repository)
92
+ logger.info(f"Using repository at {repository}")
93
+ except git.InvalidGitRepositoryError:
94
+ logger.error(f"{repository} is not a valid Git repository")
95
+ return
96
+
97
+ server = Server("mcp-git")
98
+
99
+ @server.list_tools()
100
+ async def list_tools() -> list[Tool]:
101
+ return [
102
+ Tool(
103
+ name=GitTools.STATUS,
104
+ description="Shows the working tree status",
105
+ inputSchema=GitStatus.schema(),
106
+ ),
107
+ Tool(
108
+ name=GitTools.DIFF_UNSTAGED,
109
+ description="Shows changes in the working directory that are not yet staged",
110
+ inputSchema=GitDiffUnstaged.schema(),
111
+ ),
112
+ Tool(
113
+ name=GitTools.DIFF_STAGED,
114
+ description="Shows changes that are staged for commit",
115
+ inputSchema=GitDiffStaged.schema(),
116
+ ),
117
+ Tool(
118
+ name=GitTools.COMMIT,
119
+ description="Records changes to the repository",
120
+ inputSchema=GitCommit.schema(),
121
+ ),
122
+ Tool(
123
+ name=GitTools.ADD,
124
+ description="Adds file contents to the staging area",
125
+ inputSchema=GitAdd.schema(),
126
+ ),
127
+ Tool(
128
+ name=GitTools.RESET,
129
+ description="Unstages all staged changes",
130
+ inputSchema=GitReset.schema(),
131
+ ),
132
+ Tool(
133
+ name=GitTools.LOG,
134
+ description="Shows the commit logs",
135
+ inputSchema=GitLog.schema(),
136
+ ),
137
+ ]
138
+
139
+ async def list_repos() -> Sequence[str]:
140
+ async def by_roots() -> Sequence[str]:
141
+ if not isinstance(server.request_context.session, ServerSession):
142
+ raise TypeError("server.request_context.session must be a ServerSession")
143
+
144
+ if not server.request_context.session.check_client_capability(
145
+ ClientCapabilities(roots=RootsCapability())
146
+ ):
147
+ return []
148
+
149
+ roots_result: ListRootsResult = await server.request_context.session.list_roots()
150
+ logger.debug(f"Roots result: {roots_result}")
151
+ repo_paths = []
152
+ for root in roots_result.roots:
153
+ path = root.uri.path
154
+ try:
155
+ git.Repo(path)
156
+ repo_paths.append(str(path))
157
+ except git.InvalidGitRepositoryError:
158
+ pass
159
+ return repo_paths
160
+
161
+ def by_commandline() -> Sequence[str]:
162
+ return [str(repository)] if repository is not None else []
163
+
164
+ cmd_repos = by_commandline()
165
+ root_repos = await by_roots()
166
+ return [*root_repos, *cmd_repos]
167
+
168
+ @server.call_tool()
169
+ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
170
+ repo_path = Path(arguments["repo_path"])
171
+ repo = git.Repo(repo_path)
172
+
173
+ match name:
174
+ case GitTools.STATUS:
175
+ status = git_status(repo)
176
+ return [TextContent(
177
+ type="text",
178
+ text=f"Repository status:\n{status}"
179
+ )]
180
+
181
+ case GitTools.DIFF_UNSTAGED:
182
+ diff = git_diff_unstaged(repo)
183
+ return [TextContent(
184
+ type="text",
185
+ text=f"Unstaged changes:\n{diff}"
186
+ )]
187
+
188
+ case GitTools.DIFF_STAGED:
189
+ diff = git_diff_staged(repo)
190
+ return [TextContent(
191
+ type="text",
192
+ text=f"Staged changes:\n{diff}"
193
+ )]
194
+
195
+ case GitTools.COMMIT:
196
+ result = git_commit(repo, arguments["message"])
197
+ return [TextContent(
198
+ type="text",
199
+ text=result
200
+ )]
201
+
202
+ case GitTools.ADD:
203
+ result = git_add(repo, arguments["files"])
204
+ return [TextContent(
205
+ type="text",
206
+ text=result
207
+ )]
208
+
209
+ case GitTools.RESET:
210
+ result = git_reset(repo)
211
+ return [TextContent(
212
+ type="text",
213
+ text=result
214
+ )]
215
+
216
+ case GitTools.LOG:
217
+ log = git_log(repo, arguments.get("max_count", 10))
218
+ return [TextContent(
219
+ type="text",
220
+ text="Commit history:\n" + "\n".join(log)
221
+ )]
222
+
223
+ case _:
224
+ raise ValueError(f"Unknown tool: {name}")
225
+
226
+ options = server.create_initialization_options()
227
+ async with stdio_server() as (read_stream, write_stream):
228
+ await server.run(read_stream, write_stream, options, raise_exceptions=True)