Skip to main content
Glama
24mlight

A-Share MCP Server

get_fina_indicator

Retrieve aggregated quarterly financial indicators for A-share stocks, combining profitability, operations, growth, solvency, cash flow, and DuPont analysis metrics in a single query.

Instructions

    Aggregated financial indicators from 6 Baostock APIs into one convenient query.

    **Data is returned by QUARTER** (Q1, Q2, Q3, Q4) based on financial report dates.
    Input date range determines which quarters to fetch.

    Combines data from:
    - 盈利能力 (Profitability): roeAvg, npMargin, gpMargin, epsTTM
    - 营运能力 (Operation): NRTurnRatio, INVTurnRatio, CATurnRatio
    - 成长能力 (Growth): YOYNI, YOYEquity, YOYAsset
    - 偿债能力 (Solvency): currentRatio, quickRatio, liabilityToAsset
    - 现金流量 (Cash Flow): CFOToOR, CFOToNP, CAToAsset
    - 杜邦分析 (DuPont): dupontROE, dupontAssetTurn, dupontPnitoni

    Output columns include prefixes: profit_*, operation_*, growth_*,
    balance_*, cashflow_*, dupont_* to distinguish data sources.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
start_dateYes
end_dateYes
limitNo
formatNomarkdown

Implementation Reference

  • The primary MCP tool handler for 'get_fina_indicator'. Decorated with @app.tool() for automatic registration. It invokes the use case with standardized error handling, logging context, and output formatting.
    @app.tool()
    def get_fina_indicator(code: str, start_date: str, end_date: str, limit: int = 250, format: str = "markdown") -> str:
        """
        Aggregated financial indicators from 6 Baostock APIs into one convenient query.
    
        **Data is returned by QUARTER** (Q1, Q2, Q3, Q4) based on financial report dates.
        Input date range determines which quarters to fetch.
    
        Combines data from:
        - 盈利能力 (Profitability): roeAvg, npMargin, gpMargin, epsTTM
        - 营运能力 (Operation): NRTurnRatio, INVTurnRatio, CATurnRatio
        - 成长能力 (Growth): YOYNI, YOYEquity, YOYAsset
        - 偿债能力 (Solvency): currentRatio, quickRatio, liabilityToAsset
        - 现金流量 (Cash Flow): CFOToOR, CFOToNP, CAToAsset
        - 杜邦分析 (DuPont): dupontROE, dupontAssetTurn, dupontPnitoni
    
        Output columns include prefixes: profit_*, operation_*, growth_*,
        balance_*, cashflow_*, dupont_* to distinguish data sources.
        """
        return run_tool_with_handling(
            lambda: fetch_fina_indicator(
                active_data_source, code=code, start_date=start_date, end_date=end_date, limit=limit, format=format
            ),
            context=f"get_fina_indicator:{code}:{start_date}-{end_date}",
        )
  • mcp_server.py:52-52 (registration)
    Invocation of the registration function that adds the get_fina_indicator tool (and other financial report tools) to the FastMCP app instance.
    register_financial_report_tools(app, active_data_source)
  • Interface definition for get_fina_indicator method, providing input/output schema and documentation used throughout the tool chain.
    @abstractmethod
    def get_fina_indicator(self, code: str, start_date: str, end_date: str) -> pd.DataFrame:
        """
        Fetches financial indicators (ROE, gross margin, net margin, etc.) within a date range.
    
        Args:
            code: The stock code (e.g., 'sh.600000', 'sz.000001').
            start_date: Start date in 'YYYY-MM-DD' format.
            end_date: End date in 'YYYY-MM-DD' format.
    
        Returns:
            A pandas DataFrame containing financial indicators such as:
            - roe, roe_yearly (Return on Equity)
            - netprofit_margin, grossprofit_margin (Profitability ratios)
            - expense_ratio, netprofit_ratio
            - current_ratio, quick_ratio (Liquidity ratios)
            - etc.
        """
        pass
  • Use case layer function that orchestrates data fetching from the data source and applies output formatting and validation.
    def fetch_fina_indicator(data_source: FinancialDataSource, *, code: str, start_date: str, end_date: str, limit: int, format: str) -> str:
        """Fetch financial indicators (ROE, gross margin, net margin, etc.) within a date range."""
        validate_output_format(format)
        df = data_source.get_fina_indicator(code=code, start_date=start_date, end_date=end_date)
        meta = {"code": code, "start_date": start_date, "end_date": end_date, "dataset": "Financial Indicators"}
        return format_table_output(df, format=format, max_rows=limit, meta=meta)
  • Core implementation in BaostockDataSource that aggregates data from 6 different Baostock APIs (profit, operation, growth, balance, cashflow, dupont) into a single prefixed DataFrame for each quarter in the date range.
    def get_fina_indicator(self, code: str, start_date: str, end_date: str) -> pd.DataFrame:
        """
        Fetches comprehensive financial indicators by aggregating multiple Baostock APIs.
    
        Aggregates data from:
        - Profitability (盈利能力)
        - Operation Capability (营运能力)
        - Growth Capability (成长能力)
        - Balance Sheet/Solvency (偿债能力)
        - Cash Flow (现金流量)
        - DuPont Analysis (杜邦分析)
        """
        logger.info(f"Fetching aggregated financial indicators for {code} ({start_date} to {end_date})")
    
        # 解析日期范围,获取年份列表
        from datetime import datetime
        try:
            start = datetime.strptime(start_date, "%Y-%m-%d")
            end = datetime.strptime(end_date, "%Y-%m-%d")
        except ValueError:
            raise ValueError(f"Invalid date format. Expected YYYY-MM-DD, got {start_date} to {end_date}")
    
        years = set(str(y) for y in range(start.year, end.year + 1))
    
        all_results = []
    
        try:
            with baostock_login_context():
                for year in years:
                    for quarter in [1, 2, 3, 4]:
                        # 检查季度是否在日期范围内
                        quarter_start_month = (quarter - 1) * 3
                        quarter_start = datetime(int(year), quarter_start_month + 1, 1)
                        if quarter_start > end:
                            continue
    
                        record = {"code": code, "year": year, "quarter": quarter}
    
                        # 1. 盈利能力
                        try:
                            rs = bs.query_profit_data(code=code, year=year, quarter=quarter)
                            if rs.error_code == '0' and rs.next():
                                row = rs.get_row_data()
                                for i, field in enumerate(rs.fields):
                                    record[f"profit_{field}"] = row[i] if i < len(row) else None
                        except Exception as e:
                            logger.debug(f"Failed to fetch profit data for {code} {year}Q{quarter}: {e}")
    
                        # 2. 营运能力
                        try:
                            rs = bs.query_operation_data(code=code, year=year, quarter=quarter)
                            if rs.error_code == '0' and rs.next():
                                row = rs.get_row_data()
                                for i, field in enumerate(rs.fields):
                                    record[f"operation_{field}"] = row[i] if i < len(row) else None
                        except Exception as e:
                            logger.debug(f"Failed to fetch operation data for {code} {year}Q{quarter}: {e}")
    
                        # 3. 成长能力
                        try:
                            rs = bs.query_growth_data(code=code, year=year, quarter=quarter)
                            if rs.error_code == '0' and rs.next():
                                row = rs.get_row_data()
                                for i, field in enumerate(rs.fields):
                                    record[f"growth_{field}"] = row[i] if i < len(row) else None
                        except Exception as e:
                            logger.debug(f"Failed to fetch growth data for {code} {year}Q{quarter}: {e}")
    
                        # 4. 偿债能力
                        try:
                            rs = bs.query_balance_data(code=code, year=year, quarter=quarter)
                            if rs.error_code == '0' and rs.next():
                                row = rs.get_row_data()
                                for i, field in enumerate(rs.fields):
                                    record[f"balance_{field}"] = row[i] if i < len(row) else None
                        except Exception as e:
                            logger.debug(f"Failed to fetch balance data for {code} {year}Q{quarter}: {e}")
    
                        # 5. 现金流量
                        try:
                            rs = bs.query_cash_flow_data(code=code, year=year, quarter=quarter)
                            if rs.error_code == '0' and rs.next():
                                row = rs.get_row_data()
                                for i, field in enumerate(rs.fields):
                                    record[f"cashflow_{field}"] = row[i] if i < len(row) else None
                        except Exception as e:
                            logger.debug(f"Failed to fetch cash flow data for {code} {year}Q{quarter}: {e}")
    
                        # 6. 杜邦分析
                        try:
                            rs = bs.query_dupont_data(code=code, year=year, quarter=quarter)
                            if rs.error_code == '0' and rs.next():
                                row = rs.get_row_data()
                                for i, field in enumerate(rs.fields):
                                    record[f"dupont_{field}"] = row[i] if i < len(row) else None
                        except Exception as e:
                            logger.debug(f"Failed to fetch dupont data for {code} {year}Q{quarter}: {e}")
    
                        # 只有当有数据时才添加记录
                        if len(record) > 3:  # code + year + quarter + at least one data field
                            all_results.append(record)
    
                if not all_results:
                    raise NoDataFoundError(
                        f"No financial indicator data found for {code} in range {start_date}-{end_date}")
    
                result_df = pd.DataFrame(all_results)
                logger.info(f"Retrieved {len(result_df)} aggregated financial indicator records for {code}.")
                return result_df
    
        except (LoginError, NoDataFoundError, DataSourceError, ValueError) as e:
            logger.warning(f"Known error fetching financial indicators for {code}: {type(e).__name__}")
            raise e
        except Exception as e:
            logger.exception(f"Unexpected error fetching financial indicators for {code}: {e}")
            raise DataSourceError(f"Unexpected error fetching financial indicators for {code}: {e}")
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: data is returned by quarter (Q1-Q4) based on financial report dates, input date range determines which quarters to fetch, and output columns include prefixes to distinguish data sources. It doesn't mention rate limits, authentication needs, or pagination behavior, but covers the core operational behavior adequately.

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 appropriately sized with zero wasted sentences. It front-loads the core purpose, explains key behavioral constraints, details the data sources, and describes output formatting - each sentence adds essential value. The use of bold text for important constraints (quarter-based returns) enhances clarity.

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

Completeness4/5

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

For a tool with 5 parameters, 0% schema coverage, no annotations, and no output schema, the description provides substantial context about what the tool does, how it behaves, and what data it returns. It could improve by explicitly mentioning the meaning of 'code' parameter and any limitations, but covers the essential complexity well given the lack of structured documentation.

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?

With 0% schema description coverage and 5 parameters, the description compensates excellently by explaining the semantic meaning of date parameters ('Input date range determines which quarters to fetch') and providing context about what 'code' likely represents (implied stock code from financial data context). It also mentions output format details that help understand the tool's behavior.

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 aggregates financial indicators from 6 Baostock APIs into one query, specifying the verb 'aggregates' and resource 'financial indicators'. It distinguishes from siblings by explaining it combines data from multiple specific financial categories (profitability, operation, growth, etc.) that are handled separately by other tools like get_profit_data, get_operation_data, get_growth_data, etc.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool: for aggregated financial indicators by quarter based on input date range. It doesn't explicitly state when NOT to use it or name specific alternatives, but the context of combining 6 APIs implies it's preferable when needing comprehensive data rather than individual category queries.

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