get_articles
Fetch articles from GeekNews by specifying article type (top, new, ask, show) and quantity limit to retrieve relevant content.
Instructions
GeekNews에서 아티클을 가져오는 도구
Args:
type: 아티클 유형 (top, new, ask, show)
limit: 반환할 아티클 수 (최대 30)
Returns:
List[Dict[str, Any]]: 아티클 목록
Raises:
ValueError: 유효하지 않은 아티클 유형이 지정된 경우
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | top | |
| limit | No |
Implementation Reference
- src/server.py:66-86 (registration)Registers the 'get_articles' tool using the @self.mcp.tool() decorator. Includes the schema definition in the docstring and function signature.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)
- src/server.py:139-175 (handler)Core handler logic for fetching articles: validates input, checks cache, refreshes via scheduler if needed, and limits results.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 []
- src/cache.py:163-175 (helper)Helper function to load cached articles for a given type, returning 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)
- src/scheduler.py:113-140 (helper)Helper function that refreshes articles by fetching HTML, parsing, converting to dicts, and saving 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 []
- src/server.py:72-84 (schema)Docstring defining the input schema (type, limit) and output for the MCP tool.""" GeekNews에서 아티클을 가져오는 도구 Args: type: 아티클 유형 (top, new, ask, show) limit: 반환할 아티클 수 (최대 30) Returns: List[Dict[str, Any]]: 아티클 목록 Raises: ValueError: 유효하지 않은 아티클 유형이 지정된 경우 """