get_stock_grades_historical
Retrieve historical analyst ratings for stocks using the Yahoo Finance MCP Server. Provide a ticker symbol and limit to access detailed grading data for informed investment decisions.
Instructions
获取分析师评级历史记录。
参数说明: ticker: str 股票代码,例如 "AAPL" limit: int 返回记录数量,最大 1000,默认 100
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| ticker | Yes |
Implementation Reference
- server.py:761-779 (handler)The handler function that implements the core logic of fetching historical analyst grades for a stock ticker from the Financial Modeling Prep API, handling API key, making HTTP request, and returning JSON data.async def get_stock_grades_historical(ticker: str, limit: int = 100) -> str: """获取分析师评级历史数据""" api_key = os.environ.get("FMP_API_KEY") if not api_key: return "Error: FMP_API_KEY environment variable not set." url = "https://financialmodelingprep.com/stable/grades-historical" try: resp = requests.get( url, params={"symbol": ticker, "limit": limit, "apikey": api_key}, timeout=10, ) resp.raise_for_status() data = resp.json() except Exception as e: return f"Error: getting historical grades for {ticker}: {e}" return json.dumps(data)
- server.py:751-760 (registration)The decorator that registers the 'get_stock_grades_historical' tool with the FastMCP server, including the name and a description with parameter schema details.@fmp_server.tool( name="get_stock_grades_historical", description="""获取分析师评级历史记录。 参数说明: ticker: str 股票代码,例如 "AAPL" limit: int 返回记录数量,最大 1000,默认 100""", )
- server.py:753-760 (schema)The tool description string that defines the input schema (parameters: ticker str, limit int=100) for validation and usage.description="""获取分析师评级历史记录。 参数说明: ticker: str 股票代码,例如 "AAPL" limit: int 返回记录数量,最大 1000,默认 100""", )