@cyanheads/git-mcp-server 1.2.4 → 2.0.1
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 +169 -288
- package/build/config/index.js +69 -0
- package/build/index.js +122 -41
- package/build/mcp-server/server.js +572 -0
- package/build/mcp-server/tools/gitAdd/index.js +7 -0
- package/build/mcp-server/tools/gitAdd/logic.js +118 -0
- package/build/mcp-server/tools/gitAdd/registration.js +73 -0
- package/build/mcp-server/tools/gitBranch/index.js +7 -0
- package/build/mcp-server/tools/gitBranch/logic.js +180 -0
- package/build/mcp-server/tools/gitBranch/registration.js +72 -0
- package/build/mcp-server/tools/gitCheckout/index.js +6 -0
- package/build/mcp-server/tools/gitCheckout/logic.js +165 -0
- package/build/mcp-server/tools/gitCheckout/registration.js +78 -0
- package/build/mcp-server/tools/gitCherryPick/index.js +7 -0
- package/build/mcp-server/tools/gitCherryPick/logic.js +115 -0
- package/build/mcp-server/tools/gitCherryPick/registration.js +69 -0
- package/build/mcp-server/tools/gitClean/index.js +7 -0
- package/build/mcp-server/tools/gitClean/logic.js +110 -0
- package/build/mcp-server/tools/gitClean/registration.js +98 -0
- package/build/mcp-server/tools/gitClearWorkingDir/index.js +7 -0
- package/build/mcp-server/tools/gitClearWorkingDir/logic.js +35 -0
- package/build/mcp-server/tools/gitClearWorkingDir/registration.js +73 -0
- package/build/mcp-server/tools/gitClone/index.js +7 -0
- package/build/mcp-server/tools/gitClone/logic.js +136 -0
- package/build/mcp-server/tools/gitClone/registration.js +44 -0
- package/build/mcp-server/tools/gitCommit/index.js +7 -0
- package/build/mcp-server/tools/gitCommit/logic.js +129 -0
- package/build/mcp-server/tools/gitCommit/registration.js +100 -0
- package/build/mcp-server/tools/gitDiff/index.js +6 -0
- package/build/mcp-server/tools/gitDiff/logic.js +114 -0
- package/build/mcp-server/tools/gitDiff/registration.js +74 -0
- package/build/mcp-server/tools/gitFetch/index.js +6 -0
- package/build/mcp-server/tools/gitFetch/logic.js +116 -0
- package/build/mcp-server/tools/gitFetch/registration.js +71 -0
- package/build/mcp-server/tools/gitInit/index.js +7 -0
- package/build/mcp-server/tools/gitInit/logic.js +117 -0
- package/build/mcp-server/tools/gitInit/registration.js +44 -0
- package/build/mcp-server/tools/gitLog/index.js +6 -0
- package/build/mcp-server/tools/gitLog/logic.js +148 -0
- package/build/mcp-server/tools/gitLog/registration.js +71 -0
- package/build/mcp-server/tools/gitMerge/index.js +7 -0
- package/build/mcp-server/tools/gitMerge/logic.js +160 -0
- package/build/mcp-server/tools/gitMerge/registration.js +77 -0
- package/build/mcp-server/tools/gitPull/index.js +6 -0
- package/build/mcp-server/tools/gitPull/logic.js +144 -0
- package/build/mcp-server/tools/gitPull/registration.js +81 -0
- package/build/mcp-server/tools/gitPush/index.js +6 -0
- package/build/mcp-server/tools/gitPush/logic.js +188 -0
- package/build/mcp-server/tools/gitPush/registration.js +81 -0
- package/build/mcp-server/tools/gitRebase/index.js +7 -0
- package/build/mcp-server/tools/gitRebase/logic.js +171 -0
- package/build/mcp-server/tools/gitRebase/registration.js +72 -0
- package/build/mcp-server/tools/gitRemote/index.js +7 -0
- package/build/mcp-server/tools/gitRemote/logic.js +158 -0
- package/build/mcp-server/tools/gitRemote/registration.js +76 -0
- package/build/mcp-server/tools/gitReset/index.js +6 -0
- package/build/mcp-server/tools/gitReset/logic.js +116 -0
- package/build/mcp-server/tools/gitReset/registration.js +71 -0
- package/build/mcp-server/tools/gitSetWorkingDir/index.js +7 -0
- package/build/mcp-server/tools/gitSetWorkingDir/logic.js +91 -0
- package/build/mcp-server/tools/gitSetWorkingDir/registration.js +78 -0
- package/build/mcp-server/tools/gitShow/index.js +7 -0
- package/build/mcp-server/tools/gitShow/logic.js +99 -0
- package/build/mcp-server/tools/gitShow/registration.js +83 -0
- package/build/mcp-server/tools/gitStash/index.js +7 -0
- package/build/mcp-server/tools/gitStash/logic.js +161 -0
- package/build/mcp-server/tools/gitStash/registration.js +84 -0
- package/build/mcp-server/tools/gitStatus/index.js +7 -0
- package/build/mcp-server/tools/gitStatus/logic.js +215 -0
- package/build/mcp-server/tools/gitStatus/registration.js +77 -0
- package/build/mcp-server/tools/gitTag/index.js +7 -0
- package/build/mcp-server/tools/gitTag/logic.js +142 -0
- package/build/mcp-server/tools/gitTag/registration.js +84 -0
- package/build/types-global/errors.js +68 -0
- package/build/types-global/mcp.js +59 -0
- package/build/types-global/tool.js +1 -0
- package/build/utils/errorHandler.js +237 -0
- package/build/utils/idGenerator.js +148 -0
- package/build/utils/index.js +11 -0
- package/build/utils/jsonParser.js +78 -0
- package/build/utils/logger.js +266 -0
- package/build/utils/rateLimiter.js +177 -0
- package/build/utils/requestContext.js +49 -0
- package/build/utils/sanitization.js +371 -0
- package/build/utils/tokenCounter.js +124 -0
- package/package.json +52 -8
- 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
|
-
|
|
12
|
+
Built on the [`cyanheads/mcp-ts-template`](https://github.com/cyanheads/mcp-ts-template), this server follows a modular architecture:
|
|
13
13
|
|
|
14
|
-
|
|
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:
|
|
53
|
-
|
|
54
|
-
<details>
|
|
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,148 @@ 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
|
|
133
|
-
|
|
134
|
-
Expose Git repository information through MCP resources:
|
|
57
|
+
Implemented as an MCP server, it allows LLM agents and other compatible clients to interact with local Git repositories using standardized commands.
|
|
135
58
|
|
|
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
|
|
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.
|
|
146
60
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
Execute Git commands through MCP tools:
|
|
150
|
-
|
|
151
|
-
- **Repository Operations**: Initialize repositories, clone from remotes, check repository status
|
|
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
|
|
61
|
+
## Table of Contents
|
|
156
62
|
|
|
157
|
-
|
|
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)
|
|
158
72
|
|
|
159
|
-
|
|
73
|
+
## Overview
|
|
160
74
|
|
|
161
|
-
|
|
162
|
-
- Git installed and available in the PATH
|
|
75
|
+
The Git MCP Server implements the Model Context Protocol (MCP), enabling standardized communication between LLMs and external systems through:
|
|
163
76
|
|
|
164
|
-
|
|
77
|
+
- **Clients**: Claude Desktop, IDEs, and other MCP-compatible clients.
|
|
78
|
+
- **Servers**: This server provides tools for Git operations.
|
|
79
|
+
- **LLM Agents**: AI models that leverage the server's Git capabilities.
|
|
165
80
|
|
|
166
|
-
|
|
167
|
-
npm install -g @cyanheads/git-mcp-server
|
|
168
|
-
```
|
|
81
|
+
This server enables AI assistants and other MCP clients to interact with local Git repositories. It exposes specific Git commands as MCP tools, allowing for programmatic control over repository status checking, branching, staging, committing, fetching, pulling, pushing, and more.
|
|
169
82
|
|
|
170
|
-
|
|
83
|
+
## Features
|
|
171
84
|
|
|
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
|
-
```
|
|
85
|
+
### Core Utilities (from Template)
|
|
178
86
|
|
|
179
|
-
|
|
87
|
+
Leverages the robust utilities provided by the `mcp-ts-template`:
|
|
180
88
|
|
|
181
|
-
|
|
89
|
+
- **Logging**: Structured, configurable logging (file rotation, console, MCP notifications) with sensitive data redaction.
|
|
90
|
+
- **Error Handling**: Centralized error processing, standardized error types (`McpError`), and automatic logging.
|
|
91
|
+
- **Configuration**: Environment variable loading (`dotenv`).
|
|
92
|
+
- **Input Validation/Sanitization**: Uses `zod` for schema validation and custom sanitization logic (crucial for paths).
|
|
93
|
+
- **Request Context**: Tracking and correlation of operations via unique request IDs.
|
|
94
|
+
- **Type Safety**: Strong typing enforced by TypeScript and Zod schemas.
|
|
95
|
+
- **HTTP Transport Option**: Built-in Express server with SSE, session management, and CORS support.
|
|
182
96
|
|
|
183
|
-
|
|
97
|
+
### Git Operations
|
|
184
98
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
99
|
+
- **Comprehensive Command Coverage**: Exposes a wide range of Git commands as MCP tools (see [Tools](#tools) section).
|
|
100
|
+
- **Repository Interaction**: Supports status checking, branching, staging, committing, fetching, pulling, pushing, diffing, logging, resetting, tagging, and more.
|
|
101
|
+
- **Working Directory Management**: Allows setting and clearing a session-specific working directory for context persistence across multiple Git operations.
|
|
102
|
+
- **Safety Features**: Includes checks and requires explicit confirmation for potentially destructive operations like `git clean` and `git reset --hard`.
|
|
188
103
|
|
|
189
|
-
|
|
104
|
+
## Installation
|
|
190
105
|
|
|
191
|
-
|
|
192
|
-
node build/index.js
|
|
193
|
-
```
|
|
106
|
+
### Prerequisites
|
|
194
107
|
|
|
195
|
-
|
|
108
|
+
- [Node.js (v18+)](https://nodejs.org/)
|
|
109
|
+
- [npm](https://www.npmjs.com/) (comes with Node.js)
|
|
110
|
+
- [Git](https://git-scm.com/) installed and accessible in the system PATH.
|
|
196
111
|
|
|
197
|
-
###
|
|
112
|
+
### Install from Source
|
|
198
113
|
|
|
199
|
-
|
|
114
|
+
1. Clone the repository:
|
|
115
|
+
```bash
|
|
116
|
+
git clone https://github.com/cyanheads/git-mcp-server.git
|
|
117
|
+
cd git-mcp-server
|
|
118
|
+
```
|
|
119
|
+
2. Install dependencies:
|
|
120
|
+
```bash
|
|
121
|
+
npm install
|
|
122
|
+
```
|
|
123
|
+
3. Build the project:
|
|
124
|
+
```bash
|
|
125
|
+
npm run build
|
|
126
|
+
```
|
|
127
|
+
This compiles the TypeScript code to JavaScript in the `build/` directory and makes the entry point executable.
|
|
128
|
+
|
|
129
|
+
## Configuration
|
|
130
|
+
|
|
131
|
+
### Environment Variables
|
|
132
|
+
|
|
133
|
+
Configure the server using environment variables. Create a `.env` file in the project root (copy from `.env.example`) or set them in your environment.
|
|
134
|
+
|
|
135
|
+
| Variable | Description | Default |
|
|
136
|
+
| ---------------------- | ---------------------------------------------------------------------------------------- | ------------------- |
|
|
137
|
+
| `MCP_TRANSPORT_TYPE` | Transport mechanism: `stdio` or `http`. | `stdio` |
|
|
138
|
+
| `MCP_HTTP_PORT` | Port for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). Retries next ports if busy. | `3000` |
|
|
139
|
+
| `MCP_HTTP_HOST` | Host address for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). | `127.0.0.1` |
|
|
140
|
+
| `MCP_ALLOWED_ORIGINS` | Comma-separated list of allowed origins for CORS (if `MCP_TRANSPORT_TYPE=http`). | (none) |
|
|
141
|
+
| `MCP_SERVER_NAME` | Name reported during MCP initialization. | `git-mcp-server` |
|
|
142
|
+
| `MCP_SERVER_VERSION` | Version reported during MCP initialization. | (from package.json) |
|
|
143
|
+
| `LOG_LEVEL` | Logging level (`debug`, `info`, `notice`, `warning`, `error`, `crit`, `alert`, `emerg`). | `info` |
|
|
144
|
+
| `LOG_REDACT_PATTERNS` | Comma-separated regex patterns for redacting sensitive data in logs. | (predefined) |
|
|
145
|
+
| `LOG_FILE_PATH` | Path for log file output. If unset, logs only to console. | (none) |
|
|
146
|
+
| `LOG_MAX_FILE_SIZE_MB` | Max size (MB) for log file rotation. | `10` |
|
|
147
|
+
| `LOG_MAX_FILES` | Max number of rotated log files to keep. | `5` |
|
|
148
|
+
| `LOG_ZIP_ARCHIVES` | Compress rotated log files (`true`/`false`). | `true` |
|
|
149
|
+
|
|
150
|
+
### MCP Client Settings
|
|
151
|
+
|
|
152
|
+
Add to your MCP client settings (e.g., `cline_mcp_settings.json`):
|
|
200
153
|
|
|
201
154
|
```json
|
|
202
155
|
{
|
|
203
156
|
"mcpServers": {
|
|
204
157
|
"git": {
|
|
205
|
-
"command": "
|
|
206
|
-
"args": [],
|
|
207
|
-
"env": {
|
|
158
|
+
"command": "node", // Use node to run the script
|
|
159
|
+
"args": ["/path/to/your/git-mcp-server/build/index.js"], // Absolute path to the built entry point
|
|
160
|
+
"env": {
|
|
161
|
+
// "MCP_TRANSPORT_TYPE": "http", // Optional: if using http
|
|
162
|
+
// "MCP_HTTP_PORT": "3001" // Optional: if using http and non-default port
|
|
163
|
+
},
|
|
208
164
|
"disabled": false,
|
|
209
165
|
"autoApprove": [] // Configure auto-approval rules if desired
|
|
210
166
|
}
|
|
@@ -212,172 +168,97 @@ Add to your Claude configuration file (e.g., `cline_mcp_settings.json` or `claud
|
|
|
212
168
|
}
|
|
213
169
|
```
|
|
214
170
|
|
|
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
171
|
## Project Structure
|
|
228
172
|
|
|
229
|
-
The codebase follows a modular structure:
|
|
173
|
+
The codebase follows a modular structure within the `src/` directory:
|
|
230
174
|
|
|
231
175
|
```
|
|
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
|
|
176
|
+
src/
|
|
177
|
+
├── index.ts # Entry point: Initializes and starts the server
|
|
178
|
+
├── config/ # Configuration loading (env vars, package info)
|
|
179
|
+
│ └── index.ts
|
|
180
|
+
├── mcp-server/ # Core MCP server logic and capability registration
|
|
181
|
+
│ ├── server.ts # Server setup, transport handling, tool registration
|
|
182
|
+
│ ├── resources/ # MCP Resource implementations (currently none)
|
|
183
|
+
│ └── tools/ # MCP Tool implementations (subdirs per tool)
|
|
184
|
+
├── types-global/ # Shared TypeScript type definitions
|
|
185
|
+
└── utils/ # Common utility functions (logger, error handler, etc.)
|
|
269
186
|
```
|
|
270
187
|
|
|
188
|
+
For a detailed file tree, run `npm run tree` or see [docs/tree.md](docs/tree.md).
|
|
189
|
+
|
|
271
190
|
## Tools
|
|
272
191
|
|
|
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. |
|
|
192
|
+
The Git MCP Server provides a suite of tools for interacting with Git repositories, callable via the Model Context Protocol.
|
|
193
|
+
|
|
194
|
+
| Tool Name | Description | Key Arguments |
|
|
195
|
+
| :---------------------- | :------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------- |
|
|
196
|
+
| `git_add` | Stages specified files or patterns. | `path?`, `files?` |
|
|
197
|
+
| `git_branch` | Manages branches (list, create, delete, rename, show current). | `path?`, `mode`, `branchName?`, `newBranchName?`, `startPoint?`, `force?`, `all?`, `remote?` |
|
|
198
|
+
| `git_checkout` | Switches branches or restores working tree files. | `path?`, `branchOrPath`, `newBranch?`, `force?` |
|
|
199
|
+
| `git_cherry_pick` | Applies changes introduced by existing commits. | `path?`, `commitRef`, `mainline?`, `strategy?`, `noCommit?`, `signoff?` |
|
|
200
|
+
| `git_clean` | Removes untracked files. **Requires `force: true`**. | `path?`, `force`, `dryRun?`, `directories?`, `ignored?` |
|
|
201
|
+
| `git_clear_working_dir` | Clears the session-specific working directory. | (none) |
|
|
202
|
+
| `git_clone` | Clones a repository into a specified absolute path. | `repositoryUrl`, `targetPath`, `branch?`, `depth?`, `quiet?` |
|
|
203
|
+
| `git_commit` | Commits staged changes with a message. | `path?`, `message`, `author?`, `allowEmpty?`, `amend?` |
|
|
204
|
+
| `git_diff` | Shows changes between commits, working tree, etc. | `path?`, `commit1?`, `commit2?`, `staged?`, `file?` |
|
|
205
|
+
| `git_fetch` | Downloads objects and refs from other repositories. | `path?`, `remote?`, `prune?`, `tags?`, `all?` |
|
|
206
|
+
| `git_init` | Initializes a new Git repository at the specified absolute path. | `path`, `initialBranch?`, `bare?`, `quiet?` |
|
|
207
|
+
| `git_log` | Shows commit logs. | `path?`, `maxCount?`, `author?`, `since?`, `until?`, `branchOrFile?` |
|
|
208
|
+
| `git_merge` | Merges the specified branch into the current branch. | `path?`, `branch`, `commitMessage?`, `noFf?`, `squash?`, `abort?` |
|
|
209
|
+
| `git_pull` | Fetches from and integrates with another repository or local branch. | `path?`, `remote?`, `branch?`, `rebase?`, `ffOnly?` |
|
|
210
|
+
| `git_push` | Updates remote refs using local refs. | `path?`, `remote?`, `branch?`, `remoteBranch?`, `force?`, `forceWithLease?`, `setUpstream?`, `tags?`, `delete?` |
|
|
211
|
+
| `git_rebase` | Reapplies commits on top of another base tip. | `path?`, `mode?`, `upstream?`, `branch?`, `interactive?`, `strategy?`, `strategyOption?`, `onto?` |
|
|
212
|
+
| `git_remote` | Manages remote repositories (list, add, remove, show). | `path?`, `mode`, `name?`, `url?` |
|
|
213
|
+
| `git_reset` | Resets current HEAD to a specified state. Supports soft, mixed, hard modes. **USE 'hard' WITH CAUTION**. | `path?`, `mode?`, `commit?` |
|
|
214
|
+
| `git_set_working_dir` | Sets the default working directory for the current session. Requires absolute path. | `path`, `validateGitRepo?` |
|
|
215
|
+
| `git_show` | Shows information about Git objects (commits, tags, etc.). | `path?`, `ref`, `filePath?` |
|
|
216
|
+
| `git_stash` | Manages stashed changes (list, apply, pop, drop, save). | `path?`, `mode`, `stashRef?`, `message?` |
|
|
217
|
+
| `git_status` | Gets repository status (branch, staged, modified, untracked files). | `path?` |
|
|
218
|
+
| `git_tag` | Manages tags (list, create annotated/lightweight, delete). | `path?`, `mode`, `tagName?`, `message?`, `commitRef?`, `annotate?` |
|
|
219
|
+
|
|
220
|
+
_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
221
|
|
|
330
222
|
## Resources
|
|
331
223
|
|
|
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 |
|
|
224
|
+
**MCP Resources are not implemented in this version (v2.0.0).**
|
|
225
|
+
|
|
226
|
+
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.
|
|
227
|
+
|
|
228
|
+
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)**.
|
|
229
|
+
|
|
230
|
+
Future development may reintroduce resource capabilities in a subsequent release.
|
|
350
231
|
|
|
351
232
|
## Development
|
|
352
233
|
|
|
353
234
|
### Build and Test
|
|
354
235
|
|
|
355
236
|
```bash
|
|
356
|
-
# Build the project
|
|
237
|
+
# Build the project (compile TS to JS in build/ and make executable)
|
|
357
238
|
npm run build
|
|
358
239
|
|
|
359
|
-
# Watch for changes and
|
|
240
|
+
# Watch for changes and recompile automatically
|
|
360
241
|
npm run watch
|
|
361
242
|
|
|
362
|
-
# Test the server locally using the MCP inspector tool
|
|
243
|
+
# Test the server locally using the MCP inspector tool (stdio transport)
|
|
363
244
|
npm run inspector
|
|
364
245
|
|
|
365
|
-
# Clean build artifacts
|
|
246
|
+
# Clean build artifacts (runs scripts/clean.ts)
|
|
366
247
|
npm run clean
|
|
367
248
|
|
|
368
|
-
# Generate a file tree representation for documentation
|
|
249
|
+
# Generate a file tree representation for documentation (runs scripts/tree.ts)
|
|
369
250
|
npm run tree
|
|
370
251
|
|
|
371
|
-
# Clean and rebuild the project
|
|
252
|
+
# Clean build artifacts and then rebuild the project
|
|
372
253
|
npm run rebuild
|
|
373
254
|
```
|
|
374
255
|
|
|
375
256
|
## License
|
|
376
257
|
|
|
377
|
-
Apache License 2.0 -
|
|
258
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
378
259
|
|
|
379
260
|
---
|
|
380
261
|
|
|
381
262
|
<div align="center">
|
|
382
|
-
Built with the Model Context Protocol
|
|
263
|
+
Built with the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a>
|
|
383
264
|
</div>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { logger } from "../utils/logger.js"; // Import McpLogLevel and logger
|
|
6
|
+
dotenv.config(); // Load environment variables from .env file
|
|
7
|
+
// Determine the directory name of the current module
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
// Construct the path to package.json relative to the current file
|
|
10
|
+
const pkgPath = join(__dirname, '../../package.json');
|
|
11
|
+
// Default package information in case package.json is unreadable
|
|
12
|
+
let pkg = { name: 'mcp-ts-template', version: '0.0.0' };
|
|
13
|
+
try {
|
|
14
|
+
// Read and parse package.json to get server name and version
|
|
15
|
+
pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
// Silently use default pkg info if reading fails. Error will be logged later if needed.
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Main application configuration object.
|
|
22
|
+
* Aggregates settings from environment variables and package.json.
|
|
23
|
+
*/
|
|
24
|
+
export const config = {
|
|
25
|
+
/** The name of the MCP server, derived from package.json. */
|
|
26
|
+
mcpServerName: pkg.name,
|
|
27
|
+
/** The version of the MCP server, derived from package.json. */
|
|
28
|
+
mcpServerVersion: pkg.version,
|
|
29
|
+
/** Logging level for the application (e.g., "debug", "info", "warning", "error"). Defaults to "info". */
|
|
30
|
+
logLevel: process.env.MCP_LOG_LEVEL || "info", // Use MCP_LOG_LEVEL consistently
|
|
31
|
+
/** The runtime environment (e.g., "development", "production"). Defaults to "development". */
|
|
32
|
+
environment: process.env.NODE_ENV || "development",
|
|
33
|
+
/** Security-related configurations. */
|
|
34
|
+
security: {
|
|
35
|
+
// Placeholder for security settings
|
|
36
|
+
// Example: authRequired: process.env.AUTH_REQUIRED === 'true'
|
|
37
|
+
/** Indicates if authentication is required for server operations. */
|
|
38
|
+
authRequired: false,
|
|
39
|
+
}
|
|
40
|
+
// Note: mcpClient configuration is now loaded separately from mcp-config.json
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The configured logging level for the application.
|
|
44
|
+
* Exported separately for convenience (e.g., logger initialization).
|
|
45
|
+
* @type {string}
|
|
46
|
+
*/
|
|
47
|
+
export const logLevel = config.logLevel;
|
|
48
|
+
/**
|
|
49
|
+
* The configured runtime environment for the application.
|
|
50
|
+
* Exported separately for convenience.
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
53
|
+
export const environment = config.environment;
|
|
54
|
+
// Define valid MCP log levels based on the logger's type definition
|
|
55
|
+
const validMcpLogLevels = ['debug', 'info', 'notice', 'warning', 'error', 'crit', 'alert', 'emerg'];
|
|
56
|
+
// Validate the configured log level
|
|
57
|
+
let validatedMcpLogLevel = 'info'; // Default to 'info'
|
|
58
|
+
if (validMcpLogLevels.includes(logLevel)) {
|
|
59
|
+
validatedMcpLogLevel = logLevel;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Silently default to 'info' if the configured level is invalid.
|
|
63
|
+
// The logger initialization message will show the actual level being used.
|
|
64
|
+
}
|
|
65
|
+
// Initialize the logger with the validated MCP level AFTER config is defined.
|
|
66
|
+
logger.initialize(validatedMcpLogLevel);
|
|
67
|
+
// Log initialization message using the logger itself (will go to file and potentially MCP)
|
|
68
|
+
logger.info(`Logger initialized. MCP logging level: ${validatedMcpLogLevel}`);
|
|
69
|
+
logger.debug("Configuration loaded successfully", { config }); // Log loaded config at debug level
|