使用说明
NBA MCP服务器
一种生产就绪的MCP(模型上下文协议)服务器,通过标准化的API接口提供全面的NBA数据访问。建立在官方NBA API之上,具有高级功能,包括缓存、速率限制、指标收集和强大的统一数据获取系统。
┌─────────────────────────────────────────────────────────────────┐
│ NBA MCP Server │
│ │
│ Claude Desktop ←→ MCP Protocol ←→ Unified Fetch System │
│ VS Code/Cursor ←→ FastMCP ←→ NBA API Client │
│ Custom Client ←→ HTTP/Stdio ←→ Redis Cache + Filters │
│ │
│ 📊 50+ Endpoints │ 🔍 Fuzzy Matching │ ⚡ Sub-ms Cache │
│ 🎯 Smart Filters │ 🔗 Batch Queries │ 📈 Metrics/Tracing │
└─────────────────────────────────────────────────────────────────┘
目录
特性
- 🎯 统一数据获取:单人
unified_fetch()通过灵活的过滤和粒度控制访问任何NBA数据集的功能 - ⚡ 实时和历史数据:实时比分、比赛统计数据、球员/球队信息和历史记录
- 📊 高级分析:球队和球员的高级统计数据、时代调整后的比较、投篮图表
- 💬 自然语言查询:用简单的英语提问(例如,“谁在助攻方面领先NBA?”)
- 🎮 游戏背景:丰富的赛前分析,包括排名、形式、正面交锋和叙事综合
- 🚀 生产基础结构:Redis缓存、速率限制、Prometheus指标、OpenTetry跟踪
- 🔍 实体解析:通过信心评分对球员和球队名称进行模糊匹配
- 🛡️ 稳健的错误处理:重试逻辑、断路器、优雅降级
- 🔗 批量操作:并行获取多个数据集以获得最大效率
快速开始
⚡ 30秒内尝试
# Install via pipx (recommended) or pip
pipx install nba-mcp
# OR: pip install nba-mcp
# Start the server
nba-mcp serve --mode claude
# In another terminal, try fetching data
nba-mcp fetch league_leaders --params stat_category=PTS season=2024-25 --filter "PTS >= 25"
# Browse available endpoints
nba-mcp catalog
# Show configuration
nba-mcp config
🐳 Docker快速入门
# Clone and start with docker-compose
git clone https://github.com/ghadfield32/nba_mcp.git
cd nba_mcp
docker-compose up -d
# The server is now running with Redis caching at http://localhost:8000
先决条件
- Python 3.10或更高版本
- Git
- (可选)缓存Redis
- (可选)Ollama供当地LLM使用
- (可选)用于容器化部署的Docker
安装
- 克隆存储库
git clone https://github.com/ghadfield32/nba_mcp.git
cd nba_mcp
- 创建并激活虚拟环境
# Using UV (recommended)
pip install uv
uv venv nbavenv
# Activate on Windows
.\nbavenv\Scripts\activate
# Activate on Unix/MacOS
source nbavenv/bin/activate
- 安装依赖项
# Using uv (resolves deps from pyproject.toml / uv.lock)
uv sync --extra dev
# Or use pip directly (editable install with dev extras)
pip install -e ".[dev]"
- 配置环境(可选)
# Copy example env file and customize
cp .env.example .env
# Edit .env with your preferred settings
运行服务器
新CLI(推荐)
# Start server with CLI
nba-mcp serve --mode claude
# Or with custom port
nba-mcp serve --mode local --port 8005
传统方法
# Claude Desktop Mode (Port 8000)
python -m nba_mcp.nba_server --mode claude
# Local LLM Mode (Port 8001)
python -m nba_mcp.nba_server --mode local
Docker部署
# Basic deployment with Redis
docker-compose up -d
# With monitoring (Prometheus + Grafana)
docker-compose --profile monitoring up -d
服务器将启动并显示可用的工具和配置。
🎯 统一数据获取系统
此MCP服务器的核心是 unified_fetch() 函数-一个强大、灵活的API,用于检索任何NBA数据集,具有高级过滤和粒度控制。
为什么使用unified_rech?
您可以使用一个函数来访问所有NBA数据,而不是存储数十个不同的API端点及其特定参数:
- ✅ 接口:一个函数用于所有端点
- ✅ 灵活过滤:使用简单语法应用筛选器
- ✅ 实体解析:使用球员/球队名称而不是ID
- ✅ 自动缓存:智能缓存以提高性能
- ✅ 批量操作:并行获取多个数据集
- ✅ 类型安全:完整的类型提示和验证
基本用法
from nba_api_mcp.data.unified_fetch import unified_fetch
import asyncio
# Simple fetch - get player career stats
async def get_lebron_stats():
result = await unified_fetch(
endpoint="player_career_stats",
params={"player_name": "LeBron James"}
)
print(f"Fetched {result.data.num_rows} rows")
print(f"Execution time: {result.execution_time_ms:.2f}ms")
print(f"From cache: {result.from_cache}")
# Access the data as PyArrow Table
data = result.data
# Or convert to tuple format
data, provenance = result.to_tuple()
asyncio.run(get_lebron_stats())
高级过滤
使用简单直观的语法将过滤器应用于任何数据集:
# Filter team game log for wins with 110+ points
result = await unified_fetch(
endpoint="team_game_log",
params={"team": "Lakers", "season": "2023-24"},
filters={
"WL": ["==", "W"], # Only wins
"PTS": [">=", 110], # Scored 110+ points
"FG_PCT": [">", 0.5] # Shooting over 50%
}
)
# Use IN operator for multiple values
result = await unified_fetch(
endpoint="team_standings",
params={"season": "2023-24"},
filters={
"team_abbreviation": ["IN", ["LAL", "GSW", "BOS"]]
}
)
# Use BETWEEN for ranges
result = await unified_fetch(
endpoint="player_game_logs",
params={"player_name": "Stephen Curry", "season": "2023-24"},
filters={
"PTS": ["BETWEEN", [25, 40]], # Scored between 25-40 points
"FG3M": [">=", 5] # Made 5+ threes
}
)
支持的筛选器运算符
| 操作员 | 描述 | 示例 |
|---|---|---|
== 或 = |
等于 | {"WL": ["==", "W"]} |
!= |
不等于 | {"conference": ["!=", "East"]} |
> |
大于 | {"PTS": [">", 20]} |
>= |
大于或等于 | {"PTS": [">=", 20]} |
< |
小于 | {"TOV": ["<", 3]} |
<= |
小于或等于 | {"TOV": ["<=", 3]} |
IN |
列表中的值 | {"TEAM": ["IN", ["LAL", "GSW"]]} |
BETWEEN |
在两个值之间 | {"PTS": ["BETWEEN", [20, 30]]} |
LIKE |
图案匹配 | {"PLAYER_NAME": ["LIKE", "%James%"]} |
批处理获取(并行执行)
同时获取多个数据集以获得最大效率:
from nba_api_mcp.data.unified_fetch import batch_fetch
# Fetch multiple datasets in parallel
results = await batch_fetch([
{
"endpoint": "player_career_stats",
"params": {"player_name": "LeBron James"}
},
{
"endpoint": "player_career_stats",
"params": {"player_name": "Stephen Curry"}
},
{
"endpoint": "team_standings",
"params": {"season": "2023-24"}
},
{
"endpoint": "league_leaders",
"params": {"stat_category": "PTS"},
"filters": {"PTS": [">=", 25]}
}
])
# Process results
for i, result in enumerate(results):
print(f"Query {i+1}: {result.data.num_rows} rows in {result.execution_time_ms:.2f}ms")
可用端点
以下是最常用的端点:
🏀 球员统计
player_career_stats-所有季节的职业统计数据player_game_logs-玩家的逐局统计数据player_advanced_stats-高级指标(TS%、使用率%、PER等)
🏆 团队统计
team_standings-会议和分区排名team_game_log-团队游戏历史team_advanced_stats-团队效率指标
📈 联盟数据
league_leaders-任何统计类别的联盟领导者league_game_log-联盟中的所有比赛
🎯 游戏数据
live_scoreboard-实时比分和比赛状态play_by_play-详细的逐场比赛数据box_score-传统盒子得分统计
📊 高级分析
shot_chart-使用六边形分箱的射击位置数据player_tracking-球员追踪和冲刺统计
有关端点的完整列表,请参阅 数据目录.
参数参考
端点间的通用参数:
| 参数 | 类型 | 描述 | 示例 |
|---|---|---|---|
player_name |
string | 玩家名称(模糊匹配) | "LeBron James" |
team 或 team_name |
string | 团队名称或缩写 | "Lakers" 或 "LAL" |
season |
NBA赛季 | "2023-24" |
|
date_from |
string | 开始日期 | "2024-01-01" |
date_to |
string | 结束日期 | "2024-03-01" |
stat_category |
string | 统计类别 | "PTS", "AST", "REB" |
per_mode |
string | 统计计算模式 | "PerGame", "Totals" |
处理结果
这 UnifiedFetchResult 对象提供丰富的元数据:
result = await unified_fetch(
endpoint="player_career_stats",
params={"player_name": "LeBron James"}
)
# Access the data (PyArrow Table)
data = result.data
print(f"Rows: {data.num_rows}")
print(f"Columns: {data.num_columns}")
# Performance metrics
print(f"Execution time: {result.execution_time_ms:.2f}ms")
print(f"From cache: {result.from_cache}")
# Provenance tracking
print(f"Source endpoints: {result.provenance.source_endpoints}")
print(f"Operations: {result.provenance.operations}")
print(f"Parameters: {result.provenance.parameters}")
# Warnings and transformations
if result.warnings:
print(f"Warnings: {result.warnings}")
if result.transformations:
print(f"Transformations: {result.transformations}")
# Convert to pandas DataFrame
df = data.to_pandas()
# Or get as tuple for backward compatibility
data, provenance = result.to_tuple()
过滤器下推优化
系统通过在可能的情况下将过滤器下推至API级别来自动优化查询:
# This filter will be pushed to the API level (faster)
result = await unified_fetch(
endpoint="player_game_logs",
params={"player_name": "Stephen Curry"},
filters={
"date_from": [">=", "2024-01-01"], # ✅ Pushed to API
"date_to": ["<=", "2024-03-01"] # ✅ Pushed to API
}
)
# These filters are applied post-fetch using DuckDB (still fast)
result = await unified_fetch(
endpoint="player_game_logs",
params={"player_name": "Stephen Curry"},
filters={
"PTS": [">=", 30], # Applied post-fetch
"FG3M": [">=", 5], # Applied post-fetch
"PLUS_MINUS": [">", 10] # Applied post-fetch
}
)
检查转换日志,查看推送了哪些过滤器:
print(result.transformations)
# Output: ['Pushed 2 filter(s) to API: [\'date_from\', \'date_to\']']
高速缓存控制
控制每个请求的缓存行为:
# Use cache (default)
result = await unified_fetch(
endpoint="player_career_stats",
params={"player_name": "LeBron James"},
use_cache=True
)
# Disable cache for this request
result = await unified_fetch(
endpoint="live_scoreboard",
params={"target_date": "2024-03-15"},
use_cache=False
)
# Force refresh even if cached
result = await unified_fetch(
endpoint="team_standings",
params={"season": "2023-24"},
force_refresh=True
)
🔧 配置和设置
设置NBA MCP工具
NBA MCP服务器可以与Claude Desktop、带Claude Code的VS Code、Cursor或任何兼容MCP的客户端一起使用。
选项1:克劳德桌面(建议用于聊天)
-
找到您的Claude Desktop配置文件:
- 视窗:
%APPDATA%\Claude\claude_desktop_config.json - MacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- 视窗:
-
添加NBA MCP服务器配置:
{ "mcpServers": { "nba": { "command": "python", "args": ["-m", "nba_api_mcp.nba_server", "--mode", "claude"], "env": { "PYTHONPATH": "C:\\path\\to\\nba_api_mcp" } } } }重要:替换
C:\\path\\to\\nba_api_mcp安装的实际路径。 -
重新启动克劳德桌面
-
验证连接:
- 打开克劳德桌面
- 寻找🔌 右下角的MCP图标
- NBA服务器应出现在连接的服务器列表中
选项2:VS代码与克劳德代码
-
找到您的MCP配置文件:
- 视窗:
%APPDATA%\Code\User\mcp.json - macOS/Linux:
~/.config/Code/User/mcp.json
- 视窗:
-
添加NBA MCP服务器:
{ "mcpServers": { "nba": { "command": "python", "args": ["-m", "nba_api_mcp.nba_server", "--mode", "local"], "env": { "PYTHONPATH": "C:\\path\\to\\nba_api_mcp" } } } } -
重新启动VS代码
选项3:光标IDE
-
找到您的Cursor MCP配置文件:
- 视窗:
%APPDATA%\Cursor\User\mcp.json - macOS/Linux:
~/.config/Cursor/User/mcp.json
- 视窗:
-
添加与VS代码相同的配置
-
重新启动游标
选项4:远程服务器模式(HTTP)
对于高级设置或远程访问:
-
手动启动服务器:
python -m nba_api_mcp.nba_server --mode local -
配置您的MCP客户端以通过HTTP连接:
{ "mcpServers": { "nba": { "url": "http://localhost:8000" } } }
环境变量
通过环境变量配置可选功能:
# Server configuration
export NBA_MCP_PORT=8000
export NBA_MCP_LOG_LEVEL=INFO
# Redis caching (optional)
export REDIS_HOST=localhost
export REDIS_PORT=6379
export REDIS_DB=0
export ENABLE_REDIS_CACHE=true
# Rate limiting
export NBA_MCP_DAILY_QUOTA=10000
export NBA_MCP_SIMPLE_RATE_LIMIT=60
export NBA_MCP_COMPLEX_RATE_LIMIT=30
# Observability (optional)
export ENABLE_METRICS=true
export ENABLE_TRACING=false
export OTLP_ENDPOINT=http://localhost:4317
🎮 使用NBA MCP工具
配置后,您可以通过MCP客户端(Claude Desktop、VS Code等)与NBA MCP服务器进行交互。服务器提供了一套全面的工具来查询NBA数据。
在克劳德桌面
只需问克劳德关于NBA数据的自然语言问题:
You: "What are the current NBA standings for the Western Conference?"
Claude: [Uses get_team_standings tool to fetch data]
Here are the current Western Conference standings...
You: "Show me LeBron James' stats from last season"
Claude: [Uses get_player_career_information tool]
LeBron James' 2023-24 season statistics:
- Games: 71
- PPG: 25.7
- RPG: 7.3
- APG: 8.3
...
可用的MCP工具
服务器通过MCP协议公开这些工具:
📊 游戏信息
get_live_scores
- 获取当前或历史游戏分数
- 参数:
target_date(可选,默认为今天) - 示例:“显示昨天的分数”
play_by_play
- 特定游戏的详细逐个游戏数据
- 参数:
game_id - 示例:“通过游戏0022300515获取游戏玩法”
get_game_context
- 丰富的赛前分析,包括排名、状态、正面交锋
- 参数:
team1_name,team2_name,season - 示例:“给我讲讲湖人队对阵勇士队的比赛背景”
🏀 球员统计
get_player_career_information
- 球员的全面职业统计
- 参数:
player_name,seasons(可选) - 示例:“获取勒布朗·詹姆斯的职业生涯统计数据”
get_player_advanced_stats
- 高级指标(TS%、使用率%、eFG%、PER等)
- 参数:
player_name,season - 例如:“斯蒂芬·库里的真实投篮命中率是多少?”
compare_players
- 两名球员的正面比较
- 参数:
player1_name,player2_name,stat_categories - 示例:“比较扬尼斯和恩比德的得分和篮板”
compare_players_era_adjusted
- 跨时代比较与统计调整
- 参数:
player1_name,player2_name - 示例:“比较不同时代的迈克尔·乔丹和勒布朗·詹姆斯”
🏆 团队统计
get_team_standings
- 会议和分区排名
- 参数:
season,conference(可选) - 示例:“东部联盟的排名如何?”
get_team_advanced_stats
- 团队效率指标
- 参数:
team_name,season - 示例:“给我看看凯尔特人队的高级统计数据”
get_date_range_game_log_or_team_game_log
- 日期范围内的团队比赛历史
- 参数:
team_name,season,date_from,date_to - 示例:“从1月到3月看湖人队的比赛”
📈 联盟数据
get_league_leaders_info
- 任何统计类别的联盟领导者
- 参数:
stat_category,per_mode,season - 例如:“谁在助攻方面领先联盟?”
🎯 射击图表
get_shot_chart
- 使用六边形分箱的射击位置数据
- 参数:
player_or_team_name,season,granularity - 示例:“给我看看斯蒂芬·库里的投篮图表”
💬 自然语言查询
answer_nba_question
- 用简单的英语提问
- 参数:
question - 该工具将自动:
- 解析你的问题
- 确定要获取哪些数据
- 执行适当的查询
- 合成自然语言响应
支持的问题类型:
- “本赛季谁在助攻方面领先NBA?”
- “比较勒布朗·詹姆斯和迈克尔·乔丹的职业生涯数据”
- “湖人队的排名是多少?”
- “给我看看斯蒂芬·库里的投篮数据”
- “昨晚谁得分最多?”
🔍 实体解析
resolve_nba_entity
- 球员和球队名称的模糊匹配
- 参数:
entity_name,entity_type(球员/球队) - 自动处理:
- 拼写错误和拼写错误
- 部分名称
- 常见昵称
- 团队缩写
对话示例
获取实时分数
You: What games are on today?
Claude: [Calls get_live_scores()]
Today's NBA games:
1. Lakers vs Warriors (7:30 PM PT) - Live: GSW 98, LAL 95 (Q3)
2. Celtics vs Heat (7:00 PM ET) - Final: BOS 112, MIA 103
3. Nuggets vs Suns (8:00 PM MT) - Upcoming
玩家分析
You: Show me Giannis Antetokounmpo's stats this season
Claude: [Calls get_player_career_information(player_name="Giannis Antetokounmpo", seasons=["2024-25"])]
Giannis Antetokounmpo 2024-25 Season:
- Games Played: 45
- PPG: 30.8
- RPG: 11.2
- APG: 6.1
- FG%: 61.2%
- Advanced: 65.3 TS%, 34.2 USG%, 28.5 PER
团队排名
You: What are the current Western Conference standings?
Claude: [Calls get_team_standings(season="2024-25", conference="West")]
Western Conference Standings:
1. Thunder (35-8) - 81.4%
2. Nuggets (32-11) - 74.4%
3. Grizzlies (31-12) - 72.1%
...
比较分析
You: Compare Luka Doncic and Shai Gilgeous-Alexander this season
Claude: [Calls compare_players(player1_name="Luka Doncic", player2_name="Shai Gilgeous-Alexander", stat_categories=["PTS", "AST", "REB"])]
Luka Doncic vs Shai Gilgeous-Alexander (2024-25):
Points per game:
- Luka: 28.9
- SGA: 30.3 ✓
Assists per game:
- Luka: 8.2 ✓
- SGA: 5.6
Rebounds per game:
- Luka: 8.3 ✓
- SGA: 5.7
最佳结果提示
- 具体:尽可能包括赛季年份、球员全名
- 使用自然语言:工具支持模糊匹配-“Lebron”和“Lebron James”一样有效
- 组合工具:提出需要多个数据源的复杂问题
- 检查可用性:使用MCP工具菜单查看所有可用功能
程序化使用
您还可以通过MCP协议以编程方式使用这些工具:
from nba_api_mcp.nba_server import mcp
# Example: Call a tool directly
result = await mcp.call_tool(
"get_player_career_information",
{
"player_name": "LeBron James",
"seasons": ["2023-24"]
}
)
与当地LLMs(Ollama)合作
- 拉一个Ollama模型
ollama pull llama3.2:3b
- 以本地模式启动NBA MCP服务器
python -m nba_mcp.nba_server --mode local
- 运行示例代理
python examples/langgraph_ollama_agent_w_tools.py --mode local
- 与代理交互
Enter a question:
> who leads the nba in assists this season?
AIMessage: Let me check the league leaders for assists this season.
ToolMessage: [League leaders data for assists...]
AIMessage: Based on the data, Tyrese Haliburton leads the NBA in assists...
发展
运行测试
# Run all tests
pytest tests/
# Run specific test categories
pytest tests/test_api_client.py
pytest tests/api/test_live_scores.py
pytest tests/api/test_player_stats.py
# Run integration tests
pytest tests/integration/
# Run with coverage
pytest --cov=nba_mcp --cov-report=html tests/
验证脚本
运行综合验证套件:
python run_validation.py
这将运行23个核心测试,涵盖:
- 实体解析
- 实时数据提取
- 球员和球队统计
- 高级分析
- 比较
- 射击图表
- 自然语言查询
代码质量
# Format code
black nba_api_mcp/
isort nba_api_mcp/
# Type checking
mypy nba_api_mcp/
# Linting
flake8 nba_api_mcp/
监测和可观察性
指标端点
启用指标后,请访问Prometheus指标:
http://localhost:8000/metrics
包括14种度量类型:
- 请求计数和持续时间
- 按类型划分的错误率
- 缓存命中率/未命中率
- 速率限制使用
- 工具执行时间
Grafana仪表板
预构建的Grafana仪表板可在 grafana/:
# Start Grafana (with Docker)
cd grafana
docker-compose up -d
# Access at http://localhost:3000
# Default credentials: admin/admin
演出
- 高速缓存性能:Redis加速410倍(820ms→ 2缓存响应的毫秒数)
- 并行执行:游戏上下文组合使用4个并行API调用
- 速率限制:
- 简单工具:60个请求/分钟
- 复杂工具:30个请求/分钟
- 多API工具:20个请求/分钟
- 全球配额:10000个请求/天
故障排除
常见问题
1.找不到模块错误
# Ensure PYTHONPATH is set correctly
export PYTHONPATH=/path/to/nba_mcp
# Or reinstall in development mode
pip install -e .
2.API速率限制
# Check rate limit status in logs
# Reduce request frequency
# Wait for quota reset (daily)
3.Redis连接问题
# Verify Redis is running
redis-cli ping
# Or disable Redis caching
export ENABLE_REDIS_CACHE=false
4.NBA API错误
# The NBA API can be flaky
# The server includes automatic retries with exponential backoff
# Check logs for specific error details
调试模式
启用详细日志记录:
export NBA_MCP_LOG_LEVEL=DEBUG
python -m nba_mcp.nba_server --mode claude
验证安装
# Check Python version
python --version # Should be 3.10+
# Verify dependencies
pip list | grep nba_api
pip list | grep fastmcp
# Test API connectivity
python -c "from nba_api.stats.static import players; print(len(players.get_players()))"
建筑
NBA MCP Server
├── nba_server.py # Main FastMCP server
├── api/ # Core API layer
│ ├── client.py # NBA API client
│ ├── advanced_stats.py # Advanced statistics
│ ├── entity_resolver.py # Fuzzy entity matching
│ ├── shot_charts.py # Shot chart data
│ ├── game_context.py # Multi-source composition
│ ├── era_adjusted.py # Cross-era adjustments
│ └── tools/ # API utilities
├── nlq/ # Natural language processing
│ ├── parser.py # Query parsing
│ ├── planner.py # Query planning
│ ├── executor.py # Parallel execution
│ └── synthesizer.py # Response formatting
├── cache/ # Redis caching layer
├── rate_limit/ # Token bucket rate limiting
├── observability/ # Metrics and tracing
└── schemas/ # Pydantic models and schemas
API响应格式
所有工具都返回一个标准化的响应信封:
{
"status": "success",
"data": { ... },
"metadata": {
"version": "v1",
"schema_version": "2025-01",
"timestamp": "2024-03-15T10:30:00Z",
"source": "nba_api",
"cached": true,
"cache_ttl": 3600
},
"errors": []
}
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/your-feature) - 进行更改
- 运行测试(
pytest tests/) - 格式代码(
black nba_api_mcp/ && isort nba_api_mcp/) - 提交您的更改(
git commit -m "Add your feature") - 推到分支(
git push origin feature/your-feature) - 打开拉取请求
许可证
MIT许可证-有关详细信息,请参阅许可证文件
致谢
📚 快速参考
常用命令
# Install dependencies
uv sync --extra dev
# or
pip install -e ".[dev]"
# Start server for Claude Desktop
python -m nba_api_mcp.nba_server --mode claude
# Start server for local LLMs
python -m nba_api_mcp.nba_server --mode local
# Run tests
pytest tests/
# Run validation
python run_validation.py
# Format code
black nba_api_mcp/ && isort nba_api_mcp/
统一提取备忘单
from nba_api_mcp.data.unified_fetch import unified_fetch, batch_fetch
# Basic fetch
result = await unified_fetch("player_career_stats", {"player_name": "LeBron James"})
# With filters
result = await unified_fetch(
"team_game_log",
{"team": "Lakers", "season": "2023-24"},
filters={"WL": ["==", "W"], "PTS": [">=", 110]}
)
# Batch fetch
results = await batch_fetch([
{"endpoint": "player_career_stats", "params": {"player_name": "LeBron"}},
{"endpoint": "team_standings", "params": {"season": "2023-24"}},
])
# Cache control
result = await unified_fetch(..., use_cache=False) # Disable cache
result = await unified_fetch(..., force_refresh=True) # Force refresh
过滤器操作员快速参考
# Equality
{"WL": ["==", "W"]} # Equal to
{"conference": ["!=", "East"]} # Not equal to
# Comparison
{"PTS": [">", 20]} # Greater than
{"PTS": [">=", 20]} # Greater than or equal
{"TOV": ["<", 3]} # Less than
{"TOV": ["<=", 3]} # Less than or equal
# Lists and Patterns
{"TEAM": ["IN", ["LAL", "GSW"]]} # In list
{"PTS": ["BETWEEN", [20, 30]]} # Between values
{"PLAYER_NAME": ["LIKE", "%James%"]} # Pattern match
最常见的终点
# Player Data
"player_career_stats" # Career statistics
"player_game_logs" # Game-by-game logs
"player_advanced_stats" # Advanced metrics
# Team Data
"team_standings" # Standings
"team_game_log" # Game history
"team_advanced_stats" # Team efficiency
# League Data
"league_leaders" # League leaders
"league_game_log" # All games
# Game Data
"live_scoreboard" # Live scores
"play_by_play" # Play-by-play
"box_score" # Box scores
配置文件
# Claude Desktop Config
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# VS Code / Cursor MCP Config
Windows: %APPDATA%\Code\User\mcp.json
%APPDATA%\Cursor\User\mcp.json
macOS: ~/.config/Code/User/mcp.json
~/.config/Cursor/User/mcp.json
环境变量
# Essential
NBA_MCP_PORT=8000
NBA_MCP_LOG_LEVEL=INFO
# Redis Cache
REDIS_HOST=localhost
REDIS_PORT=6379
ENABLE_REDIS_CACHE=true
# Rate Limits
NBA_MCP_DAILY_QUOTA=10000
NBA_MCP_SIMPLE_RATE_LIMIT=60
NBA_MCP_COMPLEX_RATE_LIMIT=30
# Observability
ENABLE_METRICS=true
ENABLE_TRACING=false
故障排除快速修复
# Module not found
export PYTHONPATH=/path/to/nba_api_mcp
pip install -e .
# Redis connection issues
redis-cli ping # Check if Redis is running
export ENABLE_REDIS_CACHE=false # Or disable Redis
# Check Python version
python --version # Must be 3.10+
# Verify installation
python -c "from nba_api.stats.static import players; print(len(players.get_players()))"
支持
对于问题、疑问或功能请求:
- 在GitHub上打开一个问题
- 检查存储库中的现有文档
- 查看上面的故障排除部分
- 请咨询 快速参考 用于常见任务
� �