@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.
Files changed (105) hide show
  1. package/README.md +172 -285
  2. package/dist/config/index.js +69 -0
  3. package/dist/index.js +135 -0
  4. package/dist/mcp-server/server.js +572 -0
  5. package/dist/mcp-server/tools/gitAdd/index.js +7 -0
  6. package/dist/mcp-server/tools/gitAdd/logic.js +118 -0
  7. package/dist/mcp-server/tools/gitAdd/registration.js +73 -0
  8. package/dist/mcp-server/tools/gitBranch/index.js +7 -0
  9. package/dist/mcp-server/tools/gitBranch/logic.js +180 -0
  10. package/dist/mcp-server/tools/gitBranch/registration.js +72 -0
  11. package/dist/mcp-server/tools/gitCheckout/index.js +6 -0
  12. package/dist/mcp-server/tools/gitCheckout/logic.js +165 -0
  13. package/dist/mcp-server/tools/gitCheckout/registration.js +78 -0
  14. package/dist/mcp-server/tools/gitCherryPick/index.js +7 -0
  15. package/dist/mcp-server/tools/gitCherryPick/logic.js +115 -0
  16. package/dist/mcp-server/tools/gitCherryPick/registration.js +69 -0
  17. package/dist/mcp-server/tools/gitClean/index.js +7 -0
  18. package/dist/mcp-server/tools/gitClean/logic.js +110 -0
  19. package/dist/mcp-server/tools/gitClean/registration.js +98 -0
  20. package/dist/mcp-server/tools/gitClearWorkingDir/index.js +7 -0
  21. package/dist/mcp-server/tools/gitClearWorkingDir/logic.js +35 -0
  22. package/dist/mcp-server/tools/gitClearWorkingDir/registration.js +73 -0
  23. package/dist/mcp-server/tools/gitClone/index.js +7 -0
  24. package/dist/mcp-server/tools/gitClone/logic.js +136 -0
  25. package/dist/mcp-server/tools/gitClone/registration.js +44 -0
  26. package/dist/mcp-server/tools/gitCommit/index.js +7 -0
  27. package/dist/mcp-server/tools/gitCommit/logic.js +129 -0
  28. package/dist/mcp-server/tools/gitCommit/registration.js +100 -0
  29. package/dist/mcp-server/tools/gitDiff/index.js +6 -0
  30. package/dist/mcp-server/tools/gitDiff/logic.js +114 -0
  31. package/dist/mcp-server/tools/gitDiff/registration.js +74 -0
  32. package/dist/mcp-server/tools/gitFetch/index.js +6 -0
  33. package/dist/mcp-server/tools/gitFetch/logic.js +116 -0
  34. package/dist/mcp-server/tools/gitFetch/registration.js +71 -0
  35. package/dist/mcp-server/tools/gitInit/index.js +7 -0
  36. package/dist/mcp-server/tools/gitInit/logic.js +117 -0
  37. package/dist/mcp-server/tools/gitInit/registration.js +44 -0
  38. package/dist/mcp-server/tools/gitLog/index.js +6 -0
  39. package/dist/mcp-server/tools/gitLog/logic.js +148 -0
  40. package/dist/mcp-server/tools/gitLog/registration.js +71 -0
  41. package/dist/mcp-server/tools/gitMerge/index.js +7 -0
  42. package/dist/mcp-server/tools/gitMerge/logic.js +160 -0
  43. package/dist/mcp-server/tools/gitMerge/registration.js +77 -0
  44. package/dist/mcp-server/tools/gitPull/index.js +6 -0
  45. package/dist/mcp-server/tools/gitPull/logic.js +144 -0
  46. package/dist/mcp-server/tools/gitPull/registration.js +81 -0
  47. package/dist/mcp-server/tools/gitPush/index.js +6 -0
  48. package/dist/mcp-server/tools/gitPush/logic.js +188 -0
  49. package/dist/mcp-server/tools/gitPush/registration.js +81 -0
  50. package/dist/mcp-server/tools/gitRebase/index.js +7 -0
  51. package/dist/mcp-server/tools/gitRebase/logic.js +171 -0
  52. package/dist/mcp-server/tools/gitRebase/registration.js +72 -0
  53. package/dist/mcp-server/tools/gitRemote/index.js +7 -0
  54. package/dist/mcp-server/tools/gitRemote/logic.js +158 -0
  55. package/dist/mcp-server/tools/gitRemote/registration.js +76 -0
  56. package/dist/mcp-server/tools/gitReset/index.js +6 -0
  57. package/dist/mcp-server/tools/gitReset/logic.js +116 -0
  58. package/dist/mcp-server/tools/gitReset/registration.js +71 -0
  59. package/dist/mcp-server/tools/gitSetWorkingDir/index.js +7 -0
  60. package/dist/mcp-server/tools/gitSetWorkingDir/logic.js +91 -0
  61. package/dist/mcp-server/tools/gitSetWorkingDir/registration.js +78 -0
  62. package/dist/mcp-server/tools/gitShow/index.js +7 -0
  63. package/dist/mcp-server/tools/gitShow/logic.js +99 -0
  64. package/dist/mcp-server/tools/gitShow/registration.js +83 -0
  65. package/dist/mcp-server/tools/gitStash/index.js +7 -0
  66. package/dist/mcp-server/tools/gitStash/logic.js +161 -0
  67. package/dist/mcp-server/tools/gitStash/registration.js +84 -0
  68. package/dist/mcp-server/tools/gitStatus/index.js +7 -0
  69. package/dist/mcp-server/tools/gitStatus/logic.js +215 -0
  70. package/dist/mcp-server/tools/gitStatus/registration.js +77 -0
  71. package/dist/mcp-server/tools/gitTag/index.js +7 -0
  72. package/dist/mcp-server/tools/gitTag/logic.js +142 -0
  73. package/dist/mcp-server/tools/gitTag/registration.js +84 -0
  74. package/dist/types-global/errors.js +68 -0
  75. package/dist/types-global/mcp.js +59 -0
  76. package/dist/types-global/tool.js +1 -0
  77. package/dist/utils/errorHandler.js +237 -0
  78. package/dist/utils/idGenerator.js +148 -0
  79. package/dist/utils/index.js +11 -0
  80. package/dist/utils/jsonParser.js +78 -0
  81. package/dist/utils/logger.js +266 -0
  82. package/dist/utils/rateLimiter.js +177 -0
  83. package/dist/utils/requestContext.js +49 -0
  84. package/dist/utils/sanitization.js +371 -0
  85. package/dist/utils/tokenCounter.js +124 -0
  86. package/package.json +62 -17
  87. package/build/index.js +0 -54
  88. package/build/resources/descriptors.js +0 -77
  89. package/build/resources/diff.js +0 -241
  90. package/build/resources/file.js +0 -222
  91. package/build/resources/history.js +0 -242
  92. package/build/resources/index.js +0 -99
  93. package/build/resources/repository.js +0 -286
  94. package/build/server.js +0 -120
  95. package/build/services/error-service.js +0 -73
  96. package/build/services/git-service.js +0 -965
  97. package/build/tools/advanced.js +0 -526
  98. package/build/tools/branch.js +0 -296
  99. package/build/tools/index.js +0 -29
  100. package/build/tools/remote.js +0 -279
  101. package/build/tools/repository.js +0 -170
  102. package/build/tools/workdir.js +0 -445
  103. package/build/types/git.js +0 -7
  104. package/build/utils/global-settings.js +0 -64
  105. package/build/utils/validation.js +0 -108
