@baitong-dev/mcp-helpers 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export declare const MCP_HOME_DIR: string;
package/dist/config.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bun
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.MCP_HOME_DIR = void 0;
8
+ const path_1 = __importDefault(require("path"));
9
+ const os_1 = __importDefault(require("os"));
10
+ exports.MCP_HOME_DIR = process.env.MCP_HOME_DIR || path_1.default.join(os_1.default.homedir(), '\.baitong');
package/dist/file.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Check if a path is a directory.
4
+ * @param path The path to check
5
+ * @returns Whether the path is a directory
6
+ */
7
+ export declare function isDir(path: string): Promise<boolean>;
8
+ /**
9
+ * 检查一个目录是否是另一个目录的子目录
10
+ * @param parent - 父目录路径
11
+ * @param child - 要检查的子目录路径
12
+ * @param options - 配置选项
13
+ * @param options.includeSelf - 是否将自身视为子目录
14
+ * @returns - 同步返回 boolean,异步返回 Promise
15
+ */
16
+ export declare function isSubdirectory(parent: string, child: string, { includeSelf }: {
17
+ includeSelf: boolean;
18
+ }): boolean;
package/dist/file.js ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bun
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isDir = isDir;
8
+ exports.isSubdirectory = isSubdirectory;
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * Check if a path is a directory.
12
+ * @param path The path to check
13
+ * @returns Whether the path is a directory
14
+ */
15
+ async function isDir(path) {
16
+ try {
17
+ const stat = await Bun.file(path).stat();
18
+ return stat.isDirectory();
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ /**
25
+ * 检查一个目录是否是另一个目录的子目录
26
+ * @param parent - 父目录路径
27
+ * @param child - 要检查的子目录路径
28
+ * @param options - 配置选项
29
+ * @param options.includeSelf - 是否将自身视为子目录
30
+ * @returns - 同步返回 boolean,异步返回 Promise
31
+ */
32
+ function isSubdirectory(parent, child, { includeSelf = false }) {
33
+ const parentPath = path_1.default.resolve(parent);
34
+ const childPath = path_1.default.isAbsolute(child) ? child : path_1.default.join(parentPath, child);
35
+ const relative = path_1.default.relative(parentPath, childPath);
36
+ if (includeSelf && childPath === parentPath) {
37
+ return true;
38
+ }
39
+ return (relative && !relative.startsWith('..') && !path_1.default.isAbsolute(relative)) || false;
40
+ }
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bun
2
+ export * from './config';
3
+ export * from './file';
4
+ export * from './process';
5
+ export * from './util';
6
+ export * from './wasm';
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bun
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./file"), exports);
20
+ __exportStar(require("./process"), exports);
21
+ __exportStar(require("./util"), exports);
22
+ __exportStar(require("./wasm"), exports);
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * 将 Windows 文件路径转换为 Git Bash 路径格式
4
+ * @param path - Windows 格式的文件路径 (如 "C:\\Users")
5
+ * @returns Git Bash 格式的文件路径 (如 "/c/Users")
6
+ */
7
+ export declare function windowsToGitBashPath(path: string): string;
8
+ export declare function gitBashToWindowsPath(path: string): string;
9
+ /**
10
+ * Find Git Bash executable on Windows
11
+ * @param customPath - Optional custom path from config
12
+ * @returns Full path to bash.exe or null if not found
13
+ */
14
+ export declare function findGitBash(customPath?: string | null): string | null;
15
+ /**
16
+ * Check if a bundled binary exists
17
+ * @param name Binary Name
18
+ * @returns Whether the binary exists
19
+ */
20
+ export declare function isBinaryExists(name: string): boolean;
21
+ /**
22
+ * Get full path to a bundled binary
23
+ * @param name Binary Name
24
+ * @returns Full path to the binary
25
+ */
26
+ export declare function getBundledBinaryPath(name?: string): string;
27
+ export declare function getBinaryEnvs(): {
28
+ PATH: string;
29
+ NODE: string;
30
+ npm_config_globalconfig: string;
31
+ npm_config_global_prefix: string;
32
+ npm_config_prefix: string;
33
+ npm_node_execpath: string;
34
+ };
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env bun
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.windowsToGitBashPath = windowsToGitBashPath;
8
+ exports.gitBashToWindowsPath = gitBashToWindowsPath;
9
+ exports.findGitBash = findGitBash;
10
+ exports.isBinaryExists = isBinaryExists;
11
+ exports.getBundledBinaryPath = getBundledBinaryPath;
12
+ exports.getBinaryEnvs = getBinaryEnvs;
13
+ const path_1 = __importDefault(require("path"));
14
+ const config_1 = require("./config");
15
+ const fs_1 = __importDefault(require("fs"));
16
+ /**
17
+ * 将 Windows 文件路径转换为 Git Bash 路径格式
18
+ * @param path - Windows 格式的文件路径 (如 "C:\\Users")
19
+ * @returns Git Bash 格式的文件路径 (如 "/c/Users")
20
+ */
21
+ function windowsToGitBashPath(path) {
22
+ // 非 Windows 平台直接返回原路径
23
+ if (process.platform !== 'win32')
24
+ return path;
25
+ if (!path)
26
+ return '';
27
+ // 1. 转换驱动器号 (C: -> /c)
28
+ let bashPath = path.replace(/^([A-Za-z]):/, (_, drive) => {
29
+ return '/' + drive.toLowerCase();
30
+ });
31
+ // 2. 转换反斜杠为正斜杠
32
+ bashPath = bashPath.replace(/\\/g, '/');
33
+ // 3. 移除可能的结尾斜杠
34
+ // bashPath = bashPath.replace(/\/$/, '')
35
+ return bashPath;
36
+ }
37
+ function gitBashToWindowsPath(path) {
38
+ // 非 Git Bash 平台直接返回原路径
39
+ if (process.platform !== 'win32')
40
+ return path;
41
+ if (!path)
42
+ return '';
43
+ // 1. 转换驱动器号 (/c -> C:)
44
+ let windowsPath = path.replace(/^\/([a-z])\//, (_, drive) => `${drive.toUpperCase()}:\\`);
45
+ // 2. 转换正斜杠为反斜杠
46
+ windowsPath = windowsPath.replace(/\//g, '\\');
47
+ return windowsPath;
48
+ }
49
+ /**
50
+ * Validate Git Bash path on Windows
51
+ * @param customPath - Custom path to validate
52
+ * @returns Validated path or null if invalid
53
+ */
54
+ function validateGitBashPath(customPath) {
55
+ if (!customPath) {
56
+ return null;
57
+ }
58
+ const resolved = path_1.default.resolve(customPath);
59
+ if (!Bun.file(resolved).size) {
60
+ return null;
61
+ }
62
+ const isExe = resolved.toLowerCase().endsWith('bash.exe');
63
+ if (!isExe) {
64
+ return null;
65
+ }
66
+ return resolved;
67
+ }
68
+ /**
69
+ * Find Git Bash executable on Windows
70
+ * @param customPath - Optional custom path from config
71
+ * @returns Full path to bash.exe or null if not found
72
+ */
73
+ function findGitBash(customPath) {
74
+ // Git Bash is Windows-only
75
+ if (!(process.platform === 'win32')) {
76
+ return null;
77
+ }
78
+ // 1. Check custom path from config first
79
+ if (customPath) {
80
+ const validated = validateGitBashPath(customPath);
81
+ if (validated) {
82
+ return validated;
83
+ }
84
+ }
85
+ // 2. Check environment variable override
86
+ const envOverride = process.env.CLAUDE_CODE_GIT_BASH_PATH;
87
+ if (envOverride) {
88
+ const validated = validateGitBashPath(envOverride);
89
+ if (validated) {
90
+ return validated;
91
+ }
92
+ }
93
+ // 3. Find git.exe and derive bash.exe path
94
+ const gitPath = Bun.which('git');
95
+ if (gitPath) {
96
+ // Try multiple possible locations for bash.exe relative to git.exe
97
+ // Different Git installations have different directory structures
98
+ const possibleBashPaths = [
99
+ path_1.default.join(gitPath, '..', '..', 'bin', 'bash.exe'), // Standard Git: git.exe at Git/cmd/ -> navigate up 2 levels -> then bin/bash.exe
100
+ path_1.default.join(gitPath, '..', 'bash.exe'), // Portable Git: git.exe at Git/bin/ -> bash.exe in same directory
101
+ path_1.default.join(gitPath, '..', '..', 'usr', 'bin', 'bash.exe') // MSYS2 Git: git.exe at msys64/usr/bin/ -> navigate up 2 levels -> then usr/bin/bash.exe
102
+ ];
103
+ for (const bashPath of possibleBashPaths) {
104
+ const resolvedBashPath = path_1.default.resolve(bashPath);
105
+ if (Bun.file(resolvedBashPath).size) {
106
+ return resolvedBashPath;
107
+ }
108
+ }
109
+ }
110
+ // 4. Fallback: check common Git Bash paths directly
111
+ const commonBashPaths = [
112
+ path_1.default.join(process.env.ProgramFiles || 'C:\\Program Files', 'Git', 'bin', 'bash.exe'),
113
+ path_1.default.join(process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)', 'Git', 'bin', 'bash.exe'),
114
+ ...(process.env.LOCALAPPDATA
115
+ ? [path_1.default.join(process.env.LOCALAPPDATA, 'Programs', 'Git', 'bin', 'bash.exe')]
116
+ : [])
117
+ ];
118
+ for (const bashPath of commonBashPaths) {
119
+ if (Bun.file(bashPath).size) {
120
+ return bashPath;
121
+ }
122
+ }
123
+ return null;
124
+ }
125
+ /**
126
+ * Add .exe extension to binary name on Windows
127
+ * @param name Binary Name
128
+ * @returns Binary Name with .exe extension on Windows
129
+ */
130
+ function getBinaryName(name) {
131
+ if (process.platform == 'win32') {
132
+ if (['npm', 'npx'].includes(name)) {
133
+ return name;
134
+ }
135
+ return `${name}.exe`;
136
+ }
137
+ return name;
138
+ }
139
+ /**
140
+ * Check if a bundled binary exists
141
+ * @param name Binary Name
142
+ * @returns Whether the binary exists
143
+ */
144
+ function isBinaryExists(name) {
145
+ const cmd = getBundledBinaryPath(name);
146
+ return Bun.file(cmd).size > 0;
147
+ }
148
+ /**
149
+ * Get full path to a bundled binary
150
+ * @param name Binary Name
151
+ * @returns Full path to the binary
152
+ */
153
+ function getBundledBinaryPath(name) {
154
+ const binariesDir = path_1.default.join(config_1.MCP_HOME_DIR, 'bin');
155
+ if (!name) {
156
+ return binariesDir;
157
+ }
158
+ const binaryName = getBinaryName(name);
159
+ const binariesDirExists = fs_1.default.existsSync(binariesDir);
160
+ if (binariesDirExists) {
161
+ if (['git', 'bash', 'sh'].includes(name)) {
162
+ // Git binaries are in a subdirectory
163
+ return path_1.default.join(binariesDir, 'PortableGit/bin', binaryName);
164
+ }
165
+ if (['node', 'npm', 'npx'].includes(name)) {
166
+ // Node.js binaries are in a subdirectory
167
+ return path_1.default.join(binariesDir, 'node', binaryName);
168
+ }
169
+ if (['python', 'python3'].includes(name)) {
170
+ // Python binaries are in a subdirectory
171
+ return path_1.default.join(binariesDir, 'python', binaryName);
172
+ }
173
+ if (['pip', 'pip3'].includes(name)) {
174
+ // pip binaries are in a subdirectory
175
+ return path_1.default.join(binariesDir, 'python/Scripts', binaryName);
176
+ }
177
+ return path_1.default.join(binariesDir, binaryName);
178
+ }
179
+ return binaryName;
180
+ }
181
+ function getBinaryEnvs() {
182
+ const binariesDir = getBundledBinaryPath();
183
+ const envPaths = process.env?.path?.split(';') || [];
184
+ envPaths.unshift(binariesDir); // bun uv uvx
185
+ envPaths.unshift(path_1.default.join(binariesDir, 'node')); // node
186
+ envPaths.unshift(path_1.default.join(binariesDir, 'python')); // python
187
+ envPaths.unshift(path_1.default.join(binariesDir, 'python/Scripts')); // pip
188
+ const nodePath = getBundledBinaryPath('node');
189
+ const nodeDir = path_1.default.join(nodePath, '..');
190
+ return {
191
+ PATH: envPaths.join(';'),
192
+ NODE: nodePath,
193
+ npm_config_globalconfig: path_1.default.join(nodeDir, 'etc', 'npmrc'),
194
+ npm_config_global_prefix: nodeDir,
195
+ npm_config_prefix: nodeDir,
196
+ npm_node_execpath: nodePath
197
+ };
198
+ }
package/dist/util.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Lazily initialize a value.
4
+ * @param fn A function that returns the value to be lazily initialized
5
+ * @returns A function that, when called, either returns the cached value or initializes it
6
+ */
7
+ export declare function lazy<T>(fn: () => T): {
8
+ (): T;
9
+ reset(): void;
10
+ };
package/dist/util.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bun
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.lazy = lazy;
5
+ /**
6
+ * Lazily initialize a value.
7
+ * @param fn A function that returns the value to be lazily initialized
8
+ * @returns A function that, when called, either returns the cached value or initializes it
9
+ */
10
+ function lazy(fn) {
11
+ let value;
12
+ let loaded = false;
13
+ const result = () => {
14
+ if (loaded)
15
+ return value;
16
+ try {
17
+ value = fn();
18
+ loaded = true;
19
+ return value;
20
+ }
21
+ catch (e) {
22
+ // Don't mark as loaded if initialization failed
23
+ throw e;
24
+ }
25
+ };
26
+ result.reset = () => {
27
+ loaded = false;
28
+ value = undefined;
29
+ };
30
+ return result;
31
+ }
package/dist/wasm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const resolveWasm: (asset: string) => string;
package/dist/wasm.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveWasm = void 0;
4
+ const url_1 = require("url");
5
+ const resolveWasm = (asset) => {
6
+ if (asset.startsWith('file://'))
7
+ return (0, url_1.fileURLToPath)(asset);
8
+ if (asset.startsWith('/') || /^[a-z]:/i.test(asset))
9
+ return asset;
10
+ const url = new URL(asset, process.cwd());
11
+ return (0, url_1.fileURLToPath)(url);
12
+ };
13
+ exports.resolveWasm = resolveWasm;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@baitong-dev/mcp-helpers",
3
+ "version": "0.0.1",
4
+ "main": "./dist/index.js",
5
+ "files": [
6
+ "dist",
7
+ "README.md"
8
+ ],
9
+ "keywords": [
10
+ "mcp",
11
+ "helpers"
12
+ ],
13
+ "description": "mcp-helpers",
14
+ "dependencies": {
15
+ "@modelcontextprotocol/sdk": "^1.25.1"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.9.2"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "registry": "https://registry.npmjs.org"
23
+ },
24
+ "scripts": {
25
+ "tsc": "tsc ./src/index.ts --declaration --module commonjs --target es2021 --esModuleInterop --outDir ./dist"
26
+ }
27
+ }