@cyanheads/git-mcp-server 2.1.1 → 2.1.3
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 +91 -76
- package/dist/config/index.js +7 -7
- package/dist/index.js +35 -21
- package/dist/mcp-server/server.js +72 -56
- package/dist/mcp-server/tools/gitAdd/index.js +1 -1
- package/dist/mcp-server/tools/gitAdd/logic.js +88 -39
- package/dist/mcp-server/tools/gitAdd/registration.js +17 -14
- package/dist/mcp-server/tools/gitBranch/index.js +1 -1
- package/dist/mcp-server/tools/gitBranch/logic.js +213 -85
- package/dist/mcp-server/tools/gitBranch/registration.js +16 -13
- package/dist/mcp-server/tools/gitCheckout/index.js +1 -1
- package/dist/mcp-server/tools/gitCheckout/logic.js +85 -145
- package/dist/mcp-server/tools/gitCheckout/registration.js +16 -14
- package/dist/mcp-server/tools/gitCherryPick/index.js +1 -1
- package/dist/mcp-server/tools/gitCherryPick/logic.js +100 -41
- package/dist/mcp-server/tools/gitCherryPick/registration.js +21 -14
- package/dist/mcp-server/tools/gitClean/index.js +1 -1
- package/dist/mcp-server/tools/gitClean/logic.js +93 -41
- package/dist/mcp-server/tools/gitClean/registration.js +19 -16
- package/dist/mcp-server/tools/gitClearWorkingDir/index.js +1 -1
- package/dist/mcp-server/tools/gitClearWorkingDir/logic.js +14 -11
- package/dist/mcp-server/tools/gitClearWorkingDir/registration.js +19 -13
- package/dist/mcp-server/tools/gitClone/index.js +1 -1
- package/dist/mcp-server/tools/gitClone/logic.js +89 -30
- package/dist/mcp-server/tools/gitClone/registration.js +15 -12
- package/dist/mcp-server/tools/gitCommit/index.js +1 -1
- package/dist/mcp-server/tools/gitCommit/logic.js +198 -76
- package/dist/mcp-server/tools/gitCommit/registration.js +23 -20
- package/dist/mcp-server/tools/gitDiff/index.js +1 -1
- package/dist/mcp-server/tools/gitDiff/logic.js +124 -44
- package/dist/mcp-server/tools/gitDiff/registration.js +16 -14
- package/dist/mcp-server/tools/gitFetch/index.js +1 -1
- package/dist/mcp-server/tools/gitFetch/logic.js +78 -49
- package/dist/mcp-server/tools/gitFetch/registration.js +16 -14
- package/dist/mcp-server/tools/gitInit/index.js +1 -1
- package/dist/mcp-server/tools/gitInit/logic.js +88 -34
- package/dist/mcp-server/tools/gitInit/registration.js +32 -18
- package/dist/mcp-server/tools/gitLog/index.js +1 -1
- package/dist/mcp-server/tools/gitLog/logic.js +133 -47
- package/dist/mcp-server/tools/gitLog/registration.js +16 -14
- package/dist/mcp-server/tools/gitMerge/index.js +1 -1
- package/dist/mcp-server/tools/gitMerge/logic.js +102 -61
- package/dist/mcp-server/tools/gitMerge/registration.js +17 -14
- package/dist/mcp-server/tools/gitPull/index.js +1 -1
- package/dist/mcp-server/tools/gitPull/logic.js +90 -69
- package/dist/mcp-server/tools/gitPull/registration.js +16 -14
- package/dist/mcp-server/tools/gitPush/index.js +1 -1
- package/dist/mcp-server/tools/gitPush/logic.js +116 -100
- package/dist/mcp-server/tools/gitPush/registration.js +16 -14
- package/dist/mcp-server/tools/gitRebase/index.js +1 -1
- package/dist/mcp-server/tools/gitRebase/logic.js +121 -82
- package/dist/mcp-server/tools/gitRebase/registration.js +21 -14
- package/dist/mcp-server/tools/gitRemote/index.js +1 -1
- package/dist/mcp-server/tools/gitRemote/logic.js +108 -52
- package/dist/mcp-server/tools/gitRemote/registration.js +14 -11
- package/dist/mcp-server/tools/gitReset/index.js +1 -1
- package/dist/mcp-server/tools/gitReset/logic.js +65 -37
- package/dist/mcp-server/tools/gitReset/registration.js +14 -12
- package/dist/mcp-server/tools/gitSetWorkingDir/index.js +1 -1
- package/dist/mcp-server/tools/gitSetWorkingDir/logic.js +74 -34
- package/dist/mcp-server/tools/gitSetWorkingDir/registration.js +18 -11
- package/dist/mcp-server/tools/gitShow/index.js +1 -1
- package/dist/mcp-server/tools/gitShow/logic.js +78 -35
- package/dist/mcp-server/tools/gitShow/registration.js +17 -12
- package/dist/mcp-server/tools/gitStash/index.js +1 -1
- package/dist/mcp-server/tools/gitStash/logic.js +143 -58
- package/dist/mcp-server/tools/gitStash/registration.js +19 -12
- package/dist/mcp-server/tools/gitStatus/index.js +1 -1
- package/dist/mcp-server/tools/gitStatus/logic.js +100 -58
- package/dist/mcp-server/tools/gitStatus/registration.js +15 -12
- package/dist/mcp-server/tools/gitTag/index.js +1 -1
- package/dist/mcp-server/tools/gitTag/logic.js +124 -51
- package/dist/mcp-server/tools/gitTag/registration.js +14 -11
- package/dist/mcp-server/tools/gitWorktree/index.js +1 -1
- package/dist/mcp-server/tools/gitWorktree/logic.js +204 -95
- package/dist/mcp-server/tools/gitWorktree/registration.js +14 -11
- package/dist/mcp-server/tools/gitWrapupInstructions/index.js +1 -1
- package/dist/mcp-server/tools/gitWrapupInstructions/logic.js +21 -11
- package/dist/mcp-server/tools/gitWrapupInstructions/registration.js +14 -12
- package/dist/mcp-server/transports/httpTransport.js +187 -79
- package/dist/mcp-server/transports/stdioTransport.js +14 -8
- package/dist/types-global/errors.js +9 -4
- package/dist/utils/index.js +4 -4
- package/dist/utils/internal/errorHandler.js +62 -40
- package/dist/utils/internal/index.js +3 -3
- package/dist/utils/internal/logger.js +97 -54
- package/dist/utils/internal/requestContext.js +7 -5
- package/dist/utils/metrics/index.js +1 -1
- package/dist/utils/metrics/tokenCounter.js +18 -14
- package/dist/utils/parsing/dateParser.js +5 -5
- package/dist/utils/parsing/index.js +2 -2
- package/dist/utils/parsing/jsonParser.js +20 -11
- package/dist/utils/security/idGenerator.js +8 -10
- package/dist/utils/security/index.js +3 -3
- package/dist/utils/security/rateLimiter.js +16 -14
- package/dist/utils/security/sanitization.js +139 -82
- package/package.json +47 -25
package/README.md
CHANGED
|
@@ -1,55 +1,70 @@
|
|
|
1
1
|
# Git MCP Server
|
|
2
2
|
|
|
3
3
|
[](https://www.typescriptlang.org/)
|
|
4
|
-
[](https://modelcontextprotocol.io/)
|
|
5
|
+
[](./CHANGELOG.md)
|
|
6
6
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
7
|
[](https://github.com/cyanheads/git-mcp-server/issues)
|
|
8
8
|
[](https://github.com/cyanheads/git-mcp-server)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
**Empower your AI agents with comprehensive, secure, and programmatic control over Git repositories!**
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
An MCP (Model Context Protocol) server providing a robust, LLM-friendly interface to the standard `git` command-line tool. Enables LLMs and AI agents to perform a wide range of Git operations like clone, commit, push, pull, branch, diff, log, status, and more via the MCP standard.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Built on the [`cyanheads/mcp-ts-template`](https://github.com/cyanheads/mcp-ts-template), this server follows a modular architecture with robust error handling, logging, and security features.
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## 🚀 Core Capabilities: Git Tools 🛠️
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
This server equips your AI with a comprehensive suite of tools to interact with Git repositories:
|
|
19
19
|
|
|
20
|
-
|
|
|
20
|
+
| Tool Category | Description | Key Features - |
|
|
21
|
+
| :----------------------- | :---------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| **Repository & Staging** | Manage repository state, from initialization to staging changes. | - `git_init`: Initialize a new repository.<br/>- `git_clone`: Clone remote repositories.<br/>- `git_add`: Stage changes for commit.<br/>- `git_status`: Check the status of the working directory.<br/>- `git_clean`: Remove untracked files (requires force flag). - |
|
|
23
|
+
| **Committing & History** | Create commits, inspect history, and view changes over time. | - `git_commit`: Create new commits with conventional messages.<br/>- `git_log`: View commit history with filtering options.<br/>- `git_diff`: Show changes between commits, branches, or the working tree.<br/>- `git_show`: Inspect Git objects like commits and tags. - |
|
|
24
|
+
| **Branching & Merging** | Manage branches, merge changes, and rebase commits. | - `git_branch`: List, create, delete, and rename branches.<br/>- `git_checkout`: Switch between branches or commits.<br/>- `git_merge`: Merge branches together.<br/>- `git_rebase`: Re-apply commits on top of another base.<br/>- `git_cherry_pick`: Apply specific commits from other branches. - |
|
|
25
|
+
| **Remote Operations** | Interact with remote repositories. | - `git_remote`: Manage remote repository connections.<br/>- `git_fetch`: Download objects and refs from a remote.<br/>- `git_pull`: Fetch and integrate with another repository.<br/>- `git_push`: Update remote refs with local changes. - |
|
|
26
|
+
| **Advanced Workflows** | Support for more complex Git workflows and repository management. | - `git_tag`: Create, list, or delete tags.<br/>- `git_stash`: Temporarily store modified files.<br/>- `git_worktree`: Manage multiple working trees attached to a single repository.<br/>- `git_set_working_dir`: Set a persistent working directory for a session.<br/>- `git_wrapup_instructions`: Get a standard workflow for finalizing changes. - |
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
---
|
|
23
29
|
|
|
24
|
-
##
|
|
30
|
+
## Table of Contents
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
| [Overview](#overview) | [Features](#features) | [Installation](#installation) |
|
|
33
|
+
| :------------------------------ | :-------------------------------------- | :---------------------------- | ------------------- |
|
|
34
|
+
| [Configuration](#configuration) | [Project Structure](#project-structure) |
|
|
35
|
+
| [Tools](#tools) | [Resources](#resources) | [Development](#development) | [License](#license) |
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
## Overview
|
|
38
|
+
|
|
39
|
+
The Git MCP Server acts as a bridge, allowing applications (MCP Clients) that understand the Model Context Protocol (MCP) – like advanced AI coding assistants (LLMs), IDE extensions, or custom research tools – to interact directly and safely with local Git repositories.
|
|
29
40
|
|
|
30
|
-
Instead of complex scripting or manual
|
|
41
|
+
Instead of complex scripting or manual command-line interaction, your tools can leverage this server to:
|
|
31
42
|
|
|
32
43
|
- **Automate Git workflows**: Clone repositories, create branches, stage changes, commit work, push updates, and manage tags programmatically.
|
|
33
44
|
- **Gain repository insights**: Check status, view logs, diff changes, and inspect Git objects without leaving the host application.
|
|
34
|
-
- **Integrate Git into AI-driven development**: Enable LLMs to manage version control as part of their coding or refactoring tasks.
|
|
45
|
+
- **Integrate Git into AI-driven development**: Enable LLMs to manage version control as part of their coding or refactoring tasks, ensuring code integrity and history.
|
|
46
|
+
- **Support CI/CD and DevOps automation**: Build custom scripts and tools that orchestrate complex Git operations for automated builds, testing, and deployments.
|
|
35
47
|
|
|
36
48
|
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.
|
|
37
49
|
|
|
50
|
+
> **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.
|
|
51
|
+
|
|
38
52
|
## Features
|
|
39
53
|
|
|
40
|
-
### Core Utilities
|
|
54
|
+
### Core Utilities
|
|
41
55
|
|
|
42
56
|
Leverages the robust utilities provided by the `mcp-ts-template`:
|
|
43
57
|
|
|
44
|
-
- **Logging**: Structured, configurable logging (file rotation,
|
|
58
|
+
- **Logging**: Structured, configurable logging (file rotation, stdout JSON, MCP notifications) with sensitive data redaction.
|
|
45
59
|
- **Error Handling**: Centralized error processing, standardized error types (`McpError`), and automatic logging.
|
|
46
|
-
- **Configuration**: Environment variable loading (`dotenv`).
|
|
60
|
+
- **Configuration**: Environment variable loading (`dotenv`) with comprehensive validation.
|
|
47
61
|
- **Input Validation/Sanitization**: Uses `zod` for schema validation and custom sanitization logic (crucial for paths).
|
|
48
|
-
- **Request Context**: Tracking and correlation of operations via unique request IDs
|
|
62
|
+
- **Request Context**: Tracking and correlation of operations via unique request IDs using `AsyncLocalStorage`.
|
|
49
63
|
- **Type Safety**: Strong typing enforced by TypeScript and Zod schemas.
|
|
50
|
-
- **HTTP Transport
|
|
64
|
+
- **HTTP Transport**: High-performance HTTP server using **Hono**, featuring session management with garbage collection, CORS, and IP-based rate limiting.
|
|
65
|
+
- **Deployment**: Multi-stage `Dockerfile` for creating small, secure production images with native dependency support.
|
|
51
66
|
|
|
52
|
-
### Git
|
|
67
|
+
### Git Integration
|
|
53
68
|
|
|
54
69
|
- **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.
|
|
55
70
|
- **Comprehensive Command Coverage**: Exposes a wide range of Git commands as MCP tools (see [Tools](#tools) section).
|
|
@@ -62,39 +77,63 @@ Leverages the robust utilities provided by the `mcp-ts-template`:
|
|
|
62
77
|
|
|
63
78
|
### Prerequisites
|
|
64
79
|
|
|
65
|
-
- [Node.js (>=
|
|
80
|
+
- [Node.js (>=20.0.0)](https://nodejs.org/)
|
|
66
81
|
- [npm](https://www.npmjs.com/) (comes with Node.js)
|
|
67
82
|
- [Git](https://git-scm.com/) installed and accessible in the system PATH.
|
|
68
83
|
|
|
69
|
-
###
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
### MCP Client Settings
|
|
85
|
+
|
|
86
|
+
Add the following to your MCP client's configuration file (e.g., `cline_mcp_settings.json`). This configuration uses `npx` to run the server, which will automatically install the package if not already present:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"mcpServers": {
|
|
91
|
+
"git-mcp-server": {
|
|
92
|
+
"command": "npx",
|
|
93
|
+
"args": ["@cyanheads/git-mcp-server"],
|
|
94
|
+
"env": {
|
|
95
|
+
"MCP_LOG_LEVEL": "info",
|
|
96
|
+
"GIT_SIGN_COMMITS": "false"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### If running manually (not via MCP client for development or testing)
|
|
104
|
+
|
|
105
|
+
#### Install via npm
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm install @cyanheads/git-mcp-server
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Alternatively Install from Source (recommended for development)
|
|
112
|
+
|
|
113
|
+
1. Clone the repository:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
git clone https://github.com/cyanheads/git-mcp-server.git
|
|
117
|
+
cd git-mcp-server
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
2. Install dependencies:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm install
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
3. Build the project:
|
|
127
|
+
```bash
|
|
128
|
+
npm run build
|
|
129
|
+
# or npm run rebuild
|
|
130
|
+
```
|
|
92
131
|
|
|
93
132
|
## Configuration
|
|
94
133
|
|
|
95
134
|
### Environment Variables
|
|
96
135
|
|
|
97
|
-
Configure the server using environment variables.
|
|
136
|
+
Configure the server using environment variables. These environmental variables are set within your MCP client config/settings (e.g. `claude_desktop_config.json` for Claude Desktop)
|
|
98
137
|
|
|
99
138
|
| Variable | Description | Default |
|
|
100
139
|
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
|
|
@@ -106,31 +145,6 @@ Configure the server using environment variables. Create a `.env` file in the pr
|
|
|
106
145
|
| `GIT_SIGN_COMMITS` | Set to `"true"` to enable signing attempts for commits made by the `git_commit` tool. Requires server-side Git/key setup (see below). | `false` |
|
|
107
146
|
| `MCP_AUTH_SECRET_KEY` | Secret key for signing/verifying authentication tokens (required if auth is enabled in the future). | `''` |
|
|
108
147
|
|
|
109
|
-
### MCP Client Settings
|
|
110
|
-
|
|
111
|
-
Add to your MCP client settings (e.g., `cline_mcp_settings.json`):
|
|
112
|
-
|
|
113
|
-
```json
|
|
114
|
-
{
|
|
115
|
-
"mcpServers": {
|
|
116
|
-
"git-mcp-server": {
|
|
117
|
-
// Use a descriptive name
|
|
118
|
-
"command": "node", // Use node to run the script
|
|
119
|
-
"args": ["/path/to/your/git-mcp-server/dist/index.js"], // Absolute path to the built entry point
|
|
120
|
-
"env": {
|
|
121
|
-
// "MCP_TRANSPORT_TYPE": "http", // Optional: if using http
|
|
122
|
-
// "MCP_HTTP_PORT": "3010", // Optional: if using http and non-default port
|
|
123
|
-
// "GIT_SIGN_COMMITS": "true" // Optional: Enable commit signing attempts if server is configured
|
|
124
|
-
},
|
|
125
|
-
"disabled": false,
|
|
126
|
-
"autoApprove": [] // Configure auto-approval rules if desired
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
**Note**: You can see [mcp.json](mcp.json) for an example MCP client configuration file that includes the Git MCP Server.\*
|
|
133
|
-
|
|
134
148
|
## Project Structure
|
|
135
149
|
|
|
136
150
|
The codebase follows a modular structure within the `src/` directory:
|
|
@@ -187,16 +201,14 @@ _Note: The `path` parameter for most tools defaults to the session's working dir
|
|
|
187
201
|
|
|
188
202
|
## Resources
|
|
189
203
|
|
|
190
|
-
**MCP Resources are not implemented in this version (v2.
|
|
204
|
+
**MCP Resources are not implemented in this version (v2.1.2).**
|
|
191
205
|
|
|
192
|
-
This version focuses on the refactored Git tools implementation based on the latest `mcp-ts-template` and MCP SDK v1.
|
|
206
|
+
This version focuses on the refactored Git tools implementation based on the latest `mcp-ts-template` and MCP SDK v1.13.0. Resource capabilities, previously available, have been temporarily removed during this major update.
|
|
193
207
|
|
|
194
208
|
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)**.
|
|
195
209
|
|
|
196
210
|
Future development may reintroduce resource capabilities in a subsequent release.
|
|
197
211
|
|
|
198
|
-
> **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).
|
|
199
|
-
|
|
200
212
|
## Development
|
|
201
213
|
|
|
202
214
|
### Build and Test
|
|
@@ -211,15 +223,18 @@ npm run inspector
|
|
|
211
223
|
# Test the server locally using the MCP inspector tool (http transport)
|
|
212
224
|
npm run inspector:http
|
|
213
225
|
|
|
214
|
-
# Clean build artifacts
|
|
226
|
+
# Clean build artifacts
|
|
215
227
|
npm run clean
|
|
216
228
|
|
|
217
|
-
# Generate a file tree representation for documentation
|
|
229
|
+
# Generate a file tree representation for documentation
|
|
218
230
|
npm run tree
|
|
219
231
|
|
|
220
232
|
# Clean build artifacts and then rebuild the project
|
|
221
233
|
npm run rebuild
|
|
222
234
|
|
|
235
|
+
# Format code with Prettier
|
|
236
|
+
npm run format
|
|
237
|
+
|
|
223
238
|
# Start the server using stdio (default)
|
|
224
239
|
npm start
|
|
225
240
|
# Or explicitly:
|
package/dist/config/index.js
CHANGED
|
@@ -7,12 +7,12 @@ dotenv.config(); // Load environment variables from .env file
|
|
|
7
7
|
// Determine the directory name of the current module
|
|
8
8
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
// Construct the path to package.json relative to the current file
|
|
10
|
-
const pkgPath = join(__dirname,
|
|
10
|
+
const pkgPath = join(__dirname, "../../package.json");
|
|
11
11
|
// Default package information in case package.json is unreadable
|
|
12
|
-
let pkg = { name:
|
|
12
|
+
let pkg = { name: "obsidian-mcp-server", version: "0.0.0" };
|
|
13
13
|
try {
|
|
14
14
|
// Read and parse package.json to get server name and version
|
|
15
|
-
pkg = JSON.parse(readFileSync(pkgPath,
|
|
15
|
+
pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
16
16
|
}
|
|
17
17
|
catch (error) {
|
|
18
18
|
// Silently use default pkg info if reading fails. Error will be logged later if needed.
|
|
@@ -37,9 +37,9 @@ export const config = {
|
|
|
37
37
|
/** Host for the HTTP transport. Defaults to '127.0.0.1'. */
|
|
38
38
|
mcpHttpHost: process.env.MCP_HTTP_HOST || "127.0.0.1",
|
|
39
39
|
/** Allowed origins for HTTP transport (comma-separated). */
|
|
40
|
-
mcpAllowedOrigins: process.env.MCP_ALLOWED_ORIGINS?.split(
|
|
40
|
+
mcpAllowedOrigins: process.env.MCP_ALLOWED_ORIGINS?.split(",") || [],
|
|
41
41
|
/** Flag to enable GPG signing for commits made by the git_commit tool. Requires server-side GPG setup. */
|
|
42
|
-
gitSignCommits: process.env.GIT_SIGN_COMMITS ===
|
|
42
|
+
gitSignCommits: process.env.GIT_SIGN_COMMITS === "true",
|
|
43
43
|
/** Security-related configurations. */
|
|
44
44
|
security: {
|
|
45
45
|
// Placeholder for security settings
|
|
@@ -47,8 +47,8 @@ export const config = {
|
|
|
47
47
|
/** Indicates if authentication is required for server operations. */
|
|
48
48
|
authRequired: false,
|
|
49
49
|
/** Secret key for signing/verifying authentication tokens (required if authRequired is true). */
|
|
50
|
-
mcpAuthSecretKey: process.env.MCP_AUTH_SECRET_KEY ||
|
|
51
|
-
}
|
|
50
|
+
mcpAuthSecretKey: process.env.MCP_AUTH_SECRET_KEY || "", // Default to empty string, validation should happen elsewhere
|
|
51
|
+
},
|
|
52
52
|
// Note: mcpClient configuration is now loaded separately from mcp-config.json
|
|
53
53
|
};
|
|
54
54
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { McpServer } from
|
|
3
|
-
import http from
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import http from "http"; // Import http module
|
|
4
4
|
import { config, environment, logLevel } from "./config/index.js"; // Import logLevel from config
|
|
5
5
|
import { initializeAndStartServer } from "./mcp-server/server.js";
|
|
6
6
|
// Import utils from barrel
|
|
7
|
-
import { logger, requestContextService } from
|
|
7
|
+
import { logger, requestContextService } from "./utils/index.js"; // Import McpLogLevel type
|
|
8
8
|
/**
|
|
9
9
|
* The main MCP server instance (used for stdio transport).
|
|
10
10
|
* @type {McpServer | undefined}
|
|
@@ -22,16 +22,16 @@ let httpServerInstance;
|
|
|
22
22
|
* @param signal - The signal or event name that triggered the shutdown (e.g., "SIGTERM", "uncaughtException").
|
|
23
23
|
*/
|
|
24
24
|
const shutdown = async (signal) => {
|
|
25
|
-
const transportType = (process.env.MCP_TRANSPORT_TYPE ||
|
|
25
|
+
const transportType = (process.env.MCP_TRANSPORT_TYPE || "stdio").toLowerCase();
|
|
26
26
|
const shutdownContext = {
|
|
27
|
-
operation:
|
|
27
|
+
operation: "Shutdown",
|
|
28
28
|
signal,
|
|
29
29
|
transport: transportType,
|
|
30
30
|
};
|
|
31
31
|
logger.info(`Received ${signal}. Starting graceful shutdown...`, shutdownContext);
|
|
32
32
|
try {
|
|
33
33
|
let closePromise = Promise.resolve();
|
|
34
|
-
if (transportType ===
|
|
34
|
+
if (transportType === "stdio") {
|
|
35
35
|
// Close the main MCP server instance for stdio
|
|
36
36
|
if (mcpServerInstance) {
|
|
37
37
|
logger.info("Closing main MCP server (stdio)...", shutdownContext);
|
|
@@ -41,14 +41,17 @@ const shutdown = async (signal) => {
|
|
|
41
41
|
logger.warning("Stdio MCP server instance not found during shutdown.", shutdownContext);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
else if (transportType ===
|
|
44
|
+
else if (transportType === "http") {
|
|
45
45
|
// Close the main HTTP server listener for http
|
|
46
46
|
if (httpServerInstance) {
|
|
47
47
|
logger.info("Closing main HTTP server listener...", shutdownContext);
|
|
48
48
|
closePromise = new Promise((resolve, reject) => {
|
|
49
49
|
httpServerInstance.close((err) => {
|
|
50
50
|
if (err) {
|
|
51
|
-
logger.error("Error closing HTTP server listener", {
|
|
51
|
+
logger.error("Error closing HTTP server listener", {
|
|
52
|
+
...shutdownContext,
|
|
53
|
+
error: err.message,
|
|
54
|
+
});
|
|
52
55
|
reject(err);
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
@@ -74,7 +77,7 @@ const shutdown = async (signal) => {
|
|
|
74
77
|
logger.error("Critical error during shutdown", {
|
|
75
78
|
...shutdownContext,
|
|
76
79
|
error: error instanceof Error ? error.message : String(error),
|
|
77
|
-
stack: error instanceof Error ? error.stack : undefined
|
|
80
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
78
81
|
});
|
|
79
82
|
process.exit(1); // Exit with error code if shutdown fails
|
|
80
83
|
}
|
|
@@ -87,8 +90,17 @@ const shutdown = async (signal) => {
|
|
|
87
90
|
const start = async () => {
|
|
88
91
|
// --- Initialize Logger FIRST ---
|
|
89
92
|
// Define valid MCP log levels based on the logger's type definition
|
|
90
|
-
const validMcpLogLevels = [
|
|
91
|
-
|
|
93
|
+
const validMcpLogLevels = [
|
|
94
|
+
"debug",
|
|
95
|
+
"info",
|
|
96
|
+
"notice",
|
|
97
|
+
"warning",
|
|
98
|
+
"error",
|
|
99
|
+
"crit",
|
|
100
|
+
"alert",
|
|
101
|
+
"emerg",
|
|
102
|
+
];
|
|
103
|
+
let validatedMcpLogLevel = "info"; // Default to 'info'
|
|
92
104
|
if (validMcpLogLevels.includes(logLevel)) {
|
|
93
105
|
validatedMcpLogLevel = logLevel;
|
|
94
106
|
}
|
|
@@ -100,12 +112,12 @@ const start = async () => {
|
|
|
100
112
|
logger.initialize(validatedMcpLogLevel);
|
|
101
113
|
// Now it's safe to use the logger.
|
|
102
114
|
// --- Start Application ---
|
|
103
|
-
const transportType = (process.env.MCP_TRANSPORT_TYPE ||
|
|
115
|
+
const transportType = (process.env.MCP_TRANSPORT_TYPE || "stdio").toLowerCase();
|
|
104
116
|
const startupContext = requestContextService.createRequestContext({
|
|
105
117
|
operation: `ServerStartup_${transportType}`, // Include transport in operation name
|
|
106
118
|
appName: config.mcpServerName,
|
|
107
119
|
appVersion: config.mcpServerVersion,
|
|
108
|
-
environment: environment
|
|
120
|
+
environment: environment,
|
|
109
121
|
});
|
|
110
122
|
logger.info(`Starting ${config.mcpServerName} v${config.mcpServerVersion} (Transport: ${transportType})...`, startupContext);
|
|
111
123
|
try {
|
|
@@ -114,11 +126,13 @@ const start = async () => {
|
|
|
114
126
|
// Start the server transport. This returns the McpServer instance for stdio
|
|
115
127
|
// or the http.Server instance for http.
|
|
116
128
|
const serverOrHttpInstance = await initializeAndStartServer();
|
|
117
|
-
if (transportType ===
|
|
129
|
+
if (transportType === "stdio" &&
|
|
130
|
+
serverOrHttpInstance instanceof McpServer) {
|
|
118
131
|
mcpServerInstance = serverOrHttpInstance; // Store McpServer for stdio shutdown
|
|
119
132
|
logger.debug("Stored McpServer instance for stdio transport.", startupContext);
|
|
120
133
|
}
|
|
121
|
-
else if (transportType ===
|
|
134
|
+
else if (transportType === "http" &&
|
|
135
|
+
serverOrHttpInstance instanceof http.Server) {
|
|
122
136
|
httpServerInstance = serverOrHttpInstance; // Store http.Server for http shutdown
|
|
123
137
|
logger.debug("Stored http.Server instance for http transport.", startupContext);
|
|
124
138
|
}
|
|
@@ -126,7 +140,7 @@ const start = async () => {
|
|
|
126
140
|
// This case should ideally not happen if initializeAndStartServer works correctly
|
|
127
141
|
logger.warning("initializeAndStartServer did not return the expected instance type.", {
|
|
128
142
|
...startupContext,
|
|
129
|
-
instanceType: typeof serverOrHttpInstance
|
|
143
|
+
instanceType: typeof serverOrHttpInstance,
|
|
130
144
|
});
|
|
131
145
|
}
|
|
132
146
|
// If initializeAndStartServer failed internally, it would have thrown an error,
|
|
@@ -143,9 +157,9 @@ const start = async () => {
|
|
|
143
157
|
process.on("uncaughtException", async (error) => {
|
|
144
158
|
const errorContext = {
|
|
145
159
|
...startupContext, // Include base context for correlation
|
|
146
|
-
event:
|
|
160
|
+
event: "uncaughtException",
|
|
147
161
|
error: error instanceof Error ? error.message : String(error),
|
|
148
|
-
stack: error instanceof Error ? error.stack : undefined
|
|
162
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
149
163
|
};
|
|
150
164
|
logger.error("Uncaught exception detected. Initiating shutdown...", errorContext);
|
|
151
165
|
// Attempt graceful shutdown; shutdown() handles its own errors.
|
|
@@ -159,9 +173,9 @@ const start = async () => {
|
|
|
159
173
|
process.on("unhandledRejection", async (reason) => {
|
|
160
174
|
const rejectionContext = {
|
|
161
175
|
...startupContext, // Include base context for correlation
|
|
162
|
-
event:
|
|
176
|
+
event: "unhandledRejection",
|
|
163
177
|
reason: reason instanceof Error ? reason.message : String(reason),
|
|
164
|
-
stack: reason instanceof Error ? reason.stack : undefined
|
|
178
|
+
stack: reason instanceof Error ? reason.stack : undefined,
|
|
165
179
|
};
|
|
166
180
|
logger.error("Unhandled promise rejection detected. Initiating shutdown...", rejectionContext);
|
|
167
181
|
// Attempt graceful shutdown; shutdown() handles its own errors.
|
|
@@ -174,7 +188,7 @@ const start = async () => {
|
|
|
174
188
|
// Log the final failure context, including error details, before exiting
|
|
175
189
|
logger.error("Critical error during startup, exiting.", {
|
|
176
190
|
...startupContext,
|
|
177
|
-
finalErrorContext:
|
|
191
|
+
finalErrorContext: "Startup Failure",
|
|
178
192
|
error: error instanceof Error ? error.message : String(error),
|
|
179
193
|
stack: error instanceof Error ? error.stack : undefined,
|
|
180
194
|
});
|