Skip to main content

MCP server for Yahoo Fantasy Sports API

Project description

Yahoo Fantasy MCP Server

A Model Context Protocol (MCP) server that provides access to Yahoo Fantasy Sports data. This server acts as a front-end for the yahoo_fantasy_api library, allowing AI assistants and other MCP clients to query fantasy league information.

Features

  • Query fantasy league standings and team information
  • Retrieve player statistics and projections
  • Access matchup data and scoring details
  • Get roster information for teams
  • Search for players and free agents

Installation

From PyPI (when published)

pip install yahoo-fantasy-mcp

From Source

git clone https://github.com/yourusername/yahoo_fantasy_mcp.git
cd yahoo_fantasy_mcp
pip install -e .

Prerequisites

Before using this MCP server, you need to set up Yahoo Fantasy API credentials:

  1. Register your application at Yahoo Developer Network
  2. Obtain your consumer_key and consumer_secret
  3. Set up OAuth2 authentication using one of the methods below

Configuration

There are two ways to authenticate with Yahoo's API:

Option 1: Using oauth2.json (Recommended)

Create an oauth2.json file with your Yahoo OAuth credentials. You can generate this file using the yahoo_fantasy_api authentication flow:

from yahoo_oauth import OAuth2

# This will prompt you to authorize via browser
sc = OAuth2(None, None, from_file='oauth2.json')

The oauth2.json file will look like:

{
  "access_token": "...",
  "consumer_key": "your_consumer_key",
  "consumer_secret": "your_consumer_secret",
  "guid": "...",
  "refresh_token": "...",
  "token_time": 1234567890.123456,
  "token_type": "bearer"
}

Option 2: Using Environment Variables

Set the following environment variables:

export YAHOO_CLIENT_ID="your_consumer_key"
export YAHOO_CLIENT_SECRET="your_consumer_secret"

Setting Your League ID

The server requires a YAHOO_LEAGUE_ID environment variable to know which league to query.

Finding your League ID:

If you don't know your league ID, simply run the server without setting YAHOO_LEAGUE_ID:

python -m yahoo_fantasy_mcp

The server will list all leagues you're part of and then exit. Example output:

============================================================
YAHOO_LEAGUE_ID not set - Listing available leagues
============================================================

Checking NFL leagues...
Checking MLB leagues...

Found the following leagues:

1. [NFL 2024] My Fantasy League
   League ID: 423.l.123456

2. [MLB 2024] Baseball League
   League ID: 412.l.789012

To use one of these leagues, set the YAHOO_LEAGUE_ID environment variable:

  export YAHOO_LEAGUE_ID=<league_id>

For example:
  export YAHOO_LEAGUE_ID=423.l.123456

Then set the environment variable:

export YAHOO_LEAGUE_ID=423.l.123456

Usage

As an MCP Server

This server uses the stdio transport protocol, communicating via standard input/output streams. It does not listen on any network port.

Transport Type

  • Type: stdio (standard input/output)
  • Protocol: The server reads JSON-RPC messages from stdin and writes responses to stdout
  • Connection: Invoked as a subprocess by the MCP client

Required Environment Variables

The server requires the following environment variable to be set:

  • YAHOO_LEAGUE_ID - The ID of your Yahoo Fantasy league (e.g., "423.l.123456")

Optional Environment Variables

Depending on your authentication method, you may need:

  • YAHOO_CLIENT_ID - Your Yahoo API consumer key (if not using oauth2.json)
  • YAHOO_CLIENT_SECRET - Your Yahoo API consumer secret (if not using oauth2.json)

Command-Line Arguments

  • --oauth2-file <path> - Path to oauth2.json file (default: "oauth2.json" in current directory)

MCP Client Configuration

The server should be configured in your MCP client as a stdio server. Below are example configurations for common MCP clients.

With oauth2.json file (recommended)

The server will automatically look for oauth2.json in the current working directory.

{
  "mcpServers": {
    "yahoo-fantasy": {
      "command": "python",
      "args": ["-m", "yahoo_fantasy_mcp"],
      "cwd": "/path/to/directory/with/oauth2.json",
      "env": {
        "YAHOO_LEAGUE_ID": "423.l.123456"
      }
    }
  }
}

Or specify a custom path to the oauth2.json file:

{
  "mcpServers": {
    "yahoo-fantasy": {
      "command": "python",
      "args": ["-m", "yahoo_fantasy_mcp", "--oauth2-file", "/path/to/oauth2.json"],
      "env": {
        "YAHOO_LEAGUE_ID": "423.l.123456"
      }
    }
  }
}
With environment variables

If you don't have an oauth2.json file, you can provide credentials via environment variables:

{
  "mcpServers": {
    "yahoo-fantasy": {
      "command": "python",
      "args": ["-m", "yahoo_fantasy_mcp"],
      "env": {
        "YAHOO_CLIENT_ID": "your_consumer_key",
        "YAHOO_CLIENT_SECRET": "your_consumer_secret",
        "YAHOO_LEAGUE_ID": "423.l.123456"
      }
    }
  }
}

Important Notes

  • The server must be able to find either the oauth2.json file or the environment variables for authentication.
  • If using oauth2.json, ensure the cwd (current working directory) is set to the directory containing the file, or use the --oauth2-file argument to specify the full path.
  • The server will automatically refresh OAuth tokens as needed.
  • On first run with environment variables, you'll need to complete the OAuth flow via browser.

Standalone Testing

You can test the server standalone to verify it's working correctly:

# Using oauth2.json in current directory (default)
export YAHOO_LEAGUE_ID=423.l.123456
python -m yahoo_fantasy_mcp

# Using oauth2.json from custom path
export YAHOO_LEAGUE_ID=423.l.123456
python -m yahoo_fantasy_mcp --oauth2-file /path/to/oauth2.json

# Using environment variables
export YAHOO_LEAGUE_ID=423.l.123456
YAHOO_CLIENT_ID=your_key YAHOO_CLIENT_SECRET=your_secret python -m yahoo_fantasy_mcp

Note: When run standalone without an MCP client, the server will wait for JSON-RPC messages on stdin. This is primarily useful for testing that the server starts correctly and authentication works.

Available Tools

The MCP server exposes the following tools for read-only access to Yahoo Fantasy data:

League Information

  • get_team_key - Get the team key for the logged in user's team in a league
  • get_current_week - Get the current week number of the league
  • get_edit_date - Get the next date when lineups can be edited (roster deadline)
  • get_end_week - Get the ending week number of the league season
  • get_settings - Get comprehensive league settings (scoring, playoff, waiver, trade settings)
  • get_positions - Get the positions used in the league with their counts and types
  • get_stat_categories - Get the stat categories tracked in the league
  • get_teams - Get details of all teams in the league
  • get_league_standings - Get current standings for a fantasy league

Matchups & Scoring

  • get_matchups - Get matchup data for a given week (defaults to current week)
  • get_matchup_scores - Get scores for current or specific matchup with team stats

Team Management

  • get_team_roster - Get roster for a specific team for a given week or date
  • get_team_details - Get detailed information about a specific team
  • get_team_matchup - Get the opponent team key for a team's matchup in a given week
  • get_team_proposed_trades - Get proposed trades that include the team (both offered and received)

Player Information

  • search_players - Search for players by name or get player details by ID
  • get_player_stats - Get statistics for one or more players for a specified time period
  • get_free_agents - Get available free agents in a league for a specific position
  • get_waivers - Get players currently on waivers in the league

Transactions

  • get_transactions - Get league transactions (adds, drops, trades, commish moves)

Note: This server provides read-only access. No write operations (roster changes, trades, lineup modifications) are implemented for safety.

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/yourusername/yahoo_fantasy_mcp.git
cd yahoo_fantasy_mcp

# Install development dependencies
pip install -e ".[dev]"

Running Tests

pytest

Code Quality

# Run linter
flake8 yahoo_fantasy_mcp tests

# Run type checker
mypy yahoo_fantasy_mcp

# Format code
black yahoo_fantasy_mcp tests

Project Structure

yahoo_fantasy_mcp/
├── yahoo_fantasy_mcp/
│   ├── __init__.py
│   ├── __main__.py
│   ├── server.py          # Main MCP server implementation
│   └── tools.py           # Tool implementations
├── tests/
│   ├── __init__.py
│   └── integration/       # Integration tests with real API
│       ├── __init__.py
│       ├── test_tools_integration.py
│       └── test_get_team_roster.py
├── README.md
├── setup.py
├── requirements.txt
├── requirements-dev.txt
└── .gitignore

License

MIT License - See LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Credits

Built on top of yahoo_fantasy_api by spilchen.

Support

For issues and questions:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yahoo_fantasy_mcp-0.1.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yahoo_fantasy_mcp-0.1.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file yahoo_fantasy_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: yahoo_fantasy_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for yahoo_fantasy_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 79f9dc3d76edb547fab96a380918e84674cee9a7d706d065660eb926774ea1d7
MD5 bfbffb6c46ff1362c532ff09aca187e6
BLAKE2b-256 d5d28997e40051ad1494b0b3752fddd13764d60caf502df64feb20985729b7a8

See more details on using hashes here.

File details

Details for the file yahoo_fantasy_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yahoo_fantasy_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9e2e7543d6d28d78b904acb64f925cd120cb1d93b9e695e48f5714bbca622b8
MD5 5ba9f63d2e1ffd2f4fe8b95187775904
BLAKE2b-256 fbee21fbb231fb1242fae8ea791fabd29cae2a6b2222b15c312829c7daca080a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page