get_team_streak
Retrieve the current winning or losing streak for an NHL team by providing its abbreviation, such as TOR or NYR, based on recent game results.
Instructions
Get current winning or losing streak for an NHL team based on recent game results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| teamAbbrev | Yes | Team abbreviation (e.g., TOR, NYR) |
Implementation Reference
- src/index.ts:288-341 (handler)Core handler function that fetches the team's schedule, identifies completed games, determines the current streak (win/loss) by checking recent game outcomes, and formats the result with recent game summaries.async function analyzeStreak(teamAbbrev: string): Promise<string> { try { const schedule = await client.getTeamSchedule(teamAbbrev); if (!schedule.games || schedule.games.length === 0) { return `No games found for ${teamAbbrev}`; } // Get completed games sorted by date const completedGames = schedule.games .filter((g: any) => g.gameState === 'OFF' || g.gameState === 'FINAL') .sort((a: any, b: any) => new Date(b.gameDate).getTime() - new Date(a.gameDate).getTime()); if (completedGames.length === 0) { return `No completed games found for ${teamAbbrev} this season`; } let streakCount = 0; let streakType = ''; const recentResults: string[] = []; for (const game of completedGames) { const isHome = game.homeTeam.abbrev === teamAbbrev; const teamScore = isHome ? game.homeTeam.score : game.awayTeam.score; const oppScore = isHome ? game.awayTeam.score : game.homeTeam.score; const oppTeam = isHome ? game.awayTeam.abbrev : game.homeTeam.abbrev; const won = teamScore > oppScore; const result = won ? 'W' : 'L'; recentResults.push(`${result} ${teamScore}-${oppScore} vs ${oppTeam}`); if (streakCount === 0) { streakType = result; streakCount = 1; } else if (result === streakType) { streakCount++; } else { break; } if (recentResults.length >= 10) break; } const streakText = streakType === 'W' ? `${streakCount} game winning streak` : `${streakCount} game losing streak`; return `${teamAbbrev} Current Streak: ${streakText}\n\nLast 10 games:\n${recentResults.join('\n')}`; } catch (error: any) { return `Error analyzing streak: ${error.message}`; } }
- src/index.ts:586-591 (handler)Tool dispatcher case that extracts the teamAbbrev parameter and invokes the analyzeStreak handler function.case 'get_team_streak': { const streak = await analyzeStreak(parameters.teamAbbrev as string); return { content: [{ type: 'text', text: streak }], }; }
- src/index.ts:178-191 (registration)Tool registration in the TOOLS array, including name, description, and input schema for listing available tools.{ name: 'get_team_streak', description: 'Get current winning or losing streak for an NHL team based on recent game results.', inputSchema: { type: 'object', properties: { teamAbbrev: { type: 'string', description: 'Team abbreviation (e.g., TOR, NYR)', }, }, required: ['teamAbbrev'], }, },
- src/index.ts:181-190 (schema)Input schema defining the required 'teamAbbrev' parameter for the get_team_streak tool.inputSchema: { type: 'object', properties: { teamAbbrev: { type: 'string', description: 'Team abbreviation (e.g., TOR, NYR)', }, }, required: ['teamAbbrev'], },