package/README.md CHANGED
@@ -1,58 +1,17 @@
1
- # GIT MCP Server
1
+ # Git MCP Server
2
2
 
3
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue.svg)](https://www.typescriptlang.org/)
4
- [![Model Context Protocol](https://img.shields.io/badge/MCP-1.8.0-green.svg)](https://modelcontextprotocol.io/)
5
- [![Version](https://img.shields.io/badge/Version-1.2.4-blue.svg)]()
3
+ [![TypeScript](https://img.shields.io/badge/TypeScript-^5.8.3-blue.svg)](https://www.typescriptlang.org/)
4
+ [![Model Context Protocol](https://img.shields.io/badge/MCP%20SDK-^1.10.2-green.svg)](https://modelcontextprotocol.io/)
5
+ [![Version](https://img.shields.io/badge/Version-2.0.2-blue.svg)](./CHANGELOG.md)
6
6
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
- [![Status](https://img.shields.io/badge/Status-Beta-orange.svg)]()
7
+ [![Status](https://img.shields.io/badge/Status-Stable-green.svg)](https://github.com/cyanheads/git-mcp-server/issues)
8
8
  [![GitHub](https://img.shields.io/github/stars/cyanheads/git-mcp-server?style=social)](https://github.com/cyanheads/git-mcp-server)
9
9
 
10
- A Model Context Protocol (MCP) server that provides tools for interacting with Git repositories. This server allows AI assistants and LLM agents to manage repositories, branches, commits, and files through a standardized interface without requiring direct filesystem or command-line access. It exposes Git operations as MCP resources and tools, leveraging the `simple-git` library for core functionality while maintaining proper security boundaries.
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
- ## Table of Contents
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
- <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,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 Services"]
27
+ subgraph Core["Core Components"]
68
28
  direction LR
69
- GitService["Git Service (simple-git)"]
70
- ErrorService["Error Service"]
71
-
72
- GitService <--> ErrorService
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 Resources["Resource Layer"]
39
+ subgraph Implementation["Implementation Layer"]
76
40
  direction LR
77
- Repo["Repository Resources"]
78
- Diff["Diff Resources"]
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
- subgraph Tools["Tool Layer"]
88
- direction LR
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
- Val --> GitService
102
- GitService --> Resources
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
- classDef api fill:#3182ce,stroke:#90cdf4,stroke-width:2px,rx:3,color:#fff
108
- classDef core fill:#319795,stroke:#81e6d9,stroke-width:2px,rx:3,color:#fff
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
- </details>
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
- Expose Git repository information through MCP resources:
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
- - **Repository Information**: Access basic Git repository information including current branch, status, and reference details
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
- ### Git Operations
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
- Execute Git commands through MCP tools:
73
+ ## Overview
150
74
 
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
75
+ **Empower your AI agents and development tools with seamless Git integration!**
156
76
 
157
- ## Installation
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
- ### Prerequisites
79
+ Instead of complex scripting or manual CLI, your tools can leverage this server to:
160
80
 
161
- - Node.js 16 or higher
162
- - Git installed and available in the PATH
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
- ### Install from NPM
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
- ```bash
167
- npm install -g @cyanheads/git-mcp-server
168
- ```
87
+ ## Features
169
88
 
170
- ### Install from Source
89
+ ### Core Utilities (from Template)
171
90
 
172
- ```bash
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
- ## Usage
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
- ### Running the Server
101
+ ### Git Operations
182
102
 
183
- If installed globally via NPM:
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
- ```bash
186
- git-mcp-server
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
- If running from source:
110
+ ## Installation
190
111
 
191
- ```bash
192
- node build/index.js
193
- ```
112
+ ### Prerequisites
194
113
 
195
- The server communicates through stdin/stdout using the Model Context Protocol, making it compatible with any MCP client.
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
- ### Integration with Claude
118
+ ### Install from Source
198
119
 
199
- Add to your Claude configuration file (e.g., `cline_mcp_settings.json` or `claude_desktop_config.json`):
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": "git-mcp-server", // Or the full path to build/index.js if not installed globally
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
- git-mcp-server/
233
- ├── src/
234
- ├── index.ts # Entry point: Initializes and starts the server
235
- ├── server.ts # Core MCP server implementation and setup
236
- ├── resources/ # MCP Resource implementations
237
- ├── descriptors.ts # Resource URI templates and descriptions
238
- ├── diff.ts # Diff-related resources (staged, unstaged, commit)
239
- │ ├── file.ts # File content and directory listing resources
240
- │ │ ├── history.ts # Commit history and blame resources
241
- │ │ ├── index.ts # Aggregates and registers all resources
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 comprehensive suite of tools for Git operations:
274
-
275
- ### Repository Operations
276
-
277
- | Tool | Description |
278
- | ------------ | ------------------------------------------------------------------------------------------------ |
279
- | `git_init` | Initialize a new Git repository at the specified path with options for bare repositories. |
280
- | `git_clone` | Clone a Git repository from a remote URL to a local path with branch and depth options. |
281
- | `git_status` | Get the current status of a Git repository including working directory and staging area changes. |
282
-
283
- ### Branch Operations
284
-
285
- | Tool | Description |
286
- | ------------------- | ---------------------------------------------------------------------------------------------- |
287
- | `git_branch_list` | List all branches in a repository with options to include remote branches. |
288
- | `git_branch_create` | Create a new branch with options for specifying the starting point and automatic checkout. |
289
- | `git_checkout` | Checkout a branch, tag, or commit with options to create a new branch during checkout. |
290
- | `git_branch_delete` | Delete a branch with options for force deletion of unmerged branches. |
291
- | `git_merge` | Merge a branch into the current branch with customizable commit messages and merge strategies. |
292
-
293
- ### Working Directory Operations
294
-
295
- | Tool | Description |
296
- | ------------------- | ----------------------------------------------------------------------------------------------- |
297
- | `git_add` | Stage files for commit with support for individual files or entire directories. |
298
- | `git_reset` | Unstage files from the staging area with options for specific files or all staged changes. |
299
- | `git_commit` | Commit staged changes with customizable commit messages, author information, and amend options. |
300
- | `git_diff_unstaged` | Get a diff of all unstaged changes in the working directory with options for specific files. |
301
- | `git_diff_staged` | Get a diff of all staged changes in the index with options for specific files. |
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
- Git MCP Server exposes Git data through standard MCP resources:
333
-
334
- ### Repository Resources
335
-
336
- | Resource | Description |
337
- | ----------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
338
- | `git://repo/{repoPath}/info` | Basic Git repository information including current branch, status, and reference details |
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 rebuild automatically
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 completely
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 - See [LICENSE](LICENSE) for details.
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>