SuperAPIAI Directory

modelcontextprotocol/server-git

github.com · Other AI tools

mcp-server-git is one of the reference servers of the Model Context Protocol, used to read, search, and operate on Git repositories through large language models. It is built on the MCP Python SDK 2.x and wraps each Git operation as a typed Python function tool, with the SDK automatically generating input schemas from function signatures. The server is currently in an early development stage, and its features and available tools may change as development progresses. It provides tools for viewing workspace status, comparing staged and unstaged diffs, committing, adding, resetting, querying logs, creating and switching branches, merging, viewing commit contents, and listing branches and remotes. The repo_path parameter of all tools is treated literally and does not expand ~ or environment variables; relative paths are relative to the server's working directory.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsAPI

About this tool

Purpose

mcp-server-git is a server based on the Model Context Protocol (MCP), designed to enable large language models to interact with and automate operations on Git repositories. It provides a set of tools for reading, searching, and operating on Git repositories, allowing LLMs to perform common version control tasks within a controlled scope.

Main capabilities

The server provides the following tools (each tool is a typed Python function, with input schemas automatically generated by the MCP Python SDK from the signature):

  • git_status: Displays the working tree status. Input repo_path (string, path to the Git repository), returns text output of the current state of the working directory.
  • git_diff_unstaged: Displays changes in the working directory that have not yet been staged. Input repo_path and optional context_lines (number, default 3), returns diff output of unstaged changes.
  • git_diff_staged: Displays changes that have been staged for commit. Input repo_path and optional context_lines (default 3), returns diff output of staged changes.
  • git_diff: Displays differences between branches or commits, or differences across a revision range. Input repo_path, target (target branch or commit, or revision range a..b / a...b; omitting an endpoint means HEAD; each endpoint must be resolvable and must not start with -) and optional context_lines (default 3). Returns diff output comparing the working tree with the target, or the diff between the two endpoints of the range.
  • git_commit: Records changes to the repository. Input repo_path and message (commit message). Returns confirmation with the new commit hash; errors if there is nothing staged (similar to git commit without --allow-empty), but git also allows empty commits while a merge is in progress (MERGE_HEAD exists). While a merge is in progress, the commit concludes the merge: its parents are HEAD and all MERGE_HEAD commits, and the merge state is cleared.
  • git_add: Adds file contents to the staging area. Input repo_path and files (non-empty string array, ["."] meansStage everything). Returns confirmation of the staged files, or a message that nothing was staged when the call did not change the index.
  • git_reset: Unstage all staged changes. Input repo_path, returns confirmation of the reset operation.
  • git_log: Show the commit log, with the latest commit first. When only repo_path is provided, returns the latest commit; the two timestamps are optional date range filters. Input repo_path, optional max_count (number, at least 1, default 10), optional start_timestamp (only show commits at or after this time; accepts ISO 8601 format, relative dates such as '2 weeks ago', 'yesterday', or absolute dates such as '2024-01-15', 'Jan 15 2024') and optional end_timestamp (only show commits at or before this time, format as above). Returns the commit history: one record per commit (hash, author, date and message), latest first. When the timestamp filters match no commits, the text says so and suggests omitting both timestamps, rather than returning an empty history.
  • git_create_branch: Create a new branch. Input repo_path, branch_name (name of the new branch) and optional base_branch (the branch, tag or commit SHA to create from; defaults to the current branch, or the current commit when HEAD is detached). Returns confirmation of branch creation, indicating the base branch, or the short SHA when the base is a commit.
  • git_checkout: Switch branches. Input repo_path and branch_name (name of the branch to check out). Returns confirmation of the branch switch, or HEAD is now detached at <short sha> when branch_name is not a branch (SHA, tag or other revision).
  • git_merge: Merge a branch into the current branch, or make no changes. Input repo_path, source_branch (the branch, tag or commit to merge into the current branch; use git_checkout first to check out the branch to merge into) and optional fast_forward_only (boolean, default true; fast-forward only, fails when the branches have diverged; false allows Git to create amerge commit when diverged). Returns Fast-forwarded, Merged ... with merge commit <short sha> or Already up to date. The tool refuses a detached HEAD, a working tree with uncommitted changes, a merge already in progress, and merges that would overwrite ignored local files (whether fast-forwarding or creating a merge commit). A merge stopped due to conflicts is aborted (git merge --abort), and the error message lists the conflicting files, leaving the repository unchanged. Directory renames are not tracked: files added on the source branch in a directory renamed on the current branch are merged under the path given by the source branch.
  • git_show: Show the contents of a commit, or the contents of a file or directory at a revision. Input repo_path and revision (commit hash, branch name, tag or object spec such as HEAD:path/to/file). Returns the contents of the specified commit, the file contents, or a directory listing.
  • git_branch: List Git branches. Input repo_path, branch_type (list local branches 'local', remote branches 'remote' or all branches 'all'), optional contains (a commit SHA the branches should contain; do not pass this parameter when unspecified) and optional not_contains (a commit SHA the branches should not contain; do not pass this parameter when unspecified). Returns the branch list.
  • git_remote: List the repository's remotes and their fetch and push URLs, similar to git remote -v. Input repo_path. Returns one line per remote and direction, <name>\t<url> (fetch) or (push) (fetch lines of partial clones end with a filter, such as [blob:none]), or No remotes configured. Credentials embedded in URLs are never returned:https://user:token@host/... or https://token@host/... The entire user information of URLs such as is displayed as <redacted>, and so is each query value (?private_token=<redacted>, with the parameter name preserved), while non-empty fragments are displayed as #<redacted>. The SSH username (ssh://git@host/...) is preserved because it names the account rather than authenticating; the password after it is redacted. Remote helper addresses (https::https://user:token@host/...)的内部 URLs are likewise redacted. URLs where ? or # appears before the @ in the user information (https://host?t=a@b)无法安全拆分,显示为 https://<redacted>. Tokens carried as path segments (https://host/token/SECRET/r.git)不会被隐去,因为无法与仓库名区分。URL values that do not appear at the beginning (https://user:token@host/...,带前导空白)无法安全拆分,显示为 <redacted>; remote names containing tabs are matched against the configured name, so the URL after them is still redacted. scp-style addresses (git@host:path) and local paths are displayed as configured, and file:// URLs keep their ? and # parts because they belong to the local file name. Lines that cannot be parsed are displayed as <redacted>, and if the configured remote URL (or insteadOf rewrite) contains a newline (which git itself rejects), the tool returns an error instead of a list.

Usage

This server requires MCP Python SDK 2.x (mcp>=2.3,<3). It is built on the SDK's high-level MCPServer: each tool is a typed Python function, and the SDK derives the input schema from the signature. The server supports both eras of the Model Context Protocol via stdio.

The repo_path of all tools is treated literally: neither a leading ~ nor $NAME or ${NAME} is expanded, and relative paths are relative to the server's working directory.

When to use

Suitable for scenarios where a large language model needs to perform read, search, and operation tasks on Git repositories, such as viewing status, comparing diffs, committing changes, managing branches, viewing logs and remote information, etc.

Limitations

  • This server is currently in early development; features and available tools may change and expand as development progresses.
  • repo_path does not expand ~ or environment variables, and relative paths are based on the server's working directory.
  • git_merge rejects detached HEAD, a working tree with uncommitted changes, a merge already in progress, and merges that would overwrite ignored local files; conflicting merges are aborted.
  • git_remote redacts credentials in URLs, but tokens carried as path segments cannot be distinguished from repository names and are not redacted.
  • The materials do not provide specific details such as installation commands, pricing information, or platform support.
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools