Skip to main content
Glama

get_game

Retrieve detailed information about a specific NBA, MLB, or NFL game using its unique game ID. This tool helps users access game data for sports analysis or reference purposes.

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

TableJSON Schema
NameRequiredDescriptionDefault
leagueYes
gameIdYesGame ID to get the game for, the value should be Game ID from previous call of get_games tool

Implementation Reference

  • The handler function that implements the core logic of the 'get_game' tool. It fetches the game data from the appropriate league API based on the league and gameId, formats it using helper functions, and returns the formatted text or an error.
    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:289-330 (registration)
    The registration of the 'get_game' tool using McpServer.tool method, specifying name, description, input schema, 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, }; } } }, );
  • Zod input schema for the 'get_game' tool, defining league (enum) and gameId (number) parameters.
    { 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'), },
  • Shared Zod enum schema for league types, used in the input schema of 'get_game' and other tools.
    const leagueEnum = z.enum(['NBA', 'MLB', 'NFL']); export type LeagueEnum = z.infer<typeof leagueEnum>;
  • Helper function to format NBA game data into a readable string, used in the NBA case of 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`; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mikechao/balldontlie-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server