get_news_list
Retrieve today's hot news headlines by category: top, domestic, international, entertainment, sports, military, technology, finance, gaming, auto, or health. Supports pagination to browse multiple pages.
Instructions
通过新闻类型获取今日热点新闻头条
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | 新闻类型:top(推荐,默认),guonei(国内),guoji(国际),yule(娱乐),tiyu(体育),junshi(军事),keji(科技),caijing(财经),youxi(游戏),qiche(汽车),jiankang(健康) | |
| page | No | 当前页数, 默认1, 最大50 | |
| page_size | No | 每页返回新闻条数, 默认20, 最大50 |
Implementation Reference
- src/jnews_mcp_server/server.py:82-110 (handler)The actual async function that executes the 'get_news_list' tool logic. It calls the Juhe Toutiao API with type, page, page_size, and API key parameters, and returns news data as TextContent.
async def get_news_list(type: str = "top", page: int = 1, page_size: int = 20) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """ 根据新闻类型获取今日热点新闻头条. """ url = f"{JUHE_NEWS_API_BASE}/index" params = { "type": type, "page": page, "page_size": page_size, "key": JUHE_NEWS_API_KEY } async with httpx.AsyncClient() as client: response = await client.get(url, params=params) data = response.json() if data["error_code"] == 0: news_list = data["result"]["data"] return [ types.TextContent( type="text", text=f"{news_list}" ) ] else: return [ types.TextContent( type="text", text=f"Error: {data['reason']}" ) ] - src/jnews_mcp_server/server.py:24-43 (registration)Tool registration using @server.list_tools() decorator. Defines the tool name 'get_news_list', its description, and JSON Schema input schema with 'type', 'page', and 'page_size' properties.
return [ types.Tool( name="get_news_list", description="通过新闻类型获取今日热点新闻头条", inputSchema={ "type": "object", "properties": { "type": { "type": "string", "description": "新闻类型:top(推荐,默认),guonei(国内),guoji(国际),yule(娱乐),tiyu(体育),junshi(军事),keji(科技),caijing(财经),youxi(游戏),qiche(汽车),jiankang(健康)", }, "page": { "type": "number", "description": "当前页数, 默认1, 最大50" }, "page_size": { "type": "number", "description": "每页返回新闻条数, 默认20, 最大50" }, }, # "required": ["type"], }, ), - src/jnews_mcp_server/server.py:28-42 (schema)Input schema for the 'get_news_list' tool. Defines 'type' (string), 'page' (number), and 'page_size' (number) as optional parameters with descriptions.
inputSchema={ "type": "object", "properties": { "type": { "type": "string", "description": "新闻类型:top(推荐,默认),guonei(国内),guoji(国际),yule(娱乐),tiyu(体育),junshi(军事),keji(科技),caijing(财经),youxi(游戏),qiche(汽车),jiankang(健康)", }, "page": { "type": "number", "description": "当前页数, 默认1, 最大50" }, "page_size": { "type": "number", "description": "每页返回新闻条数, 默认20, 最大50" }, }, # "required": ["type"], }, - src/jnews_mcp_server/server.py:65-67 (helper)Call tool dispatcher that routes 'get_news_list' requests to the handler function, extracting 'type' from arguments (defaulting to 'top').
if name == "get_news_list": type_value = type_value = arguments.get("type", "top") if arguments else "top" return await get_news_list(type_value)