Skip to main content
Glama
mikechao

balldontlie-mcp

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

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

  • 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,
            };
          }
        }
      },
    );
  • 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,
          };
        }
      }
    },
  • 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']);
  • 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'),
    },
  • 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}`;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description lacks details on behavior like read-only status, authentication, or potential side effects, leaving agents uninformed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single, well-structured sentence with no redundant information, efficiently conveying the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is too sparse, omitting return values, usage constraints, and other context needed for proper invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Only one of two parameters (gameId) has a description in the schema; the description does not add meaningful info beyond enumerating leagues and referencing the game ID source.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool retrieves a specific game from NBA, MLB, or NFL leagues, distinguishing it from siblings like get_games (list) and other tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implicitly, the tool is for fetching a single game, but no explicit guidance on when not to use it or alternatives is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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