Git MCP Server

repository·main·Indexed 42 days ago

https://github.com/cyanheads/git-mcp-server

A secure and scalable Model Context Protocol (MCP) server enabling AI agents to perform comprehensive Git version control operations via STDIO and Streamable HTTP. Version 2.15.3 provides 28 tools across categories including repository management, staging, history inspection, branching, merging, and remote operations. It supports Node.js (>= 20.0.0) and Bun (>= 1.2.0) runtimes and includes security features such as path validation and sandboxing via GIT_BASE_DIR.

Tokens
46.5K
Snippets
135
Records
214
Agent score
53%

What's inside Git MCP Server

  1. Overview of git-mcp-server directory structure

    main

    The git-mcp-server repository is organized into several key functional areas:

    • src/mcp-server: The core Model Context Protocol (MCP) implementation, containing definitions for tools, resources, and prompts.
    • src/mcp-server/tools: Contains the specific Git operations exposed as MCP tools (e.g., git-add, git-commit, git-push).
    • src/mcp-server/transports: Handles communication protocols, including stdio (standard input/output) and http.
    • src/services/git: The business logic layer that executes Git operations, primarily using a CLI-based provider.
    • src/services/storage: Manages data persistence with various providers like fileSystem, inMemory, cloudflare (KV/R2), and supabase.
    • skills/: Contains specialized MCP skills for tasks like maintenance, reporting issues, and releasing/publishing.
    • tests/: Comprehensive test suite covering unit, integration, and end-to-end (e2e) tests for tools, services, and transports.
  2. Overview of @cyanheads/git-mcp-server

    main
    The @cyanheads/git-mcp-server is a Model Context Protocol (MCP) server designed for AI agents to perform Git operations. It provides 28 tools across seven categories, one resource, and one prompt to enable automated repository management, history inspection, and advanced Git workflows. It supports both stdio and Streamable http transports and is compatible with both Bun and Node.js runtimes.
  3. What is field-testing for the git-mcp-server?

    main

    Field testing is a debugging and verification process used to exercise the real HTTP transport and JSON-RPC layer of the MCP server. Unlike unit tests that use mocked contexts, field testing uses a live HTTP server to catch issues like:

    • Awkward input shapes and unhelpful error messages.
    • Missing responseFormatter output.
    • Drift between structuredContent and content[] fields.
    • Git-specific edge cases (e.g., conflicts, bare repositories, protected branches, or working directory state).

    Best Practice: When testing git tools, use a throwaway test repository (e.g., /tmp/field-test-repo initialized with git init and a seed commit) instead of the project itself to ensure state changes are bounded and easy to clean up.

  4. Understand response formats and verbosity

    main

    The server provides different output formats via MCP_RESPONSE_FORMAT. Regardless of the format chosen for the client, the LLM always receives the complete structured data via the responseFormatter (including full file lists, metadata, and timestamps).

    JSON Format (Default)

    Optimized for LLM consumption. Example:

    {
      "success": true,
      "branch": "main",
      "staged": ["src/index.ts", "README.md"],
      "unstaged": ["package.json"],
      "untracked": []
    }

    Markdown Format

    Human-readable format. Example:

    # Git Status: main
    
    ## Staged (2)
    - src/index.ts
    - README.md
    
    ## Unstaged (1)
    - package.json

    Verbosity Levels

    Controlled by MCP_RESPONSE_VERBOSITY:

    • minimal: Core fields only.
    • standard: Balanced detail (default).
    • full: Includes all available metadata and details.
  5. Initialize an MCP session via HTTP

    main

    To interact with an MCP HTTP server, you must perform a two-step initialization sequence to establish a session ID:

    1. Initialize: Send a POST request to the server URL with the initialize method. The server returns a mcp-session-id in the HTTP response headers.
    2. Notify: Send a POST request with the notifications/initialized method, including the captured Mcp-Session-Id in the headers.

    All subsequent requests must include the Mcp-Session-Id header to be associated with the active session.

  6. Interpret MCP tool error responses

    main

    When testing tools, distinguish between protocol-level errors and tool-domain errors:

    • Tool Domain Errors: These occur when a tool executes but the operation fails (e.g., a Git conflict or invalid command). These return a successful JSON-RPC response where isError: true is set inside the result object. Do not look for the JSON-RPC error field for these.
      • Format: { "result": { "content": [...], "isError": true } }
    • Protocol Errors: These occur when the JSON-RPC envelope is malformed, the session is invalid, or the method is unknown. These return a standard JSON-RPC error field.

    Structured Git Errors: When the server throws a formal McpError, it will include a code and context. The content[] array should contain a human-readable explanation of the error reason.

  7. Redact sensitive information before posting

    main

    GitHub issues are public. You must redact all secrets, credentials, API keys, JWT tokens, or git remote URLs that encode credentials before submitting.

    Redaction Rules:

    • Do not rely on partial masking; replace sensitive values entirely.
    • Use obvious placeholders like REDACTED or sk-...REDACTED.
    • Example: https://REDACTED@github.com/...
  8. Maintain the CHANGELOG.md using Keep a Changelog

    main

    The repository uses a monolithic changelog following the Keep a Changelog format.

    Conventions:

    • Headers: Every release must have a top-level ## v<version> - <YYYY-MM-DD> header. Never use [Unreleased].
    • Sections: Group entries under ### Added, ### Changed, ### Fixed, ### Removed, or ### Security.
    • Breaking Changes: Call these out in bold at the top of the relevant section or use a dedicated ### Breaking header.
    • References: Use code blocks for tool names (e.g., `git_merge`) and reference PR/issue numbers (e.g., (#42)).
    • Ordering: Newest releases at the top; oldest at the bottom.
  9. Security and Safety Features

    main

    The server implements several security measures:

    • Path Validation: All file paths are sanitized to prevent directory traversal.
    • Sandboxing: Setting GIT_BASE_DIR restricts all git operations to a specific directory tree.
    • Argument Safety: Git commands use validated arguments via process spawning to avoid shell interpolation.
    • Destructive Operation Safety: Operations like git clean or git reset --hard require explicit confirmation flags.
    • Authentication: Supports none, jwt, and oauth modes for deployed environments.
    • Auditability: All operations are logged with request context.
  10. Sync Agent Skills to your local environment

    main

    The skills/ directory at the project root is the source of truth for agent-specific capabilities. To use these skills with an AI agent (like Claude Code, Codex, Cursor, or Windsurf), you must sync the contents of the root skills/ directory to the agent's specific configuration directory.

    Important: Do not delete existing skills in the agent's directory that are not present in the root skills/ folder, as those may be general-purpose skills provided by the agent itself (e.g., code-security).

    mkdir -p .claude/skills && cp -R skills/* .claude/skills/
  11. Configure the Git MCP Server in an MCP Client

    main

    To use the server with an MCP client (like Cline), add it to your configuration file (e.g., cline_mcp_settings.json). You must configure environment variables to define your git identity and working directories.

    Node.js Configuration Example:

    {
      "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": "casey@caseyjhand.com",
            "GIT_SIGN_COMMITS": "true"
          }
        }
      }
    }

    Bun Configuration: Replace "command": "npx" with "command": "bunx" in the JSON above.

    Streamable HTTP Configuration: Set MCP_TRANSPORT_TYPE=http and MCP_HTTP_PORT=3015 in your environment variables.

  12. Adopt dependency changes in the codebase

    main

    After investigating changelogs, apply the necessary changes to the codebase. Focus on:

    • Breaking changes: Fix call sites. Priority areas include src/mcp-server/, src/services/, src/utils/, src/storage/, and src/container/.
    • Deprecations: Migrate code to new APIs while the context is fresh.
    • New APIs: Refactor targeted areas to use better APIs; avoid unnecessary wide-scale refactoring.
    • New configuration: Update .env.example, the Zod schema in src/config/index.ts, and README.md if the changes are user-facing.

    Specific areas to re-check based on package type:

    • src/services/git/providers/cli/ (if child-process libraries changed)
    • src/mcp-server/transports/http/ (if Hono / MCP SDK changed)
    • src/utils/telemetry/ (if OpenTelemetry SDK changed)
    • src/mcp-server/transports/auth/ (if jose changed)