get_ratings
Retrieve real-time or historical stock ratings using the Yahoo Finance MCP Server. Input a stock symbol to access snapshot or past rating data, with customizable limits for results.
Instructions
获取股票评级数据,可选择快照或历史记录。
参数说明: symbol: str 股票代码,例如 "AAPL" rating_type: str snapshot 或 historical,默认 snapshot limit: int 返回数量,默认 1
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| rating_type | No | snapshot | |
| symbol | Yes |
Implementation Reference
- server.py:1016-1042 (handler)The handler function that implements the get_ratings tool by fetching stock analyst ratings (snapshot or historical) from the Financial Modeling Prep API using the provided symbol, rating_type, and limit parameters.async def get_ratings(symbol: str, rating_type: str = "snapshot", limit: int = 1) -> str: """根据类型获取评级信息""" api_key = os.environ.get("FMP_API_KEY") if not api_key: return "Error: FMP_API_KEY environment variable not set." base = "https://financialmodelingprep.com/stable" endpoint_map = { "snapshot": "ratings-snapshot", "historical": "ratings-historical", } endpoint = endpoint_map.get(rating_type.lower()) if not endpoint: return "Error: invalid rating type" url = f"{base}/{endpoint}" try: resp = requests.get( url, params={"symbol": symbol, "limit": limit, "apikey": api_key}, timeout=10, ) resp.raise_for_status() data = resp.json() except Exception as e: return f"Error: getting {rating_type} ratings for {symbol}: {e}" return json.dumps(data)
- server.py:1004-1015 (registration)The decorator that registers the get_ratings tool with the MCP server, including name, description, and parameter documentation.@fmp_server.tool( name="get_ratings", description="""获取股票评级数据,可选择快照或历史记录。 参数说明: symbol: str 股票代码,例如 "AAPL" rating_type: str snapshot 或 historical,默认 snapshot limit: int 返回数量,默认 1""", )
- server.py:1016-1016 (schema)Type annotations defining the input schema (symbol: str, rating_type: str='snapshot', limit: int=1) and output str for the tool.async def get_ratings(symbol: str, rating_type: str = "snapshot", limit: int = 1) -> str: