@cyanheads/git-mcp-server
Version:
An MCP (Model Context Protocol) server enabling LLMs and AI agents to interact with Git repositories. Provides tools for comprehensive Git operations including clone, commit, branch, diff, log, status, push, pull, merge, rebase, worktree, tag management,
62 lines • 2.86 kB
JavaScript
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
import { addGitFiles, GitAddInputSchema, GitAddOutputSchema, } from "./logic.js";
const TOOL_NAME = "git_add";
const TOOL_DESCRIPTION = "Stages changes in the Git repository for the next commit by adding file contents to the index (staging area). Can stage specific files/patterns or all changes (default: '.'). Returns the result as a JSON object.";
export const registerGitAddTool = async (server, getWorkingDirectory, getSessionId) => {
const operation = "registerGitAddTool";
const context = requestContextService.createRequestContext({ operation });
await ErrorHandler.tryCatch(async () => {
server.registerTool(TOOL_NAME, {
title: "Git Add",
description: TOOL_DESCRIPTION,
inputSchema: GitAddInputSchema.shape,
outputSchema: GitAddOutputSchema.shape,
annotations: {
readOnlyHint: false,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
}, async (validatedArgs, callContext) => {
const toolOperation = "tool:git_add";
const requestContext = requestContextService.createRequestContext({
operation: toolOperation,
parentContext: callContext,
});
const sessionId = getSessionId(requestContext);
const logicContext = {
...requestContext,
sessionId: sessionId,
getWorkingDirectory: () => getWorkingDirectory(sessionId),
};
logger.info(`Executing tool: ${TOOL_NAME}`, logicContext);
try {
const result = await addGitFiles(validatedArgs, logicContext);
return {
structuredContent: result,
content: [
{ type: "text", text: JSON.stringify(result, null, 2) },
],
};
}
catch (error) {
const mcpError = ErrorHandler.handleError(error, {
operation: "gitAddToolHandler",
context: logicContext,
input: validatedArgs,
});
return {
isError: true,
content: [{ type: "text", text: `Error: ${mcpError.message}` }],
structuredContent: {
code: mcpError.code,
message: mcpError.message,
details: mcpError.details,
},
};
}
});
logger.info(`Tool registered: ${TOOL_NAME}`, context);
}, { operation, context, critical: true });
};
//# sourceMappingURL=registration.js.map