pia-mcp-server-git 0.1.0__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.
@@ -0,0 +1,3 @@
1
+ __pycache__
2
+ .venv
3
+ .history
@@ -0,0 +1 @@
1
+ 3.10
@@ -0,0 +1,46 @@
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
+ COPY uv.lock pyproject.toml ./
15
+ RUN --mount=type=cache,target=/root/.cache/uv \
16
+ uv sync --locked --no-install-project --no-dev --no-editable
17
+
18
+ # Then, add the rest of the project source code and install it
19
+ # Installing separately from its dependencies allows optimal layer caching
20
+ ADD . /app
21
+ RUN --mount=type=cache,target=/root/.cache/uv \
22
+ uv sync --locked --no-dev --no-editable
23
+
24
+ FROM python:3.12-slim-bookworm
25
+
26
+ RUN apt-get update && apt-get install -y git git-lfs && rm -rf /var/lib/apt/lists/* \
27
+ && git lfs install --system
28
+
29
+ WORKDIR /app
30
+
31
+ COPY --from=uv /root/.local /root/.local
32
+
33
+ RUN if ! id -u app >/dev/null 2>&1; then \
34
+ useradd -rUM -s /usr/sbin/nologin app; \
35
+ fi
36
+ COPY --from=uv --chown=app:app /app/.venv /app/.venv
37
+
38
+ # Place executables in the environment at the front of the path
39
+ ENV PATH="/app/.venv/bin:$PATH"
40
+ ENV HOST=0.0.0.0
41
+
42
+ EXPOSE 8000
43
+
44
+ # when running the container, add --db-path and a bind mount to the host's db file
45
+ ENTRYPOINT ["pia-mcp-server-git"]
46
+ CMD ["--transport", "streamable-http"]
@@ -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.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.5
2
+ Name: pia-mcp-server-git
3
+ Version: 0.1.0
4
+ Summary: A Model Context Protocol server providing tools to read, search, and manipulate Git repositories programmatically via LLMs
5
+ Author: Anthropic, PBC., PIA Shanghai
6
+ Maintainer: PIA Shanghai
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Keywords: automation,git,llm,mcp
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: click>=8.1.7
17
+ Requires-Dist: gitpython>=3.1.50
18
+ Requires-Dist: mcp<2,>=1.29.0
19
+ Requires-Dist: pydantic>=2.0.0
20
+ Description-Content-Type: text/markdown
21
+
22
+ # pia-mcp-server-git: A git MCP server
23
+
24
+ ## Overview
25
+
26
+ 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.
27
+
28
+ Requires MCP Python SDK 1.x (`mcp>=1.29.0,<2`). SDK 2.0 renamed APIs this server uses. The port to v2 is in progress.
29
+
30
+ Please note that pia-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.
31
+
32
+ ### Tools
33
+
34
+ 1. `git_status`
35
+ - Shows the working tree status
36
+ - Input:
37
+ - `repo_path` (string): Path to Git repository
38
+ - Returns: Current status of working directory as text output
39
+
40
+ 2. `git_diff_unstaged`
41
+ - Shows changes in working directory not yet staged
42
+ - Inputs:
43
+ - `repo_path` (string): Path to Git repository
44
+ - `context_lines` (number, optional): Number of context lines to show (default: 3)
45
+ - Returns: Diff output of unstaged changes
46
+
47
+ 3. `git_diff_staged`
48
+ - Shows changes that are staged for commit
49
+ - Inputs:
50
+ - `repo_path` (string): Path to Git repository
51
+ - `context_lines` (number, optional): Number of context lines to show (default: 3)
52
+ - Returns: Diff output of staged changes
53
+
54
+ 4. `git_diff`
55
+ - Shows differences between branches or commits
56
+ - Inputs:
57
+ - `repo_path` (string): Path to Git repository
58
+ - `target` (string): Target branch or commit to compare with
59
+ - `context_lines` (number, optional): Number of context lines to show (default: 3)
60
+ - Returns: Diff output comparing current state with target
61
+
62
+ 5. `git_commit`
63
+ - Records changes to the repository
64
+ - Inputs:
65
+ - `repo_path` (string): Path to Git repository
66
+ - `message` (string): Commit message
67
+ - Returns: Confirmation with new commit hash
68
+
69
+ 6. `git_add`
70
+ - Adds file contents to the staging area
71
+ - Inputs:
72
+ - `repo_path` (string): Path to Git repository
73
+ - `files` (string[]): Array of file paths to stage
74
+ - Returns: Confirmation of staged files
75
+
76
+ 7. `git_reset`
77
+ - Unstages all staged changes
78
+ - Input:
79
+ - `repo_path` (string): Path to Git repository
80
+ - Returns: Confirmation of reset operation
81
+
82
+ 8. `git_log`
83
+ - Shows the commit logs with optional date filtering
84
+ - Inputs:
85
+ - `repo_path` (string): Path to Git repository
86
+ - `max_count` (number, optional): Maximum number of commits to show (default: 10)
87
+ - `start_timestamp` (string, optional): Start timestamp for filtering commits. Accepts ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')
88
+ - `end_timestamp` (string, optional): End timestamp for filtering commits. Accepts ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')
89
+ - Returns: Array of commit entries with hash, author, date, and message
90
+
91
+ 9. `git_create_branch`
92
+ - Creates a new branch
93
+ - Inputs:
94
+ - `repo_path` (string): Path to Git repository
95
+ - `branch_name` (string): Name of the new branch
96
+ - `base_branch` (string, optional): Base branch to create from (defaults to current branch)
97
+ - Returns: Confirmation of branch creation
98
+
99
+ 10. `git_checkout`
100
+ - Switches branches
101
+ - Inputs:
102
+ - `repo_path` (string): Path to Git repository
103
+ - `branch_name` (string): Name of branch to checkout
104
+ - Returns: Confirmation of branch switch
105
+
106
+ 11. `git_show`
107
+ - Shows the contents of a commit
108
+ - Inputs:
109
+ - `repo_path` (string): Path to Git repository
110
+ - `revision` (string): The revision (commit hash, branch name, tag) to show
111
+ - Returns: Contents of the specified commit
112
+
113
+ 12. `git_branch`
114
+ - List Git branches
115
+ - Inputs:
116
+ - `repo_path` (string): Path to the Git repository.
117
+ - `branch_type` (string): Whether to list local branches ('local'), remote branches ('remote') or all branches('all').
118
+ - `contains` (string, optional): The commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified
119
+ - `not_contains` (string, optional): The commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified
120
+ - Returns: List of branches
121
+
122
+ ## Installation
123
+
124
+ ### Using uv (recommended)
125
+
126
+ Install `uv`, then prepare the project environment from the lock file:
127
+
128
+ ```bash
129
+ uv --directory /path/to/pia-mcp-server-git sync --locked
130
+ ```
131
+
132
+ ### Using pip
133
+
134
+ Alternatively, install the package with pip:
135
+
136
+ ```bash
137
+ pip install pia-mcp-server-git
138
+ ```
139
+
140
+ ## Deployment
141
+
142
+ This server communicates over stdio. A host service must launch the process and connect its standard input and output to the MCP client. The project does not expose an HTTP endpoint by itself.
143
+
144
+ ### Using uv from the source tree
145
+
146
+ ```bash
147
+ uv --directory /path/to/pia-mcp-server-git run --no-sync pia-mcp-server-git --repository /path/to/git/repo
148
+ ```
149
+
150
+ `--repository` limits the server to the specified repository and its subdirectories. Omit `--no-sync` if the environment has not been prepared with `uv sync`.
151
+
152
+ ### Using an installed package
153
+
154
+ ```bash
155
+ pia-mcp-server-git --repository /path/to/git/repo
156
+ ```
157
+
158
+ The equivalent module invocation is:
159
+
160
+ ```bash
161
+ python -m mcp_server_git --repository /path/to/git/repo
162
+ ```
163
+
164
+ ### Docker
165
+
166
+ Build the image from the project root:
167
+
168
+ ```bash
169
+ docker build -t mcp/git .
170
+ ```
171
+
172
+ Run it with a repository mounted into the container:
173
+
174
+ ```bash
175
+ docker run --rm -i \
176
+ --mount type=bind,src=/path/to/git/repo,dst=/workspace \
177
+ mcp/git --repository /workspace
178
+ ```
179
+
180
+ The container also communicates over stdio, so it must be started by an MCP-capable host service.
181
+
182
+ ### Verification
183
+
184
+ Use the MCP Inspector to verify the stdio server locally:
185
+
186
+ ```bash
187
+ npx @modelcontextprotocol/inspector uv --directory /path/to/pia-mcp-server-git run --no-sync pia-mcp-server-git --repository /path/to/git/repo
188
+ ```
189
+
190
+ For automated unit tests:
191
+
192
+ ```bash
193
+ uv --directory /path/to/pia-mcp-server-git run pytest
194
+ ```
@@ -0,0 +1,173 @@
1
+ # pia-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
+ Requires MCP Python SDK 1.x (`mcp>=1.29.0,<2`). SDK 2.0 renamed APIs this server uses. The port to v2 is in progress.
8
+
9
+ Please note that pia-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.
10
+
11
+ ### Tools
12
+
13
+ 1. `git_status`
14
+ - Shows the working tree status
15
+ - Input:
16
+ - `repo_path` (string): Path to Git repository
17
+ - Returns: Current status of working directory as text output
18
+
19
+ 2. `git_diff_unstaged`
20
+ - Shows changes in working directory not yet staged
21
+ - Inputs:
22
+ - `repo_path` (string): Path to Git repository
23
+ - `context_lines` (number, optional): Number of context lines to show (default: 3)
24
+ - Returns: Diff output of unstaged changes
25
+
26
+ 3. `git_diff_staged`
27
+ - Shows changes that are staged for commit
28
+ - Inputs:
29
+ - `repo_path` (string): Path to Git repository
30
+ - `context_lines` (number, optional): Number of context lines to show (default: 3)
31
+ - Returns: Diff output of staged changes
32
+
33
+ 4. `git_diff`
34
+ - Shows differences between branches or commits
35
+ - Inputs:
36
+ - `repo_path` (string): Path to Git repository
37
+ - `target` (string): Target branch or commit to compare with
38
+ - `context_lines` (number, optional): Number of context lines to show (default: 3)
39
+ - Returns: Diff output comparing current state with target
40
+
41
+ 5. `git_commit`
42
+ - Records changes to the repository
43
+ - Inputs:
44
+ - `repo_path` (string): Path to Git repository
45
+ - `message` (string): Commit message
46
+ - Returns: Confirmation with new commit hash
47
+
48
+ 6. `git_add`
49
+ - Adds file contents to the staging area
50
+ - Inputs:
51
+ - `repo_path` (string): Path to Git repository
52
+ - `files` (string[]): Array of file paths to stage
53
+ - Returns: Confirmation of staged files
54
+
55
+ 7. `git_reset`
56
+ - Unstages all staged changes
57
+ - Input:
58
+ - `repo_path` (string): Path to Git repository
59
+ - Returns: Confirmation of reset operation
60
+
61
+ 8. `git_log`
62
+ - Shows the commit logs with optional date filtering
63
+ - Inputs:
64
+ - `repo_path` (string): Path to Git repository
65
+ - `max_count` (number, optional): Maximum number of commits to show (default: 10)
66
+ - `start_timestamp` (string, optional): Start timestamp for filtering commits. Accepts ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')
67
+ - `end_timestamp` (string, optional): End timestamp for filtering commits. Accepts ISO 8601 format (e.g., '2024-01-15T14:30:25'), relative dates (e.g., '2 weeks ago', 'yesterday'), or absolute dates (e.g., '2024-01-15', 'Jan 15 2024')
68
+ - Returns: Array of commit entries with hash, author, date, and message
69
+
70
+ 9. `git_create_branch`
71
+ - Creates a new branch
72
+ - Inputs:
73
+ - `repo_path` (string): Path to Git repository
74
+ - `branch_name` (string): Name of the new branch
75
+ - `base_branch` (string, optional): Base branch to create from (defaults to current branch)
76
+ - Returns: Confirmation of branch creation
77
+
78
+ 10. `git_checkout`
79
+ - Switches branches
80
+ - Inputs:
81
+ - `repo_path` (string): Path to Git repository
82
+ - `branch_name` (string): Name of branch to checkout
83
+ - Returns: Confirmation of branch switch
84
+
85
+ 11. `git_show`
86
+ - Shows the contents of a commit
87
+ - Inputs:
88
+ - `repo_path` (string): Path to Git repository
89
+ - `revision` (string): The revision (commit hash, branch name, tag) to show
90
+ - Returns: Contents of the specified commit
91
+
92
+ 12. `git_branch`
93
+ - List Git branches
94
+ - Inputs:
95
+ - `repo_path` (string): Path to the Git repository.
96
+ - `branch_type` (string): Whether to list local branches ('local'), remote branches ('remote') or all branches('all').
97
+ - `contains` (string, optional): The commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified
98
+ - `not_contains` (string, optional): The commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified
99
+ - Returns: List of branches
100
+
101
+ ## Installation
102
+
103
+ ### Using uv (recommended)
104
+
105
+ Install `uv`, then prepare the project environment from the lock file:
106
+
107
+ ```bash
108
+ uv --directory /path/to/pia-mcp-server-git sync --locked
109
+ ```
110
+
111
+ ### Using pip
112
+
113
+ Alternatively, install the package with pip:
114
+
115
+ ```bash
116
+ pip install pia-mcp-server-git
117
+ ```
118
+
119
+ ## Deployment
120
+
121
+ This server communicates over stdio. A host service must launch the process and connect its standard input and output to the MCP client. The project does not expose an HTTP endpoint by itself.
122
+
123
+ ### Using uv from the source tree
124
+
125
+ ```bash
126
+ uv --directory /path/to/pia-mcp-server-git run --no-sync pia-mcp-server-git --repository /path/to/git/repo
127
+ ```
128
+
129
+ `--repository` limits the server to the specified repository and its subdirectories. Omit `--no-sync` if the environment has not been prepared with `uv sync`.
130
+
131
+ ### Using an installed package
132
+
133
+ ```bash
134
+ pia-mcp-server-git --repository /path/to/git/repo
135
+ ```
136
+
137
+ The equivalent module invocation is:
138
+
139
+ ```bash
140
+ python -m mcp_server_git --repository /path/to/git/repo
141
+ ```
142
+
143
+ ### Docker
144
+
145
+ Build the image from the project root:
146
+
147
+ ```bash
148
+ docker build -t mcp/git .
149
+ ```
150
+
151
+ Run it with a repository mounted into the container:
152
+
153
+ ```bash
154
+ docker run --rm -i \
155
+ --mount type=bind,src=/path/to/git/repo,dst=/workspace \
156
+ mcp/git --repository /workspace
157
+ ```
158
+
159
+ The container also communicates over stdio, so it must be started by an MCP-capable host service.
160
+
161
+ ### Verification
162
+
163
+ Use the MCP Inspector to verify the stdio server locally:
164
+
165
+ ```bash
166
+ npx @modelcontextprotocol/inspector uv --directory /path/to/pia-mcp-server-git run --no-sync pia-mcp-server-git --repository /path/to/git/repo
167
+ ```
168
+
169
+ For automated unit tests:
170
+
171
+ ```bash
172
+ uv --directory /path/to/pia-mcp-server-git run pytest
173
+ ```
@@ -0,0 +1,45 @@
1
+ [project]
2
+ name = "pia-mcp-server-git"
3
+ version = "0.1.0"
4
+ description = "A Model Context Protocol server providing tools to read, search, and manipulate Git repositories programmatically via LLMs"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ authors = [
8
+ { name = "Anthropic, PBC." },
9
+ { name = "PIA Shanghai" },
10
+ ]
11
+ maintainers = [{ name = "PIA Shanghai" }]
12
+ keywords = ["git", "mcp", "llm", "automation"]
13
+ license = { text = "MIT" }
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ ]
21
+ dependencies = [
22
+ "click>=8.1.7",
23
+ "gitpython>=3.1.50",
24
+ "mcp>=1.29.0,<2",
25
+ "pydantic>=2.0.0",
26
+ ]
27
+
28
+ [project.scripts]
29
+ pia-mcp-server-git = "mcp_server_git:main"
30
+
31
+ [build-system]
32
+ requires = ["hatchling"]
33
+ build-backend = "hatchling.build"
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["src/mcp_server_git"]
37
+
38
+ [dependency-groups]
39
+ dev = ["pyright>=1.1.407", "ruff>=0.7.3", "pytest>=8.0.0"]
40
+
41
+ [tool.pytest.ini_options]
42
+ testpaths = ["tests"]
43
+ python_files = "test_*.py"
44
+ python_classes = "Test*"
45
+ python_functions = "test_*"
@@ -0,0 +1,74 @@
1
+ import click
2
+ from pathlib import Path
3
+ import logging
4
+ import sys
5
+ from .server import serve
6
+
7
+ @click.command()
8
+ @click.option(
9
+ "--repository",
10
+ "-r",
11
+ type=Path,
12
+ help="Single Git repository boundary; cannot be combined with --workspace-root",
13
+ )
14
+ @click.option(
15
+ "--workspace-root",
16
+ type=click.Path(path_type=Path, file_okay=False),
17
+ help=(
18
+ "Directory boundary for repository access and clone destinations; cannot be "
19
+ "combined with --repository"
20
+ ),
21
+ )
22
+ @click.option(
23
+ "--allowed-git-host",
24
+ "allowed_git_hosts",
25
+ multiple=True,
26
+ help="Git host allowed for clone, fetch, pull, and push; repeat as needed",
27
+ )
28
+ @click.option("-v", "--verbose", count=True)
29
+ @click.option(
30
+ "--transport",
31
+ type=click.Choice(["stdio", "streamable-http"]),
32
+ default="stdio",
33
+ show_default=True,
34
+ )
35
+ @click.option("--host", envvar="HOST", default="127.0.0.1", show_default=True)
36
+ @click.option(
37
+ "--port",
38
+ envvar="PORT",
39
+ type=click.IntRange(1, 65535),
40
+ default=8000,
41
+ show_default=True,
42
+ )
43
+ def main(
44
+ repository: Path | None,
45
+ workspace_root: Path | None,
46
+ allowed_git_hosts: tuple[str, ...],
47
+ verbose: bool,
48
+ transport: str,
49
+ host: str,
50
+ port: int,
51
+ ) -> None:
52
+ """MCP Git Server - Git functionality for MCP"""
53
+ import asyncio
54
+
55
+ logging_level = logging.WARN
56
+ if verbose == 1:
57
+ logging_level = logging.INFO
58
+ elif verbose >= 2:
59
+ logging_level = logging.DEBUG
60
+
61
+ logging.basicConfig(level=logging_level, stream=sys.stderr)
62
+ asyncio.run(
63
+ serve(
64
+ repository,
65
+ transport=transport,
66
+ host=host,
67
+ port=port,
68
+ workspace_root=workspace_root,
69
+ allowed_git_hosts=allowed_git_hosts,
70
+ )
71
+ )
72
+
73
+ if __name__ == "__main__":
74
+ main()
@@ -0,0 +1,5 @@
1
+ # __main__.py
2
+
3
+ from mcp_server_git import main
4
+
5
+ main()
File without changes