Skip to content

Commit 00306e3

Browse files
committed
docs(git): add MCP usage instructions for git_commit_signed
- Document how to call git_commit_signed via MCP and examples
1 parent 825251a commit 00306e3

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

src/git/README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,29 @@ Please note that mcp-server-git is currently in early development. The functiona
4343
- `message` (string): Commit message
4444
- Returns: Confirmation with new commit hash
4545

46-
6. `git_add`
46+
6. `git_commit_signed`
47+
- Records changes to the repository and signs the commit with GPG
48+
- Inputs:
49+
- `repo_path` (string): Path to Git repository
50+
- `message` (string): Commit message
51+
- `key_id` (string, optional): GPG key ID to use for signing. If omitted, the default signing key configured in Git will be used.
52+
- Behavior: Uses the Git CLI `-S`/`--gpg-sign` flag to create a GPG-signed commit. This passes through to the system's `git` and `gpg` configuration, so GPG must be available and configured on the host.
53+
- Returns: Confirmation with new commit hash. If signing fails (for example, no GPG key is configured), the underlying Git command will raise an error.
54+
55+
7. `git_add`
4756
- Adds file contents to the staging area
4857
- Inputs:
4958
- `repo_path` (string): Path to Git repository
5059
- `files` (string[]): Array of file paths to stage
5160
- Returns: Confirmation of staged files
5261

53-
7. `git_reset`
62+
8. `git_reset`
5463
- Unstages all staged changes
5564
- Input:
5665
- `repo_path` (string): Path to Git repository
5766
- Returns: Confirmation of reset operation
5867

59-
8. `git_log`
68+
9. `git_log`
6069
- Shows the commit logs with optional date filtering
6170
- Inputs:
6271
- `repo_path` (string): Path to Git repository
@@ -65,34 +74,36 @@ Please note that mcp-server-git is currently in early development. The functiona
6574
- `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')
6675
- Returns: Array of commit entries with hash, author, date, and message
6776

68-
9. `git_create_branch`
77+
10. `git_create_branch`
6978
- Creates a new branch
7079
- Inputs:
7180
- `repo_path` (string): Path to Git repository
7281
- `branch_name` (string): Name of the new branch
7382
- `base_branch` (string, optional): Base branch to create from (defaults to current branch)
7483
- Returns: Confirmation of branch creation
75-
10. `git_checkout`
84+
85+
11. `git_checkout`
7686
- Switches branches
7787
- Inputs:
7888
- `repo_path` (string): Path to Git repository
7989
- `branch_name` (string): Name of branch to checkout
8090
- Returns: Confirmation of branch switch
81-
11. `git_show`
91+
92+
12. `git_show`
8293
- Shows the contents of a commit
8394
- Inputs:
8495
- `repo_path` (string): Path to Git repository
8596
- `revision` (string): The revision (commit hash, branch name, tag) to show
8697
- Returns: Contents of the specified commit
8798

88-
12. `git_branch`
89-
- List Git branches
90-
- Inputs:
91-
- `repo_path` (string): Path to the Git repository.
92-
- `branch_type` (string): Whether to list local branches ('local'), remote branches ('remote') or all branches('all').
93-
- `contains` (string, optional): The commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified
94-
- `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
95-
- Returns: List of branches
99+
13. `git_branch`
100+
- List Git branches
101+
- Inputs:
102+
- `repo_path` (string): Path to the Git repository.
103+
- `branch_type` (string): Whether to list local branches ('local'), remote branches ('remote') or all branches('all').
104+
- `contains` (string, optional): The commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified
105+
- `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
106+
- Returns: List of branches
96107

97108
## Installation
98109

src/git/src/mcp_server_git/server.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ def git_commit_signed(repo: git.Repo, message: str, key_id: str | None = None) -
137137
repo.git.commit("-S" + key_id, "-m", message)
138138
else:
139139
repo.git.commit("-S", "-m", message)
140-
141140
# Get the commit hash of HEAD
142141
commit_hash = repo.head.commit.hexsha
143142
return f"Changes committed and signed successfully with hash {commit_hash}"
@@ -162,9 +161,9 @@ def git_log(repo: git.Repo, max_count: int = 10, start_timestamp: Optional[str]
162161
if end_timestamp:
163162
args.extend(['--until', end_timestamp])
164163
args.extend(['--format=%H%n%an%n%ad%n%s%n'])
165-
164+
166165
log_output = repo.git.log(*args).split('\n')
167-
166+
168167
log = []
169168
# Process commits in groups of 4 (hash, author, date, message)
170169
for i in range(0, len(log_output), 4):
@@ -368,7 +367,7 @@ def by_commandline() -> Sequence[str]:
368367
@server.call_tool()
369368
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
370369
repo_path = Path(arguments["repo_path"])
371-
370+
372371
# For all commands, we need an existing repo
373372
repo = git.Repo(repo_path)
374373

@@ -410,7 +409,7 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
410409

411410
case GitTools.COMMIT_SIGNED:
412411
result = git_commit_signed(
413-
repo,
412+
repo,
414413
arguments["message"],
415414
arguments.get("key_id")
416415
)
@@ -436,7 +435,7 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
436435
# Update the LOG case:
437436
case GitTools.LOG:
438437
log = git_log(
439-
repo,
438+
repo,
440439
arguments.get("max_count", 10),
441440
arguments.get("start_timestamp"),
442441
arguments.get("end_timestamp")
@@ -445,7 +444,7 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
445444
type="text",
446445
text="Commit history:\n" + "\n".join(log)
447446
)]
448-
447+
449448
case GitTools.CREATE_BRANCH:
450449
result = git_create_branch(
451450
repo,
@@ -482,7 +481,7 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
482481
type="text",
483482
text=result
484483
)]
485-
484+
486485
case _:
487486
raise ValueError(f"Unknown tool: {name}")
488487

src/git/tests/test_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ def test_git_commit_signed_without_key_id(test_repository):
103103
file_path = Path(test_repository.working_dir) / "signed_test.txt"
104104
file_path.write_text("testing signed commit")
105105
test_repository.index.add(["signed_test.txt"])
106-
106+
107107
# Note: This test may fail if GPG is not configured on the system
108108
# In that case, it should raise a GitCommandError
109109
try:
110110
result = git_commit_signed(test_repository, "Test signed commit")
111111
assert "Changes committed and signed successfully" in result
112112
assert "with hash" in result
113-
113+
114114
# Verify the commit was actually created
115115
latest_commit = test_repository.head.commit
116116
assert latest_commit.message.strip() == "Test signed commit"
@@ -123,13 +123,13 @@ def test_git_commit_signed_with_key_id(test_repository):
123123
file_path = Path(test_repository.working_dir) / "signed_test_with_key.txt"
124124
file_path.write_text("testing signed commit with key")
125125
test_repository.index.add(["signed_test_with_key.txt"])
126-
126+
127127
# Note: This test may fail if GPG is not configured or key doesn't exist
128128
try:
129129
result = git_commit_signed(test_repository, "Test signed commit with key", "TESTKEY123")
130130
assert "Changes committed and signed successfully" in result
131131
assert "with hash" in result
132-
132+
133133
# Verify the commit was actually created
134134
latest_commit = test_repository.head.commit
135135
assert latest_commit.message.strip() == "Test signed commit with key"

0 commit comments

Comments
 (0)