Skip to main content
Glama
README.md
# Amplitude MCP Server

A Model Context Protocol (MCP) server for integrating with Amplitude Analytics API. This server provides tools to track events, manage user properties, and query analytics data from your Amplitude projects.

## Features

- **Event Tracking**: Track single events or batch events to Amplitude
- **User Identification**: Set and update user properties
- **Analytics Queries**: Get user activity, event segmentation, and cohort data
- **Secure Configuration**: Environment-based API key management

## Installation

```bash
npm install amplitude-mcp-server
```

## Setup

### Configuration Options

You can configure the Amplitude MCP server in three ways:

#### Option 1: MCP Client Configuration (Recommended)

Add the server to your MCP client configuration with API keys as arguments:

```json
{
  "mcpServers": {
    "amplitude": {
      "command": "npx",
      "args": [
        "amplitude-mcp-server",
        "--api-key=your_amplitude_api_key_here",
        "--secret-key=your_amplitude_secret_key_here"
      ]
    }
  }
}
```

**For Claude Desktop users**, add this to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "amplitude": {
      "command": "npx",
      "args": [
        "amplitude-mcp-server",
        "--api-key=your_amplitude_api_key_here",
        "--secret-key=your_amplitude_secret_key_here"
      ]
    }
  }
}
```

#### Option 2: Environment Variables

Create a `.env` file in your project root:

```env
AMPLITUDE_API_KEY=your_amplitude_api_key_here
AMPLITUDE_SECRET_KEY=your_amplitude_secret_key_here
```

Then use the basic MCP client configuration:

```json
{
  "mcpServers": {
    "amplitude": {
      "command": "npx",
      "args": ["amplitude-mcp-server"]
    }
  }
}
```

#### Option 3: Mixed Configuration

You can also mix both approaches - environment variables as defaults and command line arguments to override:

```json
{
  "mcpServers": {
    "amplitude": {
      "command": "npx",
      "args": [
        "amplitude-mcp-server",
        "--api-key=your_amplitude_api_key_here"
      ],
      "env": {
        "AMPLITUDE_SECRET_KEY": "your_amplitude_secret_key_here"
      }
    }
  }
}
```

## Available Tools

### 1. track_event

Track a single event to Amplitude.

**Parameters:**

- `event_type` (required): Name of the event
- `user_id`: User identifier
- `device_id`: Device identifier
- `event_properties`: Custom event properties object
- `user_properties`: User properties to set
- `time`: Event timestamp in milliseconds
- `app_version`: Application version
- `platform`: Platform (iOS, Android, Web)
- `country`: Country code
- `region`: Region
- `city`: City
- `language`: Language code
- `revenue`: Revenue amount
- `price`: Product price
- `quantity`: Product quantity

**Example:**

```json
{
  "event_type": "button_clicked",
  "user_id": "user123",
  "event_properties": {
    "button_name": "signup",
    "page": "homepage"
  },
  "user_properties": {
    "subscription_plan": "premium"
  }
}
```

### 2. track_batch_events

Track multiple events in a single API call for better performance.

**Parameters:**

- `events` (required): Array of event objects (same structure as track_event)

### 3. identify_user

Set or update user properties without tracking an event.

**Parameters:**

- `user_id` or `device_id`: User/device identifier
- `user_properties` (required): User properties to set
- `app_version`: Application version
- `platform`: Platform identifier

### 4. get_user_activity

Retrieve user activity data from Amplitude.

**Parameters:**

- `user_id` (required): User ID to query
- `start_time`: Start time (YYYY-MM-DD format)
- `end_time`: End time (YYYY-MM-DD format)
- `limit`: Maximum number of events to return

### 5. get_event_segmentation

Get event segmentation data for analysis.

**Parameters:**

- `event_type` (required): Event type to analyze
- `start_date` (required): Start date (YYYY-MM-DD)
- `end_date` (required): End date (YYYY-MM-DD)
- `group_by`: Array of properties to group by
- `interval`: Interval in days ("1", "7", or "30")

### 6. get_cohort_data

Retrieve cohort analysis data.

**Parameters:**

- `cohort_id` (required): Cohort identifier
- `props`: Include user properties (boolean)

## Development

### Building the Project

```bash
npm run build
```

### Running in Development

For development, you can use environment variables in a `.env` file:

```bash
npm run dev
```

Or run with specific API keys:

```bash
node dist/index.js --api-key=your_key --secret-key=your_secret
```

### Testing

```bash
npm test
```

### Linting and Formatting

```bash
npm run lint
npm run format
```

## API Keys and Authentication

You'll need two types of API keys from Amplitude:

1. **API Key**: Used for tracking events (HTTP API)
2. **Secret Key**: Used for querying analytics data (Dashboard REST API)

### Getting Your API Keys

Get these from your Amplitude project settings:

- Go to Settings → Projects → [Your Project] → General
- Copy the API Key and Secret Key

### Configuration Priority

The server looks for API keys in this order:

1. Command line arguments (`--api-key` and `--secret-key`)
2. Environment variables (`AMPLITUDE_API_KEY` and `AMPLITUDE_SECRET_KEY`)

This allows you to set defaults via environment variables and override them via MCP client configuration as needed.

## Security Notes

- **Never commit API keys to version control**
- **MCP Client Configuration**: API keys in MCP client config are typically stored in user-specific configuration files
- **Environment Variables**: Use environment variables for server deployments or when sharing the same keys across multiple projects
- **Command Line Arguments**: Most secure for single-use or testing scenarios
- The secret key provides read access to your analytics data
- The API key allows event tracking to your project
- Consider using different approaches for development vs production environments

## Error Handling

The server includes comprehensive error handling:

- Network connectivity issues
- Invalid API keys
- Malformed requests
- Rate limiting responses

Errors are returned as text content with descriptive messages.

## Rate Limits

Be aware of Amplitude's rate limits:

- HTTP API: 1000 events per second per project
- Dashboard REST API: 360 requests per hour per project

Use batch tracking for high-volume scenarios.

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Submit a pull request

## License

MIT License - see LICENSE file for details.

## Support

For issues related to this MCP server, please file an issue on the GitHub repository.

For Amplitude API questions, refer to the [Amplitude Developer Documentation](https://developers.amplitude.com/).

# amplitude-mcp

TDQS

C2.7/5.0

Scored across 6 tools

Disambiguation4/5

The set splits cleanly into write tools (track_event, track_batch_events, identify_user) and read tools (get_user_activity, get_event_segmentation, get_cohort_data), with each query tool targeting a distinct analytics viewpoint. The only mild overlap is track_event vs track_batch_events, which descriptions differentiate by single-vs-batch semantics.

Naming Consistency5/5

All names follow a consistent snake_case verb_noun pattern (track_*, get_*, identify_user). Verbs map intuitively to actions and resource nouns are unambiguous.

Tool Count4/5

Six tools is lean and well-scoped for an analytics ingestion + query server, with each tool earning its place. It sits at the lower edge of the comfortable range, so a couple more query helpers could be justified.

Completeness3/5

Ingestion (single/batch events, user properties) and three core read queries are covered, but notable gaps remain: no cohort/event listing or taxonomy retrieval, no group identify, and no user deletion/GDPR endpoint. Agents can handle the main track-then-query workflow but will hit dead ends on discovery and cleanup operations.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues