git-status
Check the current git status and recent commit history of a repository. Specify a directory path or use the default to view status details. Handles errors for non-git directories.
Instructions
Get the current git status of the repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | No | Directory path to check git status (defaults to current directory) |
Implementation Reference
- src/index.ts:30-42 (registration)Registration of the 'git-status' tool in the tools/list response, including name, description, and input schema.{ name: "git-status", description: "Get the current git status of the repository", inputSchema: { type: "object", properties: { directory: { type: "string", description: "Directory path to check git status (defaults to current directory)" } } } },
- src/index.ts:33-41 (schema)Input schema definition for the 'git-status' tool, specifying optional directory parameter.inputSchema: { type: "object", properties: { directory: { type: "string", description: "Directory path to check git status (defaults to current directory)" } } }
- src/index.ts:69-129 (handler)Handler implementation for 'git-status' tool. Runs git status --porcelain=v1, git branch --show-current, and git remote -v commands in the specified directory, formats the output with branch and remotes info, and returns formatted text response or error.if (name === "git-status") { const { directory }: { directory?: string } = args || {}; try { // Change to the specified directory if provided, otherwise use current directory const cwd = directory || process.cwd(); // Execute git status command const gitStatus = execSync("git status --porcelain=v1", { cwd: cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }); // Also get the branch information const gitBranch = execSync("git branch --show-current", { cwd: cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim(); // Get additional git info const gitRemote = execSync("git remote -v", { cwd: cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }); // Format the response let statusText = `Git Status for: ${cwd}\n`; statusText += `Current branch: ${gitBranch}\n`; statusText += `\nStatus:\n`; if (gitStatus.trim() === "") { statusText += "Working directory clean - no changes detected\n"; } else { statusText += gitStatus; } statusText += `\nRemotes:\n${gitRemote}`; return { content: [{ type: "text", text: statusText }] }; } catch (error) { // Handle errors (e.g., not a git repository, git not installed, etc.) const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error running git status: ${errorMessage}\n\nPlease ensure:\n1. You are in a git repository\n2. Git is installed and available in PATH\n3. You have proper permissions to access the directory` }], isError: true }; } }