@cyanheads/git-mcp-server 2.0.2 → 2.0.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/README.md +45 -85
- package/dist/config/index.js +16 -18
- package/dist/index.js +80 -30
- package/dist/mcp-server/server.js +247 -523
- package/dist/mcp-server/tools/gitAdd/logic.js +9 -6
- package/dist/mcp-server/tools/gitAdd/registration.js +7 -4
- package/dist/mcp-server/tools/gitBranch/logic.js +23 -12
- package/dist/mcp-server/tools/gitBranch/registration.js +8 -5
- package/dist/mcp-server/tools/gitCheckout/logic.js +92 -44
- package/dist/mcp-server/tools/gitCheckout/registration.js +8 -5
- package/dist/mcp-server/tools/gitCherryPick/logic.js +10 -7
- package/dist/mcp-server/tools/gitCherryPick/registration.js +8 -5
- package/dist/mcp-server/tools/gitClean/logic.js +9 -6
- package/dist/mcp-server/tools/gitClean/registration.js +8 -5
- package/dist/mcp-server/tools/gitClearWorkingDir/logic.js +3 -2
- package/dist/mcp-server/tools/gitClearWorkingDir/registration.js +7 -4
- package/dist/mcp-server/tools/gitClone/logic.js +8 -5
- package/dist/mcp-server/tools/gitClone/registration.js +7 -4
- package/dist/mcp-server/tools/gitCommit/logic.js +98 -20
- package/dist/mcp-server/tools/gitCommit/registration.js +22 -15
- package/dist/mcp-server/tools/gitDiff/logic.js +9 -6
- package/dist/mcp-server/tools/gitDiff/registration.js +8 -5
- package/dist/mcp-server/tools/gitFetch/logic.js +10 -7
- package/dist/mcp-server/tools/gitFetch/registration.js +8 -5
- package/dist/mcp-server/tools/gitInit/index.js +2 -2
- package/dist/mcp-server/tools/gitInit/logic.js +9 -6
- package/dist/mcp-server/tools/gitInit/registration.js +66 -12
- package/dist/mcp-server/tools/gitLog/logic.js +53 -16
- package/dist/mcp-server/tools/gitLog/registration.js +8 -5
- package/dist/mcp-server/tools/gitMerge/logic.js +9 -6
- package/dist/mcp-server/tools/gitMerge/registration.js +8 -5
- package/dist/mcp-server/tools/gitPull/logic.js +11 -8
- package/dist/mcp-server/tools/gitPull/registration.js +7 -4
- package/dist/mcp-server/tools/gitPush/logic.js +12 -9
- package/dist/mcp-server/tools/gitPush/registration.js +7 -4
- package/dist/mcp-server/tools/gitRebase/logic.js +9 -6
- package/dist/mcp-server/tools/gitRebase/registration.js +8 -5
- package/dist/mcp-server/tools/gitRemote/logic.js +4 -5
- package/dist/mcp-server/tools/gitRemote/registration.js +2 -4
- package/dist/mcp-server/tools/gitReset/logic.js +5 -6
- package/dist/mcp-server/tools/gitReset/registration.js +2 -4
- package/dist/mcp-server/tools/gitSetWorkingDir/logic.js +5 -6
- package/dist/mcp-server/tools/gitSetWorkingDir/registration.js +22 -13
- package/dist/mcp-server/tools/gitShow/logic.js +5 -6
- package/dist/mcp-server/tools/gitShow/registration.js +3 -5
- package/dist/mcp-server/tools/gitStash/logic.js +5 -6
- package/dist/mcp-server/tools/gitStash/registration.js +3 -5
- package/dist/mcp-server/tools/gitStatus/logic.js +5 -6
- package/dist/mcp-server/tools/gitStatus/registration.js +2 -4
- package/dist/mcp-server/tools/gitTag/logic.js +3 -4
- package/dist/mcp-server/tools/gitTag/registration.js +2 -4
- package/dist/mcp-server/transports/authentication/authMiddleware.js +145 -0
- package/dist/mcp-server/transports/httpTransport.js +432 -0
- package/dist/mcp-server/transports/stdioTransport.js +87 -0
- package/dist/types-global/errors.js +2 -2
- package/dist/utils/index.js +12 -11
- package/dist/utils/{errorHandler.js → internal/errorHandler.js} +18 -8
- package/dist/utils/internal/index.js +3 -0
- package/dist/utils/internal/logger.js +254 -0
- package/dist/utils/{requestContext.js → internal/requestContext.js} +2 -3
- package/dist/utils/metrics/index.js +1 -0
- package/dist/utils/{tokenCounter.js → metrics/tokenCounter.js} +3 -3
- package/dist/utils/parsing/dateParser.js +62 -0
- package/dist/utils/parsing/index.js +2 -0
- package/dist/utils/{jsonParser.js → parsing/jsonParser.js} +3 -2
- package/dist/utils/{idGenerator.js → security/idGenerator.js} +4 -5
- package/dist/utils/security/index.js +3 -0
- package/dist/utils/{rateLimiter.js → security/rateLimiter.js} +7 -10
- package/dist/utils/{sanitization.js → security/sanitization.js} +4 -3
- package/package.json +12 -9
- package/dist/types-global/mcp.js +0 -59
- package/dist/types-global/tool.js +0 -1
- package/dist/utils/logger.js +0 -266
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
5
|
+
import { logger } from '../../../utils/index.js';
|
|
6
|
+
// Import utils from barrel (RequestContext from ../utils/internal/requestContext.js)
|
|
7
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
8
|
+
// Import utils from barrel (sanitization from ../utils/security/sanitization.js)
|
|
7
9
|
import path from 'path'; // Import path module
|
|
10
|
+
import { sanitization } from '../../../utils/index.js';
|
|
8
11
|
const execAsync = promisify(exec);
|
|
9
12
|
// Define the input schema for the git_merge tool
|
|
10
13
|
export const GitMergeInputSchema = z.object({
|
|
11
|
-
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the session
|
|
14
|
+
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
12
15
|
branch: z.string().min(1).describe('The name of the branch to merge into the current branch.'),
|
|
13
16
|
commitMessage: z.string().optional().describe('Commit message to use for the merge commit (if required, e.g., not fast-forward).'),
|
|
14
17
|
noFf: z.boolean().default(false).describe('Create a merge commit even when the merge resolves as a fast-forward (`--no-ff`).'),
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
2
|
+
import { logger } from '../../../utils/index.js';
|
|
3
|
+
// Import utils from barrel (ErrorHandler from ../utils/internal/errorHandler.js)
|
|
4
|
+
import { ErrorHandler } from '../../../utils/index.js';
|
|
5
|
+
// Import utils from barrel (requestContextService from ../utils/internal/requestContext.js)
|
|
6
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
7
|
+
import { requestContextService } from '../../../utils/index.js';
|
|
8
|
+
import { GitMergeInputSchema, gitMergeLogic } from './logic.js';
|
|
6
9
|
let _getWorkingDirectory;
|
|
7
10
|
let _getSessionId;
|
|
8
11
|
/**
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
5
|
+
import { logger } from '../../../utils/index.js';
|
|
6
|
+
// Import utils from barrel (RequestContext from ../utils/internal/requestContext.js)
|
|
7
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
8
|
+
// Import utils from barrel (sanitization from ../utils/security/sanitization.js)
|
|
9
|
+
import { sanitization } from '../../../utils/index.js';
|
|
7
10
|
const execAsync = promisify(exec);
|
|
8
11
|
// Define the input schema for the git_pull tool using Zod
|
|
9
12
|
export const GitPullInputSchema = z.object({
|
|
10
|
-
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the session
|
|
13
|
+
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
11
14
|
remote: z.string().optional().describe("The remote repository to pull from (e.g., 'origin'). Defaults to the tracked upstream or 'origin'."),
|
|
12
|
-
branch: z.string().optional().describe("The remote branch to pull. Defaults to the current branch's upstream."),
|
|
15
|
+
branch: z.string().optional().describe("The remote branch to pull (e.g., 'main'). Defaults to the current branch's upstream."),
|
|
13
16
|
rebase: z.boolean().optional().default(false).describe("Use 'git pull --rebase' instead of merge."),
|
|
14
17
|
ffOnly: z.boolean().optional().default(false).describe("Use '--ff-only' to only allow fast-forward merges."),
|
|
15
18
|
// Add other relevant git pull options as needed (e.g., --prune, --tags, --depth)
|
|
@@ -125,7 +128,7 @@ export async function pullGitChanges(input, context) {
|
|
|
125
128
|
throw new McpError(BaseErrorCode.NOT_FOUND, `Path is not a Git repository: ${targetPath}`, { context, operation, originalError: error });
|
|
126
129
|
}
|
|
127
130
|
if (errorMessage.includes('resolve host') || errorMessage.includes('Could not read from remote repository')) {
|
|
128
|
-
throw new McpError(BaseErrorCode.
|
|
131
|
+
throw new McpError(BaseErrorCode.SERVICE_UNAVAILABLE, `Failed to connect to remote repository. Error: ${errorMessage}`, { context, operation, originalError: error });
|
|
129
132
|
}
|
|
130
133
|
if (errorMessage.includes('merge conflict') || errorMessage.includes('fix conflicts')) {
|
|
131
134
|
// This might be caught here if execAsync throws due to non-zero exit code during conflict
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
// Import utils from barrel (ErrorHandler from ../utils/internal/errorHandler.js)
|
|
2
|
+
import { ErrorHandler } from '../../../utils/index.js';
|
|
3
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
4
|
+
import { logger } from '../../../utils/index.js';
|
|
5
|
+
// Import utils from barrel (requestContextService, RequestContext from ../utils/internal/requestContext.js)
|
|
6
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
7
|
+
import { requestContextService } from '../../../utils/index.js';
|
|
4
8
|
import { GitPullInputSchema, pullGitChanges } from './logic.js';
|
|
5
|
-
import { BaseErrorCode } from '../../../types-global/errors.js';
|
|
6
9
|
let _getWorkingDirectory;
|
|
7
10
|
let _getSessionId;
|
|
8
11
|
/**
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
5
|
+
import { logger } from '../../../utils/index.js';
|
|
6
|
+
// Import utils from barrel (RequestContext from ../utils/internal/requestContext.js)
|
|
7
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
8
|
+
// Import utils from barrel (sanitization from ../utils/security/sanitization.js)
|
|
9
|
+
import { sanitization } from '../../../utils/index.js';
|
|
7
10
|
const execAsync = promisify(exec);
|
|
8
11
|
// Define the input schema for the git_push tool using Zod
|
|
9
12
|
export const GitPushInputSchema = z.object({
|
|
10
|
-
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the session
|
|
13
|
+
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
11
14
|
remote: z.string().optional().describe("The remote repository to push to (e.g., 'origin'). Defaults to the tracked upstream or 'origin'."),
|
|
12
|
-
branch: z.string().optional().describe("The local branch to push. Defaults to the current branch."),
|
|
13
|
-
remoteBranch: z.string().optional().describe("The remote branch to push to. Defaults to the same name as the local branch."),
|
|
15
|
+
branch: z.string().optional().describe("The local branch to push (e.g., 'main', 'feat/new-login'). Defaults to the current branch."),
|
|
16
|
+
remoteBranch: z.string().optional().describe("The remote branch to push to (e.g., 'main', 'develop'). Defaults to the same name as the local branch."),
|
|
14
17
|
force: z.boolean().optional().default(false).describe("Force the push (use with caution: `--force-with-lease` is generally safer)."),
|
|
15
18
|
forceWithLease: z.boolean().optional().default(false).describe("Force the push only if the remote ref is the expected value (`--force-with-lease`). Safer than --force."),
|
|
16
19
|
setUpstream: z.boolean().optional().default(false).describe("Set the upstream tracking configuration (`-u` or `--set-upstream`)."),
|
|
@@ -169,7 +172,7 @@ export async function pushGitChanges(input, context) {
|
|
|
169
172
|
throw new McpError(BaseErrorCode.NOT_FOUND, `Path is not a Git repository: ${targetPath}`, { context, operation, originalError: error });
|
|
170
173
|
}
|
|
171
174
|
if (errorMessage.includes('resolve host') || errorMessage.includes('Could not read from remote repository') || errorMessage.includes('Connection timed out')) {
|
|
172
|
-
throw new McpError(BaseErrorCode.
|
|
175
|
+
throw new McpError(BaseErrorCode.SERVICE_UNAVAILABLE, `Failed to connect to remote repository. Error: ${errorMessage}`, { context, operation, originalError: error });
|
|
173
176
|
}
|
|
174
177
|
if (errorMessage.includes('rejected') || errorMessage.includes('failed to push some refs')) {
|
|
175
178
|
// This might be caught here if execAsync throws due to non-zero exit code on rejection
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
// Import utils from barrel (ErrorHandler from ../utils/internal/errorHandler.js)
|
|
2
|
+
import { ErrorHandler } from '../../../utils/index.js';
|
|
3
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
4
|
+
import { logger } from '../../../utils/index.js';
|
|
5
|
+
// Import utils from barrel (requestContextService, RequestContext from ../utils/internal/requestContext.js)
|
|
6
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
7
|
+
import { requestContextService } from '../../../utils/index.js';
|
|
4
8
|
import { GitPushInputSchema, pushGitChanges } from './logic.js';
|
|
5
|
-
import { BaseErrorCode } from '../../../types-global/errors.js';
|
|
6
9
|
let _getWorkingDirectory;
|
|
7
10
|
let _getSessionId;
|
|
8
11
|
/**
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
5
|
+
import { logger } from '../../../utils/index.js';
|
|
6
|
+
// Import utils from barrel (RequestContext from ../utils/internal/requestContext.js)
|
|
7
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
8
|
+
// Import utils from barrel (sanitization from ../utils/security/sanitization.js)
|
|
9
|
+
import { sanitization } from '../../../utils/index.js';
|
|
7
10
|
const execAsync = promisify(exec);
|
|
8
11
|
// Define the BASE input schema for the git_rebase tool using Zod
|
|
9
12
|
export const GitRebaseBaseSchema = z.object({
|
|
10
|
-
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository.
|
|
13
|
+
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
11
14
|
mode: z.enum(['start', 'continue', 'abort', 'skip']).default('start').describe("Rebase operation mode: 'start' (initiate rebase), 'continue', 'abort', 'skip' (manage ongoing rebase)."),
|
|
12
15
|
upstream: z.string().min(1).optional().describe("The upstream branch or commit to rebase onto. Required for 'start' mode unless 'interactive' is true with default base."),
|
|
13
16
|
branch: z.string().min(1).optional().describe("The branch to rebase. Defaults to the current branch if omitted."),
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
// Import utils from barrel (logger from ../utils/internal/logger.js)
|
|
2
|
+
import { logger } from '../../../utils/index.js';
|
|
3
|
+
// Import utils from barrel (ErrorHandler from ../utils/internal/errorHandler.js)
|
|
4
|
+
import { ErrorHandler } from '../../../utils/index.js';
|
|
5
|
+
// Import utils from barrel (requestContextService from ../utils/internal/requestContext.js)
|
|
6
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Keep direct import for types-global
|
|
7
|
+
import { requestContextService } from '../../../utils/index.js';
|
|
8
|
+
import { GitRebaseBaseSchema, gitRebaseLogic } from './logic.js';
|
|
6
9
|
let _getWorkingDirectory;
|
|
7
10
|
let _getSessionId;
|
|
8
11
|
/**
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { exec } from 'child_process';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { BaseErrorCode, McpError } from '../../../types-global/errors.js';
|
|
5
|
-
import { logger } from '../../../utils/
|
|
6
|
-
import { sanitization } from '../../../utils/sanitization.js';
|
|
4
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
5
|
+
import { logger, sanitization } from '../../../utils/index.js'; // Logger (./utils/internal/logger.js) & RequestContext (./utils/internal/requestContext.js) & sanitization (./utils/security/sanitization.js)
|
|
7
6
|
const execAsync = promisify(exec);
|
|
8
7
|
// Define the input schema for the git_remote tool using Zod
|
|
9
8
|
export const GitRemoteInputSchema = z.object({
|
|
10
|
-
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the session
|
|
9
|
+
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
11
10
|
mode: z.enum(['list', 'add', 'remove', 'show']).describe("Operation mode: 'list', 'add', 'remove', 'show'"),
|
|
12
11
|
name: z.string().min(1).optional().describe("Remote name (required for 'add', 'remove', 'show')"),
|
|
13
|
-
url: z.string().
|
|
12
|
+
url: z.string().optional().describe("Remote URL (required for 'add')"), // Removed .url() validation
|
|
14
13
|
});
|
|
15
14
|
/**
|
|
16
15
|
* Executes git remote commands based on the specified mode.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { BaseErrorCode } from '../../../types-global/errors.js';
|
|
2
|
-
import { ErrorHandler } from '../../../utils/
|
|
3
|
-
import { logger } from '../../../utils/logger.js';
|
|
4
|
-
import { requestContextService } from '../../../utils/requestContext.js';
|
|
1
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
2
|
+
import { ErrorHandler, logger, requestContextService } from '../../../utils/index.js'; // ErrorHandler (./utils/internal/errorHandler.js), logger (./utils/internal/logger.js), requestContextService (./utils/internal/requestContext.js)
|
|
5
3
|
import { GitRemoteInputSchema, gitRemoteLogic } from './logic.js';
|
|
6
4
|
let _getWorkingDirectory;
|
|
7
5
|
let _getSessionId;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
5
|
+
import { logger, sanitization } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), RequestContext (./utils/internal/requestContext.js), sanitization (./utils/security/sanitization.js)
|
|
7
6
|
const execAsync = promisify(exec);
|
|
8
7
|
// Define the reset modes
|
|
9
8
|
const ResetModeEnum = z.enum(['soft', 'mixed', 'hard', 'merge', 'keep']);
|
|
10
9
|
// Define the input schema for the git_reset tool using Zod
|
|
11
10
|
export const GitResetInputSchema = z.object({
|
|
12
|
-
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the session
|
|
11
|
+
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
13
12
|
mode: ResetModeEnum.optional().default('mixed').describe("Reset mode: 'soft' (reset HEAD only), 'mixed' (reset HEAD and index, default), 'hard' (reset HEAD, index, and working tree - USE WITH CAUTION), 'merge', 'keep'."),
|
|
14
13
|
commit: z.string().optional().describe("Commit, branch, or ref to reset to. Defaults to HEAD (useful for unstaging with 'mixed' mode)."),
|
|
15
14
|
// file: z.string().optional().describe("If specified, reset only this file in the index (unstaging). Mode must be 'mixed' or omitted."), // Git reset [<mode>] [<tree-ish>] [--] <paths>… is complex, handle separately if needed
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { logger } from '../../../utils/
|
|
3
|
-
import { requestContextService } from '../../../utils/requestContext.js';
|
|
1
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
2
|
+
import { ErrorHandler, logger, requestContextService } from '../../../utils/index.js'; // ErrorHandler (./utils/internal/errorHandler.js), logger (./utils/internal/logger.js), requestContextService & RequestContext (./utils/internal/requestContext.js)
|
|
4
3
|
import { GitResetInputSchema, resetGitState } from './logic.js';
|
|
5
|
-
import { BaseErrorCode } from '../../../types-global/errors.js';
|
|
6
4
|
let _getWorkingDirectory;
|
|
7
5
|
let _getSessionId;
|
|
8
6
|
/**
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { exec } from 'child_process';
|
|
3
|
-
import { promisify } from 'util';
|
|
4
2
|
import fs from 'fs/promises';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
6
|
+
import { logger, sanitization } from '../../../utils/index.js'; // RequestContext (./utils/internal/requestContext.js), logger (./utils/internal/logger.js), sanitization (./utils/security/sanitization.js)
|
|
8
7
|
const execAsync = promisify(exec);
|
|
9
8
|
// Define the Zod schema for input validation
|
|
10
9
|
export const GitSetWorkingDirInputSchema = z.object({
|
|
11
|
-
path: z.string().min(1, "Path cannot be empty.").describe("The absolute path to set as the default working directory for the current session."),
|
|
10
|
+
path: z.string().min(1, "Path cannot be empty.").describe("The absolute path to set as the default working directory for the current session. Set this before using other git_* tools."),
|
|
12
11
|
validateGitRepo: z.boolean().default(true).describe("Whether to validate that the path is a Git repository"),
|
|
13
12
|
});
|
|
14
13
|
/**
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { logger } from '../../../utils/
|
|
3
|
-
import { requestContextService } from '../../../utils/requestContext.js';
|
|
1
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
2
|
+
import { ErrorHandler, logger, requestContextService } from '../../../utils/index.js'; // ErrorHandler (./utils/internal/errorHandler.js), logger (./utils/internal/logger.js), requestContextService & RequestContext (./utils/internal/requestContext.js)
|
|
4
3
|
import { GitSetWorkingDirInputSchema, gitSetWorkingDirLogic } from './logic.js';
|
|
5
|
-
|
|
4
|
+
let _getWorkingDirectory; // Added getter
|
|
6
5
|
let _setWorkingDirectory;
|
|
7
6
|
let _getSessionId;
|
|
8
7
|
/**
|
|
9
8
|
* Initializes the state accessors needed by the tool registration.
|
|
10
9
|
* This should be called once during server setup.
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
10
|
+
* @param getWdFn - Function to get the working directory for a session.
|
|
11
|
+
* @param setWdFn - Function to set the working directory for a session.
|
|
12
|
+
* @param getSidFn - Function to get the session ID from context.
|
|
13
13
|
*/
|
|
14
|
-
export function initializeGitSetWorkingDirStateAccessors(
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export function initializeGitSetWorkingDirStateAccessors(getWdFn, // Added getter parameter
|
|
15
|
+
setWdFn, getSidFn) {
|
|
16
|
+
_getWorkingDirectory = getWdFn; // Store getter
|
|
17
|
+
_setWorkingDirectory = setWdFn;
|
|
18
|
+
_getSessionId = getSidFn;
|
|
17
19
|
logger.info('State accessors initialized for git_set_working_dir tool registration.');
|
|
18
20
|
}
|
|
19
21
|
const TOOL_NAME = 'git_set_working_dir';
|
|
@@ -25,8 +27,9 @@ const TOOL_DESCRIPTION = "Sets the default working directory for the current ses
|
|
|
25
27
|
* @throws {Error} If state accessors are not initialized.
|
|
26
28
|
*/
|
|
27
29
|
export async function registerGitSetWorkingDirTool(server) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
// Check all required accessors
|
|
31
|
+
if (!_getWorkingDirectory || !_setWorkingDirectory || !_getSessionId) {
|
|
32
|
+
throw new Error('State accessors (getWD, setWD, getSID) for git_set_working_dir must be initialized before registration.');
|
|
30
33
|
}
|
|
31
34
|
try {
|
|
32
35
|
server.tool(TOOL_NAME, TOOL_DESCRIPTION, GitSetWorkingDirInputSchema.shape, // Pass the shape for SDK validation
|
|
@@ -40,11 +43,17 @@ export async function registerGitSetWorkingDirTool(server) {
|
|
|
40
43
|
const setWorkingDirectoryForSession = (path) => {
|
|
41
44
|
_setWorkingDirectory(sessionId, path); // Non-null assertion
|
|
42
45
|
};
|
|
43
|
-
//
|
|
46
|
+
// Define the session-specific getter function (needed by logic?)
|
|
47
|
+
// If the logic needs the current WD, pass the getter too. Assuming it might.
|
|
48
|
+
const getWorkingDirectoryForSession = () => {
|
|
49
|
+
return _getWorkingDirectory(sessionId); // Non-null assertion
|
|
50
|
+
};
|
|
51
|
+
// Enhance context with session ID and the getter/setter functions
|
|
44
52
|
const logicContext = {
|
|
45
53
|
...requestContext,
|
|
46
54
|
sessionId: sessionId,
|
|
47
|
-
|
|
55
|
+
getWorkingDirectory: getWorkingDirectoryForSession, // Pass getter
|
|
56
|
+
setWorkingDirectory: setWorkingDirectoryForSession, // Pass setter
|
|
48
57
|
};
|
|
49
58
|
return await ErrorHandler.tryCatch(async () => {
|
|
50
59
|
// Call the core logic function with validated args and enhanced context
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
5
|
+
import { logger, sanitization } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), RequestContext (./utils/internal/requestContext.js), sanitization (./utils/security/sanitization.js)
|
|
7
6
|
const execAsync = promisify(exec);
|
|
8
7
|
// Define the input schema for the git_show tool using Zod
|
|
9
8
|
// No refinements needed here, so we don't need a separate BaseSchema
|
|
10
9
|
export const GitShowInputSchema = z.object({
|
|
11
|
-
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository.
|
|
10
|
+
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
12
11
|
ref: z.string().min(1).describe("The object reference (commit hash, tag name, branch name, HEAD, etc.) to show."),
|
|
13
12
|
filePath: z.string().optional().describe("Optional specific file path within the ref to show (e.g., show a file's content at a specific commit). If provided, use the format '<ref>:<filePath>'."),
|
|
14
13
|
// format: z.string().optional().describe("Optional format string for the output"), // Consider adding later
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ErrorHandler } from '../../../utils/
|
|
3
|
-
import { requestContextService } from '../../../utils/requestContext.js';
|
|
1
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
2
|
+
import { ErrorHandler, logger, requestContextService } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), ErrorHandler (./utils/internal/errorHandler.js), requestContextService (./utils/internal/requestContext.js)
|
|
4
3
|
// Import the schema and types
|
|
5
|
-
import {
|
|
6
|
-
import { BaseErrorCode } from '../../../types-global/errors.js';
|
|
4
|
+
import { GitShowInputSchema, gitShowLogic } from './logic.js';
|
|
7
5
|
let _getWorkingDirectory;
|
|
8
6
|
let _getSessionId;
|
|
9
7
|
/**
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
5
|
+
import { logger, sanitization } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), RequestContext (./utils/internal/requestContext.js), sanitization (./utils/security/sanitization.js)
|
|
7
6
|
const execAsync = promisify(exec);
|
|
8
7
|
// Define the BASE input schema for the git_stash tool using Zod
|
|
9
8
|
export const GitStashBaseSchema = z.object({
|
|
10
|
-
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository.
|
|
9
|
+
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
11
10
|
mode: z.enum(['list', 'apply', 'pop', 'drop', 'save']).describe("The stash operation to perform: 'list', 'apply', 'pop', 'drop', 'save'."),
|
|
12
11
|
stashRef: z.string().optional().describe("Stash reference (e.g., 'stash@{1}'). Required for 'apply', 'pop', 'drop' modes."),
|
|
13
12
|
message: z.string().optional().describe("Optional descriptive message used only for 'save' mode."),
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ErrorHandler } from '../../../utils/
|
|
3
|
-
import { requestContextService } from '../../../utils/requestContext.js';
|
|
1
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
2
|
+
import { ErrorHandler, logger, requestContextService } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), ErrorHandler (./utils/internal/errorHandler.js), requestContextService (./utils/internal/requestContext.js)
|
|
4
3
|
// Import the final schema and types for handler logic
|
|
5
4
|
// Import the BASE schema separately for registration shape
|
|
6
|
-
import {
|
|
7
|
-
import { BaseErrorCode } from '../../../types-global/errors.js';
|
|
5
|
+
import { GitStashBaseSchema, gitStashLogic } from './logic.js';
|
|
8
6
|
let _getWorkingDirectory;
|
|
9
7
|
let _getSessionId;
|
|
10
8
|
/**
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
1
|
import { exec } from 'child_process';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
5
|
+
import { logger, sanitization } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), RequestContext (./utils/internal/requestContext.js), sanitization (./utils/security/sanitization.js)
|
|
7
6
|
const execAsync = promisify(exec);
|
|
8
7
|
// Define the input schema for the git_status tool using Zod
|
|
9
8
|
export const GitStatusInputSchema = z.object({
|
|
10
|
-
path: z.string().min(1).optional().default('.').describe("Path to the Git repository
|
|
9
|
+
path: z.string().min(1).optional().default('.').describe("Path to the Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
11
10
|
});
|
|
12
11
|
/**
|
|
13
12
|
* Parses the output of 'git status --porcelain=v1 -b'.
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ErrorHandler } from '../../../utils/
|
|
3
|
-
import { requestContextService } from '../../../utils/requestContext.js';
|
|
1
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
2
|
+
import { ErrorHandler, logger, requestContextService } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), ErrorHandler (./utils/internal/errorHandler.js), requestContextService (./utils/internal/requestContext.js)
|
|
4
3
|
// Import the result type along with the function and input schema
|
|
5
4
|
import { getGitStatus, GitStatusInputSchema } from './logic.js';
|
|
6
|
-
import { BaseErrorCode } from '../../../types-global/errors.js'; // Import BaseErrorCode
|
|
7
5
|
let _getWorkingDirectory;
|
|
8
6
|
let _getSessionId;
|
|
9
7
|
/**
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { exec } from 'child_process';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { BaseErrorCode, McpError } from '../../../types-global/errors.js';
|
|
5
|
-
import { logger } from '../../../utils/
|
|
6
|
-
import { sanitization } from '../../../utils/sanitization.js';
|
|
4
|
+
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
5
|
+
import { logger, sanitization } from '../../../utils/index.js'; // logger (./utils/internal/logger.js), RequestContext (./utils/internal/requestContext.js), sanitization (./utils/security/sanitization.js)
|
|
7
6
|
const execAsync = promisify(exec);
|
|
8
7
|
// Define the base input schema for the git_tag tool using Zod
|
|
9
8
|
// We export this separately to access its .shape for registration
|
|
10
9
|
export const GitTagBaseSchema = z.object({
|
|
11
|
-
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository.
|
|
10
|
+
path: z.string().min(1).optional().default('.').describe("Path to the local Git repository. Defaults to the directory set via `git_set_working_dir` for the session; set 'git_set_working_dir' if not set."),
|
|
12
11
|
mode: z.enum(['list', 'create', 'delete']).describe("The tag operation to perform: 'list' (show all tags), 'create' (add a new tag), 'delete' (remove a local tag)."),
|
|
13
12
|
tagName: z.string().min(1).optional().describe("The name for the tag. Required for 'create' and 'delete' modes. e.g., 'v2.3.0'."),
|
|
14
13
|
message: z.string().optional().describe("The annotation message for the tag. Required and used only when 'mode' is 'create' and 'annotate' is true."),
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { logger } from '../../../utils/
|
|
3
|
-
import { requestContextService } from '../../../utils/requestContext.js';
|
|
1
|
+
import { BaseErrorCode } from '../../../types-global/errors.js'; // Direct import for types-global
|
|
2
|
+
import { ErrorHandler, logger, requestContextService } from '../../../utils/index.js'; // ErrorHandler (./utils/internal/errorHandler.js), logger (./utils/internal/logger.js), requestContextService (./utils/internal/requestContext.js)
|
|
4
3
|
// Import the final schema and types for handler logic
|
|
5
4
|
// Import the BASE schema separately for registration shape
|
|
6
|
-
import { BaseErrorCode } from '../../../types-global/errors.js';
|
|
7
5
|
import { GitTagBaseSchema, gitTagLogic } from './logic.js';
|
|
8
6
|
let _getWorkingDirectory;
|
|
9
7
|
let _getSessionId;
|