compare_teams
Compare head-to-head statistics between two NHL teams, including recent matchups and historical records, to analyze team performance and rivalries.
Instructions
Compare head-to-head statistics between two NHL teams including recent matchups and historical records.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| team1 | Yes | First team abbreviation (e.g., TOR) | |
| team2 | Yes | Second team abbreviation (e.g., MTL) | |
| season | No | Season in format YYYYYYYY (optional, defaults to current) |
Implementation Reference
- src/index.ts:343-391 (handler)The core handler function that implements the compare_teams tool logic by fetching team schedules from NHLAPIClient, filtering head-to-head matchups, calculating wins, and formatting the comparison results.async function compareTeamsHeadToHead(team1: string, team2: string, season?: string): Promise<string> { try { const schedule1 = await client.getTeamSchedule(team1, season); if (!schedule1.games) { return `No schedule data found for ${team1}`; } // Find games between these two teams const matchups = schedule1.games.filter((game: any) => { return ( (game.homeTeam.abbrev === team1 && game.awayTeam.abbrev === team2) || (game.homeTeam.abbrev === team2 && game.awayTeam.abbrev === team1) ); }); if (matchups.length === 0) { return `No matchups found between ${team1} and ${team2} this season`; } let team1Wins = 0; let team2Wins = 0; const results: string[] = []; matchups.forEach((game: any) => { const isTeam1Home = game.homeTeam.abbrev === team1; const team1Score = isTeam1Home ? game.homeTeam.score : game.awayTeam.score; const team2Score = isTeam1Home ? game.awayTeam.score : game.homeTeam.score; if (game.gameState === 'OFF' || game.gameState === 'FINAL') { if (team1Score > team2Score) { team1Wins++; results.push(`${game.gameDate}: ${team1} ${team1Score}, ${team2} ${team2Score} - ${team1} WIN`); } else { team2Wins++; results.push(`${game.gameDate}: ${team1} ${team1Score}, ${team2} ${team2Score} - ${team2} WIN`); } } else if (game.gameState === 'FUT') { results.push(`${game.gameDate}: Upcoming game`); } else { results.push(`${game.gameDate}: ${team1} ${team1Score}, ${team2} ${team2Score} - IN PROGRESS`); } }); return `Head-to-Head: ${team1} vs ${team2}\n\nSeason Series: ${team1} ${team1Wins}-${team2Wins} ${team2}\n\nGames:\n${results.join('\n')}`; } catch (error: any) { return `Error comparing teams: ${error.message}`; } }
- src/index.ts:156-177 (schema)The tool schema definition including name, description, input schema with properties for team1, team2 (required), and optional season.{ name: 'compare_teams', description: 'Compare head-to-head statistics between two NHL teams including recent matchups and historical records.', inputSchema: { type: 'object', properties: { team1: { type: 'string', description: 'First team abbreviation (e.g., TOR)', }, team2: { type: 'string', description: 'Second team abbreviation (e.g., MTL)', }, season: { type: 'string', description: 'Season in format YYYYYYYY (optional, defaults to current)', }, }, required: ['team1', 'team2'], }, },
- src/index.ts:575-584 (registration)The registration and dispatch logic in the CallToolRequestSchema handler that matches the tool name and calls the compareTeamsHeadToHead handler with parsed parameters.case 'compare_teams': { const comparison = await compareTeamsHeadToHead( parameters.team1 as string, parameters.team2 as string, parameters.season as string | undefined ); return { content: [{ type: 'text', text: comparison }], }; }