Skip to main content
Glama
24mlight

A Share MCP

by 24mlight

get_forecast_report

Retrieve earnings forecast reports for A-share stocks within specified date ranges to analyze financial projections and support investment decisions.

Instructions

Earnings forecast report within date range.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
start_dateYes
end_dateYes
limitNo
formatNomarkdown

Implementation Reference

  • mcp_server.py:52-52 (registration)
    Explicit registration call for the financial_reports tools module, which includes the get_forecast_report tool.
    register_financial_report_tools(app, active_data_source)
  • The handler function for the 'get_forecast_report' tool. Decorated with @app.tool(), it wraps the use case execution with standardized error handling and logging.
    @app.tool()
    def get_forecast_report(code: str, start_date: str, end_date: str, limit: int = 250, format: str = "markdown") -> str:
        """Earnings forecast report within date range."""
        return run_tool_with_handling(
            lambda: fetch_forecast_report(
                active_data_source, code=code, start_date=start_date, end_date=end_date, limit=limit, format=format
            ),
            context=f"get_forecast_report:{code}:{start_date}-{end_date}",
        )
  • Helper function that fetches the forecast report data from the data source and formats it for output.
    def fetch_forecast_report(data_source: FinancialDataSource, *, code: str, start_date: str, end_date: str, limit: int, format: str) -> str:
        validate_output_format(format)
        df = data_source.get_forecast_report(code=code, start_date=start_date, end_date=end_date)
        meta = {"code": code, "start_date": start_date, "end_date": end_date, "dataset": "Forecast"}
        return format_table_output(df, format=format, max_rows=limit, meta=meta)
  • Core implementation of the data source method that queries the Baostock API for forecast reports, handles pagination and errors, and returns a DataFrame.
    def get_forecast_report(self, code: str, start_date: str, end_date: str) -> pd.DataFrame:
        """Fetches performance forecast reports (业绩预告) using Baostock."""
        logger.info(
            f"Fetching Performance Forecast Report for {code} ({start_date} to {end_date})")
        try:
            with baostock_login_context():
                rs = bs.query_forecast_report(
                    code=code, start_date=start_date, end_date=end_date)
                # Note: Baostock docs mention pagination for this, but the Python API doesn't seem to expose it directly.
                # We fetch all available pages in the loop below.
    
                if rs.error_code != '0':
                    logger.error(
                        f"Baostock API error (Forecast) 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 performance forecast report found for {code} in range {start_date}-{end_date}. Baostock msg: {rs.error_msg}")
                    else:
                        raise DataSourceError(
                            f"Baostock API error fetching performance forecast report: {rs.error_msg} (code: {rs.error_code})")
    
                data_list = []
                while rs.next():  # Loop should handle pagination implicitly if rs manages it
                    data_list.append(rs.get_row_data())
    
                if not data_list:
                    logger.warning(
                        f"No performance forecast report found for {code} in range {start_date}-{end_date} (empty result set).")
                    raise NoDataFoundError(
                        f"No performance forecast report found for {code} in range {start_date}-{end_date} (empty result set).")
    
                result_df = pd.DataFrame(data_list, columns=rs.fields)
                logger.info(
                    f"Retrieved {len(result_df)} performance forecast report records for {code}.")
                return result_df
    
        except (LoginError, NoDataFoundError, DataSourceError, ValueError) as e:
            logger.warning(
                f"Caught known error fetching performance forecast report for {code}: {type(e).__name__}")
            raise e
        except Exception as e:
            logger.exception(
                f"Unexpected error fetching performance forecast report for {code}: {e}")
            raise DataSourceError(
                f"Unexpected error fetching performance forecast report for {code}: {e}")
  • Interface definition specifying the signature for the get_forecast_report method in the FinancialDataSource.
    @abstractmethod
    def get_forecast_report(self, code: str, start_date: str, end_date: str) -> pd.DataFrame:
        pass
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states this retrieves a 'report' but doesn't disclose format details, pagination behavior, rate limits, authentication requirements, or what happens when parameters are invalid. For a data retrieval tool with 5 parameters, this leaves significant behavioral questions unanswered.

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 extremely concise at just 5 words. While arguably too brief for a tool with 5 parameters, it's front-loaded with the core purpose and wastes no words. Every word contributes meaning, though more detail would be helpful.

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?

For a financial data tool with 5 parameters, 0% schema coverage, no annotations, and no output schema, the description is inadequate. It doesn't explain what an 'earnings forecast report' contains, how it differs from other financial reports, what the parameters mean, or what format the output takes. The context demands much more complete documentation.

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

Parameters2/5

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

Schema description coverage is 0%, so parameters are completely undocumented in the schema. The description only mentions 'date range' which maps to start_date and end_date, but doesn't explain the 'code' parameter (stock code? index code?), 'limit' (pagination? max results?), or 'format' (output format options?). It fails to compensate for the schema's lack of documentation.

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

Purpose3/5

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

The description 'Earnings forecast report within date range' clearly states the tool's purpose (retrieving earnings forecasts) and mentions date range filtering. However, it doesn't distinguish this tool from its many financial data siblings like 'get_profit_data' or 'get_performance_express_report' - it's unclear what makes 'forecast report' unique versus other performance-related tools.

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?

No guidance is provided about when to use this tool versus alternatives. With 40+ sibling tools including many financial data retrieval tools, the description offers no context about when this specific earnings forecast report is appropriate versus other performance metrics, profit data, or analysis tools.

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