Skip to content

Commit e515378

Browse files
committed
restore git as ola asked for it
1 parent 2dc1a34 commit e515378

File tree

11 files changed

+1298
-0
lines changed

11 files changed

+1298
-0
lines changed

src/git/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__
2+
.venv

src/git/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10

src/git/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use a Python image with uv pre-installed
2+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS uv
3+
4+
# Install the project into `/app`
5+
WORKDIR /app
6+
7+
# Enable bytecode compilation
8+
ENV UV_COMPILE_BYTECODE=1
9+
10+
# Copy from the cache instead of linking since it's a mounted volume
11+
ENV UV_LINK_MODE=copy
12+
13+
# Install the project's dependencies using the lockfile and settings
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-install-project --no-dev --no-editable
18+
19+
# Then, add the rest of the project source code and install it
20+
# Installing separately from its dependencies allows optimal layer caching
21+
ADD . /app
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
uv sync --frozen --no-dev --no-editable
24+
25+
FROM python:3.12-slim-bookworm
26+
27+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
28+
29+
WORKDIR /app
30+
31+
COPY --from=uv /root/.local /root/.local
32+
COPY --from=uv --chown=app:app /app/.venv /app/.venv
33+
34+
# Place executables in the environment at the front of the path
35+
ENV PATH="/app/.venv/bin:$PATH"
36+
37+
# when running the container, add --db-path and a bind mount to the host's db file
38+
ENTRYPOINT ["mcp-server-git"]

src/git/LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2024 Anthropic, PBC.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

