Goatcounter MCP Server

Goatcounter MCP Server

Enables language models to query Goatcounter web analytics data, including pageviews, visitor statistics, referrers, browsers, and operating systems through a standardized tool interface with automatic rate limit handling.

Category
访问服务器

README

Goatcounter MCP Server

smithery badge

Overview

This project provides a Model Context Protocol (MCP) server for interacting with the Goatcounter web analytics API. It allows language models or other MCP clients to easily query Goatcounter statistics and information using a standardized tool interface.

The server is built using Python and the FastMCP library. It reads your Goatcounter site code and API key from environment variables for authentication.

Features

  • Provides tools for most Goatcounter API endpoints.
  • Handles API key and site code configuration via environment variables (GOATCOUNTER_API_KEY, GOATCOUNTER_CODE).
  • Lazy initialization of the API client: Tools can be listed even if API credentials are not yet configured.
  • Rate Limit Handling: Implements automatic retries with backoff when encountering API rate limits (HTTP 429).
    • Prioritizes the X-Rate-Limit-Reset header for waiting if provided by the API.
    • Falls back to exponential backoff (starting at 1 second) with random jitter if the header is unavailable or invalid.
    • Retries up to 5 times before failing.
  • Runs directly using the fastmcp command-line tool.

Installation

Option 1: Installing via Smithery (Recommended)

To install X (Twitter) MCP server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @rafaljanicki/goatcounter-mcp-server --client claude

Option 2: Install from PyPI

The easiest way to install goatcounter-mcp-server is via PyPI:

pip install goatcounter-mcp-server

Or install directly from the repository:

pip install git+https://github.com/rafaljanicki/goatcounter-mcp-server.git

Option 3: Install from Source

If you prefer to install from the source repository:

  1. Clone the repository:

    git clone https://github.com/rafaljanicki/goatcounter-mcp-server
    cd goatcounter-mcp-server
    
  2. Create a virtual environment:

    python3.13 -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    
  3. Install dependencies: Install FastMCP and other required packages:

    pip install -r requirements.txt
    
  4. Configure environment variables: Copy the example .env.example file to .env:

    cp .env.example .env
    

    Edit the .env file and add your Goatcounter details (see Environment Variables section below).

Environment Variables

The server requires the following environment variables to be set:

  • GOATCOUNTER_CODE: Your Goatcounter site code (the subdomain part, e.g., 'mycoolsite').
  • GOATCOUNTER_API_KEY: Your Goatcounter API token. You can generate one in your Goatcounter site under Settings -> API tokens. Ensure it has the necessary permissions for the API actions you intend to use.

You can set these variables directly in your environment or place them in a .env file in the project root.

Running the Server

Option 1: Using the CLI Script

The project defines a CLI script goatcounter-mcp-server.

If installed from PyPI:

goatcounter-mcp-server

If installed from source with uv:

uv run goatcounter-mcp-server

Option 2: Using FastMCP Directly (Source Only)

If you installed from source and prefer to run the server using FastMCP's development mode:

fastmcp dev src/goatcounter_mcp_server/server.py

Using with Claude Desktop

To use this MCP server with Claude Desktop, you need to configure Claude to connect to the server. Follow these steps:

Step 1: Install Node.js

Claude Desktop uses Node.js to run MCP servers. If you don't have Node.js installed:

  • Download and install Node.js from nodejs.org.
  • Verify installation:
    node --version
    

Step 2: Locate Claude Desktop Configuration

Claude Desktop uses a claude_desktop_config.json file to configure MCP servers.

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

If the file doesn't exist, create it.

Step 3: Configure the MCP Server

Edit claude_desktop_config.json to include the goatcounter-mcp-server server. Replace /path/to/goatcounter-mcp-server with the actual path to your project directory (if installed from source) or the path to your Python executable (if installed from PyPI).

If installed from PyPI:

{
  "mcpServers": {
    "goatcounter-mcp-server": {
      "command": "goatcounter-mcp-server",
      "args": [],
      "env": {
        "PYTHONUNBUFFERED": "1",
        "GOATCOUNTER_CODE": "goatcounter_code",
        "GOATCOUNTER_API_KEY": "goatcounter_api_key"
      }
    }
  }
}

If installed from source with uv:

