get_teams
Retrieve team lists for NBA, MLB, or NFL leagues using the Balldontlie API to access sports data.
Instructions
Gets the list of team from one of the following leagues NBA (National Basketball Association), MLB (Major League Baseball), NFL (National Football League)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| league | Yes |
Implementation Reference
- src/index.ts:45-97 (handler)The handler function for the 'get_teams' tool. It uses a switch statement to call the appropriate API (api.nba.getTeams(), api.mlb.getTeams(), or api.nfl.getTeams()) based on the input league, formats each team's details into a string, joins them, and returns structured content.async ({ league }) => { switch (league) { case 'NBA': { const nbaTeams = await api.nba.getTeams(); const text = nbaTeams.data.map((team) => { return `Team ID: ${team.id}\n` + `Full Name: ${team.full_name}\n` + `Name: ${team.name}\n` + `Abbreviation: ${team.abbreviation}\n` + `City: ${team.city}\n` + `Conference: ${team.conference}\n` + `Division: ${team.division}\n`; }).join('\n-----\n'); return { content: [{ type: 'text', text }] }; } case 'MLB': { const mlbTeams = await api.mlb.getTeams(); const text = mlbTeams.data.map((team) => { return `Team ID: ${team.id}\n` + `Display Name: ${team.display_name}\n` + `Name: ${team.name}\n` + `Abbreviation: ${team.abbreviation}\n` + `Location: ${team.location}\n` + `League: ${team.league}\n` + `Division: ${team.division}\n` + `Slug: ${team.slug}\n`; }).join('\n-----\n'); ; return { content: [{ type: 'text', text }] }; } case 'NFL': { const nlfTeams = await api.nfl.getTeams(); const text = nlfTeams.data.map((team) => { return `Team ID: ${team.id}\n` + `Name: ${team.name}\n` + `Abbreviation: ${team.abbreviation}\n` + `Full Name: ${team.full_name}\n` + `Location: ${team.location}\n` + `Conference: ${team.conference}\n` + `Division: ${team.division}\n`; }).join('\n-----\n'); return { content: [{ type: 'text', text }] }; } default: { return { content: [{ type: 'text', text: `Unknown league: ${league}` }], isError: true, }; } } },
- src/index.ts:39-98 (registration)Registers the 'get_teams' tool with the MCP server using server.tool(), providing the tool name, description, input schema, and the handler function.server.tool( 'get_teams', 'Gets the list of team from one of the following leagues NBA (National Basketball Association), MLB (Major League Baseball), NFL (National Football League)', { league: leagueEnum, }, async ({ league }) => { switch (league) { case 'NBA': { const nbaTeams = await api.nba.getTeams(); const text = nbaTeams.data.map((team) => { return `Team ID: ${team.id}\n` + `Full Name: ${team.full_name}\n` + `Name: ${team.name}\n` + `Abbreviation: ${team.abbreviation}\n` + `City: ${team.city}\n` + `Conference: ${team.conference}\n` + `Division: ${team.division}\n`; }).join('\n-----\n'); return { content: [{ type: 'text', text }] }; } case 'MLB': { const mlbTeams = await api.mlb.getTeams(); const text = mlbTeams.data.map((team) => { return `Team ID: ${team.id}\n` + `Display Name: ${team.display_name}\n` + `Name: ${team.name}\n` + `Abbreviation: ${team.abbreviation}\n` + `Location: ${team.location}\n` + `League: ${team.league}\n` + `Division: ${team.division}\n` + `Slug: ${team.slug}\n`; }).join('\n-----\n'); ; return { content: [{ type: 'text', text }] }; } case 'NFL': { const nlfTeams = await api.nfl.getTeams(); const text = nlfTeams.data.map((team) => { return `Team ID: ${team.id}\n` + `Name: ${team.name}\n` + `Abbreviation: ${team.abbreviation}\n` + `Full Name: ${team.full_name}\n` + `Location: ${team.location}\n` + `Conference: ${team.conference}\n` + `Division: ${team.division}\n`; }).join('\n-----\n'); return { content: [{ type: 'text', text }] }; } default: { return { content: [{ type: 'text', text: `Unknown league: ${league}` }], isError: true, }; } } }, );
- src/index.ts:24-25 (schema)Zod enum schema defining the allowed leagues ('NBA', 'MLB', 'NFL') for the 'league' input parameter of the get_teams tool and other tools.const leagueEnum = z.enum(['NBA', 'MLB', 'NFL']); export type LeagueEnum = z.infer<typeof leagueEnum>;