Skip to main content
Glama
guillochon

mlb-api-mcp

get_mlb_game_scoring_plays

Retrieve scoring plays and game events from MLB games by game ID, with options to filter by event type, timecode, or specific fields.

Instructions

Get plays for a specific game by game_id, with optional filtering by eventType.

Args: game_id (int): The game ID. eventType (Optional[str]): Filter plays by this event type (e.g., 'scoring_play', 'home_run'). timecode (Optional[str]): Specific timecode for the play-by-play snapshot. fields (Optional[str]): Comma-separated list of fields to include.

Returns: dict: Game plays, optionally filtered by eventType.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
game_idYes
eventTypeNo
timecodeNo
fieldsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler implementation for the get_mlb_game_scoring_plays tool. Decorated with @mcp.tool() for automatic registration. Fetches play-by-play data using mlbstatsapi, filters by eventType if provided (e.g., scoring plays), and returns structured plays or error.
    @mcp.tool()
    def get_mlb_game_scoring_plays(
        game_id: int, eventType: Optional[str] = None, timecode: Optional[str] = None, fields: Optional[str] = None
    ) -> dict:
        """
        Get plays for a specific game by game_id, with optional filtering by eventType.
    
        Args:
            game_id (int): The game ID.
            eventType (Optional[str]): Filter plays by this event type (e.g., 'scoring_play', 'home_run').
            timecode (Optional[str]): Specific timecode for the play-by-play snapshot.
            fields (Optional[str]): Comma-separated list of fields to include.
    
        Returns:
            dict: Game plays, optionally filtered by eventType.
        """
        try:
            params = {}
            if timecode is not None:
                params["timecode"] = timecode
            if fields is not None:
                params["fields"] = fields
            plays = mlb.get_game_play_by_play(game_id, **params)
            if eventType:
                filtered_plays = [
                    play for play in plays.allplays if getattr(play.result, "eventType", None) == eventType
                ]
                return {"plays": filtered_plays}
            else:
                return {"plays": plays.allplays}
        except Exception as e:
            return {"error": str(e)}
  • main.py:21-23 (registration)
    Registers the MLB tools (including get_mlb_game_scoring_plays) by invoking setup_mlb_tools(mcp), which defines all @mcp.tool() decorated functions.
    # Setup all MLB and generic tools
    setup_mlb_tools(mcp)
    setup_generic_tools(mcp)
  • In tests, registers tools via setup_mlb_tools(mcp) for testing the get_mlb_game_scoring_plays tool.
    mcp = MagicMock()
    patch_mcp_tool(mcp)
    mlb_api.setup_mlb_tools(mcp)
  • Test confirming the handler works, retrieves via get_tool and tests filtering by eventType."
    def test_get_mlb_game_scoring_plays(mcp):
        get_mlb_game_scoring_plays = get_tool(mcp, "get_mlb_game_scoring_plays")
        assert get_mlb_game_scoring_plays is not None
        # Corrected: Each play should be a MagicMock with .result.eventType
        mock_play1 = MagicMock()
        mock_play1.result.eventType = "scoring_play"
        mock_play2 = MagicMock()
        mock_play2.result.eventType = "other"
        mock_plays = MagicMock()
        mock_plays.allplays = [mock_play1, mock_play2]
        with patch("mlb_api.mlb.get_game_play_by_play", return_value=mock_plays):
            result = get_mlb_game_scoring_plays(game_id=1, eventType="scoring_play")
            assert "plays" in result
  • Docstring defining input parameters and output format (schema).
    """
    Get plays for a specific game by game_id, with optional filtering by eventType.
    
    Args:
        game_id (int): The game ID.
        eventType (Optional[str]): Filter plays by this event type (e.g., 'scoring_play', 'home_run').
        timecode (Optional[str]): Specific timecode for the play-by-play snapshot.
        fields (Optional[str]): Comma-separated list of fields to include.
    
    Returns:
        dict: Game plays, optionally filtered by eventType.
    """
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is a 'Get' operation, implying it's read-only, but doesn't clarify authentication needs, rate limits, error handling, or what 'plays' entails (e.g., format, pagination). For a tool with 4 parameters and no annotation coverage, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It starts with a clear purpose sentence, followed by an 'Args' section detailing parameters and a 'Returns' section. While efficient, the 'Args' formatting could be slightly more concise, but overall, it avoids waste and is easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no annotations, but with an output schema), the description is adequate but has gaps. It covers parameters well and mentions the return type, but lacks behavioral context like error cases or usage scenarios. The output schema likely handles return values, so the description doesn't need to detail them, but overall completeness is minimal viable.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds substantial value beyond the input schema, which has 0% description coverage. It explains each parameter's purpose: game_id identifies the game, eventType filters plays (with examples like 'scoring_play'), timecode specifies a snapshot, and fields controls output inclusion. This compensates fully for the schema's lack of descriptions, making parameter usage clear.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get plays for a specific game by game_id, with optional filtering by eventType.' This specifies the verb ('Get'), resource ('plays'), and scope ('specific game'), though it doesn't explicitly distinguish it from sibling tools like get_mlb_game_highlights or get_mlb_game_lineup, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like get_mlb_boxscore or get_mlb_linescore that might overlap in functionality, nor does it specify prerequisites or exclusions. The agent must infer usage from the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/guillochon/mlb-api-mcp'

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