get_game
Retrieve details of a specific game from NBA, MLB, or NFL by providing league and game ID obtained from a prior get_games call.
Instructions
Get a specific game from one of the following leagues NBA (National Basketball Association), MLB (Major League Baseball), NFL (National Football League)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| league | Yes | ||
| gameId | Yes | Game ID to get the game for, the value should be Game ID from previous call of get_games tool |
Implementation Reference
- src/index.ts:289-330 (registration)Registration of the 'get_game' tool via server.tool() with name 'get_game', description, schema (league + gameId), and handler function.
server.tool( 'get_game', 'Get a specific game from one of the following leagues NBA (National Basketball Association), MLB (Major League Baseball), NFL (National Football League)', { league: leagueEnum, gameId: z.number().describe('Game ID to get the game for, the value should be Game ID from previous call of get_games tool'), }, async ({ league, gameId }) => { switch (league) { case 'NBA': { const nbaGame = await api.nba.getGame(gameId); if (nbaGame.data) { const text = formatNBAGame(nbaGame.data); return { content: [{ type: 'text', text }] }; } return { content: [{ type: 'text', text: `Game ID ${gameId} not found` }], isError: true }; } case 'MLB': { const mlbGame = await api.mlb.getGame(gameId); if (mlbGame.data) { const text = formatMLBGame(mlbGame.data); return { content: [{ type: 'text', text }] }; } return { content: [{ type: 'text', text: `Game ID ${gameId} not found` }], isError: true }; } case 'NFL': { const nflGame = await api.nfl.getGame(gameId); if (nflGame.data) { const text = formatNFLGame(nflGame.data); return { content: [{ type: 'text', text }] }; } return { content: [{ type: 'text', text: `Game ID ${gameId} not found` }], isError: true }; } default: { return { content: [{ type: 'text', text: `Unknown league: ${league}` }], isError: true, }; } } }, ); - src/index.ts:296-329 (handler)The handler function for get_game. It accepts { league, gameId }, dispatches to NBA/MLB/NFL API calls, formats the response using formatNBAGame/formatMLBGame/formatNFLGame, and returns the result.
async ({ league, gameId }) => { switch (league) { case 'NBA': { const nbaGame = await api.nba.getGame(gameId); if (nbaGame.data) { const text = formatNBAGame(nbaGame.data); return { content: [{ type: 'text', text }] }; } return { content: [{ type: 'text', text: `Game ID ${gameId} not found` }], isError: true }; } case 'MLB': { const mlbGame = await api.mlb.getGame(gameId); if (mlbGame.data) { const text = formatMLBGame(mlbGame.data); return { content: [{ type: 'text', text }] }; } return { content: [{ type: 'text', text: `Game ID ${gameId} not found` }], isError: true }; } case 'NFL': { const nflGame = await api.nfl.getGame(gameId); if (nflGame.data) { const text = formatNFLGame(nflGame.data); return { content: [{ type: 'text', text }] }; } return { content: [{ type: 'text', text: `Game ID ${gameId} not found` }], isError: true }; } default: { return { content: [{ type: 'text', text: `Unknown league: ${league}` }], isError: true, }; } } }, - src/index.ts:24-24 (schema)The leagueEnum is defined as z.enum(['NBA', 'MLB', 'NFL']) and reused in the get_game tool's input schema.
const leagueEnum = z.enum(['NBA', 'MLB', 'NFL']); - src/index.ts:292-295 (schema)The input schema for get_game: 'league' (enum of NBA/MLB/NFL) and 'gameId' (number described as game ID from previous get_games call).
{ league: leagueEnum, gameId: z.number().describe('Game ID to get the game for, the value should be Game ID from previous call of get_games tool'), }, - src/utils.ts:3-74 (helper)Helper functions formatNBAGame, formatMLBGame, and formatNFLGame that format game data into human-readable text, used by the get_game handler.
export function formatNBAGame(game: NBAGame): string { return `Game ID: ${game.id}\n` + `Date: ${game.date}\n` + `Season: ${game.season}\n` + `Status: ${game.status}\n` + `Period: ${game.period}\n` + `Time: ${game.time}\n` + `Postseason: ${game.postseason}\n` + `Score: ${game.home_team.full_name} ${game.home_team_score} - ${game.visitor_team_score} ${game.visitor_team.full_name}\n` + `Home Team: ${game.home_team.full_name} (${game.home_team.abbreviation})\n` + `Visitor Team: ${game.visitor_team.full_name} (${game.visitor_team.abbreviation})\n`; } export function formatMLBGame(game: MLBGame): string { // Format inning scores nicely const homeInnings = game.home_team_data.inning_scores.map((score, i) => `Inning ${i + 1}: ${score}`).join(', '); const awayInnings = game.away_team_data.inning_scores.map((score, i) => `Inning ${i + 1}: ${score}`).join(', '); return `Game ID: ${game.id}\n` + `Date: ${game.date}\n` + `Season: ${game.season}\n` + `Postseason: ${game.postseason}\n` + `Status: ${game.status}\n` + `Venue: ${game.venue}\n` + `Attendance: ${game.attendance}\n` + `\nMatchup: ${game.home_team_name} vs ${game.away_team_name}\n` + `\nHome Team: ${game.home_team.display_name} (${game.home_team.abbreviation})\n` + ` League: ${game.home_team.league}\n` + ` Division: ${game.home_team.division}\n` + ` Runs: ${game.home_team_data.runs}\n` + ` Hits: ${game.home_team_data.hits}\n` + ` Errors: ${game.home_team_data.errors}\n` + ` Inning Scores: ${homeInnings}\n` + `\nAway Team: ${game.away_team.display_name} (${game.away_team.abbreviation})\n` + ` League: ${game.away_team.league}\n` + ` Division: ${game.away_team.division}\n` + ` Runs: ${game.away_team_data.runs}\n` + ` Hits: ${game.away_team_data.hits}\n` + ` Errors: ${game.away_team_data.errors}\n` + ` Inning Scores: ${awayInnings}\n` + `\nFinal Score: ${game.home_team_name} ${game.home_team_data.runs} - ${game.away_team_data.runs} ${game.away_team_name}`; } export function formatNFLGame(game: NFLGame) { const winner = game.home_team_score > game.visitor_team_score ? game.home_team.full_name : game.visitor_team_score > game.home_team_score ? game.visitor_team.full_name : 'Tie'; return `Game ID: ${game.id}\n` + `Date: ${game.date}\n` + `Season: ${game.season}\n` + `Week: ${game.week}\n` + `Status: ${game.status}\n` + `Postseason: ${game.postseason}\n` + `Venue: ${game.venue}\n` + `Summary: ${game.summary}\n` + `\nMatchup: ${game.home_team.full_name} vs ${game.visitor_team.full_name}\n` + `\nHome Team: ${game.home_team.full_name} (${game.home_team.abbreviation})\n` + ` Location: ${game.home_team.location}\n` + ` Conference: ${game.home_team.conference}\n` + ` Division: ${game.home_team.division}\n` + ` Score: ${game.home_team_score}\n` + `\nVisitor Team: ${game.visitor_team.full_name} (${game.visitor_team.abbreviation})\n` + ` Location: ${game.visitor_team.location}\n` + ` Conference: ${game.visitor_team.conference}\n` + ` Division: ${game.visitor_team.division}\n` + ` Score: ${game.visitor_team_score}\n` + `\nFinal Score: ${game.home_team.full_name} ${game.home_team_score} - ${game.visitor_team_score} ${game.visitor_team.full_name}\n` + `Winner: ${winner}`; }