MLB Stats MCP Server
A Cloudflare Worker that provides access to MLB Statistics API data through the Model Context Protocol, supporting multiple endpoints like team info, player stats, game schedules, and live game data.
README
MLB Stats MCP Server - Enhanced with Meta-Tools
🔧 Version 2.1 - Now with Entity Resolution Meta-Tools!
A Cloudflare Worker that serves as an enhanced MCP (Model Context Protocol) server for accessing MLB Stats API data. Features meta-tools for intelligent entity resolution, comprehensive team/player mappings, and optimized data access patterns.
🎯 Enhanced Features
🔧 Meta-Tools for Entity Resolution
- resolve_team: Convert team names to canonical MLB team IDs
- resolve_player: Convert player names to canonical MLB player IDs
- Comprehensive Mappings: All 30 MLB teams with aliases and abbreviations
- Fuzzy Matching: "Yankees", "NYY", "New York Yankees" all resolve correctly
- Smart Suggestions: "Did you mean?" fallbacks for typos and partial matches
⚾ MLB Data Access
- Direct MLB API proxy with zero additional latency
- All MLB endpoints supported (teams, players, stats, schedules, etc.)
- CORS enabled for web applications
- No API keys required (MLB Stats API is public)
- Error handling and validation with detailed responses
🏗️ Architecture Benefits
- Domain logic ownership: All MLB-specific logic contained within this worker
- Service binding ready: Optimized for Cloudflare worker-to-worker communication
- Token efficient: Meta-tools reduce round-trips and enable smart caching
- Future-proof: Extensible pattern for other sports (NFL, NBA, NHL)
🛠️ Available Commands
🔧 Meta-Tools (Entity Resolution)
resolve_team - Team Name Resolution
Convert any team reference to canonical MLB team information.
Request:
{
"command": "resolve_team",
"params": {
"name": "Yankees"
}
}
Response:
{
"result": {
"id": 147,
"name": "New York Yankees",
"abbreviation": "NYY",
"query": "Yankees",
"resolved": true
}
}
Supported Inputs:
- Team names: "Yankees", "Red Sox", "Dodgers"
- Full names: "New York Yankees", "Boston Red Sox"
- Abbreviations: "NYY", "BOS", "LAD"
- Cities: "New York", "Boston", "Los Angeles"
resolve_player - Player Name Resolution
Convert any player reference to canonical MLB player information.
Request:
{
"command": "resolve_player",
"params": {
"name": "Judge"
}
}
Response:
{
"result": {
"id": 592450,
"name": "Aaron Judge",
"team": "New York Yankees",
"query": "Judge",
"resolved": true
}
}
Supported Players:
- Aaron Judge, Shohei Ohtani, Mookie Betts, Freddie Freeman
- Ronald Acuna Jr., Mike Trout, and other star players
- Both full names and last names supported
⚾ MLB Data Commands
getTeamInfo- Get team information and detailsgetRoster- Get team roster and player positionsgetPlayerStats- Get player statistics (hitting, pitching)getSchedule- Get game schedule and datesgetLiveGame- Get live game data and updatesgetStandings- Get league and division standingsgetGameBoxscore- Get detailed game boxscoregetPlayerInfo- Get player biographical informationgetSeasons- Get season information and yearsgetVenues- Get stadium and venue information
🎯 Enhanced Workflow
Traditional Approach:
// Step 1: User needs to know exact team ID
{"command": "getRoster", "params": {"pathParams": {"teamId": "147"}}}
Enhanced Meta-Tool Approach:
// Step 1: Resolve team name to ID
{"command": "resolve_team", "params": {"name": "Yankees"}}
// Returns: {"result": {"id": 147, "name": "New York Yankees"}}
// Step 2: Use resolved ID automatically (handled by sports-proxy)
{"command": "getRoster", "params": {"pathParams": {"teamId": "147"}}}
Request Format
Send POST requests to the worker endpoint with the following JSON structure:
{
"command": "getPlayerStats",
"params": {
"pathParams": {
"playerId": "660271"
},
"queryParams": {
"stats": "season",
"group": "hitting",
"season": "2024"
}
}
}
Response Format
Successful responses return:
{
"result": {
// MLB API response data
}
}
Error responses return:
{
"error": "Error message"
}
Development
-
Install Wrangler CLI:
npm install -g wrangler -
Login to Cloudflare:
wrangler login -
Deploy the worker:
wrangler deploy
📋 Complete Usage Examples
🔧 Meta-Tool Examples
Resolve Team Names
# Basic team resolution
curl -X POST https://mlbstats-mcp.your-domain.workers.dev \
-H "Content-Type: application/json" \
-d '{
"command": "resolve_team",
"params": {"name": "Yankees"}
}'
# Response: {"result": {"id": 147, "name": "New York Yankees", "abbreviation": "NYY"}}
# Handle abbreviations and cities
curl -X POST https://mlbstats-mcp.your-domain.workers.dev \
-H "Content-Type: application/json" \
-d '{
"command": "resolve_team",
"params": {"name": "LAD"}
}'
# Response: {"result": {"id": 119, "name": "Los Angeles Dodgers", "abbreviation": "LAD"}}
Resolve Player Names
# Resolve player by last name
curl -X POST https://mlbstats-mcp.your-domain.workers.dev \
-H "Content-Type: application/json" \
-d '{
"command": "resolve_player",
"params": {"name": "Ohtani"}
}'
# Response: {"result": {"id": 660271, "name": "Shohei Ohtani", "team": "Los Angeles Dodgers"}}
⚾ Data Retrieval Examples
Get Team Information
{
"command": "getTeamInfo",
"params": {
"queryParams": {
"season": "2025",
"sportId": "1"
}
}
}
Get Player Stats (with resolved player ID)
{
"command": "getPlayerStats",
"params": {
"pathParams": {
"playerId": "592450" // Aaron Judge (from resolve_player)
},
"queryParams": {
"stats": "season",
"group": "hitting",
"season": "2025"
}
}
}
Get Team Roster (with resolved team ID)
{
"command": "getRoster",
"params": {
"pathParams": {
"teamId": "147" // Yankees (from resolve_team)
},
"queryParams": {
"season": "2025"
}
}
}
Get Schedule
{
"command": "getSchedule",
"params": {
"queryParams": {
"sportId": "1",
"date": "2025-07-04",
"teamId": "147" // Optional: filter by resolved team
}
}
}
🔍 Error Handling Examples
Team Not Found
// Request: {"command": "resolve_team", "params": {"name": "Cowbays"}}
// Response:
{
"error": "Team \"Cowbays\" not found. Did you mean: cowboys, astros, royals?"
}
Player Not Found
// Request: {"command": "resolve_player", "params": {"name": "Jduge"}}
// Response:
{
"error": "Player \"Jduge\" not found. Did you mean: judge?"
}
🚀 Integration with Sports-Proxy
When used with the enhanced sports-proxy, the workflow becomes seamless:
# User input: "Get the Yankees roster"
# 1. Sports-proxy detects MLB sport
# 2. Extracts tools: resolve_team("yankees"), get_team_roster({})
# 3. MLB MCP resolves: resolve_team → {id: 147}
# 4. Sports-proxy enriches: get_team_roster({teamId: "147"})
# 5. MLB MCP returns: Complete roster data
This eliminates the need for manual entity resolution and creates a natural language interface to MLB data!
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。