Yahoo Fantasy MCP
A Model Context Protocol server that provides read-only access to Yahoo Fantasy Sports data, enabling AI assistants to query league standings, player stats, matchups, and rosters.
README
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:
- Register your application at Yahoo Developer Network
- Obtain your
consumer_keyandconsumer_secret - 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.jsonfile or the environment variables for authentication. - If using
oauth2.json, ensure thecwd(current working directory) is set to the directory containing the file, or use the--oauth2-fileargument 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 leagueget_current_week- Get the current week number of the leagueget_edit_date- Get the next date when lineups can be edited (roster deadline)get_end_week- Get the ending week number of the league seasonget_settings- Get comprehensive league settings (scoring, playoff, waiver, trade settings)get_positions- Get the positions used in the league with their counts and typesget_stat_categories- Get the stat categories tracked in the leagueget_teams- Get details of all teams in the leagueget_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 dateget_team_details- Get detailed information about a specific teamget_team_matchup- Get the opponent team key for a team's matchup in a given weekget_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 IDget_player_stats- Get statistics for one or more players for a specified time periodget_free_agents- Get available free agents in a league for a specific positionget_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:
- File an issue on GitHub
- Check the yahoo_fantasy_api documentation
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。