google-alerts-mcp
Allows searching Google Alerts for news articles based on a query, with support for multiple languages and regions, and optional URL cleaning to remove Google redirect parameters.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@google-alerts-mcpfind news about artificial intelligence"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Google Alerts MCP Server
一个基于 MCP (Model Context Protocol) 的 Google Alerts 插件,通过模拟浏览器工作流程来获取特定主题的新闻资讯。该插件能够动态提取 Google Alerts 页面的状态参数,避免被检测和封锁。
本 MCP Server 需要访问 Google 服务,某些地区需要科学上网环境。
功能特性
动态状态提取:自动从 Google Alerts 页面提取
window.STATE参数防检测机制:每次请求使用新鲜的令牌和会话 cookies 避免被封锁
多语言支持:支持中文、英文等多种语言搜索
浏览器工作流程模拟:完全模拟浏览器访问流程:访问主页 → 提取 cookies/状态 → 构建预览 URL
无硬编码参数:所有认证令牌和状态参数都动态提取,不使用硬编码值
URL清理功能:可配置是否移除Google重定向参数,直接获取目标新闻链接
Related MCP server: mcp-techTrend
工作流程
获取初始 cookies:访问
https://www.google.com/alerts?hl={language}获取初始 cookies状态参数提取:从页面中提取
window.STATE参数,包括认证令牌构建预览 URL:使用提取的参数和搜索查询构建预览 URL
获取内容:使用正确的 cookies 和状态参数获取预览页面
文章解析:从 HTML 响应中提取文章标题、URL、摘要和来源
安装
使用 UV 包管理器:
# 克隆项目
git clone https://github.com/ycrao/google-alerts-mcp.git
cd google-alerts-mcp
# 安装依赖
uv sync
# 激活虚拟环境
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 或者直接
uv run python src/google_alerts_mcp/server.py使用方法
作为 MCP 服务器运行
在 MCP 客户端配置中添加:
{
"mcpServers": {
"google-alerts": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/google-alerts-mcp/src/google_alerts_mcp/",
"run",
"server.py"
],
"env": {}
}
}
}或者如果已经发布为包:
{
"mcpServers": {
"google-alerts": {
"command": "uvx",
"args": ["google-alerts-mcp"],
"env": {}
}
}
}可用工具
search_google_alerts
根据特定主题搜索 Google Alerts 新闻文章。
参数:
query(必需): 搜索查询/主题(如 "白银", "bitcoin", "人工智能")language(可选): 语言代码(默认: "zh-CN")region(可选): 地区代码(默认: "US")clean_urls(可选): 是否清理Google重定向参数获取直接链接(默认: true)
示例:
{
"query": "bitcoin",
"language": "en-US",
"region": "US",
"clean_urls": true
}URL清理功能:
当
clean_urls=true时,会自动移除Google重定向参数,直接返回目标新闻网站的链接当
clean_urls=false时,保留原始的Google重定向URL清理前:
https://www.google.com/url?q=https://example.com/article&sa=U&ved=...清理后:
https://example.com/article
技术细节
动态参数提取
服务器从 window.STATE 中提取以下参数:
domain: Google 域名(通常是 "com")language: 状态中的语言代码region: 状态中的地区代码number_param: 数字参数(因语言而异)locale_format: 区域格式字符串token: 认证令牌(避免检测的关键)
防检测功能
每次请求提取新鲜令牌
会话 cookie 持久化
正确的浏览器头部
无硬编码认证参数
令牌提取失败时优雅降级
测试
运行测试套件验证功能:
# 测试完整 MCP 服务器功能
python test_mcp_server.py测试示例
# 测试搜索功能
import asyncio
from google_alerts_mcp.server import GoogleAlertsClient
async def test():
client = GoogleAlertsClient()
try:
# 中文搜索
articles = await client.get_preview_content("白银", "zh-CN")
for article in articles:
print(f"标题: {article.title}")
print(f"链接: {article.url}")
print(f"摘要: {article.snippet}")
print(f"来源: {article.source}")
print("-" * 50)
# 英文搜索(启用URL清理)
client_clean = GoogleAlertsClient(clean_urls=True)
articles = await client_clean.get_preview_content("bitcoin", "en-US")
for article in articles:
print(f"Title: {article.title}")
print(f"URL: {article.url}") # 直接链接,无Google重定向参数
print(f"Snippet: {article.snippet}")
print(f"Source: {article.source}")
print("-" * 50)
await client_clean.close()
# 英文搜索(保留原始URL)
client_original = GoogleAlertsClient(clean_urls=False)
articles = await client_original.get_preview_content("bitcoin", "en-US")
for article in articles:
print(f"Title: {article.title}")
print(f"URL: {article.url}") # 包含Google重定向参数
print(f"Snippet: {article.snippet}")
print(f"Source: {article.source}")
print("-" * 50)
await client_original.close()
finally:
await client.close()
asyncio.run(test())注意事项
动态令牌:系统现在完全依赖动态提取的令牌,不再使用任何硬编码值
URL清理:默认启用URL清理功能,可通过
clean_urls=false参数保留原始Google重定向URL请求频率:避免过于频繁的请求,建议适当间隔
错误处理:如果令牌提取失败,请求会优雅失败而不是使用过时的硬编码值
实时状态:每次搜索都会获取新的状态参数,确保最佳的反检测效果
依赖库
mcp: Model Context Protocol 支持
httpx: 异步 HTTP 客户端
beautifulsoup4: HTML 解析
pydantic: 数据验证和序列化
许可证
MIT License
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Tools
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ycrao/google-alerts-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server