Skip to main content
Glama
ceshine

Git Prompts MCP Server

by ceshine

git-cached-diff

Compare staged changes against the last commit to review modifications before finalizing them in Git.

Instructions

Get a diff between the files in the staging area (the index) and the HEAD

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registration of the 'git-cached-diff' tool using FastMCP's @APP.tool decorator, linking to the handler.
    @APP.tool(
        name="git-cached-diff",
        description="Get a diff between the files in the staging area (the index) and the HEAD",
    )
    async def git_cached_diff_tool() -> list[dict[str, str]]:
        return await GIT_METHOD_COLLETION.get_cached_diff_data()
  • Core handler method in GitMethodCollection that executes the git-cached-diff logic: computes staged changes diff (HEAD vs index).
    async def get_cached_diff_data(self) -> list[dict[str, str]]:
        diff_results = _get_diff_results(self.repo.head.commit, None, self.excludes)
        return _get_diff_results_as_list_of_dict(diff_results)
  • Helper function to retrieve and filter git diff results between commits or index.
    def _get_diff_results(
        source_commit: git.Commit, target_commit: git.Commit | None, excludes: list[str]
    ) -> list[git.Diff]:
        if target_commit is None:
            # Note: source_commit.diff() compares source with the index (staged changes)
            #       source_commit.diff(None) compares source with the working tree
            diff_results = source_commit.diff(create_patch=True)
        else:
            diff_results = source_commit.diff(target_commit, create_patch=True)
    
        for exclude_pattern in excludes:
            diff_results = [
                item
                for item in diff_results
                if not fnmatch(item.a_path or "", exclude_pattern) and not fnmatch(item.b_path or "", exclude_pattern)
            ]
        return diff_results
  • Helper to convert git diff results to structured list of dictionaries for output.
    def _get_diff_results_as_list_of_dict(diff_results: list[git.Diff]) -> list[dict[str, str]]:
        return [
            {
                "a_path": item.a_path or "New Addition",
                "b_path": item.b_path or "Deleted",
                "diff": cast(bytes, item.diff).decode("utf-8"),
            }
            for item in diff_results
        ]
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ceshine/git-prompts-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server