HG MCP Server
Enables AI assistants to interact with Mercurial repositories, supporting version control operations like cloning, committing, branching, merging, and remote synchronization through natural language.
README
HG MCP Server
A Model Context Protocol (MCP) server for Mercurial repository interaction, written in Python 3.10+ with AsyncIO.
Features
Core Version Control
- Repository Creation: Create new repositories (
hg_init) or clone existing ones (hg_clone) - Status & Diff: View working directory status (
hg_status) and line-by-line changes (hg_diff) - Commit Management: Add files (
hg_add), commit changes (hg_commit), remove files (hg_remove), and amend the last commit (hg_amend) - Stashing: Temporarily shelve changes (
hg_shelve) and restore them (hg_unshelve) - File Inspection: View file content at any revision (
hg_cat) and rename or move files (hg_rename)
Branching & Navigation
- Navigation: Update to any revision, branch, or bookmark (
hg_update) - Named Branches: Create and list permanent Mercurial branches (
hg_branch) - Bookmarks: Manage lightweight, Git-like pointers (
hg_bookmark,hg_bookmarks) - Advanced Topics: WIP feature isolation with lightweight branches (
hg_topic,hg_topics,hg_topic_current) - Phases: Manage changeset phases for safe history rewriting (
hg_phases) - Tags: Create, remove, and list repository tags (
hg_tag,hg_tags)
Remote Synchronization
- Push/Pull: Sync changes with remote repositories (
hg_push,hg_pull) - Remote Insights: Preview incoming or outgoing changesets (
hg_incoming,hg_outgoing) - Path Management: List and manage configured remote paths (
hg_paths) - Branch Heads: Identify branch heads across the repository (
hg_heads)
History Rewriting & Recovery
- Rebase & Strip: Move changesets (
hg_rebase) or permanently remove them (hg_strip) - Evolve Toolset: Auto-amend (
hg_absorb), fold changesets (hg_fold), split changesets (hg_split), uncommit (hg_uncommit), prune (hg_prune), rewind for undo (hg_rewind), edit metadata (hg_metaedit) - Stack Navigation: Move through topic stacks (
hg_next,hg_previous,hg_stack) - Interactive Editing: Modify a linear series of changesets non-interactively (
hg_histedit) - Graft & Transplant: Copy changesets via merge machinery (
hg_graft) or patch-based (hg_transplant) - Backout: Reverse the effects of earlier changesets (
hg_backout) - Evolve: Track the evolution of rewritten changesets (
hg_evolve)
Merge & Conflict Resolution
- Merging: Combine changes from different branches (
hg_merge) - Conflict Management: List and track files with unresolved merge conflicts (
hg_resolve) - Revert: Discard uncommitted changes and restore files to their last committed state (
hg_revert)
Repository Inspection & Diagnostics
- Blame/Annotate: Show line-by-line changeset information (
hg_annotate) - Bisect: Binary search for regression-introducing changesets (
hg_bisect) - File Listing: List all tracked files in the current revision (
hg_files) - State Summary: Get a concise summary of the working directory state (
hg_summary) - Integrity & Identity: Verify repository integrity (
hg_verify) and identify the current revision (hg_identify) - Patch Management: Export changesets as patches (
hg_export) or import patch files (hg_import)
Technical Features
- Async I/O: Asynchronous command execution for high-performance operations
- Git Integration (hg-git): Automatic detection of Git-backed repos and branch mapping (
hg_git) - HTTP Transports: Streamable HTTP and SSE support for web-based clients (e.g., llama.cpp WebUI)
- Security: Jail path restriction (required for HTTP) and secure API key authentication
- JSON Output: Automatic JSON formatting for 20+ commands for easy machine parsing
- Large File Support: Management of binaries outside normal history (
hg_largefiles) - Diagnostics & Help: List extensions (
hg_extensions), config (hg_config), and access built-in help (hg_help) - Reliability: 349 tests with 87% coverage, using tmpfs on Linux for extremely fast verification
- 62 MCP Tools: Comprehensive coverage of Mercurial 7.1.x standard commands and built-in extensions
Installation
# Clone the repository
git clone <repository-url>
cd hg-mcp
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install in editable mode
pip install -e .
# Optional: Install with performance enhancements
pip install uvloop # On Unix/macOS
pip install winloop # On Windows
Usage
Standard Input/Output (stdio) - Default Mode
# Activate your virtual environment first
source .venv/bin/activate # On Windows: .venv\Scripts\activate
hg-mcp
This starts the MCP server using stdio transport, which can be used with MCP clients like Claude for Desktop, Qwen-Coder, Gemini-CLI, and OpenCode.
HTTP Transport (SSE and/or Streamable HTTP)
For web-based MCP clients like llama.cpp WebUI, you can run the server with HTTP transport:
# SSE only (compatible with llama.cpp WebUI)
hg-mcp --transport sse --port 8000
# Streamable HTTP only
hg-mcp --transport streamable-http --port 8000
# Both SSE and Streamable HTTP on the same server
hg-mcp --transport sse streamable-http --port 8000
Endpoints:
- SSE:
http://localhost:8000/sse - Streamable HTTP:
http://localhost:8000/mcp
Options:
--transport: One or more transport protocols (stdio,sse,streamable-http)- Default:
stdio - Multiple values:
--transport sse streamable-http
- Default:
--port: Port to listen on (default: 8000)--host: Host to bind to (default: 0.0.0.0)--api-key: Optional. Enable mandatory API key authentication. When set, clients must provide this key in their request headers.--jail: Required for HTTP transports. Restrict repository access to this directory tree for security.--mercurial: Optional. Path to the Mercurial (hg) executable. Defaults tohg(resolved from PATH). Example:--mercurial /usr/local/bin/hg
Security Features
When exposing the MCP server over TCP/IP, two security mechanisms are available:
1. Jail Path Restriction (--jail)
Required for all HTTP transports. This restricts repository access to a specific directory tree, preventing unauthorized access to paths outside the jail:
# Restrict access to /home/user/projects and its subdirectories
hg-mcp --transport streamable-http --port 8000 --jail /home/user/projects
2. API Key Authentication (--api-key)
Optional. You can require clients to authenticate by providing a valid API key. When this option is enabled, the server will reject any request that does not include a matching X-API-Key or API-Key header:
# Enable mandatory API key authentication
hg-mcp --transport streamable-http --port 8000 --jail /home/user/projects --api-key your-secret-key
Integration with AI Assistants
To use this MCP server with your AI coding assistant, point to the correct executable path in your virtual environment.
Configuration Examples
Claude Desktop / Qwen-Coder / Gemini-CLI
{
"mcpServers": {
"hg-mcp": {
"command": "/path/to/your/venv/bin/hg-mcp"
}
}
}
OpenCode
{
"mcp": {
"hg-mcp": {
"type": "local",
"command": ["/path/to/your/venv/bin/hg-mcp"],
"enabled": true
}
}
}
Requirements
- Python 3.10+
- Mercurial installed and available in PATH
- MCP-compatible client
Development
Running Tests
# Install development dependencies
pip install -e ".[dev]"
# Run all tests with coverage
./scripts/runtest.sh
Code Quality
# Run linting
./scripts/lint-check-and-fix.sh
# Run type checking
./scripts/type-check.sh
# Run formatter
./scripts/code-format.sh
Acknowledgments
This project is inspired by mcp-server-mercurial.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器