Skip to main content
Glama

MCP YFinance Stock Server

by sauniket
state.pyβ€’2.33 kB
from enum import Enum import time from typing import Optional, Any from threading import Thread, Lock # Financial statement types class FinancialType(str, Enum): income_stmt = "income_stmt" quarterly_income_stmt = "quarterly_income_stmt" balance_sheet = "balance_sheet" quarterly_balance_sheet = "quarterly_balance_sheet" cashflow = "cashflow" quarterly_cashflow = "quarterly_cashflow" # Holder types class HolderType(str, Enum): major_holders = "major_holders" institutional_holders = "institutional_holders" mutualfund_holders = "mutualfund_holders" insider_transactions = "insider_transactions" insider_purchases = "insider_purchases" insider_roster_holders = "insider_roster_holders" # Recommendation types class RecommendationType(str, Enum): recommendations = "recommendations" upgrades_downgrades = "upgrades_downgrades" class ServerState: """Global state manager for MCP server.""" def __init__(self): self.watchlist = set() self.watchlist_prices = {} self.price_cache = {} self.cache_timeout = 300 # seconds self.update_thread: Optional[Thread] = None self.running = True self._lock = Lock() def add_to_cache(self, symbol: str, data: Any): """Add data to cache with timestamp""" with self._lock: self.price_cache[symbol] = { 'data': data, 'timestamp': time.time() } def get_from_cache(self, symbol: str) -> Optional[Any]: """Get data from cache if not expired""" with self._lock: if symbol in self.price_cache: cache_entry = self.price_cache[symbol] if time.time() - cache_entry['timestamp'] < self.cache_timeout: return cache_entry['data'] else: del self.price_cache[symbol] return None def cleanup_cache(self): """Remove expired cache entries""" current_time = time.time() with self._lock: expired_keys = [ key for key, value in self.price_cache.items() if current_time - value['timestamp'] > self.cache_timeout ] for key in expired_keys: del self.price_cache[key]

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/sauniket/mcp-yfinance-server'

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