Skip to main content
Glama
24mlight

A-Share MCP Server

get_dividend_data

Retrieve dividend payout information for specific A-share stocks by stock code and year, including announcement and ex-dividend dates.

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

  • The primary MCP tool handler for 'get_dividend_data'. Decorated with @app.tool(), it logs the call, invokes the fetch_dividend_data use case wrapped in error handling, and returns formatted results.
    @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)
    The registration call in the main MCP server that registers all stock market tools, including 'get_dividend_data', via the register_stock_market_tools function.
    register_stock_market_tools(app, active_data_source)
  • Helper use case function that performs input validation and formats the dividend DataFrame returned from the data source into the requested output format.
    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)
  • The core data fetching implementation in BaostockDataSource class, which queries the Baostock API (bs.query_dividend_data) to retrieve raw dividend data as a pandas 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
    
        except (LoginError, NoDataFoundError, DataSourceError, ValueError) as e:
            logger.warning(
                f"Caught known error fetching dividend data for {code}: {type(e).__name__}")
            raise e
        except Exception as e:
            logger.exception(
                f"Unexpected error fetching dividend data for {code}: {e}")
            raise DataSourceError(
                f"Unexpected error fetching dividend data for {code}: {e}")
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 mentions that the tool 'fetches' data, implying a read-only operation, but does not disclose other behavioral traits such as rate limits, authentication needs, error handling, or what 'Dividend records table' entails (e.g., structure, pagination). The description adds minimal context beyond the basic action.

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 appropriately sized and front-loaded, starting with a clear purpose statement followed by structured parameter explanations. Every sentence earns its place by providing essential information without redundancy. The use of bullet-like formatting for parameters enhances readability without unnecessary verbosity.

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 complexity (5 parameters, no annotations, no output schema), the description is partially complete. It covers the purpose and key parameters well but lacks details on behavioral aspects, output structure, and undocumented parameters. For a data-fetching tool with multiple parameters and no structured output, it should provide more context on what the return value looks like and how to handle the data.

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

Parameters4/5

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

The description adds significant meaning beyond the input schema, which has 0% schema description coverage. It explains the semantics of 'code' (Baostock format with examples), 'year' (query year), and 'year_type' (valid options and defaults with explanations). However, it omits 'limit' and 'format' parameters entirely, leaving them undocumented. Since schema coverage is low, the description compensates well for the documented parameters but not fully.

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

Purpose5/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 with a specific verb ('fetches') and resource ('dividend information'), and distinguishes it from siblings by specifying the exact data type (dividends) and scope (for a given stock code and year). It goes beyond just restating the name by detailing what information is retrieved.

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. While it mentions sibling tools like 'get_balance_data' or 'get_profit_data' in the list, it does not explain how this tool differs from them or when to choose one over another. Usage is implied by the purpose but not explicitly stated.

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