src/git/README.md

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
# mcp-server-git: A git MCP server
2+
3+
## Overview
4+
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.
6+
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+
9+
### Tools
10+
11+
1. `git_status`
12+
- Shows the working tree status
13+
- Input:
14+
- `repo_path` (string): Path to Git repository
15+
- Returns: Current status of working directory as text output
16+
17+
2. `git_diff_unstaged`
18+
- Shows changes in working directory not yet staged
19+
- Input:
20+
- `repo_path` (string): Path to Git repository
21+
- Returns: Diff output of unstaged changes
22+
23+
3. `git_diff_staged`
24+
- Shows changes that are staged for commit
25+
- Input:
26+
- `repo_path` (string): Path to Git repository
27+
- Returns: Diff output of staged changes
28+
29+
4. `git_diff`
30+
- Shows differences between branches or commits
31+
- Inputs:
32+
- `repo_path` (string): Path to Git repository
33+
- `target` (string): Target branch or commit to compare with
34+
- Returns: Diff output comparing current state with target
35+
36+
5. `git_commit`
37+
- Records changes to the repository
38+
- Inputs:
39+
- `repo_path` (string): Path to Git repository
40+
- `message` (string): Commit message
41+
- Returns: Confirmation with new commit hash
42+
43+
6. `git_add`
44+
- Adds file contents to the staging area
45+
- Inputs:
46+
- `repo_path` (string): Path to Git repository
47+
- `files` (string[]): Array of file paths to stage
48+
- Returns: Confirmation of staged files
49+
50+
7. `git_reset`
51+
- Unstages all staged changes
52+
- Input:
53+
- `repo_path` (string): Path to Git repository
54+
- Returns: Confirmation of reset operation
55+
56+
8. `git_log`
57+
- Shows the commit logs
58+
- Inputs:
59+
- `repo_path` (string): Path to Git repository
60+
- `max_count` (number, optional): Maximum number of commits to show (default: 10)
61+
- Returns: Array of commit entries with hash, author, date, and message
62+
63+
9. `git_create_branch`
64+
- Creates a new branch
65+
- Inputs:
66+
- `repo_path` (string): Path to Git repository
67+
- `branch_name` (string): Name of the new branch
68+
- `start_point` (string, optional): Starting point for the new branch
69+
- Returns: Confirmation of branch creation
70+
10. `git_checkout`
71+
- Switches branches
72+
- Inputs:
73+
- `repo_path` (string): Path to Git repository
74+
- `branch_name` (string): Name of branch to checkout
75+
- Returns: Confirmation of branch switch
76+
11. `git_show`
77+
- Shows the contents of a commit
78+
- Inputs:
79+
- `repo_path` (string): Path to Git repository
80+
- `revision` (string): The revision (commit hash, branch name, tag) to show
81+
- Returns: Contents of the specified commit
82+
12. `git_init`
83+
- Initializes a Git repository
84+
- Inputs:
85+
- `repo_path` (string): Path to directory to initialize git repo
86+
- Returns: Confirmation of repository initialization
87+
88+
## Installation
89+
90+
### Using uv (recommended)
91+
92+
When using [`uv`](https://docs.astral.sh/uv/) no specific installation is needed. We will
93+
use [`uvx`](https://docs.astral.sh/uv/guides/tools/) to directly run *mcp-server-git*.
94+
95+
### Using PIP
96+
97+
Alternatively you can install `mcp-server-git` via pip:
98+
99+
```
100+
pip install mcp-server-git
101+
```
102+
103+
After installation, you can run it as a script using:
104+
105+
```
106+
python -m mcp_server_git
107+
```
108+
109+
## Configuration
110+
111+
### Usage with Claude Desktop
112+
113+
Add this to your `claude_desktop_config.json`:
114+
115+
<details>
116+
<summary>Using uvx</summary>
117+
118+
```json
119+
"mcpServers": {
120+
"git": {
121+
"command": "uvx",
122+
"args": ["mcp-server-git", "--repository", "path/to/git/repo"]
123+
}
124+
}
125+
```
126+
</details>
127+
128+
<details>
129+
<summary>Using docker</summary>
130+
131+
* Note: replace '/Users/username' with the a path that you want to be accessible by this tool
132+
133+
```json
134+
"mcpServers": {
135+
"git": {
136+
"command": "docker",
137+
"args": ["run", "--rm", "-i", "--mount", "type=bind,src=/Users/username,dst=/Users/username", "mcp/git"]
138+
}
139+
}
140+
```
141+
</details>
142+
143+
<details>
144+
<summary>Using pip installation</summary>
145+
146+
```json
147+
"mcpServers": {
148+
"git": {
149+
"command": "python",
150+
"args": ["-m", "mcp_server_git", "--repository", "path/to/git/repo"]
151+
}
152+
}
153+
```
154+
</details>
155+
156+
### Usage with VS Code
157+
158+
For quick installation, use one of the one-click install buttons below...
159+
160+
[![Install with UV in VS Code](https://img.shields.io/badge/VS_Code-UV-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=git&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22mcp-server-git%22%5D%7D) [![Install with UV in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-UV-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=git&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22mcp-server-git%22%5D%7D&quality=insiders)
161+
162+
[![Install with Docker in VS Code](https://img.shields.io/badge/VS_Code-Docker-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=git&config=%7B%22command%22%3A%22docker%22%2C%22args%22%3A%5B%22run%22%2C%22--rm%22%2C%22-i%22%2C%22--mount%22%2C%22type%3Dbind%2Csrc%3D%24%7BworkspaceFolder%7D%2Cdst%3D%2Fworkspace%22%2C%22mcp%2Fgit%22%5D%7D) [![Install with Docker in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Docker-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect/mcp/install?name=git&config=%7B%22command%22%3A%22docker%22%2C%22args%22%3A%5B%22run%22%2C%22--rm%22%2C%22-i%22%2C%22--mount%22%2C%22type%3Dbind%2Csrc%3D%24%7BworkspaceFolder%7D%2Cdst%3D%2Fworkspace%22%2C%22mcp%2Fgit%22%5D%7D&quality=insiders)
163+
164+
For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing `Ctrl + Shift + P` and typing `Preferences: Open Settings (JSON)`.
165+
166+
Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace. This will allow you to share the configuration with others.
167+
168+
> Note that the `mcp` key is not needed in the `.vscode/mcp.json` file.
169+
170+
```json
171+
{
172+
"mcp": {
173+
"servers": {
174+
"git": {
175+
"command": "uvx",
176+
"args": ["mcp-server-git"]
177+
}
178+
}
179+
}
180+
}
181+
```
182+
183+
For Docker installation:
184+
185+
```json
186+
{
187+
"mcp": {
188+
"servers": {
189+
"git": {
190+
"command": "docker",
191+
"args": [
192+
"run",
193+
"--rm",
194+
"-i",
195+
"--mount", "type=bind,src=${workspaceFolder},dst=/workspace",
196+
"mcp/git"
197+
]
198+
}
199+
}
200+
}
201+
}
202+
```
203+
204+
### Usage with [Zed](https://github.com/zed-industries/zed)
205+
206+
Add to your Zed settings.json:
207+
208+
<details>
209+
<summary>Using uvx</summary>
210+
211+
```json
212+
"context_servers": [
213+
"mcp-server-git": {
214+
"command": {
215+
"path": "uvx",
216+
"args": ["mcp-server-git"]
217+
}
218+
}
219+
],
220+
```
221+
</details>
222+
223+
<details>
224+
<summary>Using pip installation</summary>
225+
226+
```json
227+
"context_servers": {
228+
"mcp-server-git": {
229+
"command": {
230+
"path": "python",
231+
"args": ["-m", "mcp_server_git"]
232+
}
233+
}
234+
},
235+
```
236+
</details>
237+
238+
## Debugging
239+
240+
You can use the MCP inspector to debug the server. For uvx installations:
241+
242+
```
243+
npx @modelcontextprotocol/inspector uvx mcp-server-git
244+
```
245+
246+
Or if you've installed the package in a specific directory or are developing on it:
247+
248+
```
249+
cd path/to/servers/src/git
250+
npx @modelcontextprotocol/inspector uv run mcp-server-git
251+
```
252+
253+
Running `tail -n 20 -f ~/Library/Logs/Claude/mcp*.log` will show the logs from the server and may
254+
help you debug any issues.
255+
256+
## Development
257+
258+
If you are doing local development, there are two ways to test your changes:
259+
260+
1. Run the MCP inspector to test your changes. See [Debugging](#debugging) for run instructions.
261+
262+
2. Test using the Claude desktop app. Add the following to your `claude_desktop_config.json`:
263+
264+
### Docker
265+
266+
```json
267+
{
268+
"mcpServers": {
269+
"git": {
270+
"command": "docker",
271+
"args": [
272+
"run",
273+
"--rm",
274+
"-i",
275+
"--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
276+
"--mount", "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro",
277+
"--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
278+
"mcp/git"
279+
]
280+
}
281+
}
282+
}
283+
```
284+
285+
### UVX
286+
```json
287+
{
288+
"mcpServers": {
289+
"git": {
290+
"command": "uv",
291+
"args": [
292+
"--directory",
293+
"/<path to mcp-servers>/mcp-servers/src/git",
294+
"run",
295+
"mcp-server-git"
296+
]
297+
}
298+
}
299+
```
300+
301+
## Build
302+
303+
Docker build:
304+
305+
```bash
306+
cd src/git
307+
docker build -t mcp/git .
308+
```
309+
310+
## License
311+
312+
This MCP server 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.

0 commit comments

Comments
 (0)