Model Context Protocol server for Statsig client SDK
Project description
Statsig MCP Server
Model Context Protocol server for Statsig feature flags and experimentation platform.
This MCP server enables AI assistants to interact with Statsig's feature management and experimentation platform, allowing them to check feature flags, retrieve dynamic configurations, get experiment assignments, and log custom events.
Features
- 🚩 Feature Gate Checking: Determine if features are enabled for users
- ⚙️ Dynamic Configuration: Retrieve configuration values based on user context
- 🧪 Experiment Assignment: Get experiment variations for A/B testing
- 📊 Layer Parameter Access: Retrieve values from Statsig layers
- 📈 Event Logging: Track custom events for analytics
Installation
Using uv (Recommended)
# Clone the repository
git clone https://github.com/GeLi2001/statsig-mcp.git
cd statsig-mcp
# Install dependencies with uv
uv sync
# Install with dev dependencies
uv sync --extra dev
Using pip
# Install from source
pip install -e .
# Or install with dev dependencies
pip install -e ".[dev]"
Quick Start
1. Run the Server
With uv (Recommended):
# Using command-line arguments (MCP best practice)
uv run -m statsig_mcp --api-key "your-secret-key"
# With additional options
uv run -m statsig_mcp \
--api-key "your-secret-key" \
--environment "production" \
--api-timeout 5000 \
--debug
# Or with environment variables
STATSIG_SERVER_SECRET_KEY="your-key" uv run -m statsig_mcp
With Python:
# Using flags (recommended)
python -m statsig_mcp --api-key "your-secret-key"
# Or environment variables
export STATSIG_SERVER_SECRET_KEY="your-secret-key"
python -m statsig_mcp
2. Configuration Options
The server supports both command-line arguments (recommended for MCP) and environment variables:
Command-Line Arguments (MCP Best Practice)
uv run -m statsig_mcp --help
| Argument | Type | Default | Description |
|---|---|---|---|
--api-key |
string | None | Statsig server secret key (required) |
--environment |
string | development | Environment tier |
--api-timeout |
int | 3000 | API timeout in milliseconds |
--disable-logging |
flag | false | Disable event logging to Statsig |
--debug |
flag | false | Enable debug logging |
Environment Variables (Fallback)
| Variable | Description |
|---|---|
STATSIG_SERVER_SECRET_KEY |
Statsig server secret key |
STATSIG_ENVIRONMENT |
Environment tier |
STATSIG_API_TIMEOUT |
API timeout in milliseconds |
STATSIG_DISABLE_LOGGING |
Disable logging (true/false) |
STATSIG_DEBUG |
Enable debug mode (true/false) |
3. MCP Client Configuration
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"statsig": {
"command": "uv",
"args": [
"run",
"-m",
"statsig_mcp",
"--api-key",
"your-secret-key",
"--environment",
"production"
]
}
}
}
Alternative with Environment Variables
{
"mcpServers": {
"statsig": {
"command": "uv",
"args": ["run", "-m", "statsig_mcp"],
"env": {
"STATSIG_SERVER_SECRET_KEY": "your-secret-key",
"STATSIG_ENVIRONMENT": "production"
}
}
}
}
Available Tools
1. check_feature_gate
Check if a feature gate is enabled for a user.
Parameters:
user_id(string): User identifiergate_name(string): Name of the feature gateuser_email(string, optional): User emailuser_country(string, optional): User country codecustom_attributes(object, optional): Custom user attributes
Example:
{
"user_id": "user123",
"gate_name": "new_checkout_flow",
"user_email": "user@example.com",
"custom_attributes": { "plan": "premium" }
}
2. get_dynamic_config
Get dynamic configuration values for a user.
Parameters:
user_id(string): User identifierconfig_name(string): Name of the dynamic configuser_email(string, optional): User emailuser_country(string, optional): User country codecustom_attributes(object, optional): Custom user attributes
3. get_experiment
Get experiment assignment for a user.
Parameters:
user_id(string): User identifierexperiment_name(string): Name of the experimentuser_email(string, optional): User emailuser_country(string, optional): User country codecustom_attributes(object, optional): Custom user attributes
4. get_layer
Get layer parameter values for a user.
Parameters:
user_id(string): User identifierlayer_name(string): Name of the layeruser_email(string, optional): User emailuser_country(string, optional): User country codecustom_attributes(object, optional): Custom user attributes
5. log_event
Log a custom event.
Parameters:
user_id(string): User identifierevent_name(string): Name of the eventvalue(string|number, optional): Event valuemetadata(object, optional): Event metadatauser_email(string, optional): User emailuser_country(string, optional): User country codecustom_attributes(object, optional): Custom user attributes
Example MCP Client Usage
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
# Create server parameters with flags (recommended)
server_params = StdioServerParameters(
command="uv",
args=[
"run", "-m", "statsig_mcp",
"--api-key", "your-secret-key",
"--environment", "production",
"--debug"
]
)
async def main():
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# Check a feature gate
result = await session.call_tool(
"check_feature_gate",
arguments={
"user_id": "user123",
"gate_name": "new_feature",
"custom_attributes": {"plan": "premium"}
}
)
print(f"Feature gate result: {result}")
# Get dynamic config
config = await session.call_tool(
"get_dynamic_config",
arguments={
"user_id": "user123",
"config_name": "ui_config"
}
)
print(f"Config: {config}")
# Log an event
await session.call_tool(
"log_event",
arguments={
"user_id": "user123",
"event_name": "button_click",
"metadata": {"button": "checkout"}
}
)
Development
Setup Development Environment
Using uv (Recommended):
# Clone and setup
git clone https://github.com/GeLi2001/statsig-mcp.git
cd statsig-mcp
# Install all dependencies including dev tools
uv sync --extra dev
# Run tests
uv run pytest
# Format code
uv run black .
# Type checking
uv run mypy .
# Linting
uv run ruff check .
Using pip:
# Install in development mode with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black .
# Type checking
mypy .
Running Commands
With uv, you can run any command in the virtual environment:
# Run the server with flags
uv run -m statsig_mcp --api-key "test-key" --debug
# Run tests with verbose output
uv run pytest -v
# Run validation script
uv run python validate.py
# Format and lint
uv run black .
uv run ruff check --fix .
Project Structure
statsig_mcp/
├── __init__.py
├── __main__.py # Module entry point
├── server.py # Main MCP server implementation
├── statsig_client.py # Statsig client wrapper
└── types.py # Type definitions
tests/ # Test suite
├── test_server.py
pyproject.toml # Project configuration
uv.lock # Locked dependencies (uv)
.venv/ # Virtual environment (uv managed)
Security Notes
- Never expose your Statsig server secret key in client-side code
- Use command-line arguments or environment variables for API keys
- The server secret key provides full access to your Statsig project
- Consider using separate API keys for different environments
Requirements
- Python 3.10+
- uv (recommended) or pip for package management
Troubleshooting
Common Issues
- "Statsig not initialized" error: Ensure
--api-keyis provided orSTATSIG_SERVER_SECRET_KEYis set - Network timeouts: Increase timeout with
--api-timeout 5000 - Feature gate not found: Verify the gate name exists in your Statsig console
- Python version error: This package requires Python 3.10+ (MCP requirement)
Debug Mode
Enable debug logging for troubleshooting:
# With command-line flag (recommended)
uv run -m statsig_mcp --api-key "your-key" --debug
# With environment variable
STATSIG_DEBUG=true uv run -m statsig_mcp --api-key "your-key"
Help
Get help with command-line options:
uv run -m statsig_mcp --help
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run tests and linting:
uv run pytest && uv run ruff check - Submit a pull request
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file statsig_mcp-1.0.0.tar.gz.
File metadata
- Download URL: statsig_mcp-1.0.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f7d82185b75da1ee4bed7ca3cdbf0a3d525846542b8328da2a109ac43970f5e
|
|
| MD5 |
e455c69ca89572076232aef62f85e215
|
|
| BLAKE2b-256 |
eb52dbd64c149a629d36654734137004c955b7386e2403b6e9a339eb26e3a934
|
File details
Details for the file statsig_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: statsig_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94aa2e68ed51352f72c6b735f23054b07615ff62368ea307b43ca7460d0cadb2
|
|
| MD5 |
931ec547e8d07e46e11ae39d8de2f2e3
|
|
| BLAKE2b-256 |
3c263e18ad5263c6eb54736f7209301172a0f2af433b6abc20aceeab880a962a
|