Git Polite
Git Polite is an MCP server that enables AI agents to intelligently organize and stage git changes with surgical precision, turning messy work-in-progress into clean, focused commits.
View unstaged changes (
list_changes): List all unstaged git changes — including untracked/newly created files — with each changed line numbered for precise selection; supports byte-based pagination (default 30KB/page), smart truncation, and automatic binary file detection/skippingView full file diffs (
diff): View the complete, untruncated diff for a single file (useful whenlist_changestruncates large files), returning the same numbered line format needed for partial stagingSelectively stage changes (
apply_changes): Stage specific lines or ranges (e.g.,0001-0005,0020,0025) to the git index — including partial staging of untracked files — enabling multiple logical commits from a single fileAuto-commit organization (
auto_commit): Start a guided autopilot session that analyzes all unstaged changes, references recent commit style, and walks through creating multiple atomic, well-structured commits from intermixed WIP changesUnstack commits into parallel branches (
unstack): Transform a linear commit history into parallel branches (each branching from a base likeorigin/main), cherry-picking specific commits onto each branch to facilitate separate PRs for distinct logical changes
Provides intelligent git staging capabilities including line-by-line staging, automatic commit organization, partial file staging for untracked files, and AI-powered commit structuring from work-in-progress changes.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Git Polite auto-commit my messy changes into logical commits"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Git staging on autopilot — let AI organize your changes into clean, focused commits.
Overview
git-polite is a Model Context Protocol (MCP) server that brings intelligent git staging to AI agents. It can automatically organize messy work-in-progress into well-structured commits, or give you surgical precision with line-by-line staging when you need it.
Related MCP server: git-mcp
Features
Autopilot Mode: Let AI analyze your changes and create multiple focused commits automatically
Line-Level Staging: Stage individual additions and deletions by line number with surgical precision
Untracked File Support: Stage parts of newly created files (not just modified files)
Range Selection: Apply multiple changes at once using ranges (e.g.,
0001-0005,0020-0025)LLM-Friendly Output: Byte-based pagination and smart truncation protect context windows
Binary File Detection: Automatically detects and skips binary files
MCP Integration: Works seamlessly with Claude Code, Claude Desktop, and other MCP clients
MCP Server Mode
Run as an MCP server for integration with MCP clients:
uv run git_polite.py mcpMCP Tools
The server exposes four tools:
list_changes: List unstaged git changes (including untracked files) as numbered lines
Smart truncation: Large diffs (>10KB) are automatically truncated to protect LLM context
Parameters:
paths(optional): List of file paths to filterpage_token(optional): Pagination tokenpage_size_files(optional, default: 50): Max files per pagepage_size_bytes(optional, default: 30KB): Max cumulative bytes per pageunified(optional, default: 20): Context lines around changes
Output includes
truncated: trueflag for large files with areasonexplaining the truncationFor truncated files, use the
difftool to view complete content
diff: View complete diff for a single file without truncation
Use this for files that are truncated in
list_changesoutputReturns the same numbered line format as
list_changes, enabling partial stagingUnlike
git diff, this tool provides line numbers required byapply_changesNever truncates output, suitable for large files with extensive changes
Parameters:
path(required): File path to view diff forunified(optional, default: 20): Context lines around changes
Returns: Complete diff with
size_bytesindicating actual output size
apply_changes: Apply selected changes to git index by number (supports partial staging of untracked files)
Parameters:
path: File path to apply changes tolines: Change numbers (format:NNNN,MMMM,PPPP-QQQQ)
auto_commit: Start autopilot mode to organize all changes into focused commits
Shows recent commit messages for style reference
Analyzes all unstaged changes and suggests logical groupings
Guides AI through creating multiple atomic commits from messy WIP
MCP Client Configuration
Using uvx (Recommended)
Use uvx to run directly from GitHub:
Claude Desktop Configuration:
{
"mcpServers": {
"git-polite": {
"command": "uvx",
"args": [
"git-polite@git+https://github.com/uneco/mcp-git-polite.git",
"mcp"
]
}
}
}Claude CLI:
claude mcp add -s user git-polite uvx git-polite@git+https://github.com/uneco/mcp-git-polite.git mcpUsing Docker
Alternatively, use the Docker image from GitHub Container Registry:
{
"mcpServers": {
"git-polite": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"${workspaceFolder}:/workspace",
"-w",
"/workspace",
"ghcr.io/uneco/mcp-git-polite:latest",
"mcp"
]
}
}
}How It Works
List Phase: The tool parses
git diffoutput (including untracked files viagit diff --no-index) and numbers each addition (+) and deletion (-) sequentiallyTruncation Check: Each file's diff size is measured. Files exceeding 10KB are marked as truncated to protect LLM context
Display: Changes are shown with their numbers, along with surrounding context lines. Files are marked as "added" (untracked), "modified", or "deleted"
Pagination: Results are paginated based on cumulative byte size (default 30KB per page) to prevent overwhelming the LLM
Apply Phase: When you specify line numbers, the tool:
Reads the staged version from git index (or creates new file for untracked files)
Applies only the selected changes
Updates the git index with the partial changes
Output Format
List Output
{
"page_token_next": "optional-token",
"files": [
{
"path": "src/main.py",
"binary": false,
"status": "modified",
"lines": [
"0001: + new line 1",
" context line",
"0002: - deleted line",
"0003: + new line 2",
" ..."
]
},
{
"path": "src/new_file.py",
"binary": false,
"status": "added",
"lines": [
"0001: + def hello():",
"0002: + print('Hello')"
]
},
{
"path": "src/refactored_module.py",
"binary": false,
"status": "modified",
"truncated": true,
"reason": "diff too large (45.2 KB, max 10 KB)",
"lines": []
}
],
"stats": {
"files": 3,
"lines": 5,
"truncated_files": 1,
"page_bytes": 4532
}
}When a file shows truncated: true, use the diff tool to view its complete content. The diff tool provides the same numbered line format needed for partial staging, which git diff cannot provide.
Apply Output
{
"applied": [
{
"file": "src/main.py",
"applied_count": 3,
"after_applying": {
"diff": ["0001: + remaining", "0002: - unstaged", "0003: + changes"],
"unstaged_lines": 5
}
}
],
"skipped": [],
"stats": {
"files": 1,
"changes_applied": 3,
"changes_skipped": 0
}
}Requirements
Python 3.10 or higher
Git (command-line tool)
MCP server package (
mcp>=1.10.0)
Development
# Install dependencies
uv sync
# Run tests (if available)
uv run pytest
# Format code
uv run black git_polite.py
# Type check
uv run mypy git_polite.pyUse Cases
AI-Powered Commit Organization: Let AI analyze your WIP and create clean commit history automatically
Incremental Commits: Break down large changes into logical, atomic commits
Partial File Staging: Stage only specific lines of a new file while keeping the rest unstaged
Code Review Preparation: Stage related changes together, even if scattered across files
Refactoring: Separate formatting changes from logic changes with surgical precision
Example Workflows
Working with Truncated Files
When you encounter a truncated file (e.g., a large refactored file with many changes):
# Step 1: List all changes
result = list_changes()
# Step 2: Notice a truncated file
# {
# "path": "src/api_client.py",
# "truncated": true,
# "reason": "diff too large (45.2 KB, max 10 KB)",
# "lines": []
# }
# Step 3: View the complete numbered diff
# Use the diff tool (not git diff) because it provides line numbers needed for partial staging
full_diff = diff(path="src/api_client.py")
# Step 4: Selectively stage related changes (e.g., bug fixes separate from refactoring)
apply_changes(path="src/api_client.py", lines="0001-0050,0120-0135")Pagination Example
# Get first page (max 30KB)
page1 = list_changes(page_size_bytes=30720)
# Continue with next page if needed
if page1["page_token_next"]:
page2 = list_changes(page_token=page1["page_token_next"])Limitations
Works only with text files (binary files are detected and skipped)
Line numbers are ephemeral - they change after each apply operation
Context mismatches (file drift) will cause operations to fail safely
For untracked files, the entire file content must be present in the working directory
Large files (>10KB diff) are truncated in
list_changes- usedifftool to view them
License
MIT License - See LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
Built with FastMCP and the Model Context Protocol.
Available Tools
5 toolsapply_changesADestructive
Stage selected lines to git index for partial commits (alternative to git add -p).
After using list_changes to view numbered changes, use this tool to selectively stage specific lines or ranges to the git index. This enables creating multiple logical commits from a single file with intermixed changes.
Unlike git add, this tool can stage parts of untracked files (newly created files).
You can commit only the first 10 lines of a new file while keeping the rest unstaged.
Number format examples:
Single lines: "0001,0002,0005"
Ranges: "0001-0010"
Combined: "0001-0005,0020-0025"
The tool updates the git index directly and reports remaining unstaged changes, allowing iterative staging for multiple commits from the same file.
Args: path: File path to apply changes to numbers: Change numbers in format: NNNN,MMMM,PPPP-QQQQ
Returns: JSON string with format: {applied: [{file, applied_count, after_applying: {diff, unstaged_lines}}], skipped, stats}
Inputs: path (required), numbers (required). Returns: result
auto_commitARead-only
Start a guided session to organize and commit all unstaged changes with appropriate granularity.
This tool helps you organize your changes and create multiple focused commits by:
Showing recent commit messages as style reference
Displaying summary statistics of all unstaged changes (file counts, line counts)
Providing step-by-step instructions for the commit workflow
This tool uses progressive disclosure: it shows only statistics (additions/deletions per file) to avoid token limits. Use list_changes or diff tools to view detailed changes for specific files.
Use this when you have multiple logical changes mixed together and want to organize them into separate, well-structured commits.
Returns: JSON with recent commits, file statistics, and next steps for the agent
Inputs: no named parameters. Returns: result
diffARead-only
View complete diff for a single file without truncation.
This tool is designed for viewing the full diff of a single file, regardless of size. Unlike list_changes, this tool will NEVER truncate the output, making it suitable for reviewing large files like lock files or generated code.
Use this when you need to:
View the complete diff of a large file (e.g., uv.lock, package-lock.json)
Review all changes in a specific file before staging
Analyze files that would be truncated by list_changes
Args: path: File path to view diff for (required) unified: Context lines around changes (default: UNIFIED_LIST_DEFAULT)
Returns: JSON string with format: {path, binary, status, lines, size_bytes}
Inputs: path (required), unified. Returns: result
list_changesARead-only
View unstaged git changes with line-level selection numbers for partial staging.
PREFER THIS OVER git diff when you need to selectively stage changes. Unlike git diff,
this tool includes untracked files (newly created files) in the output. This tool numbers
each changed line (0001, 0002, etc.) so you can stage specific lines or ranges instead of
entire files. Essential for creating multiple logical commits from intermixed changes.
Key features:
Includes untracked files (status: "added") as well as modified files (status: "modified")
Numbers every changed line for precise selection
Supports byte-based pagination to protect LLM context
Auto-truncates large diffs (>10KB) with clear indication
Handling truncated files:
When a file shows truncated: true with empty lines: [], use the diff tool to view
its complete content. The diff tool returns the same numbered line format needed for
partial staging with apply_changes, whereas git diff output lacks line numbers and
cannot be used for selective staging. For example, if a large refactored file is truncated,
call diff(path="src/large_module.py") to see the full numbered diff and selectively stage
related changes.
Use cases:
Breaking up large changes into multiple focused commits
Staging only specific changes while keeping others unstaged
Creating atomic commits from work-in-progress code
Separating refactoring from feature changes
Selectively staging parts of newly created files
After viewing changes, use apply_changes with the line numbers to stage selected changes.
Args: paths: Optional list of file paths to filter (default: all files) page_token: Opaque pagination token from previous response page_size_files: Max files per page - safety limit (default: PAGE_SIZE_FILES_DEFAULT) page_size_bytes: Max bytes per page - primary limit (default: PAGE_SIZE_BYTES_DEFAULT) unified: Context lines around changes (default: UNIFIED_LIST_DEFAULT)
Returns: JSON string with format: {page_token_next, files: [{path, binary, lines}], stats}
Inputs: paths, page_token, page_size_files, page_size_bytes, +1 more. Returns: result
unstackADestructive
Unstack linear commits into parallel branches for separate PRs.
This tool transforms a linear commit history (A -> B -> C -> D) into parallel branches (A -> B, A -> C, A -> D) where each branch contains specific commits cherry-picked from the original history.
Use this when you've made multiple changes in sequence but want to create separate PRs for different logical changes. Each branch can be independently reviewed and merged.
Example scenario: You have commits: fix-bug -> add-feature -> update-docs You want separate PRs, so you create:
feat/999: [fix-bug, update-docs]
feat/1000: [add-feature]
This creates two branches from origin/main:
feat/999 with fix-bug and update-docs cherry-picked in order
feat/1000 with add-feature cherry-picked
Args: branches: Dictionary mapping branch names to lists of commit references. Commits can be specified as SHA, branch names, or symbolic refs (e.g., HEAD~2). Commits are cherry-picked in the order specified. parent: Base commit to branch from (default: "origin/main"). All branches will start from this commit.
Returns: JSON string with format: { created_branches: [{name, commits_applied, head_sha}], errors: [{branch, commit, error}], stats: {total_branches, successful_branches, failed_branches} }
Note: - Existing branches with the same name will cause an error - The current branch is not changed by this operation - Uses low-level git commands (commit-tree, update-ref) to avoid changing working directory
Inputs: branches (required), parent. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a distinct, non-overlapping purpose: list_changes shows numbered unstaged changes, apply_changes stages selected lines, diff provides full file diffs, auto_commit guides commit organization, and unstack restructures commit history. The descriptions clearly differentiate their roles, with no ambiguity about when to use each tool.
Four tools follow a consistent verb_noun pattern (list_changes, apply_changes, auto_commit, unstack), but 'diff' deviates as a single noun without a verb. While this minor inconsistency is noticeable, the naming remains readable and intuitive for the domain.
With 5 tools, this server is well-scoped for its purpose of advanced git operations like partial staging and commit management. Each tool earns its place by addressing specific workflows, such as selective staging, full diff viewing, commit organization, and history restructuring, without being overly sparse or bloated.
The tool set covers core workflows for selective staging, diff viewing, commit organization, and branch restructuring, with no obvious dead ends. A minor gap exists in lacking a tool for direct commit creation or push operations, but agents can work around this using auto_commit guidance or external commands.
Related MCP Connectors
Plain-English git for agents: 22 tools to branch, commit, push and tag. Free tier.
Git-backed platform for skills, tools, and context for AI agents
Git collaboration for AI agents and people: tasks, hand-offs, reviews, teams, shared memory.
AI that works, like you: in your own files, with every change signed.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI assistants to perform code reviews by providing access to staged files, git diffs, and repository file content. It allows users to evaluate changes and context within any local git repository before committing or pushing.34 npmISC
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to perform full Git operations including branching, committing, pushing, stashing, rebasing, and more, with safety features and support for advanced workflows like Git Flow and LFS.1MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to inspect Git repositories for changes across committed, staged, unstaged, and untracked scopes, and run allowlisted validation commands with structured results.-
- AlicenseAqualityBmaintenanceEnables AI assistants to perform Git workflows with semantic commit messages, pre-PR secret audits, conflict resolution, and release changelog generation.5MIT