Skip to content

feat(git): add date-based commit log retrieval functions #2057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a1e74eb
feat(git): add date-based commit log retrieval functions
Jun 9, 2025
728d3be
feat(git): add date-based commit log retrieval functions
Jun 9, 2025
8b1bb06
Merge branch 'main' into feature/add-git-date-tools-docs
Berg-it Jun 16, 2025
8e85b1c
Merge branch 'main' into feature/add-git-date-tools-docs
Berg-it Jun 18, 2025
5a6827e
Add first draft
olaservo Jun 11, 2025
f3bc78c
Remove duplicates in the community section
olaservo Jun 11, 2025
c99f43c
Remove Firefly for now since the icon is a 404
olaservo Jun 11, 2025
d9337b1
Fix alt text
olaservo Jun 11, 2025
b797fc5
Spacing
olaservo Jun 11, 2025
7f24b52
Fix couchbase icon 403
olaservo Jun 11, 2025
3ceadd1
Fixed firefly
olaservo Jun 11, 2025
070a707
Move MCP Watch to Resources and re-alphabetize the list
olaservo Jun 9, 2025
79d58be
Update README.md
tadasant Jun 11, 2025
2924043
Update README.md
quuu May 29, 2025
993e8a9
Update README.md
ps0394 Jun 13, 2025
420da72
Update README.md - MS Docs to Official Integrations
ps0394 Jun 13, 2025
cff024e
Update README.md
idsts2670 Jun 13, 2025
11d5634
Add file read and directory listing enhancements
mjherich Mar 22, 2025
5ff72fd
Normalize line endings when splitting file chunks
mjherich Apr 3, 2025
c80b78f
add mco-cli-host to "client" section
vincent-pli May 28, 2025
0f6b008
Add SAP ABAP MCP Server SDK to "For Servers" within "Frameworks"
wommel0 Jun 9, 2025
cc0a096
Fix json format
Mar 29, 2025
7a371c1
Add ActionKit to third-party servers list
ethanlee16 Apr 18, 2025
f014420
Add OpenSearch MCP server to Official Integrations
rithin-pullela-aws Jun 9, 2025
84202d9
address comment, better description for openSearch MCP server
rithin-pullela-aws Jun 9, 2025
73c27f4
Merge branch 'feature/add-git-date-tools-docs' of https://github.com/…
Jul 7, 2025
6bad1e9
Merge branch 'main' of https://github.com/Berg-it/servers into featur…
Jul 7, 2025
7c8a847
Merge branch 'main' into feature/add-git-date-tools-docs
Berg-it Jul 7, 2025
9b0134a
Add branch handling to Git tools in server.py
Jul 7, 2025
ae881f6
Remove date range log functionality from Git tools in server.py to st…
Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ Please note that mcp-server-git is currently in early development. The functiona
- Inputs:
- `repo_path` (string): Path to directory to initialize git repo
- Returns: Confirmation of repository initialization
13. `git_log_date_range`
- Retrieve git commits within a specified date range
- Inputs:
- `repo_path` (string): Path to Git repository
- `start_date` (string): Start date for the range
- `end_date` (string): End date for the range
- Returns: Commits within a date range
14. `git_log_by_date`
- Retrieve git commits for a specific date
- Inputs:
- `repo_path` (string): Path to Git repository
- `date` (string): The specific date to get commits for
- Returns: commits for the specified date

13. `git_branch`
- List Git branches
Expand Down
88 changes: 87 additions & 1 deletion src/git/src/mcp_server_git/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ class GitShow(BaseModel):
class GitInit(BaseModel):
repo_path: str

class GitLogDateRange(BaseModel):
repo_path: str
start_date: str
end_date: str

class GitLogByDate(BaseModel):
repo_path: str
date: str

class GitBranch(BaseModel):
repo_path: str = Field(
...,
Expand All @@ -83,6 +92,7 @@ class GitBranch(BaseModel):
description="The commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified",
)


class GitTools(str, Enum):
STATUS = "git_status"
DIFF_UNSTAGED = "git_diff_unstaged"
Expand All @@ -96,6 +106,8 @@ class GitTools(str, Enum):
CHECKOUT = "git_checkout"
SHOW = "git_show"
INIT = "git_init"
LOG_DATE_RANGE = "git_log_date_range"
LOG_BY_DATE = "git_log_by_date"
BRANCH = "git_branch"

def git_status(repo: git.Repo) -> str:
Expand Down Expand Up @@ -172,6 +184,47 @@ def git_show(repo: git.Repo, revision: str) -> str:
output.append(d.diff.decode('utf-8'))
return "".join(output)


def git_log_date_range(repo: git.Repo, start_date: str, end_date: str) -> list[str]:
log_output = repo.git.log(
'--since', f"{start_date}",
'--until', f"{end_date}",
'--format=%H%n%an%n%ad%n%s%n'
).split('\n')

log = []
# Process commits in groups of 4 (hash, author, date, message)
for i in range(0, len(log_output), 4):
if i + 3 < len(log_output):
log.append(
f"Commit: {log_output[i]}\n"
f"Author: {log_output[i+1]}\n"
f"Date: {log_output[i+2]}\n"
f"Message: {log_output[i+3]}\n"
)
return log

def git_log_by_date(repo: git.Repo, date: str) -> list[str]:
log_output = repo.git.log(
'--since', f"{date} 00:00:00",
'--until', f"{date} 23:59:59",
'--format=%H%n%an%n%ad%n%s%n'
).split('\n')

log = []
# Process commits in groups of 4 (hash, author, date, message)
for i in range(0, len(log_output), 4):
if i + 3 < len(log_output):
log.append(
f"Commit: {log_output[i]}\n"
f"Author: {log_output[i+1]}\n"
f"Date: {log_output[i+2]}\n"
f"Message: {log_output[i+3]}\n"
)
return log



def git_branch(repo: git.Repo, branch_type: str, contains: str | None = None, not_contains: str | None = None) -> str:
match contains:
case None:
Expand Down Expand Up @@ -200,6 +253,7 @@ def git_branch(repo: git.Repo, branch_type: str, contains: str | None = None, no

return branch_info


async def serve(repository: Path | None) -> None:
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -276,10 +330,21 @@ async def list_tools() -> list[Tool]:
description="Initialize a new Git repository",
inputSchema=GitInit.model_json_schema(),
),
Tool(
name=GitTools.LOG_DATE_RANGE,
description="Retrieve git commits within a specified date range",
inputSchema=GitLogDateRange.model_json_schema(),
),
Tool(
name=GitTools.LOG_BY_DATE,
description="Retrieve git commits for a specific date",
inputSchema=GitLogByDate.model_json_schema(),
),
Tool(
name=GitTools.BRANCH,
description="List Git branches",
inputSchema=GitBranch.model_json_schema(),

)
]

Expand Down Expand Up @@ -409,6 +474,27 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
text=result
)]

case GitTools.LOG_DATE_RANGE:
log = git_log_date_range(
repo,
arguments["start_date"],
arguments["end_date"]
)
return [TextContent(
type="text",
text="Commit history:\n" + "\n".join(log)
)]

case GitTools.LOG_BY_DATE:
log = git_log_by_date(
repo,
arguments["date"]
)
return [TextContent(
type="text",
text="Commit history:\n" + "\n".join(log)
)]

case GitTools.BRANCH:
result = git_branch(
repo,
Expand All @@ -420,7 +506,7 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
type="text",
text=result
)]

case _:
raise ValueError(f"Unknown tool: {name}")

Expand Down