ESPN Fantasy Basketball MCP Server
Provides NBA schedule data and player information for fantasy basketball analysis, including access to NBA game schedules and player details.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ESPN Fantasy Basketball MCP Server Show me the top free agents in my league"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ESPN Fantasy Basketball MCP Server
An MCP (Model Context Protocol) server that provides access to ESPN Fantasy Basketball APIs. This server enables Claude and other MCP clients to fetch fantasy basketball data including league teams, player rosters, waiver wire players, matchup schedules, and NBA schedules.
Note: This is an unofficial third-party tool and is not affiliated with or endorsed by ESPN.
Features
Available Tools
Core Fantasy Tools
get_league_teams - Get all teams in an ESPN Fantasy Basketball league
get_team_roster - Get roster for a specific team
get_free_agents - Get free agents/waiver wire players
get_matchups - Get league matchup schedule
get_nba_schedule - Get NBA game schedule
Live Draft Assistant Tools
get_draft_status - Get current draft status including all picks and progress
should_i_bid - Get recommendation on whether to bid for the current player being nominated
who_should_i_target_next - Get recommendation on which player to target/nominate next
analyze_my_draft_strategy - Analyze your current draft strategy and spending patterns
get_available_players - Get top available players for the draft with auction values
Related MCP server: nba-mcp
Installation
Prerequisites
Python 3.10 or higher
uv package manager
Setup
Clone this repository:
git clone <repository-url> cd espn-fantasy-basketball-mcpInstall dependencies using uv:
uv sync
Usage
Running the Server
uv run espn_fantasy_basketball.pyConfiguration for Claude Desktop
Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"espn-fantasy-basketball": {
"command": "uv",
"args": [
"--directory",
"/path/to/espn-fantasy-basketball-mcp",
"run",
"espn_fantasy_basketball.py"
],
"env": {
"ESPN_LEAGUE_ID": "your_league_id",
"ESPN_TEAM_ID": "your_team_id",
"ESPN_S2": "your_espn_s2_cookie",
"ESPN_SWID": "your_swid_cookie"
}
}
}
}Draft Tools Usage
The live draft assistant tools are designed for auction drafts and help answer key questions during your draft:
π‘ Pro Tip: These tools work seamlessly with Claude Desktop! Ask Claude questions like "Should I bid on this player?" or "Who should I target next?" and it will use these tools automatically to give you expert draft advice.
π get_draft_status
Get the current state of your draft including all picks made so far.
# Get draft status
draft_status = await get_draft_status(
league_id=123456,
year=2025,
espn_s2="your_espn_s2_cookie", # for private leagues
swid="your_swid_cookie" # for private leagues
)Returns:
inProgress: Whether draft is currently activedrafted: Whether draft is completedpicks: Array of all picks made so far with player detailscurrentPickNumber: Next pick numbercurrentNominatingTeam: Which team is nominating next
π° should_i_bid
Get AI-powered recommendation on whether to bid for the current player being nominated.
# Should I bid for this player?
recommendation = await should_i_bid(
current_player_id=12345, # Player being nominated
team_id=1, # Your team ID (optional, uses ESPN_TEAM_ID env var)
league_id=123456, # Optional, uses ESPN_LEAGUE_ID env var
year=2025, # Optional, uses ESPN_YEAR env var
espn_s2="your_espn_s2_cookie", # Optional, uses ESPN_S2 env var
swid="your_swid_cookie" # Optional, uses ESPN_SWID env var
)Returns:
action: "bid" or "pass"playerName: Name of the playersuggestedBid: Recommended bid amountmaxBid: Maximum you should bidreasoning: Explanation of the recommendationpriority: Priority score (1-10)
π― who_should_i_target_next
Get recommendation on which player to nominate when it's your turn.
# Who should I target next?
recommendation = await who_should_i_target_next(
team_id=1, # Your team ID (optional, uses ESPN_TEAM_ID env var)
league_id=123456, # Optional, uses ESPN_LEAGUE_ID env var
year=2025, # Optional, uses ESPN_YEAR env var
espn_s2="your_espn_s2_cookie", # Optional, uses ESPN_S2 env var
swid="your_swid_cookie" # Optional, uses ESPN_SWID env var
)Returns:
action: "nominate" or "pass"playerId: Recommended player IDplayerName: Player namesuggestedBid: Recommended opening bidreasoning: Why this player is recommendedpriority: Priority score (1-10)
π analyze_my_draft_strategy
Analyze your current draft progress, spending patterns, and punt strategy.
# Analyze my draft strategy
analysis = await analyze_my_draft_strategy(
team_id=1, # Your team ID (optional, uses ESPN_TEAM_ID env var)
league_id=123456, # Optional, uses ESPN_LEAGUE_ID env var
year=2025, # Optional, uses ESPN_YEAR env var
espn_s2="your_espn_s2_cookie", # Optional, uses ESPN_S2 env var
swid="your_swid_cookie" # Optional, uses ESPN_SWID env var
)Returns:
team_summary: Your current roster and spendingtotalSpent: Money spent so farplayersCount: Number of players draftedremainingBudget: Money left to spend
punt_analysis: Strategy analysis and recommendationsbudget_per_remaining_player: Average $ per remaining roster spot
π get_available_players
Get list of top available players with auction values and rankings.
# Get best available players
players = await get_available_players(
league_id=123456,
year=2025,
limit=25, # Number of players to return
espn_s2="your_espn_s2_cookie",
swid="your_swid_cookie"
)Returns: Array of available players with:
playerId: Player IDplayer: Player details (name, position, team)auctionValue: Projected auction valuerank: Overall rankingisDrafted: False (only undrafted players returned)
π‘ Draft Assistant Example Workflow
# 1. Check draft status
status = await get_draft_status(league_id, year, espn_s2, swid)
if not status["inProgress"]:
print("Draft not in progress")
# 2. If someone nominated a player, should you bid?
if current_player_being_nominated:
advice = await should_i_bid(league_id, year, team_id, player_id, espn_s2, swid)
print(f"{advice['action'].upper()}: {advice['reasoning']}")
if advice["action"] == "bid":
print(f"Suggested bid: ${advice['suggestedBid']}")
# 3. If it's your turn to nominate
if its_your_turn:
target = await who_should_i_target_next(league_id, year, team_id, espn_s2, swid)
print(f"Target: {target['playerName']} (${target['suggestedBid']})")
print(f"Reasoning: {target['reasoning']}")
# 4. Analyze your strategy periodically
strategy = await analyze_my_draft_strategy(league_id, year, team_id, espn_s2, swid)
print(f"Spent: ${strategy['team_summary']['totalSpent']}")
print(f"Budget per remaining player: ${strategy['budget_per_remaining_player']}")π Finding Your Team ID
Most draft and roster tools require your team_id. To find it:
Use the
get_league_teamstool to see all teams:
teams = await get_league_teams(league_id, year, espn_s2, swid)
# Look through the results to find your teamOr check the ESPN Fantasy Basketball URL when viewing your team:
URL format:
https://fantasy.espn.com/basketball/team?leagueId=123456&teamId=1Your team ID is the number after
teamId=
Configure it as an environment variable to avoid being asked every time:
Add
ESPN_TEAM_IDto your Claude Desktop config (see Configuration section above)Once configured, you can omit
team_idfrom tool calls and it will use your configured team automatically
Private League Access
For private leagues, you'll need ESPN authentication cookies:
ESPN_S2: ESPN authentication cookie (long string starting with "AE")ESPN_SWID: ESPN SWID cookie (format:{12345678-1234-1234-1234-123456789012})
To get these cookies:
Log into ESPN Fantasy in your browser
Open browser developer tools (F12)
Go to Application/Storage tab β Cookies β espn.com
Find and copy the
espn_s2andSWIDcookie values
Development
Running Tests
# Run all tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=espn_fantasy_basketball_mcp
# Run specific test file
uv run pytest tests/test_models.py
# Run tests in verbose mode
uv run pytest -vCode Quality
# Lint and format code
uv run ruff check --fix .
# Type checking
uv run mypy espn_fantasy_basketball_mcp/
# Run all CI checks locally
./scripts/check.shProject Structure
espn-fantasy-basketball-mcp/
βββ espn_fantasy_basketball.py # Main MCP server using FastMCP
βββ espn_fantasy_basketball_mcp/ # Core library package
β βββ __init__.py
β βββ client.py # ESPN API client
β βββ models.py # Pydantic data models
β βββ server.py # Legacy MCP server (unused)
βββ tests/ # Test suite
β βββ test_client.py # Client tests
β βββ test_models.py # Model tests
β βββ test_server.py # Server tests
βββ conftest.py # Pytest configuration
βββ pyproject.toml # Project configuration
βββ requirements.txt # Dependencies (for pip users)
βββ Pipfile # Dependencies (for pipenv users)
βββ .python-version # Python version for pyenv
βββ README.md # This fileAPI Endpoints Used
This MCP server uses the following ESPN API endpoints:
Fantasy Basketball API
Base URL:
https://lm-api-reads.fantasy.espn.com/apis/v3/games/fbaLeague Data:
/seasons/{year}/segments/0/leagues/{league_id}Teams:
?view=mTeamRosters:
?view=mRosterMatchups:
?view=mMatchupFree Agents:
?view=kona_player_info
NBA Schedule API
Base URL:
https://site.api.espn.com/apis/site/v2/sports/basketball/nbaSchedule:
/scoreboard
API Limitations & Alternatives Needed
Current Limitations
Free Agents Query Limit: ESPN API only returns up to 50 players per request for free agents
Private League Access: Requires ESPN authentication cookies (
espn_s2andSWID)Rate Limiting: ESPN may rate limit requests (not officially documented)
Undocumented API: ESPN's fantasy API is not officially documented and may change
Data Completeness: Some fields like team
locationare not provided by ESPN's APISeason Dependency: API behavior may vary between active and inactive seasons
Alternative APIs You May Need
NBA Player Stats & Advanced Metrics
NBA Stats API:
https://stats.nba.com/stats/(official but rate limited)Basketball Reference: Web scraping required
RapidAPI Sports: Paid API with comprehensive NBA data
Real-time NBA Data
ESPN NBA API:
https://site.api.espn.com/apis/site/v2/sports/basketball/nba(used for schedule)NBA Data API:
https://data.nba.net/prod/(official but limited)
Advanced Fantasy Analytics
FantasyLabs API: Paid service with projections and ownership data
DraftKings API: For DFS ownership and salaries
Hashtag Basketball: Free projections (web scraping required)
Player News & Injuries
ESPN News API: Limited access
The Athletic API: Requires subscription
Reddit API: r/fantasybball for community insights
Position IDs Reference
ESPN uses the following position IDs:
0: Point Guard (PG)
1: Shooting Guard (SG)
2: Small Forward (SF)
3: Power Forward (PF)
4: Center (C)
5: Guard (G)
6: Forward (F)
12: Bench
13: IR (Injured Reserve)
Example Usage
Via MCP Tools (in Claude Desktop)
Once configured, you can ask Claude to:
"Get all teams in my fantasy basketball league"
"Show me the roster for the Lakers team"
"What free agents are available?"
"Show me this week's matchups"
"What NBA games are today?"
Direct Python Usage
from espn_fantasy_basketball_mcp.client import ESPNFantasyBasketballClient
# Initialize client
client = ESPNFantasyBasketballClient(
league_id=12345,
year=2025,
espn_s2="your_espn_s2_cookie", # For private leagues
swid="your_swid_cookie" # For private leagues
)
# Get all teams in league
teams = await client.get_league_teams()
# Get roster for team ID 1
roster = await client.get_team_roster(team_id=1)
# Get top 25 free agent guards
free_agents = await client.get_free_agents(size=25, position_id=5)
# Get current week matchups
matchups = await client.get_matchups()
# Get today's NBA games
nba_games = await client.get_nba_schedule()Troubleshooting
Common Issues
"Team not found" errors: Verify your league ID and ensure you have access to the league
Authentication errors: Check that your
espn_s2andSWIDcookies are correct and not expiredEmpty results: Some data may not be available during off-season or for certain league settings
Rate limiting: ESPN may temporarily block requests if you make too many in quick succession
Debug Mode
The client includes error handling and logging. For debugging, check the server logs when running:
uv run espn_fantasy_basketball.pyContributing
Fork the repository
Create a feature branch:
git checkout -b feature-nameMake your changes and add tests
Run tests:
uv run pytestRun code quality checks:
uv run black . && uv run ruff .Commit your changes:
git commit -am 'Add feature'Push to the branch:
git push origin feature-nameCreate a Pull Request
License
MIT License - see LICENSE file for details.
Available Tools
14 toolsanalyze_my_draft_strategyA
Analyze your current draft strategy and spending patterns.
Args:
team_id: Your team ID (optional, uses ESPN_TEAM_ID env var)
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with punt strategy analysis, spending summary, and recommendations
Inputs: swid, year, espn_s2, team_id, +1 more.
analyze_trade_proposalA
Analyze a trade proposal using comprehensive statistical analysis.
Args:
your_player_ids: List of player IDs you would trade away
their_player_ids: List of player IDs you would receive
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with trade analysis, recommendation, and category impact
Inputs: your_player_ids (required), their_player_ids (required), swid, year, +2 more.
compare_playersA
Compare multiple players across statistical categories.
Args:
player_ids: List of ESPN player IDs to compare
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
categories: List of categories to compare (optional, defaults to 9-cat)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with detailed player comparison and winner by category
Inputs: player_ids (required), swid, year, espn_s2, +2 more.
get_available_playersA
Get top available players for the draft with auction values.
Args:
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
limit: Number of players to return (default 50)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
List of available player dictionaries with auction values and rankings
Inputs: swid, year, limit, espn_s2, +1 more. Returns: result
get_draft_statusA
Get current draft status including all picks and progress.
Args:
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with draft status, picks, and current state
Inputs: swid, year, espn_s2, league_id.
get_free_agentsA
Get free agents/waiver wire players from an ESPN Fantasy Basketball league.
Args:
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
size: Number of players to return (max 50, default 50)
position_id: Filter by position ID (optional)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
List of available free agent player dictionaries
Inputs: size, swid, year, espn_s2, +2 more. Returns: result
get_league_teamsA
Get all teams in an ESPN Fantasy Basketball league.
Args:
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
List of team dictionaries with id, name, location, record, etc.
Inputs: swid, year, espn_s2, league_id. Returns: result
get_matchupsA
Get matchups/schedule for an ESPN Fantasy Basketball league.
Args:
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
scoring_period: Specific scoring period to get matchups for (optional)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
List of matchup dictionaries with home/away teams and scores
Inputs: swid, year, espn_s2, league_id, +1 more. Returns: result
get_nba_scheduleA
Get NBA schedule for a specific date.
Args:
date: Date in YYYY-MM-DD format (optional, defaults to today)
Returns:
List of NBA game dictionaries with teams, times, and details
Inputs: date. Returns: result
get_player_statsA
Get comprehensive player statistics for specified timeframe.
Args:
player_id: ESPN player ID
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
timeframe: Time period - "season", "projections", "last_7", "last_30"
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with comprehensive player statistics across all categories
Inputs: player_id (required), swid, year, espn_s2, +2 more.
get_team_rosterA
Get roster for a specific team in an ESPN Fantasy Basketball league.
Args:
team_id: Team ID to get roster for (optional, uses ESPN_TEAM_ID env var)
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
scoring_period: Specific scoring period (optional)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with team roster including all players and their positions
Inputs: swid, year, espn_s2, team_id, +2 more.
get_trending_playersA
Get players trending up or down in adds/drops for waiver wire intelligence.
Args:
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
direction: Trending direction - "up" or "down"
limit: Number of players to return (default 20)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
List of trending player dictionaries with add/drop percentages and reasons
Inputs: swid, year, limit, espn_s2, +2 more. Returns: result
should_i_bidA
Get recommendation on whether to bid for the current player being nominated.
Args:
current_player_id: ID of player currently being nominated
team_id: Your team ID (optional, uses ESPN_TEAM_ID env var)
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with bid recommendation, suggested amount, and reasoning
Inputs: current_player_id (required), swid, year, espn_s2, +2 more.
who_should_i_target_nextA
Get recommendation on which player to target/nominate next.
Args:
team_id: Your team ID (optional, uses ESPN_TEAM_ID env var)
league_id: ESPN Fantasy Basketball league ID (optional, uses ESPN_LEAGUE_ID env var)
year: Season year (e.g., 2025) (optional, uses ESPN_YEAR env var or defaults to 2025)
espn_s2: ESPN authentication cookie for private leagues (optional, uses ESPN_S2 env var)
swid: ESPN SWID cookie for private leagues (optional, uses ESPN_SWID env var)
Returns:
Dictionary with player recommendation and reasoning
Inputs: swid, year, espn_s2, team_id, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
TDQS
Scored across 14 tools
Most tools have distinct purposes: schedule, teams, rosters, free agents, matchups, draft status, player stats, comparisons, trade analysis, and trends. However, 'get_free_agents' and 'get_available_players' could be confused (one is for waiver wire, the other for draft), and the three draft advisory tools ('should_i_bid', 'who_should_i_target_next', 'analyze_my_draft_strategy') overlap in context though they produce different outputs.
The majority follow a clear 'get_' or 'analyze_' + noun pattern, such as get_league_teams, get_player_stats, and analyze_trade_proposal. A few deviating question-style names (should_i_bid, who_should_i_target_next) stand out but are still readable and follow a similar snake_case style.
14 tools is a well-scoped set for a fantasy basketball analytics server. Each tool addresses a meaningful aspect of the domain without redundancy, and the count falls comfortably in the ideal range.
The server covers most core read and analysis workflows: schedule, rosters, matchups, draft, free agents, player stats, comparisons, trends, and trade evaluations. It lacks write operations like adding players or setting lineups, but for an advisory/analytics assistant this is a reasonable scope with only minor gaps.
Maintenance
Related MCP Connectors
Remote MCP server for live sports data. Ask for scores, standings, player stats and Elo ratings across 9 sports directly from Claude or any MCP client. Backed by the Big Balls Sports API, with one unified schema for every sport.
NBA MCP β player, team, and game data via the BallDontLie API
ESPN MCP β keyless multi-sport live scores, teams, and news via ESPN's public site API.
Hosted MCP server for live public-data APIs and Skills for AI agents.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server for accessing college basketball statistics through the SportsData.io CBB v3 Stats API, enabling AI agents to retrieve and analyze college basketball data through natural language interactions.-
- AlicenseAqualityDmaintenanceMCP server for NBA live data and stats, providing read-only tools to query live scores, box scores, player info, standings, and more from NBA.com.1515 npm1MIT
- AlicenseAqualityDmaintenanceMCP server providing access to ESPN Fantasy Baseball data, enabling league settings, rosters, player lookup, free agents, waiver claims, lineup changes, and trade management.161MIT
- FlicenseBqualityDmaintenanceMCP server that enables Claude Desktop to access real-time sports data including live scores, fixtures, standings, and NBA statistics using free APIs.10-