This guide covers setting up the development environment, running the server, testing, and the project architecture.
This project requires uv for Python package management. uv is a fast Python package installer and resolver, written in Rust.
Install uv:
curl -LsSf https://astral.sh/uv/install.sh | shInstall development dependencies:
uv sync --dev# Start MCP server (development)
uv run python -m piwik_pro_mcp.server
# Or using the package entry point
uv run piwik-pro-mcp# Check for linting issues
uv run ruff check .
# Format code
uv run ruff format .# Run all tests
uv run pytest
# Run test suite
uv run pytest src/piwik_pro_mcp/tests/
# Run with verbose output
uv run pytest src/piwik_pro_mcp/tests/ -v
# Run with coverage report
uv run pytest src/piwik_pro_mcp/tests/ --cov
# Run integration tests only
uv run pytest src/piwik_pro_mcp/tests/test_integration.py -vImportant: Always use
uv run pytest, neverpytestdirectly.
Required for running with a real Piwik PRO instance:
export PIWIK_PRO_HOST="your-instance.piwik.pro"
export PIWIK_PRO_CLIENT_ID="your-client-id"
export PIWIK_PRO_CLIENT_SECRET="your-client-secret"You can also use a .env file (supported via python-dotenv).
By default the server communicates over stdio. To expose the server remotely through streamable-http transport:
uv run piwik-pro-mcp --transport streamable-http --host 0.0.0.0 --port 8000 --path /mcpOptions:
--hostdefaults to0.0.0.0, enabling access from other machines on your network--portdefaults to8000; adjust to fit your environment or reverse proxy--pathdefaults to/mcp, matching the SDK client expectations--transport httpmay be used as an alias forstreamable-http
Ensure you protect public deployments (reverse proxy, TLS, allow-listed origins) to prevent unauthorized access.
MCP configuration for HTTP transport:
{
"mcpServers": {
"piwik-pro-analytics": {
"url": "http://localhost:8000/mcp"
}
}
}Build the Docker image:
docker build -t mcp-piwik-pro .src/piwik_pro_mcp/
├── server.py # FastMCP server creation, configuration, main entry point
├── responses.py # MCP-specific Pydantic response models
├── api/ # API client library
│ ├── client.py # Main HTTP client with OAuth2 authentication
│ ├── auth.py # Client credentials flow implementation
│ ├── config.py # Configuration management
│ ├── exceptions.py # Custom exception hierarchy
│ └── methods/ # API endpoint implementations
│ ├── apps/ # Apps management API
│ ├── analytics/ # Analytics API
│ ├── cdp/ # Customer Data Platform API
│ ├── container_settings/
│ ├── tag_manager/
│ └── tracker_settings/
├── tools/ # MCP tool implementations
│ ├── analytics/ # Analytics tools (annotations, goals, custom dimensions, query)
│ ├── apps/ # App management tools
│ ├── cdp/ # CDP tools (audiences, attributes)
│ ├── container_settings/
│ ├── tag_manager/ # Tags, triggers, variables, versions, templates
│ ├── tracker_settings/
│ └── parameters.py # Parameter discovery tool
├── common/ # Shared utilities
│ ├── utils.py # Client creation, validation utilities
│ ├── templates.py # Template loading utilities
│ ├── tool_schemas.py # Tool parameter schema mappings
│ └── settings.py # Configuration management
├── assets/ # Template assets and examples
└── tests/ # Test suite
├── test_integration.py
├── api/ # API client tests
└── tools/ # Tool-specific tests
server.py: Clean FastMCP server creation, configuration, and main entry point with argument parsingresponses.py: MCP-specific Pydantic response models for typed tool outputsapi/: Integrated API client library with OAuth2 authenticationapi/methods/: API endpoint modules organized by domain
Tools are organized by functional domain in src/piwik_pro_mcp/tools/:
analytics/: Analytics operationsannotations.py: User/System annotations toolsgoals.py: Goals management toolscustom_dimensions.py: Custom dimensions toolsquery.py: Query API tools
apps/tools.py: App management operationscdp/: Customer Data Platform operationsaudiences.py: Audience managementattributes.py: Attribute discovery
container_settings/tools.py: Container settings operationstag_manager/: Tag Manager operationstags.py,triggers.py,variables.py,versions.py,templates.py
tracker_settings/tools.py: Tracker settings operations
common/utils.py: Client creation (create_piwik_client) and validation utilities (validate_data_against_model)common/templates.py: Template loading utilitiescommon/tool_schemas.py: Tool parameter schema mappings fortools_parameters_getcommon/settings.py: Configuration management with environment variable parsing
- Unified Architecture: API client logic is integrated within the MCP module
- Error Handling: MCP tools wrap all exceptions in
RuntimeErrorwith descriptive messages - Type Safety: Full type annotations with Pydantic validation
- Authentication: OAuth2 client credentials with automatic token refresh
- Safe Mode: Tools marked with
readOnlyHint: Trueare available in safe mode