get_mlb_draft
Retrieve MLB draft data for a specified year to access player selections and draft details.
Instructions
Get draft information for a specific year.
Args: year_id (int): Draft year.
Returns: dict: Draft information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year_id | Yes |
Implementation Reference
- mlb_api.py:619-634 (handler)The core handler function for the 'get_mlb_draft' tool. It is decorated with @mcp.tool(), accepts a year_id parameter, fetches MLB draft data using the mlbstatsapi library, and returns it wrapped in a dictionary or an error message.@mcp.tool() def get_mlb_draft(year_id: int) -> dict: """ Get draft information for a specific year. Args: year_id (int): Draft year. Returns: dict: Draft information. """ try: draft = mlb.get_draft(year_id) return {"draft": draft} except Exception as e: return {"error": str(e)}
- main.py:19-23 (registration)Registers the 'get_mlb_draft' tool (along with other MLB tools) by calling setup_mlb_tools(mcp), which defines and registers the tool functions using the MCP decorator.mcp = FastMCP("MLB API MCP Server") # Setup all MLB and generic tools setup_mlb_tools(mcp) setup_generic_tools(mcp)
- mlb_api.py:619-634 (schema)The function signature and docstring define the input schema (year_id: int) and output (dict with 'draft' or 'error'), used by MCP for tool schema.@mcp.tool() def get_mlb_draft(year_id: int) -> dict: """ Get draft information for a specific year. Args: year_id (int): Draft year. Returns: dict: Draft information. """ try: draft = mlb.get_draft(year_id) return {"draft": draft} except Exception as e: return {"error": str(e)}