Skip to main content
Glama
24mlight

A Share MCP

get_dividend_data

Fetch dividend information for A-share stocks by stock code and year, returning dividend records including announcement and ex-dividend details.

Instructions

    Fetches dividend information for a given stock code and year.

    Args:
        code: The stock code in Baostock format (e.g., 'sh.600000', 'sz.000001').
        year: The year to query (e.g., '2023').
        year_type: Type of year. Valid options (from Baostock):
                     'report': Announcement year (预案公告年份)
                     'operate': Ex-dividend year (除权除息年份)
                   Defaults to 'report'.

    Returns:
        Dividend records table.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
yearYes
year_typeNoreport
limitNo
formatNomarkdown

Implementation Reference

  • MCP tool handler for get_dividend_data. Decorated with @app.tool(), logs the call, and delegates to the use case function fetch_dividend_data via run_tool_with_handling for execution and error handling.
    @app.tool()
    def get_dividend_data(code: str, year: str, year_type: str = "report", limit: int = 250, format: str = "markdown") -> str:
        """
        Fetches dividend information for a given stock code and year.
    
        Args:
            code: The stock code in Baostock format (e.g., 'sh.600000', 'sz.000001').
            year: The year to query (e.g., '2023').
            year_type: Type of year. Valid options (from Baostock):
                         'report': Announcement year (预案公告年份)
                         'operate': Ex-dividend year (除权除息年份)
                       Defaults to 'report'.
    
        Returns:
            Dividend records table.
        """
        logger.info(f"Tool 'get_dividend_data' called for {code}, year={year}, year_type={year_type}")
        return run_tool_with_handling(
            lambda: fetch_dividend_data(
                active_data_source,
                code=code,
                year=year,
                year_type=year_type,
                limit=limit,
                format=format,
            ),
            context=f"get_dividend_data:{code}:{year}",
        )
  • mcp_server.py:51-51 (registration)
    Registration call for stock market tools, including get_dividend_data, passed to the FastMCP app instance.
    register_stock_market_tools(app, active_data_source)
  • Use case helper function that performs validation and formats the dividend data fetched from the data source.
    def fetch_dividend_data(
        data_source: FinancialDataSource,
        *,
        code: str,
        year: str,
        year_type: str = "report",
        limit: int = 250,
        format: str = "markdown",
    ) -> str:
        validate_year(year)
        validate_year_type(year_type)
        validate_output_format(format)
    
        df = data_source.get_dividend_data(code=code, year=year, year_type=year_type)
        meta = {"code": code, "year": year, "year_type": year_type}
        return format_table_output(df, format=format, max_rows=limit, meta=meta)
  • Core implementation in BaostockDataSource that queries the Baostock API for dividend data and returns a DataFrame.
    def get_dividend_data(self, code: str, year: str, year_type: str = "report") -> pd.DataFrame:
        """Fetches dividend information using Baostock."""
        logger.info(
            f"Fetching dividend data for {code}, year={year}, year_type={year_type}")
        try:
            with baostock_login_context():
                rs = bs.query_dividend_data(
                    code=code, year=year, yearType=year_type)
    
                if rs.error_code != '0':
                    logger.error(
                        f"Baostock API error (Dividend) for {code}: {rs.error_msg} (code: {rs.error_code})")
                    if "no record found" in rs.error_msg.lower() or rs.error_code == '10002':
                        raise NoDataFoundError(
                            f"No dividend data found for {code} and year {year}. Baostock msg: {rs.error_msg}")
                    else:
                        raise DataSourceError(
                            f"Baostock API error fetching dividend data: {rs.error_msg} (code: {rs.error_code})")
    
                data_list = []
                while rs.next():
                    data_list.append(rs.get_row_data())
    
                if not data_list:
                    logger.warning(
                        f"No dividend data found for {code}, year {year} (empty result set from Baostock).")
                    raise NoDataFoundError(
                        f"No dividend data found for {code}, year {year} (empty result set).")
    
                result_df = pd.DataFrame(data_list, columns=rs.fields)
                logger.info(
                    f"Retrieved {len(result_df)} dividend records for {code}, year {year}.")
                return result_df
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'fetches' data, implying a read-only operation, but doesn't clarify permissions, rate limits, error handling, or return format details. The mention of 'Dividend records table' hints at the output structure, but lacks specifics like columns or pagination. For a tool with 5 parameters and no annotations, this leaves significant behavioral gaps.

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

Conciseness5/5

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

The description is well-structured and concise, with a clear purpose statement followed by parameter details in a formatted 'Args' and 'Returns' section. Every sentence adds value: the purpose is front-loaded, and parameter explanations are efficient with examples and defaults. No wasted words or redundancy.

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

Completeness2/5

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

Given the complexity (5 parameters, no annotations, no output schema), the description is incomplete. It covers the core purpose and some parameters but misses two parameters ('limit', 'format'), provides no output schema details beyond 'Dividend records table', and lacks behavioral context like error handling or data freshness. For a data-fetching tool with multiple parameters, this leaves the agent under-informed.

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

Parameters3/5

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

The description adds meaningful context for 3 parameters (code, year, year_type) by explaining formats, examples, and valid options, which compensates partially for the 0% schema description coverage. However, it omits the 'limit' and 'format' parameters entirely, leaving them undocumented. With 5 total parameters and only 3 covered, the description provides moderate but incomplete semantic value beyond the bare schema.

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: 'Fetches dividend information for a given stock code and year.' It specifies the verb ('fetches'), resource ('dividend information'), and scope ('for a given stock code and year'). However, it doesn't explicitly differentiate from sibling tools like 'get_profit_data' or 'get_balance_data', which might also fetch financial data but for different metrics.

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_profit_data' or 'get_stock_basic_info', nor does it specify prerequisites or exclusions. The agent must infer usage from the purpose alone, which is insufficient for optimal tool selection.

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/24mlight/a_share_mcp_is_just_I_need'

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