{
  "mcpServers": {
    "goatcounter-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/goatcounter-mcp-server",
        "run",
        "goatcounter-mcp-server"
      ],
      "env": {
        "PYTHONUNBUFFERED": "1",
        "GOATCOUNTER_CODE": "goatcounter_code",
        "GOATCOUNTER_API_KEY": "goatcounter_api_key"
      }
    }
  }
}
  • "command": "goatcounter-mcp-server": Uses the CLI script directly if installed from PyPI.
  • "env": If installed from PyPI, you may need to provide environment variables directly in the config (since there's no .env file). If installed from source, the .env file will be used.
  • "env": {"PYTHONUNBUFFERED": "1"}: Ensures output is unbuffered for better logging in Claude.

Step 4: Restart Claude Desktop

  • Quit Claude Desktop completely.
  • Reopen Claude Desktop to load the new configuration.

Step 5: Verify Connection

  • Open Claude Desktop.
  • Look for a hammer or connector icon in the input area (bottom right corner). This indicates MCP tools are available.
  • Click the icon to see the available tools from goatcounter-mcp-server

API Documentation: Available Tools

The following MCP tools are available:


Tool: Goatcounter_get_me

Get information about the current Goatcounter user and API key associated with the configured GOATCOUNTER_API_KEY.

  • Parameters: None
  • Returns: object - Information about the user and token.

Tool: Goatcounter_list_sites

List all Goatcounter sites accessible with the current API key.

  • Parameters: None
  • Returns: object - A list of accessible sites.

Tool: Goatcounter_list_paths

Get an overview of paths tracked on this site (without statistics).

  • Parameters:
    • limit (integer, optional): Limit number of returned results (1-200, default 20).
    • after (integer, optional): Only select paths after this path ID, for pagination.
  • Returns: object - A list of paths and pagination info.

Tool: Goatcounter_get_stats_total

Get the total number of pageviews and unique visitors for the site within a specified period.

  • Parameters:
    • start (string, optional): Start date (YYYY-MM-DD or relative e.g., '7 days ago').
    • end (string, optional): End date (YYYY-MM-DD or relative e.g., 'yesterday').
    • filter (string, optional): Filter paths (e.g., '/blog*').
    • daily (boolean, optional): Show daily statistics instead of totals (default: false).
  • Returns: object - Total statistics or daily statistics if daily is true.

Tool: Goatcounter_get_stats_hits

List page statistics (pageviews and visitors per path).

  • Parameters:
    • start (string, optional): Start date (YYYY-MM-DD or relative e.g., '7 days ago').
    • end (string, optional): End date (YYYY-MM-DD or relative e.g., 'yesterday').
    • filter (string, optional): Filter paths (e.g., '/blog*').
    • daily (boolean, optional): Show daily statistics instead of totals (default: false).
    • limit (integer, optional): Limit number of returned results (1-200, default 20).
    • after (integer, optional): Pagination cursor.
  • Returns: object - A list of path statistics and pagination info.

Tool: Goatcounter_get_stats_refs

List referrer statistics.

  • Parameters:
    • start (string, optional): Start date (YYYY-MM-DD or relative e.g., '7 days ago').
    • end (string, optional): End date (YYYY-MM-DD or relative e.g., 'yesterday').
    • filter (string, optional): Filter paths (e.g., '/blog*').
    • daily (boolean, optional): Show daily statistics instead of totals (default: false).
    • limit (integer, optional): Limit number of returned results (1-200, default 20).
    • after (integer, optional): Pagination cursor.
  • Returns: object - A list of referrer statistics and pagination info.

Tool: Goatcounter_get_stats_browsers

List browser statistics.

  • Parameters:
    • start (string, optional): Start date (YYYY-MM-DD or relative e.g., '7 days ago').
    • end (string, optional): End date (YYYY-MM-DD or relative e.g., 'yesterday').
    • filter (string, optional): Filter paths (e.g., '/blog*').
    • daily (boolean, optional): Show daily statistics instead of totals (default: false).
    • limit (integer, optional): Limit number of returned results (1-200, default 20).
    • after (integer, optional): Pagination cursor.
  • Returns: object - A list of browser statistics and pagination info.

Tool: Goatcounter_get_stats_systems

List operating system statistics.

  • Parameters:
    • start (string, optional): Start date (YYYY-MM-DD or relative e.g., '7 days ago').
    • end (string, optional): End date (YYYY-MM-DD or relative e.g., 'yesterday').
    • filter (string, optional): Filter paths (e.g., '/blog*').
    • daily (boolean, optional): Show daily statistics instead of totals (default: false).
    • limit (integer, optional): Limit number of returned results (1-200, default 20).
    • after (integer, optional): Pagination cursor.
  • Returns: object - A list of OS statistics and pagination info.

Tool: Goatcounter_get_stats_sizes

List screen size statistics.

  • Parameters:
    • start (string, optional): Start date (YYYY-MM-DD or relative e.g., '7 days ago').
    • end (string, optional): End date (YYYY-MM-DD or relative e.g., 'yesterday').
    • filter (string, optional): Filter paths (e.g., '/blog*').
    • daily (boolean, optional): Show daily statistics instead of totals (default: false).
    • limit (integer, optional): Limit number of returned results (1-200, default 20).
    • after (integer, optional): Pagination cursor.
  • Returns: object - A list of screen size statistics and pagination info.

Tool: Goatcounter_get_stats_locations

List location statistics.

  • Parameters:
    • start (string, optional): Start date (YYYY-MM-DD or relative e.g., '7 days ago').
    • end (string, optional): End date (YYYY-MM-DD or relative e.g., 'yesterday').
    • filter (string, optional): Filter paths (e.g., '/blog*').
    • daily (boolean, optional): Show daily statistics instead of totals (default: false).
    • limit (integer, optional): Limit number of returned results (1-200, default 20).
    • after (integer, optional): Pagination cursor.
  • Returns: object - A list of location statistics and pagination info.

Usage

  1. Set Environment Variables: Create a .env file in your project root or set the environment variables directly:

    GOATCOUNTER_CODE=your_site_code
    GOATCOUNTER_API_KEY=your_goatcounter_api_key
    

    You can generate an API key in your Goatcounter account settings.

  2. Run with FastMCP: Integrate this server with your FastMCP setup. Refer to the FastMCP documentation for details on connecting MCP servers.

    The server registers tools with the prefix Goatcounter (e.g., Goatcounter.list_sites).

Development

  • Install development dependencies: pip install -e ".[dev]" (if dev dependencies are specified in pyproject.toml)
  • This project uses hatch for building.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

推荐服务器

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

官方
精选