plausible-mcp

plausible-mcp

Enables querying Plausible Analytics data for website statistics, traffic, engagement, and conversions through natural language, with support for filters, dimensions, and time-series.

Category
访问服务器

README

Plausible Analytics MCP Server

A Model Context Protocol (MCP) server that provides access to the Plausible Analytics API for querying website statistics and analytics data.

Features

  • Full Plausible API Support: Query historical and real-time stats with filtering and dimensions
  • Multiple Query Tools:
    • plausible_query: Full-featured querying with filters and dimensions
    • plausible_aggregate: Simple aggregate stats
    • plausible_breakdown: Stats broken down by dimensions
    • plausible_timeseries: Time-based data for charts
  • Robust Error Handling: Automatic retries, timeout support, and detailed error messages
  • Connection Testing: Built-in health check on startup
  • Comprehensive Logging: Debug, info, and error logging through MCP

Prerequisites

  • Node.js 16 or higher
  • A Plausible Analytics account with API access
  • Plausible API key (get from https://plausible.io/settings/api-keys)

Installation

From Source

# Clone the repository
git clone https://github.com/yourusername/plausible-mcp.git
cd plausible-mcp

# Install dependencies
npm install

# Build the TypeScript code
npm run build

From NPM (when published)

npm install -g @your-org/mcp-plausible

Configuration

Environment Variables

Create a .env file in the project root (see examples/.env.example):

# Required
PLAUSIBLE_API_KEY=your-api-key-here

# Optional
PLAUSIBLE_API_URL=https://plausible.io  # For self-hosted instances
PLAUSIBLE_TIMEOUT=30000                 # Request timeout in ms

VS Code Integration

For VS Code extensions that support MCP (like Cline), add to your settings:

{
  "cline.mcpServers": {
    "plausible": {
      "command": "node",
      "args": ["/absolute/path/to/plausible-mcp/build/index.js"],
      "env": {
        "PLAUSIBLE_API_KEY": "${env:PLAUSIBLE_API_KEY}"
      }
    }
  }
}

See examples/vscode-settings.json for more configuration examples.

Claude Desktop Integration

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json

{
  "mcpServers": {
    "plausible": {
      "command": "node",
      "args": ["/absolute/path/to/plausible-mcp/build/index.js"],
      "env": {
        "PLAUSIBLE_API_KEY": "your-api-key-here"
      }
    }
  }
}

Usage

Once configured, the MCP server provides four main tools:

Getting Started

This MCP server lets you query Plausible Analytics for any site you own, directly from VS Code, Claude Desktop, or any MCP-compatible client. You can:

  • Get traffic, engagement, and conversion stats for your site
  • Break down analytics by page, device, country, source, and more
  • Run advanced filters and time-based queries
  • Automate reporting and SEO analysis

Quick Setup

  1. Get your Plausible API key from https://plausible.io/settings/api-keys
  2. Set up your .env file or VS Code/Claude config (see below)
  3. Start the MCP server:
    node build/index.js
    
  4. Connect with your MCP client and start querying!

Example Queries

Get traffic stats for your site

{
  "site_id": "alexop.dev",
  "metrics": ["visitors", "pageviews", "bounce_rate"],
  "date_range": "30d"
}

See top countries and devices

{
  "site_id": "alexop.dev",
  "metrics": ["visitors"],
  "date_range": "30d",
  "dimensions": ["visit:country_name", "visit:device"]
}

Analyze traffic sources and campaigns

{
  "site_id": "alexop.dev",
  "metrics": ["visitors"],
  "date_range": "30d",
  "dimensions": ["visit:source", "visit:utm_campaign"]
}

Get hourly traffic trends

{
  "site_id": "alexop.dev",
  "metrics": ["pageviews"],
  "date_range": "7d",
  "dimensions": ["time:hour"]
}

Conversion rate by source (if goals set)

{
  "site_id": "alexop.dev",
  "metrics": ["conversion_rate"],
  "date_range": "30d",
  "dimensions": ["visit:source"]
}

Scroll depth per page

{
  "site_id": "alexop.dev",
  "metrics": ["scroll_depth"],
  "date_range": "30d",
  "dimensions": ["event:page"]
}

What insights can you get?

  • Top pages, landing and exit pages
  • Device, browser, and OS breakdowns
  • Geographic breakdowns (country, region, city)
  • Traffic sources and UTM campaign performance
  • Conversion rates and custom event tracking
  • Scroll depth and time on page
  • Hourly/daily/weekly/monthly traffic trends
  • Advanced filters and segments

1. plausible_query

Full-featured querying with all Plausible API capabilities:

{
  "site_id": "example.com",
  "metrics": ["visitors", "pageviews", "bounce_rate"],
  "date_range": "7d",
  "filters": [
    ["is", "visit:country_name", ["United States", "Canada"]]
  ],
  "dimensions": ["visit:source"],
  "order_by": [["visitors", "desc"]],
  "pagination": { "limit": 10 }
}

2. plausible_aggregate

Simple aggregate stats without dimensions:

{
  "site_id": "example.com",
  "metrics": ["visitors", "pageviews"],
  "date_range": "month"
}

3. plausible_breakdown

Stats broken down by dimensions:

{
  "site_id": "example.com",
  "metrics": ["visitors"],
  "date_range": "7d",
  "dimensions": ["visit:country_name", "visit:device"],
  "limit": 20
}

4. plausible_timeseries

Time-based data for charts:

{
  "site_id": "example.com",
  "metrics": ["visitors", "pageviews"],
  "date_range": "30d",
  "interval": "time:day"
}

API Reference

Date Ranges

  • Relative: "day", "7d", "30d", "month", "6mo", "12mo", "year", "all"
  • Custom: ["2024-01-01", "2024-01-31"] (ISO 8601 format)

Metrics

  • Traffic: visitors, visits, pageviews, views_per_visit
  • Engagement: bounce_rate, visit_duration, scroll_depth
  • Events: events, conversion_rate, group_conversion_rate
  • Revenue: average_revenue, total_revenue
  • Other: percentage, time_on_page

Dimensions

Visit Dimensions

  • visit:source - Traffic source
  • visit:referrer - Referrer URL
  • visit:utm_medium - UTM medium
  • visit:utm_source - UTM source
  • visit:utm_campaign - UTM campaign
  • visit:utm_content - UTM content
  • visit:utm_term - UTM term
  • visit:device - Device type
  • visit:browser - Browser name
  • visit:browser_version - Browser version
  • visit:os - Operating system
  • visit:os_version - OS version
  • visit:country - Country code
  • visit:country_name - Country name
  • visit:region - Region code
  • visit:region_name - Region name
  • visit:city - City code
  • visit:city_name - City name

Event Dimensions

  • event:page - Page path
  • event:hostname - Hostname
  • event:goal - Goal name
  • event:props:* - Custom properties

Time Dimensions

  • time - Auto-detected
  • time:hour - Hourly
  • time:day - Daily
  • time:week - Weekly
  • time:month - Monthly

Filters

Simple Filters

["is", "visit:country", ["US", "CA"]]
["contains", "event:page", ["/blog/"]]
["matches", "visit:source", ["google.*"]]

Logical Filters

["and", [
  ["is", "visit:device", ["Mobile"]],
  ["is", "visit:country", ["US"]]
]]

["or", [
  ["is", "visit:source", ["google"]],
  ["is", "visit:source", ["bing"]]
]]

["not", ["is", "visit:country", ["US"]]]

Behavioral Filters

["has_done", ["is", "event:goal", ["Signup"]]]
["has_not_done", ["is", "event:goal", ["Purchase"]]]

Advanced Features

Error Handling

  • Automatic Retries: Failed requests are retried up to 3 times with exponential backoff
  • Rate Limit Handling: Respects Retry-After headers from Plausible API
  • Timeout Support: Configurable request timeout (default 30s)
  • Detailed Error Messages: Clear error messages with context

Logging

The server logs important events:

  • Connection status on startup
  • Tool invocations with parameters
  • Success/failure of queries
  • Detailed error information

To view logs:

  • Claude Desktop: tail -f ~/Library/Logs/Claude/mcp*.log (macOS)
  • VS Code: Check extension output panel

Development

# Install dependencies
npm install

# Run TypeScript compiler in watch mode
npm run build -- --watch

# Run linting
npm run lint

# Fix linting issues
npm run lint:fix

# Type checking
npm run typecheck

Troubleshooting

Connection Issues

  1. Check if API key is set correctly
  2. Verify network connectivity
  3. For self-hosted instances, ensure PLAUSIBLE_API_URL is correct
  4. Check logs for detailed error messages

Rate Limiting

  • Default limit: 600 requests/hour
  • Server automatically retries with backoff
  • Check Retry-After header in logs

Common Errors

  • "Authentication failed": Invalid API key
  • "Not found": Site doesn't exist or you don't have access
  • "Bad request": Check query parameters format

Security

  • Never commit API keys to version control
  • Use environment variables for sensitive data
  • Consider using secret management tools for production
  • All inputs are validated before sending to API

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

License

MIT - See LICENSE file for details

Support

  • Plausible API Docs: https://plausible.io/docs/stats-api
  • MCP Documentation: https://modelcontextprotocol.io
  • Issues: https://github.com/yourusername/plausible-mcp/issues

Changelog

1.0.0

  • Initial release with full Plausible Stats API support
  • Four specialized tools for different query types
  • Robust error handling and retry logic
  • Comprehensive logging through MCP
  • Connection health check on startup

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选