@nvhien20vn/git-mcp-server
Version:
37 lines (36 loc) • 1.94 kB
JavaScript
import { z } from 'zod';
// Import utils from barrel (logger from ../utils/internal/logger.js)
import { BaseErrorCode, McpError } from '../../../types-global/errors.js'; // Keep direct import for types-global
import { logger } from '../../../utils/index.js';
// Define the Zod schema for input validation (no arguments needed)
export const GitClearWorkingDirInputSchema = z.object({});
/**
* Logic for the git_clear_working_dir tool.
* Clears the global working directory setting for the current session.
*
* @param {GitClearWorkingDirInput} input - The validated input arguments (empty object).
* @param {RequestContext} context - The request context, containing session ID and the clear function.
* @returns {Promise<GitClearWorkingDirResult>} The result of the operation.
* @throws {McpError} Throws McpError for operational errors.
*/
export async function gitClearWorkingDirLogic(input, context // Assuming context provides session info and clearer
) {
const operation = 'gitClearWorkingDirLogic';
logger.info('Executing git_clear_working_dir logic', { ...context, operation });
// --- Update Session State ---
// This part needs access to the session state mechanism defined in server.ts
// We assume the context provides a way to clear the working directory for the current session.
try {
context.clearWorkingDirectory();
logger.info(`Working directory cleared for session ${context.sessionId || 'stdio'}`, { ...context, operation });
}
catch (error) {
logger.error('Failed to clear working directory in session state', error, { ...context, operation });
// This indicates an internal logic error in how state is passed/managed.
throw new McpError(BaseErrorCode.INTERNAL_ERROR, 'Failed to update session state.', { context, operation });
}
return {
success: true,
message: 'Global working directory setting cleared.',
};
}