MCP Google Trends Server

MCP Google Trends Server

Provides access to Google Trends search interest data with backtesting support, allowing retrieval of historical 30-day trend windows ending at specified cutoff dates for forecasting applications without future information leakage.

Category
访问服务器

README

MCP Google Trends Server

MCP server providing Google Trends search interest data with backtesting support via cutoff date filtering.

Overview

This server provides a tool to retrieve Google Trends data for any search query over a 30-day period ending at a specified cutoff date. It's designed for forecasting applications that require historical search interest data without future information leakage.

Features

  • Backtesting Compliant: All data is strictly filtered to before the cutoff date
  • 30-Day Windows: Retrieves search interest trends for the 30 days before cutoff
  • US Region: Currently configured for US search interest data
  • 0-100 Scale: Returns normalized interest scores where 100 = peak popularity

Tools

get_google_trends

Get Google Trends data for a query over the past 30 days before a cutoff date.

Parameters:

  • query (str): The search query to analyze trends for
  • cutoff_date (str): ISO format date (YYYY-MM-DD) - retrieve trends data ending at this date

Returns:

  • Formatted string with:
    • Query term
    • Time period (30 days before cutoff_date to cutoff_date)
    • Region (US)
    • Interest over time data (0-100 scale)
    • Marks partial data entries

Example:

result = await get_google_trends(
    query="artificial intelligence",
    cutoff_date="2024-06-01"
)
# Returns trends from 2024-05-02 to 2024-06-01

Environment Variables

Required:

  • SERPAPI_API_KEY: API key for SerpAPI Google Trends access

Get your API key at: https://serpapi.com/

Installation

cd mcp-google-trends
uv sync

Usage

Testing Locally

mcp run -t sse google_trends_server.py:mcp

As Git Submodule

git submodule add <repo-url> mcp-servers/mcp-google-trends

Backtesting Compliance

This server is designed for use in forecasting applications that require strict temporal boundaries:

  1. Date Range Enforcement: The 30-day window is calculated from the cutoff_date backwards
  2. API-Level Filtering: Date constraints are passed directly to SerpAPI's Google Trends engine
  3. No Future Data: All returned data points are guaranteed to be from before the cutoff_date

This makes it safe to use in backtesting scenarios where you're simulating predictions made at historical points in time.

Testing

Setup

  1. Install test dependencies:
uv pip install -e ".[test]"
  1. Configure environment variables by copying .env.example to .env:
cp .env.example .env
  1. Add your API key to .env:
    • SERPAPI_API_KEY - Required from https://serpapi.com/

Running Tests

Run all tests:

pytest

Run with verbose output:

pytest -v

Run specific test file:

pytest tests/test_google_trends_server.py

Run specific test:

pytest tests/test_google_trends_server.py::test_get_google_trends_basic -v

Test Coverage

The test suite covers:

  • Basic functionality: Standard Google Trends queries with various topics
  • Date handling: Different cutoff dates (recent, historical, future, invalid)
  • Query types: Single words, multi-word phrases, brands, special characters, numeric queries
  • Output format: Verification of all expected sections (header, period, region, data points)
  • Date range: Validation of 30-day lookback window
  • Error handling: Invalid date formats, malformed dates
  • Region info: Verification of US region specification

Note: Tests make real API calls to SerpAPI and require a valid SERPAPI_API_KEY. Tests will be skipped if the API key is not set. API rate limits and costs may apply.

Dependencies

  • fastmcp: MCP server framework
  • serpapi: SerpAPI Python client for Google Trends access
  • python-dotenv: Environment variable management

API Details

Uses SerpAPI's Google Trends engine with the following parameters:

  • data_type: "TIMESERIES" - returns time-series data
  • geo: "US" - United States region
  • tz: 0 - UTC timezone
  • date: Date range in format "{start_date} {end_date}"

Error Handling

The tool returns user-friendly error messages for common issues:

  • Invalid date format (not YYYY-MM-DD)
  • Missing SERPAPI_API_KEY
  • API request failures
  • No data found for query

All errors are returned as strings rather than raising exceptions, making integration more predictable.

Limitations

  • Currently configured for US region only (can be extended to other regions)
  • Fixed 30-day lookback window (can be made configurable)
  • Requires active SerpAPI subscription with Google Trends access

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选