@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 +201 -0
- package/README.md +383 -0
- package/build/index.js +54 -0
- package/build/resources/descriptors.js +77 -0
- package/build/resources/diff.js +241 -0
- package/build/resources/file.js +222 -0
- package/build/resources/history.js +242 -0
- package/build/resources/index.js +99 -0
- package/build/resources/repository.js +286 -0
- package/build/server.js +120 -0
- package/build/services/error-service.js +73 -0
- package/build/services/git-service.js +965 -0
- package/build/tools/advanced.js +526 -0
- package/build/tools/branch.js +296 -0
- package/build/tools/index.js +29 -0
- package/build/tools/remote.js +279 -0
- package/build/tools/repository.js +170 -0
- package/build/tools/workdir.js +445 -0
- package/build/types/git.js +7 -0
- package/build/utils/global-settings.js +64 -0
- package/build/utils/validation.js +108 -0
- package/package.json +39 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Utilities
|
|
3
|
+
* ===================
|
|
4
|
+
*
|
|
5
|
+
* Utilities for validating input parameters using Zod.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { getGlobalSettings } from './global-settings.js';
|
|
10
|
+
/**
|
|
11
|
+
* Common validation schemas used throughout the server
|
|
12
|
+
*/
|
|
13
|
+
export const Schemas = {
|
|
14
|
+
/**
|
|
15
|
+
* Repository path validation
|
|
16
|
+
*/
|
|
17
|
+
repoPath: z.string()
|
|
18
|
+
.min(1, "Repository path is required")
|
|
19
|
+
.transform(val => path.normalize(val)),
|
|
20
|
+
/**
|
|
21
|
+
* Commit validation
|
|
22
|
+
*/
|
|
23
|
+
commit: {
|
|
24
|
+
hash: z.string().regex(/^[0-9a-f]{4,40}$/, "Invalid commit hash format"),
|
|
25
|
+
message: z.string().min(1, "Commit message is required"),
|
|
26
|
+
author: z.object({
|
|
27
|
+
name: z.string().optional(),
|
|
28
|
+
email: z.string().email("Invalid email format").optional()
|
|
29
|
+
}).optional(),
|
|
30
|
+
date: z.date().optional(),
|
|
31
|
+
allowEmpty: z.boolean().optional().default(false),
|
|
32
|
+
amend: z.boolean().optional().default(false)
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Branch validation
|
|
36
|
+
*/
|
|
37
|
+
branch: {
|
|
38
|
+
name: z.string().min(1, "Branch name is required")
|
|
39
|
+
.regex(/^[^\s]+$/, "Branch name cannot contain spaces"),
|
|
40
|
+
checkout: z.boolean().optional().default(false),
|
|
41
|
+
startPoint: z.string().optional()
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Remote validation
|
|
45
|
+
*/
|
|
46
|
+
remote: {
|
|
47
|
+
name: z.string().min(1, "Remote name is required"),
|
|
48
|
+
url: z.string().url("Invalid URL format"),
|
|
49
|
+
branch: z.string().optional()
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* File validation
|
|
53
|
+
*/
|
|
54
|
+
file: {
|
|
55
|
+
path: z.string().min(1, "File path is required"),
|
|
56
|
+
ref: z.string().optional().default('HEAD')
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Diff validation
|
|
60
|
+
*/
|
|
61
|
+
diff: {
|
|
62
|
+
fromRef: z.string().min(1, "Source reference is required"),
|
|
63
|
+
toRef: z.string().optional().default('HEAD'),
|
|
64
|
+
path: z.string().optional()
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Tag validation
|
|
68
|
+
*/
|
|
69
|
+
tag: {
|
|
70
|
+
name: z.string().min(1, "Tag name is required"),
|
|
71
|
+
message: z.string().optional(),
|
|
72
|
+
ref: z.string().optional()
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Path validation helper functions
|
|
77
|
+
*/
|
|
78
|
+
export const PathValidation = {
|
|
79
|
+
/**
|
|
80
|
+
* Normalizes a path to ensure consistent format
|
|
81
|
+
* If path is "." and a global working directory is set, uses the global directory instead
|
|
82
|
+
*/
|
|
83
|
+
normalizePath(inputPath) {
|
|
84
|
+
// Check if this is a relative path (like ".") and we have a global working dir set
|
|
85
|
+
if (inputPath === '.') {
|
|
86
|
+
const globalWorkingDir = getGlobalSettings().globalWorkingDir;
|
|
87
|
+
if (globalWorkingDir) {
|
|
88
|
+
return path.normalize(globalWorkingDir);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return path.normalize(inputPath);
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Validates if a path is within the allowed directory
|
|
95
|
+
*/
|
|
96
|
+
isWithinDirectory(targetPath, basePath) {
|
|
97
|
+
const normalizedTarget = path.normalize(targetPath);
|
|
98
|
+
const normalizedBase = path.normalize(basePath);
|
|
99
|
+
return normalizedTarget.startsWith(normalizedBase) &&
|
|
100
|
+
normalizedTarget.length > normalizedBase.length;
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* Joins and normalizes path components
|
|
104
|
+
*/
|
|
105
|
+
joinPaths(...pathComponents) {
|
|
106
|
+
return path.normalize(path.join(...pathComponents));
|
|
107
|
+
}
|
|
108
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cyanheads/git-mcp-server",
|
|
3
|
+
"version": "1.2.4",
|
|
4
|
+
"description": "A Model Context Protocol server for Git integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Casey Hand @cyanheads",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/cyanheads/git-mcp-server"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"git-mcp-server": "./build/index.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"build"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"",
|
|
20
|
+
"prepare": "npm run build",
|
|
21
|
+
"watch": "tsc --watch",
|
|
22
|
+
"inspector": "npx @modelcontextprotocol/inspector build/index.js",
|
|
23
|
+
"clean": "ts-node scripts/clean.ts",
|
|
24
|
+
"tree": "ts-node scripts/tree.ts",
|
|
25
|
+
"rebuild": "npm run clean && npm run build"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "1.8.0",
|
|
32
|
+
"dotenv": "^16.4.7",
|
|
33
|
+
"zod": "^3.24.2",
|
|
34
|
+
"@types/node": "^22.13.17",
|
|
35
|
+
"ts-node": "^10.9.2",
|
|
36
|
+
"typescript": "^5.8.2",
|
|
37
|
+
"simple-git": "^3.27.0"
|
|
38
|
+
}
|
|
39
|
+
}
|