@cyanheads/git-mcp-server 1.2.4 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -285
- package/dist/config/index.js +69 -0
- package/dist/index.js +135 -0
- package/dist/mcp-server/server.js +572 -0
- package/dist/mcp-server/tools/gitAdd/index.js +7 -0
- package/dist/mcp-server/tools/gitAdd/logic.js +118 -0
- package/dist/mcp-server/tools/gitAdd/registration.js +73 -0
- package/dist/mcp-server/tools/gitBranch/index.js +7 -0
- package/dist/mcp-server/tools/gitBranch/logic.js +180 -0
- package/dist/mcp-server/tools/gitBranch/registration.js +72 -0
- package/dist/mcp-server/tools/gitCheckout/index.js +6 -0
- package/dist/mcp-server/tools/gitCheckout/logic.js +165 -0
- package/dist/mcp-server/tools/gitCheckout/registration.js +78 -0
- package/dist/mcp-server/tools/gitCherryPick/index.js +7 -0
- package/dist/mcp-server/tools/gitCherryPick/logic.js +115 -0
- package/dist/mcp-server/tools/gitCherryPick/registration.js +69 -0
- package/dist/mcp-server/tools/gitClean/index.js +7 -0
- package/dist/mcp-server/tools/gitClean/logic.js +110 -0
- package/dist/mcp-server/tools/gitClean/registration.js +98 -0
- package/dist/mcp-server/tools/gitClearWorkingDir/index.js +7 -0
- package/dist/mcp-server/tools/gitClearWorkingDir/logic.js +35 -0
- package/dist/mcp-server/tools/gitClearWorkingDir/registration.js +73 -0
- package/dist/mcp-server/tools/gitClone/index.js +7 -0
- package/dist/mcp-server/tools/gitClone/logic.js +136 -0
- package/dist/mcp-server/tools/gitClone/registration.js +44 -0
- package/dist/mcp-server/tools/gitCommit/index.js +7 -0
- package/dist/mcp-server/tools/gitCommit/logic.js +129 -0
- package/dist/mcp-server/tools/gitCommit/registration.js +100 -0
- package/dist/mcp-server/tools/gitDiff/index.js +6 -0
- package/dist/mcp-server/tools/gitDiff/logic.js +114 -0
- package/dist/mcp-server/tools/gitDiff/registration.js +74 -0
- package/dist/mcp-server/tools/gitFetch/index.js +6 -0
- package/dist/mcp-server/tools/gitFetch/logic.js +116 -0
- package/dist/mcp-server/tools/gitFetch/registration.js +71 -0
- package/dist/mcp-server/tools/gitInit/index.js +7 -0
- package/dist/mcp-server/tools/gitInit/logic.js +117 -0
- package/dist/mcp-server/tools/gitInit/registration.js +44 -0
- package/dist/mcp-server/tools/gitLog/index.js +6 -0
- package/dist/mcp-server/tools/gitLog/logic.js +148 -0
- package/dist/mcp-server/tools/gitLog/registration.js +71 -0
- package/dist/mcp-server/tools/gitMerge/index.js +7 -0
- package/dist/mcp-server/tools/gitMerge/logic.js +160 -0
- package/dist/mcp-server/tools/gitMerge/registration.js +77 -0
- package/dist/mcp-server/tools/gitPull/index.js +6 -0
- package/dist/mcp-server/tools/gitPull/logic.js +144 -0
- package/dist/mcp-server/tools/gitPull/registration.js +81 -0
- package/dist/mcp-server/tools/gitPush/index.js +6 -0
- package/dist/mcp-server/tools/gitPush/logic.js +188 -0
- package/dist/mcp-server/tools/gitPush/registration.js +81 -0
- package/dist/mcp-server/tools/gitRebase/index.js +7 -0
- package/dist/mcp-server/tools/gitRebase/logic.js +171 -0
- package/dist/mcp-server/tools/gitRebase/registration.js +72 -0
- package/dist/mcp-server/tools/gitRemote/index.js +7 -0
- package/dist/mcp-server/tools/gitRemote/logic.js +158 -0
- package/dist/mcp-server/tools/gitRemote/registration.js +76 -0
- package/dist/mcp-server/tools/gitReset/index.js +6 -0
- package/dist/mcp-server/tools/gitReset/logic.js +116 -0
- package/dist/mcp-server/tools/gitReset/registration.js +71 -0
- package/dist/mcp-server/tools/gitSetWorkingDir/index.js +7 -0
- package/dist/mcp-server/tools/gitSetWorkingDir/logic.js +91 -0
- package/dist/mcp-server/tools/gitSetWorkingDir/registration.js +78 -0
- package/dist/mcp-server/tools/gitShow/index.js +7 -0
- package/dist/mcp-server/tools/gitShow/logic.js +99 -0
- package/dist/mcp-server/tools/gitShow/registration.js +83 -0
- package/dist/mcp-server/tools/gitStash/index.js +7 -0
- package/dist/mcp-server/tools/gitStash/logic.js +161 -0
- package/dist/mcp-server/tools/gitStash/registration.js +84 -0
- package/dist/mcp-server/tools/gitStatus/index.js +7 -0
- package/dist/mcp-server/tools/gitStatus/logic.js +215 -0
- package/dist/mcp-server/tools/gitStatus/registration.js +77 -0
- package/dist/mcp-server/tools/gitTag/index.js +7 -0
- package/dist/mcp-server/tools/gitTag/logic.js +142 -0
- package/dist/mcp-server/tools/gitTag/registration.js +84 -0
- package/dist/types-global/errors.js +68 -0
- package/dist/types-global/mcp.js +59 -0
- package/dist/types-global/tool.js +1 -0
- package/dist/utils/errorHandler.js +237 -0
- package/dist/utils/idGenerator.js +148 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/jsonParser.js +78 -0
- package/dist/utils/logger.js +266 -0
- package/dist/utils/rateLimiter.js +177 -0
- package/dist/utils/requestContext.js +49 -0
- package/dist/utils/sanitization.js +371 -0
- package/dist/utils/tokenCounter.js +124 -0
- package/package.json +62 -17
- package/build/index.js +0 -54
- package/build/resources/descriptors.js +0 -77
- package/build/resources/diff.js +0 -241
- package/build/resources/file.js +0 -222
- package/build/resources/history.js +0 -242
- package/build/resources/index.js +0 -99
- package/build/resources/repository.js +0 -286
- package/build/server.js +0 -120
- package/build/services/error-service.js +0 -73
- package/build/services/git-service.js +0 -965
- package/build/tools/advanced.js +0 -526
- package/build/tools/branch.js +0 -296
- package/build/tools/index.js +0 -29
- package/build/tools/remote.js +0 -279
- package/build/tools/repository.js +0 -170
- package/build/tools/workdir.js +0 -445
- package/build/types/git.js +0 -7
- package/build/utils/global-settings.js +0 -64
- package/build/utils/validation.js +0 -108
package/README.md
CHANGED
|
@@ -1,58 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Git MCP Server
|
|
2
2
|
|
|
3
|
-
[](https://www.typescriptlang.org/)
|
|
4
|
+
[](https://modelcontextprotocol.io/)
|
|
5
|
+
[](./CHANGELOG.md)
|
|
6
6
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
-
[](https://github.com/cyanheads/git-mcp-server/issues)
|
|
8
8
|
[](https://github.com/cyanheads/git-mcp-server)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
An MCP (Model Context Protocol) server providing tools to interact with Git repositories. Enables LLMs and AI agents to perform Git operations like clone, commit, push, pull, branch, diff, log, status, and more via the MCP standard.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- [Overview](#overview)
|
|
15
|
-
- [Architecture & Components](#architecture--components)
|
|
16
|
-
- [Features](#features)
|
|
17
|
-
- [Resource Access](#resource-access)
|
|
18
|
-
- [Git Operations](#git-operations)
|
|
19
|
-
- [Installation](#installation)
|
|
20
|
-
- [Prerequisites](#prerequisites)
|
|
21
|
-
- [Install from NPM](#install-from-npm)
|
|
22
|
-
- [Install from Source](#install-from-source)
|
|
23
|
-
- [Usage](#usage)
|
|
24
|
-
- [Running the Server](#running-the-server)
|
|
25
|
-
- [Integration with Claude](#integration-with-claude)
|
|
26
|
-
- [Integration with Other MCP Clients](#integration-with-other-mcp-clients)
|
|
27
|
-
- [Project Structure](#project-structure)
|
|
28
|
-
- [Tools](#tools)
|
|
29
|
-
- [Repository Operations](#repository-operations)
|
|
30
|
-
- [Branch Operations](#branch-operations)
|
|
31
|
-
- [Working Directory Operations](#working-directory-operations)
|
|
32
|
-
- [Remote Operations](#remote-operations)
|
|
33
|
-
- [Advanced Operations](#advanced-operations)
|
|
34
|
-
- [Resources](#resources)
|
|
35
|
-
- [Repository Resources](#repository-resources)
|
|
36
|
-
- [Development](#development)
|
|
37
|
-
- [Build and Test](#build-and-test)
|
|
38
|
-
- [License](#license)
|
|
39
|
-
|
|
40
|
-
## Overview
|
|
41
|
-
|
|
42
|
-
Key capabilities:
|
|
43
|
-
|
|
44
|
-
- **Repository Management**: Initialize, clone, and check repository status
|
|
45
|
-
- **Branch Operations**: Create, list, checkout, delete, and merge branches
|
|
46
|
-
- **Working Directory**: Stage files, commit changes, create diffs
|
|
47
|
-
- **Remote Operations**: Add remotes, fetch, pull, push
|
|
48
|
-
- **Advanced Git Commands**: Manage tags, stash changes, cherry-pick, rebase
|
|
49
|
-
|
|
50
|
-
### Architecture & Components
|
|
51
|
-
|
|
52
|
-
Core system architecture:
|
|
12
|
+
Built on the [`cyanheads/mcp-ts-template`](https://github.com/cyanheads/mcp-ts-template), this server follows a modular architecture:
|
|
53
13
|
|
|
54
|
-
|
|
55
|
-
<summary>Click to expand Mermaid diagram</summary>
|
|
14
|
+
> **Note:** This version (v2.0.0) focuses on refactoring and updating the core Git tools based on the latest MCP SDK. MCP Resource capabilities are not implemented in this version. For resource access, please use [v1.2.4](https://github.com/cyanheads/git-mcp-server/releases/tag/v1.2.4).
|
|
56
15
|
|
|
57
16
|
```mermaid
|
|
58
17
|
flowchart TB
|
|
@@ -60,151 +19,154 @@ flowchart TB
|
|
|
60
19
|
direction LR
|
|
61
20
|
MCP["MCP Protocol"]
|
|
62
21
|
Val["Validation (Zod)"]
|
|
22
|
+
San["Sanitization"]
|
|
63
23
|
|
|
64
|
-
MCP --> Val
|
|
24
|
+
MCP --> Val --> San
|
|
65
25
|
end
|
|
66
26
|
|
|
67
|
-
subgraph Core["Core
|
|
27
|
+
subgraph Core["Core Components"]
|
|
68
28
|
direction LR
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
29
|
+
Config["Configuration"]
|
|
30
|
+
Logger["Logging System"]
|
|
31
|
+
Error["Error Handling"]
|
|
32
|
+
Server["MCP Server (SDK)"]
|
|
33
|
+
|
|
34
|
+
Config --> Server
|
|
35
|
+
Logger --> Server
|
|
36
|
+
Error --> Server
|
|
73
37
|
end
|
|
74
38
|
|
|
75
|
-
subgraph
|
|
39
|
+
subgraph Implementation["Implementation Layer"]
|
|
76
40
|
direction LR
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
File["File Resources"]
|
|
80
|
-
History["History Resources"]
|
|
81
|
-
|
|
82
|
-
Repo <--> Diff
|
|
83
|
-
Repo <--> File
|
|
84
|
-
Repo <--> History
|
|
85
|
-
end
|
|
41
|
+
Tool["Tools (Git Logic)"]
|
|
42
|
+
Util["Utilities"]
|
|
86
43
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
RepoTools["Repository Tools"]
|
|
90
|
-
BranchTools["Branch Tools"]
|
|
91
|
-
WorkdirTools["Working Directory Tools"]
|
|
92
|
-
RemoteTools["Remote Tools"]
|
|
93
|
-
AdvancedTools["Advanced Tools"]
|
|
94
|
-
|
|
95
|
-
RepoTools <--> BranchTools
|
|
96
|
-
BranchTools <--> WorkdirTools
|
|
97
|
-
WorkdirTools <--> RemoteTools
|
|
98
|
-
RemoteTools <--> AdvancedTools
|
|
44
|
+
Tool --> Server
|
|
45
|
+
Util --> Tool
|
|
99
46
|
end
|
|
100
47
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
GitService --> Tools
|
|
48
|
+
San --> Config
|
|
49
|
+
San --> Server
|
|
104
50
|
|
|
105
51
|
classDef layer fill:#2d3748,stroke:#4299e1,stroke-width:3px,rx:5,color:#fff
|
|
106
52
|
classDef component fill:#1a202c,stroke:#a0aec0,stroke-width:2px,rx:3,color:#fff
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
classDef resource fill:#2f855a,stroke:#9ae6b4,stroke-width:2px,rx:3,color:#fff
|
|
110
|
-
classDef tool fill:#805ad5,stroke:#d6bcfa,stroke-width:2px,rx:3,color:#fff
|
|
111
|
-
|
|
112
|
-
class API,Core,Resources,Tools layer
|
|
113
|
-
class MCP,Val api
|
|
114
|
-
class GitService,ErrorService core
|
|
115
|
-
class Repo,Diff,File,History resource
|
|
116
|
-
class RepoTools,BranchTools,WorkdirTools,RemoteTools,AdvancedTools tool
|
|
53
|
+
class API,Core,Implementation layer
|
|
54
|
+
class MCP,Val,San,Config,Logger,Error,Server,Tool,Util component
|
|
117
55
|
```
|
|
118
56
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
Core Components:
|
|
122
|
-
|
|
123
|
-
- **MCP Server (`server.ts`)**: Uses the `@modelcontextprotocol/sdk` to create a server exposing resources and tools.
|
|
124
|
-
- **Git Service (`services/git-service.ts`)**: Abstraction layer over the `simple-git` library providing clean interfaces for Git operations.
|
|
125
|
-
- **Resources (`resources/`)**: Expose Git data (like status, logs, file content) through MCP resources with consistent URI templates.
|
|
126
|
-
- **Tools (`tools/`)**: Expose Git actions (like commit, push, pull) through MCP tools with well-defined input schemas (validated using Zod).
|
|
127
|
-
- **Error Handling (`services/error-service.ts`)**: Standardized error handling and reporting for Git and MCP operations.
|
|
128
|
-
- **Entry Point (`index.ts`)**: Initializes and starts the server, connecting it to the standard I/O transport.
|
|
129
|
-
|
|
130
|
-
## Features
|
|
131
|
-
|
|
132
|
-
### Resource Access
|
|
57
|
+
Implemented as an MCP server, it allows LLM agents and other compatible clients to interact with local Git repositories using standardized commands.
|
|
133
58
|
|
|
134
|
-
|
|
59
|
+
> **Developer Note**: This repository includes a [.clinerules](.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.
|
|
135
60
|
|
|
136
|
-
|
|
137
|
-
- **Repository Branches**: List all branches in the repository with current branch indicator
|
|
138
|
-
- **Repository Remotes**: List all configured remote repositories with their URLs
|
|
139
|
-
- **Repository Tags**: List all tags in the repository with their references
|
|
140
|
-
- **File Content**: Access content of specific files at a given Git reference
|
|
141
|
-
- **Directory Listing**: View lists of files and directories at a specific path and reference
|
|
142
|
-
- **Diffs**: Get differences between references, unstaged changes, or staged changes
|
|
143
|
-
- **Commit History**: View detailed commit logs with author, date, and message information
|
|
144
|
-
- **File Blame**: See line-by-line attribution showing which commit last modified each line
|
|
145
|
-
- **Commit Details**: Access detailed information about specific commits including diff changes
|
|
61
|
+
## Table of Contents
|
|
146
62
|
|
|
147
|
-
|
|
63
|
+
- [Overview](#overview)
|
|
64
|
+
- [Features](#features)
|
|
65
|
+
- [Installation](#installation)
|
|
66
|
+
- [Configuration](#configuration)
|
|
67
|
+
- [Project Structure](#project-structure)
|
|
68
|
+
- [Tools](#tools)
|
|
69
|
+
- [Resources](#resources)
|
|
70
|
+
- [Development](#development)
|
|
71
|
+
- [License](#license)
|
|
148
72
|
|
|
149
|
-
|
|
73
|
+
## Overview
|
|
150
74
|
|
|
151
|
-
|
|
152
|
-
- **Branch Operations**: Create branches, list branches, checkout, delete branches, merge
|
|
153
|
-
- **Working Directory Operations**: Stage files, unstage files, commit changes, create diffs
|
|
154
|
-
- **Remote Operations**: Add remotes, list remotes, fetch, pull, push
|
|
155
|
-
- **Advanced Operations**: Manage tags, stash changes, cherry-pick commits, rebase branches, reset, clean
|
|
75
|
+
**Empower your AI agents and development tools with seamless Git integration!**
|
|
156
76
|
|
|
157
|
-
|
|
77
|
+
The Git MCP Server acts as a bridge, allowing applications (MCP Clients) that understand the Model Context Protocol (MCP) – like advanced AI assistants (LLMs), IDE extensions, or custom scripts – to interact directly and safely with local Git repositories.
|
|
158
78
|
|
|
159
|
-
|
|
79
|
+
Instead of complex scripting or manual CLI, your tools can leverage this server to:
|
|
160
80
|
|
|
161
|
-
-
|
|
162
|
-
-
|
|
81
|
+
- **Automate Git workflows**: Clone repositories, create branches, stage changes, commit work, push updates, and manage tags programmatically.
|
|
82
|
+
- **Gain repository insights**: Check status, view logs, diff changes, and inspect Git objects without leaving the host application.
|
|
83
|
+
- **Integrate Git into AI-driven development**: Enable LLMs to manage version control as part of their coding or refactoring tasks.
|
|
163
84
|
|
|
164
|
-
|
|
85
|
+
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.
|
|
165
86
|
|
|
166
|
-
|
|
167
|
-
npm install -g @cyanheads/git-mcp-server
|
|
168
|
-
```
|
|
87
|
+
## Features
|
|
169
88
|
|
|
170
|
-
###
|
|
89
|
+
### Core Utilities (from Template)
|
|
171
90
|
|
|
172
|
-
|
|
173
|
-
git clone https://github.com/cyanheads/git-mcp-server.git
|
|
174
|
-
cd git-mcp-server
|
|
175
|
-
npm install
|
|
176
|
-
npm run build
|
|
177
|
-
```
|
|
91
|
+
Leverages the robust utilities provided by the `mcp-ts-template`:
|
|
178
92
|
|
|
179
|
-
|
|
93
|
+
- **Logging**: Structured, configurable logging (file rotation, console, MCP notifications) with sensitive data redaction.
|
|
94
|
+
- **Error Handling**: Centralized error processing, standardized error types (`McpError`), and automatic logging.
|
|
95
|
+
- **Configuration**: Environment variable loading (`dotenv`).
|
|
96
|
+
- **Input Validation/Sanitization**: Uses `zod` for schema validation and custom sanitization logic (crucial for paths).
|
|
97
|
+
- **Request Context**: Tracking and correlation of operations via unique request IDs.
|
|
98
|
+
- **Type Safety**: Strong typing enforced by TypeScript and Zod schemas.
|
|
99
|
+
- **HTTP Transport Option**: Built-in Express server with SSE, session management, and CORS support.
|
|
180
100
|
|
|
181
|
-
###
|
|
101
|
+
### Git Operations
|
|
182
102
|
|
|
183
|
-
|
|
103
|
+
- **Direct Git CLI Execution**: Interacts with Git by securely executing the standard `git` command-line tool via Node.js `child_process`, ensuring full compatibility and access to Git's features.
|
|
184
104
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
105
|
+
- **Comprehensive Command Coverage**: Exposes a wide range of Git commands as MCP tools (see [Tools](#tools) section).
|
|
106
|
+
- **Repository Interaction**: Supports status checking, branching, staging, committing, fetching, pulling, pushing, diffing, logging, resetting, tagging, and more.
|
|
107
|
+
- **Working Directory Management**: Allows setting and clearing a session-specific working directory for context persistence across multiple Git operations.
|
|
108
|
+
- **Safety Features**: Includes checks and requires explicit confirmation for potentially destructive operations like `git clean` and `git reset --hard`.
|
|
188
109
|
|
|
189
|
-
|
|
110
|
+
## Installation
|
|
190
111
|
|
|
191
|
-
|
|
192
|
-
node build/index.js
|
|
193
|
-
```
|
|
112
|
+
### Prerequisites
|
|
194
113
|
|
|
195
|
-
|
|
114
|
+
- [Node.js (v18+)](https://nodejs.org/)
|
|
115
|
+
- [npm](https://www.npmjs.com/) (comes with Node.js)
|
|
116
|
+
- [Git](https://git-scm.com/) installed and accessible in the system PATH.
|
|
196
117
|
|
|
197
|
-
###
|
|
118
|
+
### Install from Source
|
|
198
119
|
|
|
199
|
-
|
|
120
|
+
1. Clone the repository:
|
|
121
|
+
```bash
|
|
122
|
+
git clone https://github.com/cyanheads/git-mcp-server.git
|
|
123
|
+
cd git-mcp-server
|
|
124
|
+
```
|
|
125
|
+
2. Install dependencies:
|
|
126
|
+
```bash
|
|
127
|
+
npm install
|
|
128
|
+
```
|
|
129
|
+
3. Build the project:
|
|
130
|
+
```bash
|
|
131
|
+
npm run build
|
|
132
|
+
```
|
|
133
|
+
This compiles the TypeScript code to JavaScript in the `build/` directory and makes the entry point executable.
|
|
134
|
+
|
|
135
|
+
## Configuration
|
|
136
|
+
|
|
137
|
+
### Environment Variables
|
|
138
|
+
|
|
139
|
+
Configure the server using environment variables. Create a `.env` file in the project root (copy from `.env.example`) or set them in your environment.
|
|
140
|
+
|
|
141
|
+
| Variable | Description | Default |
|
|
142
|
+
| ---------------------- | ---------------------------------------------------------------------------------------- | ------------------- |
|
|
143
|
+
| `MCP_TRANSPORT_TYPE` | Transport mechanism: `stdio` or `http`. | `stdio` |
|
|
144
|
+
| `MCP_HTTP_PORT` | Port for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). Retries next ports if busy. | `3000` |
|
|
145
|
+
| `MCP_HTTP_HOST` | Host address for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). | `127.0.0.1` |
|
|
146
|
+
| `MCP_ALLOWED_ORIGINS` | Comma-separated list of allowed origins for CORS (if `MCP_TRANSPORT_TYPE=http`). | (none) |
|
|
147
|
+
| `MCP_SERVER_NAME` | Name reported during MCP initialization. | `git-mcp-server` |
|
|
148
|
+
| `MCP_SERVER_VERSION` | Version reported during MCP initialization. | (from package.json) |
|
|
149
|
+
| `LOG_LEVEL` | Logging level (`debug`, `info`, `notice`, `warning`, `error`, `crit`, `alert`, `emerg`). | `info` |
|
|
150
|
+
| `LOG_REDACT_PATTERNS` | Comma-separated regex patterns for redacting sensitive data in logs. | (predefined) |
|
|
151
|
+
| `LOG_FILE_PATH` | Path for log file output. If unset, logs only to console. | (none) |
|
|
152
|
+
| `LOG_MAX_FILE_SIZE_MB` | Max size (MB) for log file rotation. | `10` |
|
|
153
|
+
| `LOG_MAX_FILES` | Max number of rotated log files to keep. | `5` |
|
|
154
|
+
| `LOG_ZIP_ARCHIVES` | Compress rotated log files (`true`/`false`). | `true` |
|
|
155
|
+
|
|
156
|
+
### MCP Client Settings
|
|
157
|
+
|
|
158
|
+
Add to your MCP client settings (e.g., `cline_mcp_settings.json`):
|
|
200
159
|
|
|
201
160
|
```json
|
|
202
161
|
{
|
|
203
162
|
"mcpServers": {
|
|
204
163
|
"git": {
|
|
205
|
-
"command": "
|
|
206
|
-
"args": [],
|
|
207
|
-
"env": {
|
|
164
|
+
"command": "node", // Use node to run the script
|
|
165
|
+
"args": ["/path/to/your/git-mcp-server/build/index.js"], // Absolute path to the built entry point
|
|
166
|
+
"env": {
|
|
167
|
+
// "MCP_TRANSPORT_TYPE": "http", // Optional: if using http
|
|
168
|
+
// "MCP_HTTP_PORT": "3001" // Optional: if using http and non-default port
|
|
169
|
+
},
|
|
208
170
|
"disabled": false,
|
|
209
171
|
"autoApprove": [] // Configure auto-approval rules if desired
|
|
210
172
|
}
|
|
@@ -212,172 +174,97 @@ Add to your Claude configuration file (e.g., `cline_mcp_settings.json` or `claud
|
|
|
212
174
|
}
|
|
213
175
|
```
|
|
214
176
|
|
|
215
|
-
### Integration with Other MCP Clients
|
|
216
|
-
|
|
217
|
-
Use the MCP inspector to test the server:
|
|
218
|
-
|
|
219
|
-
```bash
|
|
220
|
-
# If installed globally
|
|
221
|
-
npx @modelcontextprotocol/inspector git-mcp-server
|
|
222
|
-
|
|
223
|
-
# If running from source
|
|
224
|
-
npx @modelcontextprotocol/inspector build/index.js
|
|
225
|
-
```
|
|
226
|
-
|
|
227
177
|
## Project Structure
|
|
228
178
|
|
|
229
|
-
The codebase follows a modular structure:
|
|
179
|
+
The codebase follows a modular structure within the `src/` directory:
|
|
230
180
|
|
|
231
181
|
```
|
|
232
|
-
|
|
233
|
-
├──
|
|
234
|
-
|
|
235
|
-
│
|
|
236
|
-
|
|
237
|
-
│
|
|
238
|
-
│
|
|
239
|
-
│
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
│ │ └── repository.ts # Repository info, branches, remotes, tags resources
|
|
243
|
-
│ ├── services/ # Core logic and external integrations
|
|
244
|
-
│ │ ├── error-service.ts # Centralized error handling utilities
|
|
245
|
-
│ │ └── git-service.ts # Abstraction layer for simple-git operations
|
|
246
|
-
│ ├── tools/ # MCP Tool implementations
|
|
247
|
-
│ │ ├── advanced.ts # Advanced Git tools (tag, stash, cherry-pick, rebase, log, show)
|
|
248
|
-
│ │ ├── branch.ts # Branch management tools (list, create, checkout, delete, merge)
|
|
249
|
-
│ │ ├── index.ts # Aggregates and registers all tools
|
|
250
|
-
│ │ ├── remote.ts # Remote interaction tools (add, list, fetch, pull, push)
|
|
251
|
-
│ │ ├── repository.ts # Repository level tools (init, clone, status)
|
|
252
|
-
│ │ └── workdir.ts # Working directory tools (add, reset, commit, diff, reset-commit, clean)
|
|
253
|
-
│ ├── types/ # TypeScript type definitions
|
|
254
|
-
│ │ └── git.ts # Custom types related to Git operations
|
|
255
|
-
│ └── utils/ # Shared utility functions
|
|
256
|
-
│ ├── global-settings.ts # Manages global working directory setting
|
|
257
|
-
│ └── validation.ts # Input validation schemas (Zod) and helpers
|
|
258
|
-
├── build/ # Compiled JavaScript output
|
|
259
|
-
├── docs/ # Documentation files
|
|
260
|
-
├── logs/ # Log files (if any)
|
|
261
|
-
├── scripts/ # Helper scripts for development (e.g., clean, tree)
|
|
262
|
-
├── .env.example # Example environment variables
|
|
263
|
-
├── .gitignore # Git ignore rules
|
|
264
|
-
├── LICENSE # Project license file
|
|
265
|
-
├── package.json # Project metadata and dependencies
|
|
266
|
-
├── package-lock.json # Lockfile for dependencies
|
|
267
|
-
├── README.md # This file
|
|
268
|
-
└── tsconfig.json # TypeScript compiler configuration
|
|
182
|
+
src/
|
|
183
|
+
├── index.ts # Entry point: Initializes and starts the server
|
|
184
|
+
├── config/ # Configuration loading (env vars, package info)
|
|
185
|
+
│ └── index.ts
|
|
186
|
+
├── mcp-server/ # Core MCP server logic and capability registration
|
|
187
|
+
│ ├── server.ts # Server setup, transport handling, tool registration
|
|
188
|
+
│ ├── resources/ # MCP Resource implementations (currently none)
|
|
189
|
+
│ └── tools/ # MCP Tool implementations (subdirs per tool)
|
|
190
|
+
├── types-global/ # Shared TypeScript type definitions
|
|
191
|
+
└── utils/ # Common utility functions (logger, error handler, etc.)
|
|
269
192
|
```
|
|
270
193
|
|
|
194
|
+
For a detailed file tree, run `npm run tree` or see [docs/tree.md](docs/tree.md).
|
|
195
|
+
|
|
271
196
|
## Tools
|
|
272
197
|
|
|
273
|
-
Git MCP Server provides a
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
|
278
|
-
|
|
|
279
|
-
| `
|
|
280
|
-
| `
|
|
281
|
-
| `
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
|
286
|
-
|
|
|
287
|
-
| `
|
|
288
|
-
| `
|
|
289
|
-
| `
|
|
290
|
-
| `
|
|
291
|
-
| `
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
|
296
|
-
|
|
|
297
|
-
| `
|
|
298
|
-
| `
|
|
299
|
-
| `
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
| `git_reset_commit` | Reset the repository to a specific reference with options for hard, soft, or mixed mode. |
|
|
303
|
-
| `git_clean` | Remove untracked files from the working tree with options for directories and force cleaning. |
|
|
304
|
-
|
|
305
|
-
### Remote Operations
|
|
306
|
-
|
|
307
|
-
| Tool | Description |
|
|
308
|
-
| ----------------- | -------------------------------------------------------------------------------------------- |
|
|
309
|
-
| `git_remote_add` | Add a new remote repository with a name and URL. |
|
|
310
|
-
| `git_remote_list` | List all configured remote repositories and their URLs. |
|
|
311
|
-
| `git_fetch` | Fetch updates from a remote repository with options for specific branches. |
|
|
312
|
-
| `git_pull` | Pull changes from a remote repository with options for rebase strategy. |
|
|
313
|
-
| `git_push` | Push local changes to a remote repository with options for force push and upstream tracking. |
|
|
314
|
-
|
|
315
|
-
### Advanced Operations
|
|
316
|
-
|
|
317
|
-
| Tool | Description |
|
|
318
|
-
| ------------------ | ----------------------------------------------------------------------------------------- |
|
|
319
|
-
| `git_tag_create` | Create a new tag with options for annotated tags with messages. |
|
|
320
|
-
| `git_tag_list` | List all tags in the repository with their references. |
|
|
321
|
-
| `git_stash_create` | Stash changes in the working directory with options for untracked files and descriptions. |
|
|
322
|
-
| `git_stash_list` | List all stashes in the repository with their descriptions. |
|
|
323
|
-
| `git_stash_apply` | Apply a stashed change without removing it from the stash list. |
|
|
324
|
-
| `git_stash_pop` | Apply a stashed change and remove it from the stash list. |
|
|
325
|
-
| `git_cherry_pick` | Apply changes from specific commits to the current branch. |
|
|
326
|
-
| `git_rebase` | Rebase the current branch onto another branch with interactive mode options. |
|
|
327
|
-
| `git_log` | Get commit history with customizable output format and depth. |
|
|
328
|
-
| `git_show` | Show detailed information about a specific commit including diff changes. |
|
|
198
|
+
The Git MCP Server provides a suite of tools for interacting with Git repositories, callable via the Model Context Protocol.
|
|
199
|
+
|
|
200
|
+
| Tool Name | Description | Key Arguments |
|
|
201
|
+
| :---------------------- | :------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------- |
|
|
202
|
+
| `git_add` | Stages specified files or patterns. | `path?`, `files?` |
|
|
203
|
+
| `git_branch` | Manages branches (list, create, delete, rename, show current). | `path?`, `mode`, `branchName?`, `newBranchName?`, `startPoint?`, `force?`, `all?`, `remote?` |
|
|
204
|
+
| `git_checkout` | Switches branches or restores working tree files. | `path?`, `branchOrPath`, `newBranch?`, `force?` |
|
|
205
|
+
| `git_cherry_pick` | Applies changes introduced by existing commits. | `path?`, `commitRef`, `mainline?`, `strategy?`, `noCommit?`, `signoff?` |
|
|
206
|
+
| `git_clean` | Removes untracked files. **Requires `force: true`**. | `path?`, `force`, `dryRun?`, `directories?`, `ignored?` |
|
|
207
|
+
| `git_clear_working_dir` | Clears the session-specific working directory. | (none) |
|
|
208
|
+
| `git_clone` | Clones a repository into a specified absolute path. | `repositoryUrl`, `targetPath`, `branch?`, `depth?`, `quiet?` |
|
|
209
|
+
| `git_commit` | Commits staged changes with a message. | `path?`, `message`, `author?`, `allowEmpty?`, `amend?` |
|
|
210
|
+
| `git_diff` | Shows changes between commits, working tree, etc. | `path?`, `commit1?`, `commit2?`, `staged?`, `file?` |
|
|
211
|
+
| `git_fetch` | Downloads objects and refs from other repositories. | `path?`, `remote?`, `prune?`, `tags?`, `all?` |
|
|
212
|
+
| `git_init` | Initializes a new Git repository at the specified absolute path. | `path`, `initialBranch?`, `bare?`, `quiet?` |
|
|
213
|
+
| `git_log` | Shows commit logs. | `path?`, `maxCount?`, `author?`, `since?`, `until?`, `branchOrFile?` |
|
|
214
|
+
| `git_merge` | Merges the specified branch into the current branch. | `path?`, `branch`, `commitMessage?`, `noFf?`, `squash?`, `abort?` |
|
|
215
|
+
| `git_pull` | Fetches from and integrates with another repository or local branch. | `path?`, `remote?`, `branch?`, `rebase?`, `ffOnly?` |
|
|
216
|
+
| `git_push` | Updates remote refs using local refs. | `path?`, `remote?`, `branch?`, `remoteBranch?`, `force?`, `forceWithLease?`, `setUpstream?`, `tags?`, `delete?` |
|
|
217
|
+
| `git_rebase` | Reapplies commits on top of another base tip. | `path?`, `mode?`, `upstream?`, `branch?`, `interactive?`, `strategy?`, `strategyOption?`, `onto?` |
|
|
218
|
+
| `git_remote` | Manages remote repositories (list, add, remove, show). | `path?`, `mode`, `name?`, `url?` |
|
|
219
|
+
| `git_reset` | Resets current HEAD to a specified state. Supports soft, mixed, hard modes. **USE 'hard' WITH CAUTION**. | `path?`, `mode?`, `commit?` |
|
|
220
|
+
| `git_set_working_dir` | Sets the default working directory for the current session. Requires absolute path. | `path`, `validateGitRepo?` |
|
|
221
|
+
| `git_show` | Shows information about Git objects (commits, tags, etc.). | `path?`, `ref`, `filePath?` |
|
|
222
|
+
| `git_stash` | Manages stashed changes (list, apply, pop, drop, save). | `path?`, `mode`, `stashRef?`, `message?` |
|
|
223
|
+
| `git_status` | Gets repository status (branch, staged, modified, untracked files). | `path?` |
|
|
224
|
+
| `git_tag` | Manages tags (list, create annotated/lightweight, delete). | `path?`, `mode`, `tagName?`, `message?`, `commitRef?`, `annotate?` |
|
|
225
|
+
|
|
226
|
+
_Note: The `path` parameter for most tools defaults to the session's working directory if set via `git_set_working_dir`, otherwise it defaults to the server's CWD._
|
|
329
227
|
|
|
330
228
|
## Resources
|
|
331
229
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
| `git://repo/{repoPath}/branches` | List of all branches in the repository with current branch indicator |
|
|
340
|
-
| `git://repo/{repoPath}/remotes` | List of all configured remote repositories with their URLs |
|
|
341
|
-
| `git://repo/{repoPath}/tags` | List of all tags in the repository with their references |
|
|
342
|
-
| `git://repo/{repoPath}/file/{filePath}?ref={ref}` | Returns the content of a specific file at a given Git reference |
|
|
343
|
-
| `git://repo/{repoPath}/ls/{dirPath}?ref={ref}` | Returns a list of files and directories at a specific path and reference |
|
|
344
|
-
| `git://repo/{repoPath}/diff/{fromRef}/{toRef}?path={path}` | Returns a diff between two Git references (commits, branches, tags) |
|
|
345
|
-
| `git://repo/{repoPath}/diff-unstaged?path={path}` | Returns a diff of all unstaged changes in the working directory |
|
|
346
|
-
| `git://repo/{repoPath}/diff-staged?path={path}` | Returns a diff of all staged changes in the index |
|
|
347
|
-
| `git://repo/{repoPath}/log?maxCount={maxCount}&file={file}` | Returns the commit history log with author, date, and message details |
|
|
348
|
-
| `git://repo/{repoPath}/blame/{filePath}` | Returns line-by-line attribution showing which commit last modified each line |
|
|
349
|
-
| `git://repo/{repoPath}/commit/{commitHash}` | Returns detailed information about a specific commit including diff changes |
|
|
230
|
+
**MCP Resources are not implemented in this version (v2.0.0).**
|
|
231
|
+
|
|
232
|
+
This version focuses on the refactored Git tools implementation based on the latest `mcp-ts-template` and MCP SDK v1.10.2. Resource capabilities, previously available, have been temporarily removed during this major update.
|
|
233
|
+
|
|
234
|
+
If you require MCP Resource access (e.g., for reading file content directly via the server), please use the stable **[v1.2.4 release](https://github.com/cyanheads/git-mcp-server/releases/tag/v1.2.4)**.
|
|
235
|
+
|
|
236
|
+
Future development may reintroduce resource capabilities in a subsequent release.
|
|
350
237
|
|
|
351
238
|
## Development
|
|
352
239
|
|
|
353
240
|
### Build and Test
|
|
354
241
|
|
|
355
242
|
```bash
|
|
356
|
-
# Build the project
|
|
243
|
+
# Build the project (compile TS to JS in build/ and make executable)
|
|
357
244
|
npm run build
|
|
358
245
|
|
|
359
|
-
# Watch for changes and
|
|
246
|
+
# Watch for changes and recompile automatically
|
|
360
247
|
npm run watch
|
|
361
248
|
|
|
362
|
-
# Test the server locally using the MCP inspector tool
|
|
249
|
+
# Test the server locally using the MCP inspector tool (stdio transport)
|
|
363
250
|
npm run inspector
|
|
364
251
|
|
|
365
|
-
# Clean build artifacts
|
|
252
|
+
# Clean build artifacts (runs scripts/clean.ts)
|
|
366
253
|
npm run clean
|
|
367
254
|
|
|
368
|
-
# Generate a file tree representation for documentation
|
|
255
|
+
# Generate a file tree representation for documentation (runs scripts/tree.ts)
|
|
369
256
|
npm run tree
|
|
370
257
|
|
|
371
|
-
# Clean and rebuild the project
|
|
258
|
+
# Clean build artifacts and then rebuild the project
|
|
372
259
|
npm run rebuild
|
|
373
260
|
```
|
|
374
261
|
|
|
375
262
|
## License
|
|
376
263
|
|
|
377
|
-
Apache License 2.0 -
|
|
264
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
378
265
|
|
|
379
266
|
---
|
|
380
267
|
|
|
381
268
|
<div align="center">
|
|
382
|
-
Built with the Model Context Protocol
|
|
269
|
+
Built with the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a>
|
|
383
270
|
</div>
|