内容
# ai-visibility-mcp
> 一个用于审核和修复AI如何看待您的网站的MCP服务器。 机器人,架构,LLM提及,Cloudflare AI默认值 — 审核问题,生成修复方案,在一个循环中重新审核。
[](https://www.python.org/) [](https://modelcontextprotocol.io/) [](LICENSE)
大多数网站都意外地对AI搜索不可见。Cloudflare的机器人管理默认值阻止了GPTBot / ClaudeBot / PerplexityBot。 单页应用(SPAs)为不运行JS的爬虫程序渲染一个空的`<div id="root">`。 市场团队不知道他们的品牌在ChatGPT,Claude或Perplexity答案中没有浮现 — 直到流量枯竭。
`ai-visibility-mcp` 在单个代理会话中关闭了审核和修复循环:
1. **审核** — 查找阻止AI可见性的内容
2. **修复** — 生成纠正它的工件
3. **粘贴** — 站点所有者应用输出
4. **重新审核** — 验证修复是否被采纳
## 工具
### 审核工具
| 工具 | 目的 | 需要API密钥? |
|---|---|---|
| `check_ai_bot_access(domain)` | 按机器人robots.txt + Cloudflare AI默认标志,适用于22个AI用户代理 | 否 |
| `audit_ai_visibility(domain)` | 0-100综合评分,附有可解释的扣除项(robots,meta,JSON-LD,sitemap,llms.txt,SPA shell) | 否 |
| `check_llm_mention(brand, query, aliases?, models?)` | 跨模型品牌浮现(默认为Perplexity sonar + OpenAI gpt-4o-mini + Gemini 2.0 Flash) | 是 |
| `compare_competitors(your_domain, competitor_domains[])` | 并行排名审核,最大10个同时进行 | 否 |
### 生成器工具(v0.3)
| 工具 | 目的 | LLM调用? |
|---|---|---|
| `generate_robots_patch(domain, allow_bots?, deny_bots?)` | 纠正的robots.txt,开放AI机器人访问;保留现有规则;检测Cloudflare | 否 |
| `generate_json_ld(url, page_type?)` | 适用于任何页面的Schema.org JSON-LD块;自动检测类型(Product/Article/Organization/FAQPage/SoftwareApplication/WebSite);验证必填字段 | 是(gpt-4o-mini) |
| `generate_llms_txt(domain, crawl_depth?, max_pages?)` | 符合规范的llms.txt;爬取首页 + sitemap;优雅地回退到链接提取 | 是(gpt-4o-mini) |
## 为什么存在
- **Cloudflare在2024-2025年翻转了默认值** 以阻止AI爬虫。 大多数站点所有者从未更新他们的配置,因此AI机器人被质疑并弹回。
- **MCP市场于2026年推出** (MCP Hive,Smithery,mcp.so,Glama)。 每个AI代理都需要可以审核真实网络的工具。 这是其中之一。
- **LLM答案中的品牌可见性是新的SEO**。 没有人拥有一个干净的堆栈来从单个MCP调用中衡量它。
## 安装
需要Python 3.10+和[uv](https://docs.astral.sh/uv/)。
```bash
git clone https://github.com/bestaiinsider/ai-visibility-mcp
cd ai-visibility-mcp
uv sync
cp .env.example .env # 填写PERPLEXITY_API_KEY / OPENROUTER_API_KEY
```
## 运行
```bash
# 标准输入输出传输 — Claude Desktop / Claude Code
uv run ai-visibility-mcp
# HTTP传输 — 远程代理
uv run ai-visibility-mcp --http --port 8000
```
## Claude Desktop / Claude Code 配置
添加到 `~/Library/Application Support/Claude/claude_desktop_config.json` (桌面)或 `~/.claude.json` (CLI):
```json
{
"mcpServers": {
"ai-visibility": {
"command": "uv",
"args": ["--directory", "/absolute/path/to/ai-visibility-mcp", "run", "ai-visibility-mcp"]
}
}
}
```
## 审核和修复循环
```
# 步骤1 — 审核
> audit_ai_visibility(domain="example.com")
score: 55
warnings:
- "9/22 AI 机器人被阻止 — 网站对AI搜索基本不可见"
- "没有JSON-LD结构化数据 — LLMs丢失实体基础"
- "未在根目录找到/llms.txt"
# 步骤2 — 生成修复
> generate_robots_patch(domain="example.com")
→ new_robots: "User-agent: GPTBot\nAllow: /\n\nUser-agent: ClaudeBot\nAllow: /\n..."
→ diff: 统一的更改差异
→ paste_target: "/robots.txt 在站点根目录,替换现有文件"
> generate_json_ld(url="https://example.com/")
→ page_type_detected: "Organization"
→ script_tag: '<script type="application/ld+json">{"@context":"https://schema.org","@type":"Organization"...}</script>'
→ paste_target: "在<head>内部"
> generate_llms_txt(domain="example.com")
→ content: "# Example Corp\n\n> 一句话总结...\n\n## 页面\n- [首页](...): ..."
→ paste_target: "/llms.txt"
# 步骤3 — 站点所有者粘贴三个工件
# 步骤4 — 重新审核
> audit_ai_visibility(domain="example.com")
score: 95 ← 曾为55
```
## 示例会话
```
> check_ai_bot_access(domain="bandcamp.com")
summary: { total: 22, allowed: 13, disallowed: 9 }
warnings: ["9/22 AI 机器人被阻止 — 网站对AI搜索基本不可见"]
blocked: ["GPTBot", "ClaudeBot", "Google-Extended", "Bytespider",
"CCBot", "Meta-ExternalAgent", "FacebookBot", "Amazonbot", "Diffbot"]
> audit_ai_visibility(domain="bandcamp.com")
score: 49
reasons:
-36: 9 AI 机器人在robots.txt中被阻止
-10: 没有JSON-LD结构化数据
-5: 没有/sitemap.xml
> check_llm_mention(brand="Anthropic", query="谁制造了领先的基础AI模型?")
share_of_voice: 0.667
by_model:
perplexity/sonar mentioned=true citations=3
openrouter/gpt-4o-mini mentioned=true citations=0
openrouter/gemini-flash mentioned=false citations=0
est_total_cost_usd: 0.00088
daily_spend_usd: 0.00088 / $5.00 cap
```
## 安全态势
此服务器向调用者提供的域名和LLM提供商发出外部HTTP请求。 v0.2强化:
- **SSRF防护。** 所有外部HTTP请求拒绝环回,链路本地(AWS / GCP / Azure元数据IP),RFC1918,CGNAT和IPv6 ULA地址。 重定向被重新验证。
- **每日支出上限。** LLM调用由`MAX_DAILY_USD`(默认5.00美元)控制,持续到`~/.cache/ai-visibility-mcp/spend.json`。 环路放大无法耗尽您的Perplexity / OpenRouter积分。
- **每次调用成本上限。** `MAX_COST_PER_CALL`(默认0.10美元)加上`LLM_MAX_OUTPUT_TOKENS`(默认1024)硬绑定任何单个工具调用。
- **不保留用户内容。** 除了每日支出总额外,磁盘上不记录任何内容。
## 配置
| 环境变量 | 默认值 | 目的 |
|---|---|---|
| `PERPLEXITY_API_KEY` | — | `check_llm_mention`中Perplexity模型所需 |
| `OPENROUTER_API_KEY` | — | 通过OpenRouter所需的OpenAI / Gemini / Claude |
| `MAX_COST_PER_CALL` | `0.10` | 每次工具调用的美元上限 |
| `MAX_DAILY_USD` | `5.00` | 每日UTC美元上限,已持久化 |
| `LLM_MAX_OUTPUT_TOKENS` | `1024` | 每个LLM调用的输出令牌硬上限 |
| `AI_VISIBILITY_SPEND_FILE` | `~/.cache/ai-visibility-mcp/spend.json` | 覆盖支出账本位置 |
## 开发
```bash
uv sync --extra dev
uv run pytest # 40个测试
uv run ruff check . # lint
```
## 状态
v0.3 — 审核 + 修复循环完成。 7个工具(4个审核 + 3个生成器),40/40个测试,SSRF强化,支出上限。 在tealhq.com / bandcamp.com / anthropic.com上进行了烟雾验证。
## 许可证
MIT。