Google搜索控制台MCP服务器

连接Google搜索控制台与Claude、Cursor等MCP客户端,提供搜索分析、SEO优化工具及报告功能。

  • by AppsYogi-com
  • TypeScript
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 AppsYogi-com/gsc-mcp-server

使用说明

GSC MCP服务器

谷歌搜索控制台MCP服务器——将谷歌搜索控制台连接到Claude、Cursor和其他MCP客户端。

特性

  • 🔍 搜索分析 --查询点击次数、展示次数、点击率和位置数据
  • 📊 SEO机会 --查找低点击率关键字,检测蚕食问题
  • 📈 报告 --每周总结、期间比较
  • 🗺️ 站点地图 --列出、提交和管理站点地图
  • 🔎 URL检查 --检查索引状态(需要完整范围)
  • 💾 缓存 --SQLite缓存可实现更快的重复查询
  • 🔐 安全 --存储在操作系统密钥链中的OAuth令牌

快速开始

# Install globally
npm install -g @appsyogi/gsc-mcp-server

# Set up OAuth credentials
gsc-mcp init

# Verify setup
gsc-mcp doctor

# Start the server (for MCP clients)
gsc-mcp run

先决条件

1.创建Google Cloud OAuth凭据

您需要在Google Cloud Console中创建自己的OAuth凭据:

  1. 首选 谷歌云控制台
  2. 创建新项目或选择现有项目
  3. 启用 谷歌搜索控制台API:
    • 转到“API和服务”→ “图书馆”
    • 搜索“谷歌搜索控制台API”
    • 点击“启用”
  4. 创建OAuth凭据:
    • 转到“API和服务”→ “凭据”
    • 点击“创建凭据”→ “OAuth客户端ID”
    • 选择“桌面应用程序”
    • 命名(例如,“GSC-MCP”)
    • 点击“创建”
  5. 复制 客户端ID 和 客户端密钥
  6. 添加测试用户(应用程序处于测试模式时需要):
    • 转到“API和服务”→ “OAuth同意屏幕”
    • 滚动到“测试用户”部分
    • 点击“添加用户”
    • 添加您将用于身份验证的Google帐户电子邮件
    • 点击“保存”

注: 虽然您的应用程序的发布状态为“测试”,但只有测试用户可以进行身份验证。您最多可以添加100个测试用户。

2.配置GSC-MCP

运行init命令并输入您的凭据:

gsc-mcp init

这将:

  • 提示输入您的客户端ID和客户端密码
  • 打开浏览器进行谷歌身份验证
  • 将刷新令牌安全地存储在操作系统密钥链中

用法

CLI命令

# Initialize with OAuth (interactive)
gsc-mcp init

# Initialize with service account
gsc-mcp init --service-account /path/to/key.json

# Initialize with full scope (for sitemap submission, URL inspection)
gsc-mcp init --scope full

# Check configuration and connectivity
gsc-mcp doctor
gsc-mcp doctor --verbose

# Start MCP server (stdio mode)
gsc-mcp run

# Start in HTTP mode (for debugging)
gsc-mcp run --http 3333

# View current configuration
gsc-mcp config

# Clear credentials
gsc-mcp logout

MCP客户端配置

克劳德桌面版

添加到您的Claude桌面配置(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):

{
  "mcpServers": {
    "gsc": {
      "command": "gsc-mcp",
      "args": ["run"]
    }
  }
}

VS代码(副本)

添加到您的VS代码MCP设置(~/.vscode/mcp.json 或工作空间设置):

{
  "servers": {
    "gsc": {
      "command": "gsc-mcp",
      "args": ["run"],
      "type": "stdio"
    }
  }
}

光标

添加到光标MCP配置中:

{
  "mcpServers": {
    "gsc": {
      "command": "npx",
      "args": ["-y", "@appsyogi/gsc-mcp-server", "run"]
    }
  }
}

可用工具

搜索分析

工具 说明
searchanalytics.query 使用维度和过滤器查询搜索性能数据
report.comparePeriods 比较两个时间段

站点地图

工具 描述 范围
sitemaps.list 列出所有站点地图 只读
sitemaps.get 获取站点地图详细信息 只读
sitemaps.submit 提交站点地图 完整版
sitemaps.delete 删除站点地图 完整

URL检查

工具 描述 范围
urlInspection.inspect 检查URL的索引状态 已满
urlInspection.batchInspect 检查多个URL 已满

SEO机会

工具 说明
opportunities.lowCtrHighPos 查找速赢关键词(位置4-20,点击率低)
opportunities.cannibalization 检测关键字蚕食
report.weeklySummary 生成每周绩效总结

出口

工具 说明
export.csv 将数据导出为CSV
export.json 将数据导出为JSON

LLM优化(v0.2.0+)

所有工具都支持参数,以减少LLM用例的令牌消耗:

紧凑的响应格式

添加 format: "compact" 任何LLM优化输出工具:

{
  "siteUrl": "sc-domain:example.com",
  "startDate": "2026-01-01",
  "endDate": "2026-01-28",
  "dimensions": ["query"],
  "format": "compact"
}

紧凑格式功能:

  • 短键名(imp 而不是 impressions, pos 而不是 position)
  • CTR作为百分比字符串("5.41%" 而不是 0.054123...)
  • 自然语言摘要字段
  • 从页面路径中删除URL前缀

紧凑型响应示例:

{
  "summary": "Top query 'example keyword' got 150 clicks at position 3.2",
  "rows": [
    {"key": "example keyword", "clicks": 150, "imp": 2800, "ctr": "5.36%", "pos": 3.2}
  ]
}

日期汇总粒度

对于日期维度查询,请使用 granularity 为了减少行数:

{
  "siteUrl": "sc-domain:example.com",
  "startDate": "2025-07-01",
  "endDate": "2026-01-28",
  "dimensions": ["date"],
  "granularity": "weekly"
}

选项:

  • daily --默认值,返回每日数据
  • weekly --按周汇总(以星期一为基础)
  • monthly --按月汇总
  • auto --基于日期范围的选择(>90天=每月,>21天=每周)

默认行限制

默认 rowLimit 是 25 (针对LLM上下文窗口进行了优化)。需要时使用更高的值:

{
  "siteUrl": "sc-domain:example.com",
  "rowLimit": 100
}

最大值:25000行。

资源

服务器公开了可浏览的资源:

  • gsc://sites --列出所有属性
  • gsc://sites/{siteUrl}/sitemaps --列出房产的网站地图

范围

GSC-MCP支持两个权限级别:

只读(默认)

  • 搜索分析查询
  • 列出网站地图
  • SEO分析工具
gsc-mcp init  # Uses readonly by default

满的

  • 所有内容均为只读,另外:
  • 提交/删除站点地图
  • URL检查
gsc-mcp init --scope full

配置文件

GSC-MCP将配置存储在平台特定位置:

平台 配置路径
macOS ~/.config/gsc-mcp/
Linux ~/.config/gsc-mcp/
窗户 %APPDATA%/gsc-mcp/

文件夹:

  • config.json --OAuth客户端ID/秘密、范围设置
  • cache.sqlite --查询缓存和保存的预设

令牌在可用时安全地存储在操作系统密钥链中。

服务帐户设置

对于自动化/服务器使用,您可以使用服务帐户而不是OAuth:

  1. 在Google Cloud Console中创建服务帐户
  2. 下载JSON密钥文件
  3. 在Google Search Console中将服务帐户电子邮件添加为所有者
  4. 初始化:
gsc-mcp init --service-account /path/to/key.json

API配额

Google搜索控制台API的默认配额为 每天1200次查询GSC-MCP包括:

  • 指数回退自动重试
  • 查询缓存以减少API调用
  • 大型结果集的分页处理

例子

查找速赢关键词

Use gsc-mcp to find quick-win opportunities for my site https://example.com

周报

Generate a weekly performance summary for https://example.com

比较时段

Compare search performance for https://example.com between last week and the week before

导出数据

Export the top 1000 queries for https://example.com in the last 28 days as CSV

发展

# Clone the repo
git clone https://github.com/AppsYogi-com/gsc-mcp-server.git
cd gsc-mcp-server

# Install dependencies
npm install

# Build
npm run build

# Run in dev mode
npm run dev

# Test locally
node dist/cli/index.js doctor

许可证

麻省理工学院

贡献

欢迎投稿!请打开问题或PR。

学分

内置: