get_stock_grades
Retrieve the latest analyst ratings for a specific stock using its ticker symbol, such as "AAPL", to inform investment decisions with expert insights.
Instructions
获取分析师最新评级。
参数说明: ticker: str 股票代码,例如 "AAPL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes |
Implementation Reference
- server.py:734-748 (handler)The main handler function for the get_stock_grades tool. It takes a stock ticker, fetches analyst grades from the Financial Modeling Prep API using the FMP_API_KEY, handles errors, and returns the data as JSON string.async def get_stock_grades(ticker: str) -> 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" try: resp = requests.get(url, params={"symbol": ticker, "apikey": api_key}, timeout=10) resp.raise_for_status() data = resp.json() except Exception as e: return f"Error: getting stock grades for {ticker}: {e}" return json.dumps(data)
- server.py:726-733 (registration)The decorator that registers the get_stock_grades tool with the MCP server, including the tool name and input schema description.@fmp_server.tool( name="get_stock_grades", description="""获取分析师最新评级。 参数说明: ticker: str 股票代码,例如 "AAPL""", )
- server.py:728-733 (schema)The description in the tool decorator defines the input schema: ticker (str, stock symbol like AAPL). Output is str (JSON).description="""获取分析师最新评级。 参数说明: ticker: str 股票代码,例如 "AAPL""", )