Skip to main content
Glama
bpweatherill

Local Git MCP Server

by bpweatherill

Local Git MCP Server

A local Model Context Protocol (MCP) server for interacting with Git repositories. This server extends the mcp_server_git with custom tools for listing repository directories and viewing file contents, making it easier to navigate and inspect codebases programmatically.


βœ… Features

  • Custom Tools:

    • list_repo_dir: Recursively list files and directories in a Git repository. If no path is provided, it lists the root directory.

    • view_repo_file: Read and return the contents of a specific file in the repository.

  • Git Integration: Inherits all standard Git operations from mcp_server_git (e.g., git_status, git_diff, git_log, etc.).

  • Flexible Configuration: Supports environment variables for repository path configuration.

  • MCP Compatibility: Works with any MCP-compatible client (e.g., Model Context Protocol clients).


Related MCP server: MCP Git Server

πŸ› οΈ Prerequisites

Before running the server, ensure the following are installed:

1. Python 3.8+

2. pip (Python Package Manager)

  • Ensure pip is installed and up-to-date:

    python -m pip install --upgrade pip

3. Required Python Packages

Install the dependencies using pip:

pip install starlette uvicorn mcp-server-git

4. Git

5. Target Git Repository

  • Ensure the repository you want to interact with is cloned locally on your machine.

  • By default, the server uses the path specified in the TARGET_REPO environment variable. If not set, it defaults to:

    C:\Users\bpweathe\code\SCIP\scipai

πŸš€ Installation & Setup

Step 1: Clone the Repository

git clone https://github.com/bpweatherill/local-git-mcp.git
cd local-git-mcp

Step 2: Install Dependencies

pip install -r requirements.txt

Note: If requirements.txt does not exist, install the required packages manually:

pip install starlette uvicorn mcp-server-git

Step 3: Configure the Target Repository

Set the TARGET_REPO environment variable to point to your local Git repository:

Windows (PowerShell)

$env:TARGET_REPO = "C:\path\to\your\repo"

macOS/Linux (Terminal)

export TARGET_REPO="/path/to/your/repo"

Tip: If you don’t set TARGET_REPO, the server will default to C:\Users\bpweathe\code\SCIP\scipai.


πŸƒ Running the Server

Start the MCP server using the following command:

python mcp_server.py

The server will start on:

  • Host: localhost

  • Port: 8808

You should see output similar to:

INFO:     Uvicorn running on http://localhost:8808 (Press CTRL+C to quit)

πŸ› οΈ Using the Server

Connecting with an MCP Client

Once the server is running, you can connect to it using any MCP-compatible client. Here’s how to test it:

1. List Root Directory

Call the list_repo_dir tool with no arguments to list the root of the repository:

{
  "method": "tools/call",
  "params": {
    "name": "list_repo_dir",
    "arguments": {}
  }
}

2. List a Subdirectory

Pass a relative path to list the contents of a subdirectory:

{
  "method": "tools/call",
  "params": {
    "name": "list_repo_dir",
    "arguments": {
      "path": "docs/clients"
    }
  }
}

3. View a File

Use the view_repo_file tool to read a file:

{
  "method": "tools/call",
  "params": {
    "name": "view_repo_file",
    "arguments": {
      "path": "README.md"
    }
  }
}

4. Standard Git Tools

The server also supports all standard Git tools from mcp_server_git. For example:

{
  "method": "tools/call",
  "params": {
    "name": "git_status",
    "arguments": {}
  }
}

πŸ“‘ API Endpoints

The server exposes the following endpoints:

Endpoint

Method

Description

/

GET

SSE endpoint for streaming server events

/

POST

Messages endpoint for MCP tool calls

/sse

GET

Alternative SSE endpoint

/messages

POST

Alternative messages endpoint

/mcp

GET/POST

Unified MCP endpoint (SSE for GET, messages for POST)


πŸ”§ Custom Tools

1. list_repo_dir

Description: Lists files and directories in a repository path.

Parameters:

  • path (optional): Relative path of the subdirectory to list. If omitted, lists the root directory.

Example Output:

Items inside 'docs/clients':
- copilot-byok.md
- pageassist.md
- openai-api.md

2. view_repo_file

Description: Reads and returns the complete text contents of a file.

Parameters:

  • path (required): Relative path of the file to view.

Example Output:

# README.md
This is the content of the README file...

πŸ“œ Standard Git Tools

The server inherits all tools from mcp_server_git, including:

  • git_status: Show working tree status.

  • git_diff: Show changes between branches or commits.

  • git_log: Show commit history.

  • git_add: Stage files for commit.

  • git_commit: Commit changes to the repository.

  • git_branch: List branches.

  • git_reset: Unstage changes.

For a full list, call the tools/list method after connecting to the server.


πŸ§ͺ Testing

To verify the server is working correctly, you can use a tool like curl or Postman to send a test request:

Example curl Request

curl -X POST http://localhost:8808/messages \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "method": "tools/list",
    "params": {}
  }'

Expected Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "list_repo_dir",
        "description": "Lists files and items inside a specific sub-folder of the repository.",
        "inputSchema": { ... }
      },
      {
        "name": "view_repo_file",
        "description": "Reads and returns the complete text contents of a specific file.",
        "inputSchema": { ... }
      },
      {
        "name": "git_status",
        "description": "Shows the working tree status.",
        "inputSchema": { ... }
      }
    ]
  }
}

πŸ› Troubleshooting

Common Issues

1. Server Fails to Start

  • Cause: Missing dependencies or incorrect Python version.

  • Solution: Ensure Python 3.8+ and all required packages are installed:

    pip install starlette uvicorn mcp-server-git

2. Repository Not Found

  • Cause: The TARGET_REPO path is incorrect or the repository does not exist.

  • Solution: Set TARGET_REPO to the correct local path:

    # Windows (PowerShell)
    $env:TARGET_REPO = "C:\path\to\your\repo"
    
    # macOS/Linux
    export TARGET_REPO="/path/to/your/repo"

3. Permission Denied

  • Cause: The server does not have read access to the repository.

  • Solution: Ensure the repository is accessible and the server has read permissions.

4. Timeouts

  • Cause: The server takes too long to respond.

  • Solution: Check if the mcp_server_git subprocess is running correctly. Restart the server if needed.


πŸ“š Example Use Cases

1. Navigate a Codebase

// List the root directory
{
  "method": "tools/call",
  "params": {
    "name": "list_repo_dir",
    "arguments": {}
  }
}

// List the 'src' directory
{
  "method": "tools/call",
  "params": {
    "name": "list_repo_dir",
    "arguments": {
      "path": "src"
    }
  }
}

// View a file
{
  "method": "tools/call",
  "params": {
    "name": "view_repo_file",
    "arguments": {
      "path": "src/main.py"
    }
  }
}

2. Check Git Status and Diffs

// Check Git status
{
  "method": "tools/call",
  "params": {
    "name": "git_status",
    "arguments": {}
  }
}

// Show unstaged changes
{
  "method": "tools/call",
  "params": {
    "name": "git_diff_unstaged",
    "arguments": {}
  }
}

πŸ”’ Security Notes

  • The server only allows access to files within the TARGET_REPO directory. Attempts to access files outside this path will result in a "Path out of bounds" error.

  • Never expose this server to untrusted networks without proper authentication and authorization.


πŸ“œ License

This project is open-source and licensed under the MIT License.


🀝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs or suggest features by opening an issue.

  • Submit pull requests with improvements.


πŸ“ž Support

For questions or issues:

  • Check the GitHub Issues for known problems.

  • Open a new issue if you encounter unexpected behavior.


🏷️ Tags

mcp-server, git, python, starlette, uvicorn, model-context-protocol

A
license - permissive license
-
quality - not tested
B
maintenance

Maintenance

–Maintainers
–Response time
–Release cycle
–Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    A
    maintenance
    A Model Context Protocol server for Git repository interaction and automation. This server provides tools to read, search, and manipulate Git repositories via Large Language Models.
    12
    89,405
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    A Model Context Protocol server that enables LLMs to interact with Git repositories, providing tools to read, search, and manipulate Git repositories through commands like status, diff, commit, and branch management.
    12
    MIT
  • A
    license
    C
    quality
    B
    maintenance
    A Model Context Protocol server that enables LLMs to interact with Git repositories, providing tools to read, search, and manipulate Git repositories through commands like status, diff, commit, and branch operations.
    22
    4
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    A Model Context Protocol server that provides Git version control operations as structured tools for AI coding agents. It enables LLMs to programmatically manage repositories through actions like committing changes, rolling back code, and comparing diffs.
    10
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • A MCP server built for developers enabling Git based project management with project and personal…

  • A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…

  • An MCP server that gives your AI access to the source code and docs of all public github repos

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bpweatherill/local-git-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server