Skip to main content
Glama
sanchorelaxo

NHL MCP Server

by sanchorelaxo
nhl_api_client.cpython-310.pyc14.5 kB
o ��Rhj;� @s�dZddlZddlmZmZmZmZmZddlZGdd�d�Z de fdd�Z e d kr\e �Z ze � �Zed �eejed d ��WdSey[Zzed e���WYdZ[dSdZ[wwdS)z� NHL API Client A comprehensive Python client for the NHL API with functions for all documented endpoints. Based on the NHL API Reference: https://github.com/Zmalski/NHL-API-Reference �N)�Dict�Any�Optional�List�Unionc @s�eZdZdZdedefdd�Zdfdedeeeefd eeeffd d �Z d e d e de d eeeffdd�Z d e d eeeffdd�Z d e d eeeffdd�Z dgdeedee d eeeffdd�Zdgd e de deedee d eeeff dd�Zdgdeedee d eeeffdd�Zdgd e de deedee d eeeff dd�Zd eeeffdd �Zd eeeffd!d"�Zd#ed eeeffd$d%�Zd eeeffd&d'�Zd(ed eeeffd)d*�Zd(ed eeeffd+d,�Zd(ed e de d eeeffd-d.�Zd(ed eeeffd/d0�Zdfd(ed eed eeeffd1d2�Zdfd(ed eed eeeffd3d4�Zd eeeffd5d6�Zd#ed eeeffd7d8�Zd eeeffd9d:�Zd#ed eeeffd;d<�Zd eeeffd=d>�Z d#ed eeeffd?d@�Z!d eeeffdAdB�Z"dfdCeed eeeffdDdE�Z#dFe d eeeffdGdH�Z$dFe d eeeffdIdJ�Z%dFe d eeeffdKdL�Z&dFe d eeeffdMdN�Z'd#ed eeeffdOdP�Z(d eeeffdQdR�Z)d eeeffdSdT�Z*dfd ee d eeeffdUdV�Z+dfd ee d eeeffdWdX�Z,d eeeffdYdZ�Z-dfd[ee d eeeffd\d]�Z.d eeeffd^d_�Z/d`ed eeeffdadb�Z0dfd#eed eeeffdcdd�Z1dS)h� NHLAPIClientz(Client for interacting with the NHL API.�https://api-web.nhle.com�base_urlcCs&||_t��|_|jj�ddi�dS)Nz User-AgentzNHL-MCP-Client/1.0)r �requests�Session�session�headers�update)�selfr �r�6/home/rjodouin/Documents/git/nhl-mcp/nhl_api_client.py�__init__s   �zNHLAPIClient.__init__N�endpoint�params�returnc Cs�|j�|��}z|jj||d�}|��|��WStjjy/}z tdt |�����d}~wtj yD}z tdt |�����d}~ww)z"Make a GET request to the NHL API.)rzAPI request failed: Nz Failed to decode JSON response: ) r r �get�raise_for_status�jsonr � exceptions�RequestException� Exception�str�JSONDecodeError)rrr�url�response�errr� _make_requests ���zNHLAPIClient._make_request� player_id�season� game_typecCs d|�d|�d|��}|�|�S)a  Get game log for a specific player, season, and game type. Args: player_id: Player ID season: Season in YYYYYYYY format (e.g., 20232024) game_type: Game type (2 for regular season, 3 for playoffs) � /v1/player/z /game-log/�/�r!)rr"r#r$rrrr�get_player_game_log$� z NHLAPIClient.get_player_game_logcC�d|�d�}|�|�S)zp Get information for a specific player. Args: player_id: Player ID r%�/landingr'�rr"rrrr�get_player_info0�  zNHLAPIClient.get_player_infocCr*)zu Get current game log for a specific player. Args: player_id: Player ID r%z /game-log/nowr'r,rrr�get_player_game_log_now:r.z$NHLAPIClient.get_player_game_log_now� categories�limitcC�0d}i}|r ||d<|dur||d<|�||�S)z� Get current skater stats leaders. Args: categories: Optional categories filter limit: Optional limit (-1 for all results) z /v1/skater-stats-leaders/currentr0Nr1r'�rr0r1rrrrr� get_current_skater_stats_leadersF� z-NHLAPIClient.get_current_skater_stats_leaderscC�<d|�d|��}i}|r||d<|dur||d<|�||�S)aF Get skater stats leaders for a specific season and game type. Args: season: Season in YYYYYYYY format game_type: Game type (2 for regular season, 3 for playoffs) categories: Optional categories filter limit: Optional limit (-1 for all results) z/v1/skater-stats-leaders/r&r0Nr1r'�rr#r$r0r1rrrrr�get_skater_stats_leadersV�  z%NHLAPIClient.get_skater_stats_leaderscCr2)z� Get current goalie stats leaders. Args: categories: Optional categories filter limit: Optional limit (-1 for all results) z /v1/goalie-stats-leaders/currentr0Nr1r'r3rrr� get_current_goalie_stats_leadersjr5z-NHLAPIClient.get_current_goalie_stats_leaderscCr6)aF Get goalie stats leaders for a specific season and game type. Args: season: Season in YYYYYYYY format game_type: Game type (2 for regular season, 3 for playoffs) categories: Optional categories filter limit: Optional limit (-1 for all results) z/v1/goalie-stats-leaders/r&r0Nr1r'r7rrr�get_goalie_stats_leaderszr9z%NHLAPIClient.get_goalie_stats_leaderscC�d}|�|�S)zGet players in the spotlight.z/v1/player-spotlightr'�rrrrr�get_player_spotlight�� z!NHLAPIClient.get_player_spotlightcCr<)zGet current standings.z/v1/standings/nowr'r=rrr�get_standings_now�r?zNHLAPIClient.get_standings_now�datecC�d|��}|�|�S)zw Get standings for a specific date. Args: date: Date in YYYY-MM-DD format z/v1/standings/r'�rrArrrr�get_standings_by_date��  z"NHLAPIClient.get_standings_by_datecCr<)z*Get standings information for each season.z/v1/standings-seasonr'r=rrr�get_standings_season�r?z!NHLAPIClient.get_standings_season�teamcCr*)z� Get current statistics for a specific club. Args: team: Three-letter team code (e.g., 'TOR') �/v1/club-stats/�/nowr'�rrGrrrr�get_club_stats_now�r.zNHLAPIClient.get_club_stats_nowcCrB)z� Get stats overview for each season for a specific club. Args: team: Three-letter team code z/v1/club-stats-season/r'rJrrr�get_club_stats_season�rEz"NHLAPIClient.get_club_stats_seasoncCs d|�d|�d|��}|�|�S)z� Get stats for a specific team, season, and game type. Args: team: Three-letter team code season: Season in YYYYYYYY format game_type: Game type (2 for regular season, 3 for playoffs) rHr&r')rrGr#r$rrrr�get_club_stats�r)zNHLAPIClient.get_club_statscCr*)zu Get scoreboard for a specific team. Args: team: Three-letter team code z/v1/scoreboard/rIr'rJrrr�get_team_scoreboard�r.z NHLAPIClient.get_team_scoreboardcCs,|r d|�d|��}nd|�d�}|�|�S)z� Get roster for a specific team. Args: team: Three-letter team code season: Optional season parameter z /v1/roster/r&z/currentr'�rrGr#rrrr�get_team_roster��  zNHLAPIClient.get_team_rostercCs,|r d|�d|��}nd|�d�}|�|�S)z� Get schedule for a specific team. Args: team: Three-letter team code season: Optional season parameter z/v1/club-schedule-season/r&z/v1/club-schedule/rIr'rOrrr�get_team_schedule�rQzNHLAPIClient.get_team_schedulecCr<)zGet current schedule.z/v1/schedule/nowr'r=rrr�get_schedule_now�r?zNHLAPIClient.get_schedule_nowcCrB)zv Get schedule for a specific date. Args: date: Date in YYYY-MM-DD format z /v1/schedule/r'rCrrr�get_schedule_by_date�rEz!NHLAPIClient.get_schedule_by_datecCr<)zGet current schedule calendar.z/v1/schedule-calendar/nowr'r=rrr�get_schedule_calendar_nowr?z&NHLAPIClient.get_schedule_calendar_nowcCrB)z Get schedule calendar for a specific date. Args: date: Date in YYYY-MM-DD format z/v1/schedule-calendar/r'rCrrr�get_schedule_calendar_by_date rEz*NHLAPIClient.get_schedule_calendar_by_datecCr<)zGet current daily scores.z /v1/score/nowr'r=rrr�get_daily_scores_nowr?z!NHLAPIClient.get_daily_scores_nowcCrB)zz Get daily scores for a specific date. Args: date: Date in YYYY-MM-DD format z /v1/score/r'rCrrr�get_daily_scores_by_daterEz%NHLAPIClient.get_daily_scores_by_datecCr<)zGet current overall scoreboard.z/v1/scoreboard/nowr'r=rrr�get_scoreboard_now$r?zNHLAPIClient.get_scoreboard_now�includecCs d}i}|r ||d<|�||�S)zs Get streaming information. Args: include: Optional include parameter z/v1/where-to-watchrZr')rrZrrrrr�get_where_to_watch)s  zNHLAPIClient.get_where_to_watch�game_idcCr*)zw Get play-by-play information for a specific game. Args: game_id: Game ID �/v1/gamecenter/z /play-by-playr'�rr\rrrr�get_play_by_play8r.zNHLAPIClient.get_play_by_playcCr*)zr Get landing information for a specific game. Args: game_id: Game ID r]r+r'r^rrr�get_game_landingBr.zNHLAPIClient.get_game_landingcCr*)zs Get boxscore information for a specific game. Args: game_id: Game ID r]z /boxscorer'r^rrr�get_game_boxscoreLr.zNHLAPIClient.get_game_boxscorecCrB)zu Get game story information for a specific game. Args: game_id: Game ID z/v1/wsc/game-story/r'r^rrr�get_game_storyVrEzNHLAPIClient.get_game_storycCrB)zy Get TV schedule for a specific date. Args: date: Date in YYYY-MM-DD format z/v1/network/tv-schedule/r'rCrrr�get_tv_schedule_by_datebrEz$NHLAPIClient.get_tv_schedule_by_datecCr<)zGet current TV schedule.z/v1/network/tv-schedule/nowr'r=rrr�get_tv_schedule_nowlr?z NHLAPIClient.get_tv_schedule_nowcCr<)zGet playoff overview.z/v1/playoff-overviewr'r=rrr�get_playoff_overviewsr?z!NHLAPIClient.get_playoff_overviewcC�|rd|��}nd}|�|�S)zu Get playoff schedule. Args: season: Optional season in YYYYYYYY format z/v1/playoff-schedule/z/v1/playoff-schedule/nowr'�rr#rrrr�get_playoff_schedulex�  z!NHLAPIClient.get_playoff_schedulecCrf)zt Get playoff bracket. Args: season: Optional season in YYYYYYYY format z/v1/playoff-bracket/z/v1/playoff-bracket/nowr'rgrrr�get_playoff_bracket�riz NHLAPIClient.get_playoff_bracketcCr<)zGet season information.z /v1/seasonr'r=rrr�get_season_info�r?zNHLAPIClient.get_season_info�yearcCrf)ze Get draft information. Args: year: Optional draft year z /v1/draft/z /v1/draftr')rrlrrrr�get_draft_info�rizNHLAPIClient.get_draft_infocCr<)zGet meta information.z/v1/metar'r=rrr� get_meta_info�r?zNHLAPIClient.get_meta_info� postal_codecCrB)z{ Get postal code lookup information. Args: postal_code: Postal code to lookup z/v1/postal-lookup/r')rrorrrr�get_postal_lookup�rEzNHLAPIClient.get_postal_lookupcCrf)zo Get game replays. Args: date: Optional date in YYYY-MM-DD format z/v1/game-replays/z/v1/game-replaysr'rCrrr�get_game_replays�rizNHLAPIClient.get_game_replays)r)N)NN)2�__name__� __module__� __qualname__�__doc__rrrrrr!�intr(r-r/r4r8r:r;r>r@rDrFrKrLrMrNrPrRrSrTrUrVrWrXrYr[r_r`rarbrcrdrerhrjrkrmrnrprqrrrrr sV,"  ( 0(0  "  $ $           $ rrcCst�S)z Get a configured NHL API client.)rrrrr�get_nhl_client�srw�__main__zCurrent NHL Standings:�)�indentzError: )rur �typingrrrrrrrrwrr�clientr@� standings�print�dumpsrr rrrr�<module>s(>���

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/sanchorelaxo/mcp-server-sandbox'

If you have feedback or need assistance with the MCP directory API, please join our Discord server