Skip to main content
Glama
the0807

geeknews-mcp-server

get_articles

Fetch articles from GeekNews by specifying type (top, new, ask, show) and limit (up to 30). Returns structured article lists for streamlined access.

Instructions

GeekNews에서 아티클을 가져오는 도구 Args: type: 아티클 유형 (top, new, ask, show) limit: 반환할 아티클 수 (최대 30) Returns: List[Dict[str, Any]]: 아티클 목록 Raises: ValueError: 유효하지 않은 아티클 유형이 지정된 경우

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
typeNotop

Implementation Reference

  • src/server.py:66-86 (registration)
    Registers the get_articles tool using @mcp.tool() decorator, defines input parameters and docstring describing schema.
    def _setup_get_articles_tool(self) -> None: """ get_articles 도구를 설정합니다. """ @self.mcp.tool() def get_articles(type: str = "top", limit: int = DEFAULT_ARTICLE_LIMIT) -> List[Dict[str, Any]]: """ GeekNews에서 아티클을 가져오는 도구 Args: type: 아티클 유형 (top, new, ask, show) limit: 반환할 아티클 수 (최대 30) Returns: List[Dict[str, Any]]: 아티클 목록 Raises: ValueError: 유효하지 않은 아티클 유형이 지정된 경우 """ return self._get_articles(type, limit)
  • Core handler logic for fetching articles: validates type and limit, checks cache using get_articles_cache, refreshes via scheduler if needed, applies limit.
    def _get_articles(self, type: str, limit: int) -> List[Dict[str, Any]]: """ GeekNews에서 아티클을 가져옵니다. Args: type: 아티클 유형 (top, new, ask, show) limit: 반환할 아티클 수 (최대 30) Returns: List[Dict[str, Any]]: 아티클 목록 """ # 입력 유효성 검사 if type not in VALID_ARTICLE_TYPES: raise ValueError( f"유효하지 않은 아티클 유형: {type}. " f"다음 중 하나여야 합니다: {', '.join(VALID_ARTICLE_TYPES)}" ) # 아티클 수 제한 limit = max(1, min(limit, MAX_ARTICLES)) try: # 캐시에서 데이터 로드 시도 is_valid, cached_data = self.cache_manager.get_articles_cache(type) if is_valid and cached_data: logger.info(f"{type} 아티클 캐시 사용") return cached_data[:limit] # 캐시가 없거나 유효하지 않은 경우 데이터 갱신 logger.info(f"{type} 아티클 데이터 갱신") articles = self.scheduler.refresh_articles(type) return articles[:limit] except Exception as e: logger.error(f"아티클 가져오기 실패: {e}", exc_info=True) return []
  • Cache helper that loads and validates cached articles for a specific type, returns validity and data.
    def get_articles_cache(self, article_type: str) -> Tuple[bool, List[Dict[str, Any]]]: """ 아티클 캐시를 로드합니다. Args: article_type: 아티클 유형 (top, new, ask, show) Returns: Tuple[bool, List[Dict[str, Any]]]: (캐시 유효 여부, 아티클 목록) """ cache_key = f"articles_{article_type}" return self.load_cache(cache_key)
  • Supporting function that refreshes article cache: fetches HTML from client, parses articles, converts to dicts, saves to cache.
    def refresh_articles(self, article_type: str) -> List[Dict[str, Any]]: """ 특정 유형의 아티클 데이터를 갱신합니다. Args: article_type: 아티클 유형 (top, new, ask, show) Returns: List[Dict[str, Any]]: 갱신된 아티클 목록 """ try: # HTML 가져오기 html = self.client.fetch_articles(article_type) # 아티클 파싱 articles = self.parser.parse_articles(html) # 아티클 딕셔너리 변환 article_dicts = [article.to_dict() for article in articles] # 캐시 저장 self.cache_manager.save_articles_cache(article_type, article_dicts) logger.info(f"{article_type} 아티클 캐시 갱신 완료 ({len(article_dicts)}개)") return article_dicts except Exception as e: logger.error(f"{article_type} 아티클 갱신 실패: {e}", exc_info=True) return []

Other Tools

Related Tools

Latest Blog Posts

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/the0807/GeekNews-MCP-Server'

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