get_teams
Retrieve a list of teams from the NBA, MLB, or NFL leagues by specifying the league name.
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
| Name | Required | Description | Default |
|---|---|---|---|
| league | Yes |
Implementation Reference
- src/index.ts:45-97 (handler)The tool handler for 'get_teams'. It accepts a 'league' parameter (NBA, MLB, or NFL), fetches teams via the Balldontlie SDK (api.nba.getTeams(), api.mlb.getTeams(), or api.nfl.getTeams()), formats the team data into text, and returns it as 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:42-44 (schema)Input schema for the 'get_teams' tool. Defines a single required parameter 'league' which must be one of 'NBA', 'MLB', or 'NFL' (via z.enum).
{ league: leagueEnum, }, - src/index.ts:39-98 (registration)Registration of the 'get_teams' tool via server.tool(). Registers the tool name, description, input schema, and handler function with the MCP server.
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, }; } } }, );