get_recommendations
Retrieve analyst recommendations for a specific stock symbol to inform investment decisions using Yahoo Finance data. Input a valid stock symbol to receive detailed insights.
Instructions
Get analyst recommendations for a given symbol.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Stock symbol in Yahoo Finance format. |
Input Schema (JSON Schema)
{
"properties": {
"symbol": {
"description": "Stock symbol in Yahoo Finance format.",
"type": "string"
}
},
"required": [
"symbol"
],
"type": "object"
}
Implementation Reference
- src/mcp_yahoo_finance/server.py:20-32 (handler)Core handler function that fetches analyst recommendations for the given stock symbol using yfinance and returns them as formatted JSON string.def get_recommendations(self, symbol: str) -> str: """Get analyst recommendations for a given symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. """ stock = Ticker(ticker=symbol, session=self.session) recommendations = stock.get_recommendations() print(recommendations) if isinstance(recommendations, pd.DataFrame): return f"{recommendations.to_json(orient='records', indent=2)}" return f"{recommendations}"
- src/mcp_yahoo_finance/server.py:208-208 (registration)Registration of the 'get_recommendations' tool in the MCP server's list_tools() method using generate_tool.generate_tool(yf.get_recommendations),
- src/mcp_yahoo_finance/server.py:250-252 (handler)Dispatch logic in the call_tool handler that invokes the get_recommendations method and returns the result as TextContent.case "get_recommendations": recommendations = yf.get_recommendations(**args) return [TextContent(type="text", text=recommendations)]
- src/mcp_yahoo_finance/utils.py:31-65 (helper)Helper function generate_tool that dynamically generates the MCP Tool schema (including input schema) from the handler function's signature and docstring.def generate_tool(func: Any) -> Tool: """Generates a tool schema from a Python function.""" signature = inspect.signature(func) docstring = inspect.getdoc(func) or "" param_descriptions = parse_docstring(docstring) schema = { "name": func.__name__, "description": docstring.split("Args:")[0].strip(), "inputSchema": { "type": "object", "properties": {}, }, } for param_name, param in signature.parameters.items(): param_type = ( "number" if param.annotation is float else "string" if param.annotation is str else "string" ) schema["inputSchema"]["properties"][param_name] = { "type": param_type, "description": param_descriptions.get(param_name, ""), } if "required" not in schema["inputSchema"]: schema["inputSchema"]["required"] = [param_name] else: if "=" not in str(param): schema["inputSchema"]["required"].append(param_name) return Tool(**schema)
- Docstring providing the description and parameter details used to generate the tool's input schema."""Get analyst recommendations for a given symbol. Args: symbol (str): Stock symbol in Yahoo Finance format. """