search_news
Search for news articles on Naver using keywords, with options to sort by relevance or date and navigate through result pages.
Instructions
Searches for news on Naver using the given keyword. The page parameter allows for page navigation and sort='sim'/'date' is supported.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| display | No | ||
| page | No | ||
| sort | No | sim |
Implementation Reference
- server.py:383-396 (handler)The main handler function implementing the 'search_news' tool. It calculates pagination parameters, prepares API params, and delegates to the shared _make_api_call helper to fetch and format Naver news search results.async def search_news(query: str, display: int = 10, page: int = 1, sort: str = "sim") -> str: """ Searches for news on Naver using the given keyword. The page parameter allows for page navigation and sort='sim'/'date' is supported. Args: query (str): The keyword to search for display (int, optional): The number of results to display. Default is 10. page (int, optional): The starting page number. Default is 1. sort (str, optional): The sorting criteria. Default is "sim" (similarity). """ start = calculate_start(page, display) display = min(display, 100) params = {"query": query, "display": display, "start": start, "sort": sort} return await _make_api_call("news.json", params, NewsResult, "News")
- server.py:379-382 (registration)The @mcp.tool decorator that registers the 'search_news' tool with the FastMCP server, including name and description.@mcp.tool( name="search_news", description="Searches for news on Naver using the given keyword. The page parameter allows for page navigation and sort='sim'/'date' is supported." )
- server.py:124-124 (schema)Pydantic model defining the structure for Naver news search API response, used for validation and parsing in the handler.class NewsResult(SearchResultBase): items: List[NewsItem]
- server.py:54-57 (schema)Pydantic model for individual news search result items, extending DescriptionItem with news-specific fields like original link and publication date.class NewsItem(DescriptionItem): originallink: Optional[str] = None pubDate: Optional[str] = None
- server.py:348-355 (helper)Helper function to compute the 'start' parameter for paginated Naver API calls, capping at 1000.def calculate_start(page: int, display: int) -> int: """Calculates the start value for the API call based on the page number and display count.""" if page < 1: page = 1 start = (page - 1) * display + 1 # 네이버 API의 start 최대값(1000) 제한 고려 return min(start, 1000)