
Git
STDIOGit operations and repository management server for LLMs and AI agents via MCP.
Git operations and repository management server for LLMs and AI agents via MCP.
Empower your AI agents with comprehensive, secure, and programmatic control over Git repositories!
An MCP (Model Context Protocol) server providing a robust, LLM-friendly interface to the standard git
command-line tool. Enables LLMs and AI agents to perform a wide range of Git operations like clone, commit, push, pull, branch, diff, log, status, and more via the MCP standard.
Built on the cyanheads/mcp-ts-template
, this server follows a modular architecture with robust error handling, logging, and security features.
This server equips your AI with a comprehensive suite of tools to interact with Git repositories:
Tool Category | Description | Key Features - |
---|---|---|
Repository & Staging | Manage repository state, from initialization to staging changes. | - git_init : Initialize a new repository.- git_clone : Clone remote repositories.- git_add : Stage changes for commit.- git_status : Check the status of the working directory.- git_clean : Remove untracked files (requires force flag). - |
Committing & History | Create commits, inspect history, and view changes over time. | - git_commit : Create new commits with conventional messages.- git_log : View commit history with filtering options.- git_diff : Show changes between commits, branches, or the working tree.- git_show : Inspect Git objects like commits and tags. - |
Branching & Merging | Manage branches, merge changes, and rebase commits. | - git_branch : List, create, delete, and rename branches.- git_checkout : Switch between branches or commits.- git_merge : Merge branches together.- git_rebase : Re-apply commits on top of another base.- git_cherry_pick : Apply specific commits from other branches. - |
Remote Operations | Interact with remote repositories. | - git_remote : Manage remote repository connections.- git_fetch : Download objects and refs from a remote.- git_pull : Fetch and integrate with another repository.- git_push : Update remote refs with local changes. - |
Advanced Workflows | Support for more complex Git workflows and repository management. | - git_tag : Create, list, or delete tags.- git_stash : Temporarily store modified files.- git_worktree : Manage multiple working trees attached to a single repository.- git_set_working_dir : Set a persistent working directory for a session.- git_wrapup_instructions : Get a standard workflow for finalizing changes. - |
| Overview | Features | Installation | | Configuration | Project Structure | | Tools | Resources | Development | License |
The Git MCP Server acts as a bridge, allowing applications (MCP Clients) that understand the Model Context Protocol (MCP) – like advanced AI coding assistants (LLMs), IDE extensions, or custom research tools – to interact directly and safely with local Git repositories.
Instead of complex scripting or manual command-line interaction, your tools can leverage this server to:
Built on the robust mcp-ts-template
, this server provides a standardized, secure, and efficient way to expose Git functionality via the MCP standard. It achieves this by securely executing the standard git
command-line tool installed on the system using Node.js's child_process
module, ensuring compatibility and leveraging the full power of Git.
Developer Note: This repository includes a .clinerules file that serves as a developer cheat sheet for your LLM coding agent with quick reference for the codebase patterns, file locations, and code snippets.
Leverages the robust utilities provided by the mcp-ts-template
:
McpError
), and automatic logging.dotenv
) with comprehensive validation.zod
for schema validation and custom sanitization logic (crucial for paths).AsyncLocalStorage
.Dockerfile
for creating small, secure production images with native dependency support.git
command-line tool via Node.js child_process
, ensuring full compatibility and access to Git's features.git clean
and git reset --hard
.GIT_SIGN_COMMITS
environment variable and server-side Git configuration. Includes an optional tool parameter to fall back to unsigned commits on signing failure.Add the following to your MCP client's configuration file (e.g., cline_mcp_settings.json
). This configuration uses npx
to run the server, which will automatically install the package if not already present:
{ "mcpServers": { "git-mcp-server": { "command": "npx", "args": ["@cyanheads/git-mcp-server"], "env": { "MCP_LOG_LEVEL": "info", "GIT_SIGN_COMMITS": "false" } } } }
npm install @cyanheads/git-mcp-server
npm run start:stdio
npm run start:http
npm run dev:stdio
npm run dev:http
Configure the server using these environment variables (or a .env
file):
Variable | Description | Default |
---|---|---|
MCP_TRANSPORT_TYPE | Transport mechanism: stdio or http . | stdio |
MCP_HTTP_PORT | Port for the HTTP server (if MCP_TRANSPORT_TYPE=http ). Retries next ports if busy. | 3015 |
MCP_HTTP_HOST | Host address for the HTTP server (if MCP_TRANSPORT_TYPE=http ). | 127.0.0.1 |
MCP_ALLOWED_ORIGINS | Comma-separated list of allowed origins for CORS (if MCP_TRANSPORT_TYPE=http ). | (none) |
MCP_LOG_LEVEL | Logging level (debug , info , notice , warning , error , crit , alert , emerg ). Inherited from template. | info |
GIT_SIGN_COMMITS | Set to "true" to enable signing attempts for commits made by the git_commit tool. Requires server-side Git/key setup (see below). | false |
MCP_AUTH_MODE | Authentication mode: jwt , oauth , or none . | none |
MCP_AUTH_SECRET_KEY | Secret key for JWT validation (if MCP_AUTH_MODE=jwt ). | '' |
OAUTH_ISSUER_URL | OIDC issuer URL for OAuth validation (if MCP_AUTH_MODE=oauth ). | '' |
OAUTH_AUDIENCE | Audience claim for OAuth validation (if MCP_AUTH_MODE=oauth ). | '' |
src/mcp-server/
: Contains the core MCP server, tools, resources, and transport handlers.src/config/
: Handles loading and validation of environment variables.src/types-global/
: Defines shared TypeScript interfaces and type definitions.src/utils/
: Core utilities (logging, error handling, security, etc.).src/index.ts
: The main entry point that initializes and starts the server.Explore the full structure yourself:
See the current file tree in docs/tree.md or generate it dynamically:
npm run tree
In addition to tools, the server provides resources that offer contextual information about the Git environment.
Resource URI | Description |
---|---|
git://working-directory | Returns the currently configured working directory for the session as a JSON object. Shows NOT_SET if unset. |
This project is set up with modern tooling to ensure code quality and a smooth development experience.
typescript-eslint
plugin to enforce code quality and consistency. Run the linter with:
To automatically fix issues, run:npm run lint
npm run lint:fix
npm run format
You can run the TypeScript compiler to check for type errors without emitting any files:
npm run typecheck
This server uses Vitest for testing.
npm test
npm run test:watch
npm run test:coverage
API documentation is generated from JSDoc comments using TypeDoc. To generate the documentation, run:
npm run docs:generate
The output will be saved in the docs/api
directory.
The canonical pattern for adding new tools is defined in the .clinerules file. It mandates a strict separation of concerns:
logic.ts
: Contains the pure business logic, Zod schemas, and type definitions. This file throws structured errors on failure.registration.ts
: Acts as the "handler." It registers the tool with the server, wraps the logic call in a try...catch
block, and formats the final success or error response.This "Logic Throws, Handler Catches" pattern ensures that core logic remains pure and testable, while the registration layer handles all side effects and response formatting.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.