mihomo-mcp
# mihomo-mcp
> Bridge [mihomo](https://github.com/metacubex/mihomo) (clash meta) RESTful API to [Model Context Protocol](https://modelcontextprotocol.io).
> Switch proxies, refresh subscriptions, monitor traffic — directly from your AI client.
[](LICENSE)
[](pyproject.toml)
[](https://modelcontextprotocol.io)
**Status: v0.1.0 (public)** — 9 tools, 17 tests, verified on mihomo v1.19.24
## What is mihomo-mcp?
mihomo exposes a powerful RESTful API on `127.0.0.1:9090` (`external-controller`). This package wraps that API as MCP tools, so an AI client (Claude Code, OpenClaw, Cursor, etc.) can:
- List and switch proxy groups
- Test proxy latency
- Refresh provider subscriptions
- **Update provider subscription URL** (without restart in many cases)
- Set operating mode (rule / global / direct)
- Inspect active connections
## Requirements
- Python 3.10+
- mihomo running with `external-controller` enabled
- An MCP-compatible client (OpenClaw, Claude Code, Claude Desktop, etc.)
> **Not affiliated with mihomo.** This is a community project.
## Installation
```bash
# Recommended (uv)
uv tool install mihomo-mcp
# Or pip
pip install mihomo-mcp
# Or from source
git clone https://github.com/Aris-qin/mihomo-mcp.git
cd mihomo-mcp
pip install -e .
```
## Configuration
```yaml
# ~/.config/mihomo-mcp/config.yaml
mihomo:
host: 127.0.0.1
port: 9090
secret: "" # if mihomo has external-controller-secret
timeout: 10
```
Environment variables override file values:
| Var | Default |
|---|---|
| `MIHOMO_HOST` | `127.0.0.1` |
| `MIHOMO_PORT` | `9090` |
| `MIHOMO_SECRET` | (empty) |
| `MIHOMO_TIMEOUT` | `10` |
## Register with OpenClaw
In `openclaw.json`:
```json
{
"mcp": {
"servers": {
"mihomo": {
"type": "stdio",
"command": "mihomo-mcp",
"env": {
"MIHOMO_HOST": "127.0.0.1",
"MIHOMO_PORT": "9090"
}
}
}
}
}
```
## Register with Claude Desktop
Edit `claude_desktop_config.json`:
```json
{
"mcpServers": {
"mihomo": {
"command": "mihomo-mcp",
"env": {
"MIHOMO_HOST": "127.0.0.1",
"MIHOMO_PORT": "9090"
}
}
}
}
```
## Tools
| Tool | Description |
|---|---|
| `proxy_list` | List all proxy groups and their current selection |
| `proxy_select` | Switch a selector group to a specific proxy |
| `proxy_test` | Test latency of a single proxy |
| `proxy_test_group` | Test all proxies in a group, sorted by latency |
| `provider_list` | List providers (subscriptions) and node counts |
| `provider_healthcheck` | Trigger health check on a provider |
| `provider_update_url` | **Update provider's subscription URL and refresh** |
| `mode_set` | Switch operating mode (rule / global / direct) |
| `connections_list` | List active connections |
## Security & Privacy
1. **No subscription URL is persisted.** The `provider_update_url` tool receives a URL via MCP, forwards it to mihomo, and discards it. Nothing is logged or written to disk.
2. **Default host is `127.0.0.1`.** Overriding host to a public IP is not recommended and may be rejected in future versions.
3. **No credentials stored.** If your mihomo has `external-controller-secret`, pass it via `MIHOMO_SECRET` env var — never in config files checked into version control.
4. **No traffic proxying.** This package only manages mihomo state — it does not forward your traffic.
5. **Not affiliated with mihomo.** Community project, MIT licensed.
## License
MIT — see [LICENSE](LICENSE).
## Contributing
PRs welcome after the initial public release. Please open an issue first for major changes.
TDQS
Scored across 10 tools
Each tool targets a distinct resource+action: proxy_test vs proxy_test_group are clearly separate (single proxy vs group), provider_list/healthcheck/update_url each cover a unique provider operation, and mode_set, connections_list, and version are unambiguous. No two tools could be easily confused.
Names are mostly snake_case with a resource prefix and a verb (proxy_list, proxy_select, provider_update_url, mode_set), but 'version' is a bare noun and 'provider_healthcheck' is a compound rather than a clear verb_noun pattern. The slight inconsistencies are minor and do not harm readability.
10 tools is within the well-scoped 3-15 range. Each tool serves a meaningful operational purpose for controlling a mihomo proxy client, with no redundancy or bloat.
Core proxy operations are covered: list proxies, select proxy, test single/group latency, manage providers, set mode, view connections, and version. Missing features like config read/write or connection termination are minor gaps that do not block primary workflows.