git-context-mcp

git-context-mcp

A secure MCP server for local Git operations with path traversal protection, input validation, and 15 supported Git commands.

Category
Visit Server

README

Git MCP Server

A Model Context Protocol (MCP) server for local Git operations with security and validation.

Features

  • 🔒 Secure: Path traversal protection and input validation
  • Validated: Runtime Zod validation for all inputs
  • ⏱️ Timeout Protection: Configurable timeouts prevent indefinite blocking
  • 🛠️ Complete: 15 Git operations supported
  • 📝 Well-tested: Comprehensive integration test suite

Available Tools

  • git_clone: Clone a Git repository
  • git_status: Get the status of the repository
  • git_diff: Get the diff of the repository (supports staged files)
  • git_list_branches: List local and remote branches
  • git_checkout: Switch between branches and update files
  • git_list_files: List files in the repository
  • git_read_file: Read the content of a file (with path traversal protection)
  • git_add: Add files to the staging area
  • git_reset: Reset current HEAD to the specified state (supports soft, mixed, hard)
  • git_pull: Pull changes from remote (uses rebase)
  • git_commit: Commit changes to the repository
  • git_push: Push changes to remote (automatically performs pull --rebase first)
  • git_log: Get the commit log of the repository
  • git_create_branch: Create a new branch (optionally from a specific starting point)
  • git_merge: Merge a branch into the current branch (supports --no-ff)

Setup

  1. Install dependencies:

    npm install
    
  2. Build:

    npm run build
    
  3. Run:

    npm run start
    

Configuration Examples

Claude Desktop

{
  "mcpServers": {
    "git-mcp-server": {
      "command": "node",
      "args": ["/absolute/path/to/git-context-mcp/dist/index.js"]
    }
  }
}

Cline / Windsurf

{
  "mcpServers": {
    "git-mcp-server": {
      "command": "npx",
      "args": ["-y", "git-mcp-server"]
    }
  }
}

Usage Examples

Clone a Repository

{
  "tool": "git_clone",
  "arguments": {
    "repoUrl": "https://github.com/user/repo.git",
    "localPath": "/path/to/local/repo"
  }
}

Read a File

{
  "tool": "git_read_file",
  "arguments": {
    "repoPath": "/path/to/repo",
    "filePath": "src/index.ts"
  }
}

Create and Checkout a Branch

{
  "tool": "git_create_branch",
  "arguments": {
    "repoPath": "/path/to/repo",
    "branch": "feature/new-feature",
    "checkout": true
  }
}

Security

  • Path Traversal Protection: File paths are validated to prevent access outside the repository
  • Input Validation: All inputs are validated with Zod schemas before processing
  • Error Handling: Proper error context preservation throughout the stack
  • Timeout Protection: Operations have configurable timeouts (30s default, 60s for clone)

Testing

Run the integration test suite to verify all Git tools work correctly:

npx tsx test_script.ts

The script creates temporary local repositories, exercises all 15 tools plus error handling scenarios, and cleans up automatically.

Troubleshooting

Error: "Path does not exist"

Ensure the repository path exists and is accessible.

Error: "File path must be within the repository"

The requested file path is outside the repository boundaries. This is a security feature to prevent directory traversal attacks.

Timeout errors

Operations have a 30-second timeout by default (60 seconds for clone). For very large repositories or slow networks, operations may timeout. This is a safety feature to prevent indefinite blocking.

Error: "Git pull --rebase failed"

The rebase was automatically aborted to restore the repository to a clean state. Check for uncommitted changes or conflicts.

Development

Running Tests

npx tsx test_script.ts

Building

npm run build

Watching for Changes

npm run watch

Prerequisites

  • Node.js 18+
  • Git

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured