MLB
MLB standings, schedules, box scores and player statistics
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/mlb/index.md to help me query MLB with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Current division tables in official rank order.
Example output · captured
- Connector release
- v0.5.1
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT division_name, division_rank, team_name, wins, losses, games_back
FROM mlb.main.current_standings
ORDER BY division_name, division_rank
| division_name | division_rank | team_name | wins | losses | games_back |
|---|---|---|---|---|---|
| American League Central | 1 | Cleveland Guardians | 85 | 77 | 0 |
| American League Central | 2 | Chicago White Sox | 84 | 78 | 1 |
| American League Central | 3 | Minnesota Twins | 77 | 85 | 8 |
| American League Central | 4 | Detroit Tigers | 76 | 86 | 9 |
| American League Central | 5 | Kansas City Royals | 69 | 93 | 16 |
Quick start
Choose where to run MLB, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'mlb' AS mlb (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-mlb'
);
3. Run a query
SELECT division_name, division_rank, team_name, wins, losses, games_back
FROM mlb.main.current_standings
ORDER BY division_name, division_rank
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'mlb' AS mlb
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT division_name, division_rank, team_name, wins, losses, games_back
FROM mlb.main.current_standings
ORDER BY division_name, division_rank
Query Farm operates MLB for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use mlb as the catalog alias for the query below.
4. Run a query
SELECT division_name, division_rank, team_name, wins, losses, games_back
FROM mlb.main.current_standings
ORDER BY division_name, division_rank
Technical details
- Verified connector release
- v0.5.1
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'mlb' AS mlb (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-mlb'
);
Overview
Read-only Major League Baseball standings and player statistics from MLB's Stats API
Query current and historical Major League Baseball data directly from SQL. The catalog contains team standings and complete batting, pitching, and fielding season lines, plus advanced metrics, career totals, team splits, and per-game logs.
Data model
Current tables are the quickest entry point. Parameterized functions select seasons, leagues, game types, qualified pools, or individual players. Multi-team season totals never claim to belong to one club: use the team-split functions when attribution matters.
All access is read-only and requires no credential. Rate statistics are exact decimals; baseball innings remain display strings alongside exact integer outs.
Sources and references
- MLB Stats API: the keyless MLB Advanced Media API every function calls.
- MLB.com Stats: the official leaderboards the qualified pools mirror.
- MLB data copyright notice: the terms that apply to Stats API data.
- MLB-StatsAPI wiki: a community reference for the Stats API's endpoints and parameters.
Catalog
Everything mlb exposes once attached — read straight from the worker's
released build.
main 4 tables · 16 functions
Current and historical MLB standings
Schema examples (6)
Current division tables in official rank order.
SELECT division_name, division_rank, team_name, wins, losses, games_back
FROM mlb.main.current_standings
ORDER BY division_name, division_rank;
| division_name | division_rank | team_name | wins | losses | games_back |
|---|---|---|---|---|---|
| American League Central | 1 | Cleveland Guardians | 85 | 77 | 0 |
| American League Central | 2 | Chicago White Sox | 84 | 78 | 1 |
| American League Central | 3 | Minnesota Twins | 77 | 85 | 8 |
| American League Central | 4 | Detroit Tigers | 76 | 86 | 9 |
| American League Central | 5 | Kansas City Royals | 69 | 93 | 16 |
Teams with the best run differential.
SELECT team_name, wins, losses, run_differential
FROM mlb.main.current_standings
ORDER BY run_differential DESC;
Each 2025 division winner's lowest-ERA qualified pitcher, joining standings() to pitching_stats() on team_id (pitchers traded mid-season have no team_id and are excluded).
SELECT s.division_name, s.team_name, s.wins, p.player_name,
p.innings_pitched, p.strikeouts, p.era
FROM mlb.main.standings(season := 2025) s
JOIN mlb.main.pitching_stats(season := 2025, qualified_only := true) p ON p.team_id = s.team_id
WHERE s.division_rank = 1
QUALIFY row_number() OVER (PARTITION BY s.team_id ORDER BY p.era, p.player_id) = 1
ORDER BY s.division_name;
2025 hitters with at least 50 plate appearances who also pitched, joining batting_stats() to pitching_stats() on player_id; mostly position players in mop-up relief, led by two-way Shohei Ohtani.
SELECT b.player_name, b.position_abbreviation, b.plate_appearances, b.ops,
p.games_pitched, p.innings_pitched, p.era
FROM mlb.main.batting_stats(season := 2025) b
JOIN mlb.main.pitching_stats(season := 2025) p USING (player_id)
WHERE b.plate_appearances >= 50
ORDER BY p.games_pitched DESC, b.player_name
LIMIT 20;
2 more examples
2025 shortstops with at least 2,400 defensive outs (800 innings) at the position, ranked by OPS alongside their errors and fielding percentage there.
SELECT f.player_name, f.last_team_abbreviation, f.outs, f.errors,
f.fielding_percentage, b.plate_appearances, b.ops
FROM mlb.main.fielding_stats(season := 2025) f
JOIN mlb.main.batting_stats(season := 2025) b USING (player_id)
WHERE f.position_abbreviation = 'SS' AND f.outs >= 2400
ORDER BY b.ops DESC, f.player_id
LIMIT 10;
Shohei Ohtani's 2025 batting split by whether the opponent finished at .500 or better, joining his batting_game_log() to the final standings() on opponent_id.
SELECT s.winning_percentage >= 0.500 AS opponent_500_or_better,
count(*) AS games, sum(g.at_bats) AS at_bats, sum(g.hits) AS hits,
sum(g.home_runs) AS home_runs,
round(sum(g.hits) / sum(g.at_bats), 3) AS batting_average
FROM mlb.main.batting_game_log(660271, season := 2025) g
JOIN mlb.main.standings(season := 2025) s ON s.team_id = g.opponent_id
GROUP BY ALL
ORDER BY opponent_500_or_better;
current_batting
Current-season batting statistics, one row per MLB player
Current MLB home-run leaders.
SELECT player_name, last_team_abbreviation, home_runs, ops
FROM mlb.main.current_batting
ORDER BY home_runs DESC
LIMIT 20;
current_fielding
Current-season fielding statistics at player-position grain
Current shortstops with substantial defensive playing time.
SELECT player_name, last_team_abbreviation, outs, errors,
fielding_percentage
FROM mlb.main.current_fielding
WHERE position_abbreviation = 'SS' AND outs >= 600
ORDER BY fielding_percentage DESC;
current_pitching
Current-season pitching statistics, one row per MLB player
Current ERA leaders among pitchers with at least 300 outs.
SELECT player_name, last_team_abbreviation, innings_pitched, strikeouts, era
FROM mlb.main.current_pitching
WHERE outs >= 300
ORDER BY era
LIMIT 20;
current_standings
Current AL and NL regular-season standings, one row per team
Current division tables in official rank order.
SELECT division_name, division_rank, team_name, wins, losses, games_back
FROM mlb.main.current_standings
ORDER BY division_name, division_rank;
| division_name | division_rank | team_name | wins | losses | games_back |
|---|---|---|---|---|---|
| American League Central | 1 | Cleveland Guardians | 85 | 77 | 0 |
| American League Central | 2 | Chicago White Sox | 84 | 78 | 1 |
| American League Central | 3 | Minnesota Twins | 77 | 85 | 8 |
| American League Central | 4 | Detroit Tigers | 76 | 86 | 9 |
| American League Central | 5 | Kansas City Royals | 69 | 93 | 16 |
Teams with the best run differential.
SELECT team_name, wins, losses, run_differential
FROM mlb.main.current_standings
ORDER BY run_differential DESC;
advanced_batting_stats (game_type := VARCHAR, league := VARCHAR, qualified_only := BOOLEAN, season := INTEGER)
Advanced MLB batting statistics by season, league, and game type
Qualified 2025 isolated-power leaders.
SELECT player_name, plate_appearances, isolated_power,
strikeouts_per_plate_appearance
FROM mlb.main.advanced_batting_stats(season := 2025, qualified_only := true)
ORDER BY isolated_power DESC
LIMIT 20;
advanced_pitching_stats (game_type := VARCHAR, league := VARCHAR, qualified_only := BOOLEAN, season := INTEGER)
Advanced MLB pitching statistics by season, league, and game type
Qualified 2025 pitchers by K-minus-BB percentage.
SELECT player_name, strikeouts_minus_walks_percentage, whiff_percentage
FROM mlb.main.advanced_pitching_stats(season := 2025, qualified_only := true)
ORDER BY strikeouts_minus_walks_percentage DESC
LIMIT 20;
all_current_batting ()
Current MLB batting lines (scan behind current_batting)
Current home-run leaders from the backing scan.
SELECT player_name, home_runs
FROM mlb.main.all_current_batting()
ORDER BY home_runs DESC
LIMIT 10;
all_current_fielding ()
Current MLB fielding lines (scan behind current_fielding)
Current shortstop fielding lines from the backing scan.
SELECT player_name, outs, errors
FROM mlb.main.all_current_fielding()
WHERE position_abbreviation = 'SS'
ORDER BY outs DESC
LIMIT 10;
all_current_pitching ()
Current MLB pitching lines (scan behind current_pitching)
Current strikeout leaders from the backing scan.
SELECT player_name, strikeouts
FROM mlb.main.all_current_pitching()
ORDER BY strikeouts DESC
LIMIT 10;
all_current_standings ()
Current MLB regular-season standings (scan behind current_standings)
Read the table's backing scan directly.
SELECT division_name, team_name, wins, losses
FROM mlb.main.all_current_standings()
WHERE division_rank = 1
ORDER BY division_name;
batting_career (player_id INTEGER, game_type := VARCHAR)
Career batting totals for one MLB player
Shohei Ohtani's regular-season career batting totals.
SELECT player_name, games_played, hits, home_runs, batting_average, ops
FROM mlb.main.batting_career(660271);
batting_game_log (player_id INTEGER, end_date := DATE, game_type := VARCHAR, season := INTEGER, start_date := DATE)
Per-game batting lines for one MLB player
Shohei Ohtani's June 2025 batting game log.
SELECT game_date, opponent_abbreviation, summary
FROM mlb.main.batting_game_log(660271, season := 2025, start_date := DATE '2025-06-01', end_date := DATE '2025-06-30')
ORDER BY game_date;
Shohei Ohtani's 2025 batting split by whether the opponent finished at .500 or better, joining his batting_game_log() to the final standings() on opponent_id.
SELECT s.winning_percentage >= 0.500 AS opponent_500_or_better,
count(*) AS games, sum(g.at_bats) AS at_bats, sum(g.hits) AS hits,
sum(g.home_runs) AS home_runs,
round(sum(g.hits) / sum(g.at_bats), 3) AS batting_average
FROM mlb.main.batting_game_log(660271, season := 2025) g
JOIN mlb.main.standings(season := 2025) s ON s.team_id = g.opponent_id
GROUP BY ALL
ORDER BY opponent_500_or_better;
batting_stats (game_type := VARCHAR, league := VARCHAR, qualified_only := BOOLEAN, season := INTEGER)
MLB player batting statistics by season and league
Qualified 2025 MLB OPS leaders.
SELECT player_name, last_team_abbreviation, home_runs, ops
FROM mlb.main.batting_stats(season := 2025, qualified_only := true)
ORDER BY ops DESC
LIMIT 20;
batting_team_splits (player_id INTEGER, season INTEGER, game_type := VARCHAR)
One MLB player's season batting totals split by team
Josh Naylor's 2025 batting totals separated by team.
SELECT team_name, games_played, hits, home_runs, ops
FROM mlb.main.batting_team_splits(647304, 2025)
ORDER BY team_name;
fielding_stats (game_type := VARCHAR, league := VARCHAR, season := INTEGER)
MLB player fielding statistics by season, league, and game type
2025 shortstops with at least 900 defensive outs.
SELECT player_name, last_team_abbreviation, outs, errors,
fielding_percentage
FROM mlb.main.fielding_stats(season := 2025)
WHERE position_abbreviation = 'SS' AND outs >= 900
ORDER BY fielding_percentage DESC;
2025 shortstops with at least 2,400 defensive outs (800 innings) at the position, ranked by OPS alongside their errors and fielding percentage there.
SELECT f.player_name, f.last_team_abbreviation, f.outs, f.errors,
f.fielding_percentage, b.plate_appearances, b.ops
FROM mlb.main.fielding_stats(season := 2025) f
JOIN mlb.main.batting_stats(season := 2025) b USING (player_id)
WHERE f.position_abbreviation = 'SS' AND f.outs >= 2400
ORDER BY b.ops DESC, f.player_id
LIMIT 10;
pitching_career (player_id INTEGER, game_type := VARCHAR)
Career pitching totals for one MLB player
Shohei Ohtani's regular-season career pitching totals.
SELECT player_name, games_started, innings_pitched, strikeouts, era, whip
FROM mlb.main.pitching_career(660271);
pitching_game_log (player_id INTEGER, end_date := DATE, game_type := VARCHAR, season := INTEGER, start_date := DATE)
Per-game pitching lines for one MLB player
Shohei Ohtani's 2025 pitching game log.
SELECT game_date, opponent_abbreviation, innings_pitched, strikeouts,
summary
FROM mlb.main.pitching_game_log(660271, season := 2025)
ORDER BY game_date;
pitching_stats (game_type := VARCHAR, league := VARCHAR, qualified_only := BOOLEAN, season := INTEGER)
MLB player pitching statistics by season and league
Qualified 2025 pitchers ordered by ERA.
SELECT player_name, last_team_abbreviation, innings_pitched, strikeouts, era
FROM mlb.main.pitching_stats(season := 2025, qualified_only := true)
ORDER BY era
LIMIT 20;
2025 hitters with at least 50 plate appearances who also pitched, joining batting_stats() to pitching_stats() on player_id; mostly position players in mop-up relief, led by two-way Shohei Ohtani.
SELECT b.player_name, b.position_abbreviation, b.plate_appearances, b.ops,
p.games_pitched, p.innings_pitched, p.era
FROM mlb.main.batting_stats(season := 2025) b
JOIN mlb.main.pitching_stats(season := 2025) p USING (player_id)
WHERE b.plate_appearances >= 50
ORDER BY p.games_pitched DESC, b.player_name
LIMIT 20;
pitching_team_splits (player_id INTEGER, season INTEGER, game_type := VARCHAR)
One MLB player's season pitching totals split by team
Jhoan Duran's 2025 pitching totals separated by team.
SELECT team_name, games_pitched, innings_pitched, strikeouts, era
FROM mlb.main.pitching_team_splits(661395, 2025)
ORDER BY team_name;
standings (league := VARCHAR, season := INTEGER, standings_type := VARCHAR)
MLB standings by season, league, and standings view
The 2025 final division standings.
SELECT division_name, division_rank, team_name, wins, losses
FROM mlb.main.standings(season := 2025)
ORDER BY division_name, division_rank;
The current American League wild-card race.
SELECT wild_card_rank, team_name, wild_card_games_back
FROM mlb.main.standings(league := 'AL', standings_type := 'wildCard')
ORDER BY wild_card_rank;
Each 2025 division winner's lowest-ERA qualified pitcher, joining standings() to pitching_stats() on team_id (pitchers traded mid-season have no team_id and are excluded).
SELECT s.division_name, s.team_name, s.wins, p.player_name,
p.innings_pitched, p.strikeouts, p.era
FROM mlb.main.standings(season := 2025) s
JOIN mlb.main.pitching_stats(season := 2025, qualified_only := true) p ON p.team_id = s.team_id
WHERE s.division_rank = 1
QUALIFY row_number() OVER (PARTITION BY s.team_id ORDER BY p.era, p.player_id) = 1
ORDER BY s.division_name;
Try these queries
current_standings_are_populated — MLB regular-season standings contain team rows.
SELECT count(*) > 0 AS populated FROM mlb.main.current_standings;
Uses current_standings
current_batting_has_players — The complete current batting pool has stable player identifiers.
SELECT count(*) > 0 AND count(player_id) = count(*) AS populated
FROM mlb.main.current_batting;
Uses current_batting
baseball_innings_are_exact — Every displayed pitching inning count agrees with the exact outs count.
SELECT bool_and(outs >= 0) AS valid_outs
FROM mlb.main.current_pitching
WHERE innings_pitched IS NOT NULL;
Uses current_pitching
Each 2025 division winner's lowest-ERA qualified pitcher, joining standings() to pitching_stats() on team_id (pitchers traded mid-season have no team_id and are excluded).
SELECT s.division_name, s.team_name, s.wins, p.player_name,
p.innings_pitched, p.strikeouts, p.era
FROM mlb.main.standings(season := 2025) s
JOIN mlb.main.pitching_stats(season := 2025, qualified_only := true) p ON p.team_id = s.team_id
WHERE s.division_rank = 1
QUALIFY row_number() OVER (PARTITION BY s.team_id ORDER BY p.era, p.player_id) = 1
ORDER BY s.division_name
2025 hitters with at least 50 plate appearances who also pitched, joining batting_stats() to pitching_stats() on player_id; mostly position players in mop-up relief, led by two-way Shohei Ohtani.
SELECT b.player_name, b.position_abbreviation, b.plate_appearances, b.ops,
p.games_pitched, p.innings_pitched, p.era
FROM mlb.main.batting_stats(season := 2025) b
JOIN mlb.main.pitching_stats(season := 2025) p USING (player_id)
WHERE b.plate_appearances >= 50
ORDER BY p.games_pitched DESC, b.player_name
LIMIT 20
2025 shortstops with at least 2,400 defensive outs (800 innings) at the position, ranked by OPS alongside their errors and fielding percentage there.
SELECT f.player_name, f.last_team_abbreviation, f.outs, f.errors,
f.fielding_percentage, b.plate_appearances, b.ops
FROM mlb.main.fielding_stats(season := 2025) f
JOIN mlb.main.batting_stats(season := 2025) b USING (player_id)
WHERE f.position_abbreviation = 'SS' AND f.outs >= 2400
ORDER BY b.ops DESC, f.player_id
LIMIT 10
22 more examples in the Catalog, each listed under the table or function it uses.
Questions it can answer
Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.
- Show the current MLB division leaders and how many games back each second-place team is.
- Who were the top ten qualified MLB hitters by OPS in 2025?
- Break Jhoan Duran's 2025 pitching results out by team; his MLB player ID is 661395.
- List Shohei Ohtani's June 2025 batting game log; his MLB player ID is 660271.
- Who currently leads MLB in home runs, and who currently leads in strikeouts?
- Return the final 2025 MLB division standings in division-rank order.
MLB is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Formula 1
Sports
F1 standings, results, calendars, lap times, and session timing as SQL tables
NBA
Sports
Standings, scores, schedules, box scores, play-by-play, and player and team stats
NCAA football
Sports
FBS and FCS scores, standings, polls, box scores and player statistics as SQL