Git
STDIO安全的Git MCP服务器,包含27个版本控制工具
安全的Git MCP服务器,包含27个版本控制工具
A secure and scalable Git MCP server giving AI agents powerful version control for local and (soon) serverless environments. STDIO & Streamable HTTP
This server provides 27 comprehensive Git operations organized into six functional categories:
| Category | Tools | Description | 
|---|---|---|
| Repository Management | git_init, git_clone, git_status, git_clean | Initialize repos, clone from remotes, check status, and clean untracked files | 
| Staging & Commits | git_add, git_commit, git_diff | Stage changes, create commits, and compare changes | 
| History & Inspection | git_log, git_show, git_blame, git_reflog | View commit history, inspect objects, trace line-by-line authorship, and view ref logs | 
| Branching & Merging | git_branch, git_checkout, git_merge, git_rebase, git_cherry_pick | Manage branches, switch contexts, integrate changes, and apply specific commits | 
| Remote Operations | git_remote, git_fetch, git_pull, git_push | Configure remotes, download updates, synchronize repositories, and publish changes | 
| Advanced Workflows | git_tag, git_stash, git_reset, git_worktree, git_set_working_dir, git_clear_working_dir, git_wrapup_instructions | Tag releases, stash changes, reset state, manage worktrees, set/clear session directory, and access workflow guidance | 
The server provides resources that offer contextual information about the Git environment:
| Resource | URI | Description | 
|---|---|---|
| Git Working Directory | git://working-directory | Provides the current session working directory for git operations. This is the directory set via git_set_working_dir and used as the default. | 
The server provides structured prompt templates that guide AI agents through complex workflows:
| Prompt | Description | Parameters | 
|---|---|---|
| Git Wrap-up | A systematic workflow protocol for completing git sessions. Guides agents through reviewing, documenting, committing, and tagging changes. | changelogPath, skipDocumentation, createTag, and updateAgentFiles. | 
This server works with both Bun and Node.js runtimes:
| Runtime | Command | Minimum Version | Notes | 
|---|---|---|---|
| Bun | bunx @cyanheads/git-mcp-server@latest | ≥ 1.2.0 | Native Bun runtime (optimal performance) | 
| Node.js | npx @cyanheads/git-mcp-server@latest | ≥ 20.0.0 | Via npx/bunx (universal compatibility) | 
The server automatically detects the runtime and uses the appropriate process spawning method for git operations.
Add the following to your MCP Client configuration file (e.g., cline_mcp_settings.json). Clients have different ways to configure servers, so refer to your client's documentation for specifics.
Be sure to update environment variables as needed (especially your Git information!)
{ "mcpServers": { "git-mcp-server": { "type": "stdio", "command": "bunx", "args": ["@cyanheads/git-mcp-server@latest"], "env": { "MCP_TRANSPORT_TYPE": "stdio", "MCP_LOG_LEVEL": "info", "GIT_BASE_DIR": "~/Developer/", "LOGS_DIR": "~/Developer/logs/git-mcp-server/", "GIT_USERNAME": "cyanheads", "GIT_EMAIL": "[email protected]", "GIT_SIGN_COMMITS": "false" } } } }
{ "mcpServers": { "git-mcp-server": { "type": "stdio", "command": "npx", "args": ["@cyanheads/git-mcp-server@latest"], "env": { "MCP_TRANSPORT_TYPE": "stdio", "MCP_LOG_LEVEL": "info", "GIT_BASE_DIR": "~/Developer/", "LOGS_DIR": "~/Developer/logs/git-mcp-server/", "GIT_USERNAME": "cyanheads", "GIT_EMAIL": "[email protected]", "GIT_SIGN_COMMITS": "false" } } } }
MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3015
This server is built on the mcp-ts-template and inherits its rich feature set:
McpError system ensures consistent, structured error responses.none, jwt, or oauth modes.in-memory, filesystem, Supabase, Cloudflare KV/R2) without changing business logic.tsyringe for a clean, decoupled, and testable architecture.Plus, specialized features for Git integration:
git clean and git reset --hard.Note: Development uses Bun for the best experience, but the published package works with both Bun (
bunx) and Node.js (npx).
git clone https://github.com/cyanheads/git-mcp-server.git
cd git-mcp-server
With Bun (recommended for development):
bun install
With Node.js:
npm install
All configuration is centralized and validated at startup in src/config/index.ts. Key environment variables in your .env file include:
| Variable | Description | Default | 
|---|---|---|
MCP_TRANSPORT_TYPE | The transport to use: stdio or http. | stdio | 
MCP_SESSION_MODE | Session mode for HTTP transport: stateless, stateful, or auto. | auto | 
MCP_RESPONSE_FORMAT | Response format: json (LLM-optimized), markdown (human-readable), or auto. | json | 
MCP_RESPONSE_VERBOSITY | Response detail level: minimal, standard, or full. | standard | 
MCP_HTTP_PORT | The port for the HTTP server. | 3015 | 
MCP_HTTP_HOST | The hostname for the HTTP server. | 127.0.0.1 | 
MCP_HTTP_ENDPOINT_PATH | The endpoint path for MCP requests. | /mcp | 
MCP_AUTH_MODE | Authentication mode: none, jwt, or oauth. | none | 
STORAGE_PROVIDER_TYPE | Storage backend: in-memory, filesystem, supabase, cloudflare-kv, r2. | in-memory | 
OTEL_ENABLED | Set to true to enable OpenTelemetry. | false | 
MCP_LOG_LEVEL | The minimum level for logging (debug, info, warn, error). | info | 
GIT_SIGN_COMMITS | Set to "true" to enable GPG/SSH signing for all commits, merges, rebases, cherry-picks, and tags. Requires GPG/SSH configuration. | false | 
GIT_AUTHOR_NAME | Git author name. Aliases: GIT_USERNAME, GIT_USER. Falls back to global git config if not set. | (none) | 
GIT_AUTHOR_EMAIL | Git author email. Aliases: GIT_EMAIL, GIT_USER_EMAIL. Falls back to global git config if not set. | (none) | 
GIT_BASE_DIR | Optional absolute path to restrict all git operations to a specific directory tree. Provides security sandboxing for multi-tenant or shared environments. | (none) | 
GIT_WRAPUP_INSTRUCTIONS_PATH | Optional path to custom markdown file with Git workflow instructions. | (none) | 
MCP_AUTH_SECRET_KEY | Required for jwt auth. A 32+ character secret key. | (none) | 
OAUTH_ISSUER_URL | Required for oauth auth. URL of the OIDC provider. | (none) | 
The easiest way to use the server is via bunx or npx (no installation required):
With Bun:
bunx @cyanheads/git-mcp-server@latest
With Node.js:
npx @cyanheads/git-mcp-server@latest
Both commands work identically and are configured through environment variables or your MCP client configuration.
Build and run the production version:
# One-time build bun rebuild # Run the built server bun start:http # or bun start:stdio
Development mode with hot reload:
bun dev:http # or bun dev:stdio
Run checks and tests:
bun devcheck # Lints, formats, type-checks, and more bun test # Runs the test suite
bun build:worker
bun deploy:dev
bun deploy:prod
| Directory | Purpose & Contents | 
|---|---|
src/mcp-server/tools | Your tool definitions (*.tool.ts). This is where Git capabilities are defined. | 
src/mcp-server/resources | Your resource definitions (*.resource.ts). Provides Git context data sources. | 
src/mcp-server/transports | Implementations for HTTP and STDIO transports, including auth middleware. | 
src/storage | StorageService abstraction and all storage provider implementations. | 
src/services | Integrations with external services (LLMs, Speech, etc.). | 
src/container | Dependency injection container registrations and tokens. | 
src/utils | Core utilities for logging, error handling, performance, and security. | 
src/config | Environment variable parsing and validation with Zod. | 
tests/ | Unit and integration tests, mirroring the src/ directory structure. | 
This server follows MCP's dual-output architecture for all tools (MCP Tools Specification):
Configure response format and verbosity via environment variables (see Configuration):
| Variable | Values | Description | 
|---|---|---|
MCP_RESPONSE_FORMAT | json (default), markdown, auto | Output format: JSON for LLM parsing, Markdown for human UIs | 
MCP_RESPONSE_VERBOSITY | minimal, standard (default), full | Detail level: minimal (core only), standard (balanced), full (everything) | 
When you invoke a tool through your MCP client, you see a formatted summary designed for human consumption. For example, git_status might show:
Markdown Format:
# Git Status: main
## Staged (2)
- src/index.ts
- README.md
## Unstaged (1)
- package.json
JSON Format (LLM-Optimized):
{ "success": true, "branch": "main", "staged": ["src/index.ts", "README.md"], "unstaged": ["package.json"], "untracked": [] }
Behind the scenes, the LLM receives complete structured data as content blocks via the responseFormatter function. This includes:
Why This Matters: The LLM can answer detailed questions like "Who made the last commit?" or "What files changed in commit abc123?" because it has access to the full dataset, even if you only saw a summary.
Verbosity Levels: Control the amount of detail returned:
For Developers: When creating custom tools, always include complete data in your responseFormatter. Balance human-readable summaries with comprehensive structured information. See AGENTS.md for response formatter best practices and the MCP specification for technical details.
For strict rules when using this server with an AI agent, refer to the AGENTS.md file in this repository. Key principles include:
try/catch in your tool logic. Throw an McpError instead.RequestContext object through your call stack for logging and tracing.index.ts barrel files within their respective definitions directories.*.tool.ts file with schema, logic, and response formatting.GIT_BASE_DIR configuration to restrict all git operations to a specific directory tree, providing security sandboxing for multi-tenant or shared hosting environments.RateLimiter service.This server uses Vitest for testing.
Run all tests:
bun test
Run tests with coverage:
bun test:coverage
Run tests in watch mode:
bun test --watch
The server uses a provider-based architecture to support multiple git implementation backends:
✅ CLI Provider (Current): Full-featured git operations via native git CLI
🚧 Isomorphic Git Provider (Planned): Pure JavaScript git implementation
💡 GitHub API Provider (Maybe): Cloud-native git operations via GitHub REST/GraphQL APIs
The provider system allows seamless switching between implementations based on deployment environment and requirements. See AGENTS.md for architectural details.
Issues and pull requests are welcome! If you plan to contribute, please run the local checks and tests before submitting your PR.
bun run devcheck bun test
git checkout -b feature/amazing-feature)bun devcheck to ensure code qualitybun test to verify all tests passThis project is licensed under the Apache 2.0 License. See the LICENSE file for details.
Built with ❤️ using the mcp-ts-template