Skip to main content
Glama

FinDataMCP

by coreyjwang
findata.py1.49 kB
# If using apis # from typing import Any # import httpx # from mcp.server.fastmcp import FastMCP import yfinance as yf # https://modelcontextprotocol.io/quickstart/server ##### Initialize FastMCP server ############################################# mcp = FastMCP("findata") # BASE_URL = "https://query1.finance.yahoo.com" # HEADERS = { # "User-Agent": "finance-mcp/1.0" # } ##### Helper functions to query & format #################################### # async def fetch_json(url: str) -> dict[str, Any] | None: # async with httpx.AsyncClient() as client: # try: # response = await client.get(url, headers=HEADERS) # response.raise_for_status() # return response.json() # except Exception: # return None ##### Tool execution handler ################################################ @mcp.tool() async def get_stock_price(symbol: str) -> str: """Get the current stock price using yfinance. Args: symbol: Stock ticker (e.g. AAPL, TSLA, MSFT) """ try: stock = yf.Ticker(symbol) info = stock.info price = info["currentPrice"] currency = info.get("currency", "USD") return f"{symbol.upper()} is trading at {price} {currency}." except Exception: return f"Could not retrieve stock price for {symbol}." ##### Run server ############################################################ if __name__ == "__main__": mcp.run(transport="stdio")

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/coreyjwang/FinDataMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server