内容
# tor-mcp
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/downloads/)
[](https://github.com/rushikeshmore/tor-mcp/actions/workflows/tests.yml)
> 每个LLM工具的网络请求都会泄露您的IP地址。tor-mcp将请求通过Tor路由,并支持按URL选择路由,确保某些阻止Tor的服务仍可正常工作。
适用于Claude Code、Claude Desktop、Cursor、Windsurf以及其他MCP客户端的MCP服务器。快速接入,享受匿名网络请求服务。
## 为什么存在
当LLM代理使用`fetch`或`web_search`等工具时,请求直接从您的机器发出。您的IP地址、ISP、地理位置和指纹都会被暴露。对于OSINT查找、漏洞检查、威胁情报API或简单的匿名需求,这是一个设计上的漏洞。
tor-mcp作为MCP服务器,将代理的网络请求通过本地Tor SOCKS5代理路由,确保DNS安全(使用`socks5h://`,无DNS泄露)。它不旨在匿名您的浏览器,而是匿名化AI工具为您进行的网络请求。
## 您将获得
四个MCP工具,均支持JSON和Markdown输出:
| 工具 | 功能 |
|---|---|
| `tor_private_fetch` | 获取URL。通过Tor或直接路由,基于URL模式匹配或强制使用`force_tor` / `force_direct`(互斥)。 |
| `tor_check_anonymity` | 验证Tor是否活跃。比较Tor出口IP与您的真实IP,通过多提供商备用链。 |
| `tor_new_identity` | 旋转Tor电路。通过Tor控制端口获取新的出口IP,速率限制为每10秒一次。 |
| `tor_privacy_status` | 完整健康检查:连接、出口IP、控制端口、路由规则、配置。 |
### 示例输出
`tor_private_fetch(url="https://api.ipify.org?format=json")` →
```json
{
"status_code": 200,
"url": "https://api.ipify.org?format=json",
"content_type": "application/json",
"content": "{\"ip\":\"185.220.101.20\"}",
"routed_through": "tor",
"routing": {"route": "tor", "reason": "default route: tor"}
}
```
`tor_check_anonymity(response_format="markdown")` →
```markdown
## 匿名性检查
- **状态**: 匿名
- **Tor 出口 IP**: 185.220.101.20
- **直接 IP**: 106.213.80.181
- **Tor 验证**: 是
```
## 快速开始
### 1. 安装Tor
```bash
# macOS
brew install tor && brew services start tor
# Ubuntu/Debian
sudo apt install tor && sudo systemctl start tor
# 验证
curl --socks5-hostname 127.0.0.1:9050 https://check.torproject.org/api/ip
```
### 2. 克隆并添加到您的MCP客户端
```bash
git clone https://github.com/rushikeshmore/tor-mcp.git
cd tor-mcp
uv sync
```
<details>
<summary>Claude Code</summary>
```bash
claude mcp add tor-mcp -- uv --directory $(pwd) run tor-mcp
```
</details>
<details>
<summary>Claude Desktop</summary>
在 `claude_desktop_config.json` 中:
```json
{
"mcpServers": {
"tor-mcp": {
"command": "uv",
"args": ["--directory", "/absolute/path/to/tor-mcp", "run", "tor-mcp"]
}
}
}
```
</details>
<details>
<summary>Cursor / Windsurf / 通用MCP客户端</summary>
```json
{
"mcpServers": {
"tor-mcp": {
"command": "uv",
"args": ["--directory", "/absolute/path/to/tor-mcp", "run", "tor-mcp"],
"env": {
"TOR_SOCKS_PORT": "9050",
"TOR_DEFAULT_ROUTE": "tor"
}
}
}
}
```
</details>
您也可以使用 `python -m tor_mcp` 启动服务器,如果它已安装在您的环境中。
### 3. 可选:启用电路旋转
要使用 `tor_new_identity`,请编辑您的 `torrc`(macOS上的 `/usr/local/etc/tor/torrc`,Linux上的 `/etc/tor/torrc`):
```
ControlPort 9051
CookieAuthentication 1
```
之后重启Tor。
## 路由
URL → 路由按以下顺序决定:
| 优先级 | 规则 | 路由 |
|---|---|---|
| 1 | `.onion` 域名 | Tor(始终) |
| 2 | `localhost`、`127.0.0.1`、`*.local` | 直接(始终) |
| 3 | 用户 `TOR_PATTERNS` | Tor |
| 4 | 用户 `DIRECT_PATTERNS` | 直接 |
| 5 | 默认OSINT/安全域名(Shodan、HIBP、Censys、urlscan、VirusTotal、OTX、crt.sh) | Tor |
| 6 | 默认阻止Tor的域名(GitHub、OpenAI、Anthropic、Google) | 直接 |
| 7 | 其他所有情况 | `TOR_DEFAULT_ROUTE`(默认:`tor`) |
没有方案的URL输入会自动添加方案 — 远程主机使用 `https://`,`localhost` / `127.0.0.1` / `*.local` 使用 `http://`,以防止与纯开发服务器的TLS冲突。
## 配置
所有配置均通过环境变量:
| 变量 | 默认值 | 描述 |
|---|---|---|
| `TOR_SOCKS_PORT` | `9050` | Tor SOCKS5代理端口 |
| `TOR_CONTROL_PORT` | `9051` | Tor控制端口(用于电路旋转) |
| `TOR_CONTROL_PASSWORD` | | 控制端口密码(如果在torrc中设置) |
| `TOR_DEFAULT_ROUTE` | `tor` | 默认路由:`tor`或`direct` |
| `TOR_TIMEOUT` | `30` | HTTP请求超时(秒) |
| `TOR_PATTERNS` | | 以逗号分隔的要通过Tor路由的主机名列表(支持 `*.example.com`) |
| `DIRECT_PATTERNS` | | 以逗号分隔的要直接路由的主机名列表 |
## 威胁模型
tor-mcp **保护**:
- LLM工具发出的HTTP(S)请求的源IP暴露。流量从Tor中继器退出,而不是您的家庭IP。
- DNS泄露。SOCKS5h强制在出口处进行远程DNS解析;您的解析器看不到目标主机名。
- 基于源的简单地理围栏和IP速率限制(使用 `tor_new_identity`进行旋转)。
tor-mcp **不保护**:
- TLS / JA3 / HTTP头指纹识别。流量通过Tor,但仍然可以识别为Python `httpx`。如果目标比较指纹,他们可以识别。
- 来自全球对手的流量关联。标准的Tor警告。
- 账户级去匿名化。如果您登录,目标知道您是谁,与路由无关。
- 浏览器指纹识别。不适用 — 这里没有浏览器,只有HTTP客户端。
- 操作系统 / 进程 / 剪贴板 / 文件系统元数据。tor-mcp仅处理HTTP流量。
- 恶意或监控退出。使用HTTPS-only目标,将退出服务的内容视为不信任。
没有身份验证的Tor控制端口假设是单用户机器。在共享或多用户主机上,请设置 `TOR_CONTROL_PASSWORD`和 `torrc`中的哈希密码。
这是一个隐私工具,而不是一个逃避工具。不要将其用于欺诈、滥用或您不愿意解释的事情。Tor退出操作员会因人们这样做而受到很多批评,不法行为者会伤害整个网络。
## 工具(参数)
### `tor_private_fetch`
- `url`(字符串,必填):目标URL。
- `method`(字符串,可选):`GET`、`POST`、`HEAD`、`PUT`、`DELETE`、`PATCH`、`OPTIONS`。默认为 `GET`。
- `force_tor`(布尔值,可选):强制使用Tor,无论路由规则如何。
- `force_direct`(布尔值,可选):强制直接路由,无论路由规则如何。
同时设置 `force_tor=true` 和 `force_direct=true` 是无效的。
- `response_format`(字符串,可选):`json` 或 `markdown`。默认为 `json`。
### `tor_check_anonymity`
- `response_format`(字符串,可选):`json` 或 `markdown`。默认为 `json`。
通过多提供商链(ipify → httpbin → ifconfig.co)比较Tor出口IP和直接IP,以防止单个提供商宕机。
### `tor_new_identity`
- `verify`(布尔值,可选):检查IP是否实际更改。默认为 `true`。
- `response_format`(字符串,可选):`json` 或 `markdown`。默认为 `json`。
### `tor_privacy_status`
- `response_format`(字符串,可选):`json` 或 `markdown`。默认为 `json`。
## 开发
```bash
git clone https://github.com/rushikeshmore/tor-mcp.git
cd tor-mcp
uv sync --dev
uv run python -m pytest # 运行测试(不需要Tor,所有测试均模拟)
uv run python -m ruff check src/ tests/
uv run tor-mcp # 在标准输入/输出上启动MCP服务器
```
测试完全模拟 — 您不需要运行Tor来进行开发。在 `CLAUDE.md` 中记录了针对正在运行的Tor守护进程的实时验证。
## 许可证
[MIT](LICENSE)。