@cyanheads/git-mcp-server 1.2.4

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 GitHub Cyanheads
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,383 @@
1
+ # GIT MCP Server
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)]()
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)]()
8
+ [![GitHub](https://img.shields.io/github/stars/cyanheads/git-mcp-server?style=social)](https://github.com/cyanheads/git-mcp-server)
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.
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:
53
+
54
+ <details>
55
+ <summary>Click to expand Mermaid diagram</summary>
56
+
57
+ ```mermaid
58
+ flowchart TB
59
+ subgraph API["API Layer"]
60
+ direction LR
61
+ MCP["MCP Protocol"]
62
+ Val["Validation (Zod)"]
63
+
64
+ MCP --> Val
65
+ end
66
+
67
+ subgraph Core["Core Services"]
68
+ direction LR
69
+ GitService["Git Service (simple-git)"]
70
+ ErrorService["Error Service"]
71
+
72
+ GitService <--> ErrorService
73
+ end
74
+
75
+ subgraph Resources["Resource Layer"]
76
+ 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
86
+
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
99
+ end
100
+
101
+ Val --> GitService
102
+ GitService --> Resources
103
+ GitService --> Tools
104
+
105
+ classDef layer fill:#2d3748,stroke:#4299e1,stroke-width:3px,rx:5,color:#fff
106
+ 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
117
+ ```
118
+
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
133
+
134
+ Expose Git repository information through MCP resources:
135
+
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
146
+
147
+ ### Git Operations
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
156
+
157
+ ## Installation
158
+
159
+ ### Prerequisites
160
+
161
+ - Node.js 16 or higher
162
+ - Git installed and available in the PATH
163
+
164
+ ### Install from NPM
165
+
166
+ ```bash
167
+ npm install -g @cyanheads/git-mcp-server
168
+ ```
169
+
170
+ ### Install from Source
171
+
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
+ ```
178
+
179
+ ## Usage
180
+
181
+ ### Running the Server
182
+
183
+ If installed globally via NPM:
184
+
185
+ ```bash
186
+ git-mcp-server
187
+ ```
188
+
189
+ If running from source:
190
+
191
+ ```bash
192
+ node build/index.js
193
+ ```
194
+
195
+ The server communicates through stdin/stdout using the Model Context Protocol, making it compatible with any MCP client.
196
+
197
+ ### Integration with Claude
198
+
199
+ Add to your Claude configuration file (e.g., `cline_mcp_settings.json` or `claude_desktop_config.json`):
200
+
201
+ ```json
202
+ {
203
+ "mcpServers": {
204
+ "git": {
205
+ "command": "git-mcp-server", // Or the full path to build/index.js if not installed globally
206
+ "args": [],
207
+ "env": {},
208
+ "disabled": false,
209
+ "autoApprove": [] // Configure auto-approval rules if desired
210
+ }
211
+ }
212
+ }
213
+ ```
214
+
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
+ ## Project Structure
228
+
229
+ The codebase follows a modular structure:
230
+
231
+ ```
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
269
+ ```
270
+
271
+ ## Tools
272
+
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. |
329
+
330
+ ## Resources
331
+
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 |
350
+
351
+ ## Development
352
+
353
+ ### Build and Test
354
+
355
+ ```bash
356
+ # Build the project
357
+ npm run build
358
+
359
+ # Watch for changes and rebuild automatically
360
+ npm run watch
361
+
362
+ # Test the server locally using the MCP inspector tool
363
+ npm run inspector
364
+
365
+ # Clean build artifacts
366
+ npm run clean
367
+
368
+ # Generate a file tree representation for documentation
369
+ npm run tree
370
+
371
+ # Clean and rebuild the project completely
372
+ npm run rebuild
373
+ ```
374
+
375
+ ## License
376
+
377
+ Apache License 2.0 - See [LICENSE](LICENSE) for details.
378
+
379
+ ---
380
+
381
+ <div align="center">
382
+ Built with the Model Context Protocol
383
+ </div>
package/build/index.js ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Git MCP Server Entry Point
4
+ * =========================
5
+ *
6
+ * This is the main entry point for the Git MCP server.
7
+ * It creates a server instance and connects it to a stdio transport.
8
+ */
9
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10
+ import { GitMcpServer } from './server.js';
11
+ import dotenv from 'dotenv';
12
+ // Load environment variables from .env file if it exists
13
+ dotenv.config();
14
+ /**
15
+ * Main function to start the server
16
+ */
17
+ async function main() {
18
+ console.error('Starting Git MCP Server...');
19
+ try {
20
+ // Create server instance
21
+ const server = new GitMcpServer();
22
+ // Use stdio transport for communication
23
+ const transport = new StdioServerTransport();
24
+ // Connect the server to the transport
25
+ await server.connect(transport);
26
+ console.error('Git MCP Server running on stdio transport');
27
+ // Handle interruption signals
28
+ process.on('SIGINT', async () => {
29
+ console.error('Received SIGINT, shutting down Git MCP Server');
30
+ process.exit(0);
31
+ });
32
+ process.on('SIGTERM', async () => {
33
+ console.error('Received SIGTERM, shutting down Git MCP Server');
34
+ process.exit(0);
35
+ });
36
+ }
37
+ catch (error) {
38
+ console.error('Failed to start Git MCP Server:');
39
+ console.error(error instanceof Error ? error.message : String(error));
40
+ if (error instanceof Error && error.stack) {
41
+ console.error(error.stack);
42
+ }
43
+ process.exit(1);
44
+ }
45
+ }
46
+ // Start the server
47
+ main().catch((error) => {
48
+ console.error('Unhandled error in main process:');
49
+ console.error(error instanceof Error ? error.message : String(error));
50
+ if (error instanceof Error && error.stack) {
51
+ console.error(error.stack);
52
+ }
53
+ process.exit(1);
54
+ });