Skip to main content
Glama
dburge86

kenpom-mcp

by dburge86
README.md
# KenPom MCP Server ๐Ÿ€

[![CI](https://github.com/dburge86/kenpom-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/dburge86/kenpom-mcp/actions/workflows/ci.yml)
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)

Production-ready async MCP server for KenPom basketball analytics.

> **Note**: Requires a paid KenPom subscription ([kenpom.com](https://kenpom.com)) - email/password login, no API key needed.

## โœจ Project Status: Production Ready

- โœ… **100% Test Coverage** โ€” 61 tests covering all parsers and scraper
- โœ… **CI/CD Pipeline** โ€” GitHub Actions running tests, linting, and formatting
- โœ… **Code Quality** โ€” Pre-commit hooks with ruff enforcement
- โœ… **Network Resilience** โ€” Retry logic with exponential backoff
- โœ… **Dual Transport** โ€” Local (STDIO) and self-hosted HTTP/SSE support

## Features

- ๐Ÿš€ **Async Architecture** โ€” Built with httpx for non-blocking requests
- โ˜๏ธ **Self-Hostable** โ€” Optional HTTP/SSE server for remote access
- ๐Ÿ’พ **Smart Caching** โ€” KV-based caching to reduce scraping frequency
- ๐Ÿ”ง **Dual Transport** โ€” Local (STDIO) and Remote (SSE) support
- ๐Ÿ“Š **13+ Data Tools** โ€” Full coverage of KenPom stats
- ๐Ÿ”„ **Retry Logic** โ€” Automatic retry with backoff for network failures
- ๐Ÿงช **Well Tested** โ€” Comprehensive unit and integration tests

## Quick Start (Local)

```bash
cd /path/to/mcp_kenpom
cp .env.example .env  # Add your credentials
uv sync
uv run kenpom-mcp
```

## MCP Client Configuration

### Local Mode

```json
{
  "mcpServers": {
    "kenpom": {
      "command": "uv",
      "args": ["--directory", "/path/to/mcp_kenpom", "run", "kenpom-mcp"]
    }
  }
}
```

### Remote Mode (Self-Hosted)

If you run the HTTP server on your own infrastructure:

```json
{
  "mcpServers": {
    "kenpom": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://your-server-url/sse"
      ]
    }
  }
}
```

## Available Tools

| Tool                     | Description                                   |
| ------------------------ | --------------------------------------------- |
| `get_ratings`            | Pomeroy ratings (rank, adj efficiency, tempo) |
| `get_efficiency`         | Efficiency and tempo stats                    |
| `get_four_factors`       | eFG%, TO%, OR%, FTRate                        |
| `get_team_stats`         | Miscellaneous team stats (offense/defense)    |
| `get_player_stats`       | Player leaders by metric                      |
| `get_height`             | Height/experience data                        |
| `get_fanmatch`           | Game predictions by date                      |
| `get_arenas`             | Arena information                             |
| `get_game_attrs`         | Top games by attribute (excitement, upsets)   |
| `get_program_ratings`    | Historical program rankings                   |
| `get_kpoy`               | Player of the Year standings                  |
| `get_point_distribution` | Scoring breakdown by shot type                |
| `get_hca`                | Home court advantage data                     |

## Architecture

```
src/kenpom_mcp/
โ”œโ”€โ”€ server.py          # FastMCP server with 13 tools (STDIO transport)
โ”œโ”€โ”€ http_server.py     # Starlette server (HTTP/SSE transport)
โ”œโ”€โ”€ tools.py           # Unified tool registry (single source of truth)
โ”œโ”€โ”€ scraper.py         # Async httpx scraper with retry logic
โ””โ”€โ”€ parsers/           # HTML parsing modules
    โ”œโ”€โ”€ ratings.py     # Pomeroy ratings
    โ”œโ”€โ”€ efficiency.py  # Efficiency and tempo stats
    โ”œโ”€โ”€ stats.py       # Team and player stats
    โ”œโ”€โ”€ fanmatch.py    # Game predictions
    โ””โ”€โ”€ misc.py        # Arena, HCA, program ratings, KPOY

tests/
โ”œโ”€โ”€ conftest.py        # Pytest fixtures
โ”œโ”€โ”€ fixtures/          # 14 HTML sample files
โ”œโ”€โ”€ test_fixtures.py   # Fixture loading tests
โ”œโ”€โ”€ test_parsers.py    # 33 parser unit tests
โ””โ”€โ”€ test_scraper.py    # 14 scraper integration tests
```

## Development

### Setup

```bash
# Install dependencies
uv sync

# Copy environment template
cp .env.example .env  # Add your KenPom credentials

# Install pre-commit hooks (optional but recommended)
uv run pre-commit install
```

### Running

```bash
# Local dev (STDIO)
uv run kenpom-mcp

# HTTP dev server (port 8000)
uv run uvicorn kenpom_mcp.http_server:app --reload

# Test with MCP inspector
npx @modelcontextprotocol/inspector uv --directory . run kenpom-mcp
```

### Testing & Quality

```bash
# Run all tests
uv run pytest tests/

# Run tests with coverage
uv run pytest tests/ --cov=kenpom_mcp

# Run specific test file
uv run pytest tests/test_parsers.py -v

# Lint and format
uv run ruff check src/ tests/
uv run ruff format src/ tests/

# Run pre-commit hooks manually
uv run pre-commit run --all-files
```

## ๐Ÿค Contributing

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

This project uses:
- **pytest** for testing with async support
- **ruff** for linting and formatting
- **pre-commit** for automated quality checks
- **GitHub Actions** for CI/CD

All PRs must pass tests and linting checks.

## ๐Ÿ”’ Security

For security issues, please see [SECURITY.md](SECURITY.md) for responsible disclosure guidelines.

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- **KenPom** ([kenpom.com](https://kenpom.com)) - Ken Pomeroy's advanced basketball analytics
- **FastMCP** ([github.com/jlowin/fastmcp](https://github.com/jlowin/fastmcp)) - MCP server framework
- **MCP Protocol** ([modelcontextprotocol.io](https://modelcontextprotocol.io)) - Model Context Protocol specification

## ๐Ÿ“ž Support

- **Issues**: [GitHub Issues](https://github.com/dburge86/kenpom-mcp/issues)
- **Discussions**: [GitHub Discussions](https://github.com/dburge86/kenpom-mcp/discussions)
- **Security**: See [SECURITY.md](SECURITY.md)

---

**Made with โค๏ธ for basketball analytics enthusiasts**

TDQS

A4/5.0

Scored across 18 tools

Disambiguation4/5

Most tools target a distinct resource (ratings, efficiency, four factors, player stats, arenas, schedule, etc.). However, several team-level stat tools (get_ratings, get_efficiency, get_four_factors, get_team_stats, get_scouting_report) overlap in content, though descriptions clarify their specific focuses.

Naming Consistency5/5

All tool names follow a consistent 'get_<noun>' pattern in snake_case, making them highly predictable. Examples include get_ratings, get_schedule, get_scouting_report, and get_conference_standings.

Tool Count4/5

With 18 tools, the server is comprehensive but slightly heavy for a niche stats domain. The count is justifiable given the breadth of KenPom data, but it edges into the upper range of ideal scope.

Completeness4/5

The surface covers a wide range of college basketball analytics: ratings, efficiency, player stats, schedule, conference stats, and more. Minor gaps exist (e.g., no direct box score or team roster details beyond height), but core use cases are well covered.

Maintenance

ActivityInactive
ResponsivenessNo issues