使用说明
谷歌趋势MCP服务器
⚠️ 重要安全通知:永远不要将API密钥提交到版本控制。此程序包需要通过环境变量设置API密钥。
一个MCP(模型上下文协议)服务器,通过Google趋势抓取器API提供对Google趋势数据的访问。
特性
- 状态:检查API状态和运行状况
- 问题:从谷歌趋势中获取趋势问题
- 趋势:从谷歌趋势中获取当前热门话题
安装
选项1:使用npx(推荐)
# Set your API key first
export GOOGLE_TRENDS_API_KEY="your-api-key-here"
# Run directly with npx
npx @andrewlwn77/google-trends-mcp
选项2:全局安装
npm install -g @andrewlwn77/google-trends-mcp
方案3:地方发展
git clone <repository-url>
cd google-trends-mcp
npm install
npm run build
配置
可选的:您可以设置 GOOGLE_TRENDS_API_KEY 环境变量。如果未设置,将使用默认的API密钥。
- 从获取API密钥 RapidAPI谷歌趋势抓取器
- 设置环境变量:
# Option 1: Export in your shell export GOOGLE_TRENDS_API_KEY="your-api-key-here" # Option 2: Create a .env file (for local development) echo "GOOGLE_TRENDS_API_KEY=your-api-key-here" > .env
⚠️ 安全:永远不要承诺你的 .env 文件或API密钥到版本控制!
用法
运行服务器
# If installed globally or using npx
google-trends-mcp
# For local development
npm start
# For development with auto-reload
npm run dev
可用工具
1. google_trends_status
查看Google趋势API的状态。
参数:
language(可选):语言代码(默认值:“en”)country(可选):国家代码(默认值:“US”)
2. google_trends_questions
从谷歌趋势中获取趋势问题。
参数:
language(可选):语言代码(默认值:“en”)country(可选):国家代码(默认值:“US”)
3. google_trends_trending
从谷歌趋势中获取当前热门话题。
参数:
language(可选):语言代码(默认值:“en”)country(可选):国家代码(默认值:“US”)
MCP客户端使用示例
// Check API status
const status = await client.callTool('google_trends_status', {
language: 'en',
country: 'US'
});
// Get trending questions
const questions = await client.callTool('google_trends_questions', {
language: 'en',
country: 'US'
});
// Get trending topics
const trending = await client.callTool('google_trends_trending', {
language: 'en',
country: 'US'
});
配置
可以使用环境变量配置服务器:
GOOGLE_TRENDS_API_KEY:Google Trends Scraper API的RapidAPI密钥(可选,默认为示例密钥)
发展
项目结构
google-trends-mcp/
├── src/
│ ├── index.ts # Main MCP server implementation
│ └── types.ts # TypeScript type definitions
├── tests/
│ ├── integration/ # API integration tests
│ ├── unit/ # Unit tests
│ └── helpers/ # Test helper utilities
├── package.json
├── tsconfig.json
├── .env.example
└── README.md
类型安全
此服务器是用TypeScript编写的,为以下内容提供了完全的类型安全:
- API参数
- API响应
- 错误处理
- 谷歌趋势数据结构
许可证
麻省理工学院