get_news_content
Retrieve detailed news content by providing a unique news ID, enabling access to full articles from the Juhe News MCP Server for analysis or integration.
Instructions
根据新闻ID获取新闻的详细内容
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uniquekey | Yes | 新闻ID(gew_news_list中返回的uniquekey) |
Implementation Reference
- src/jnews_mcp_server/server.py:112-148 (handler)The core handler function that implements the 'get_news_content' tool logic. It makes an HTTP request to the Juhe News API with the uniquekey to retrieve detailed news content and returns it as TextContent.async def get_news_content(uniquekey: str) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """ 根据新闻ID(uniquekey)获取新闻的详细内容. """ url = f"{JUHE_NEWS_API_BASE}/content" params = { "uniquekey": uniquekey, "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_content = data["result"] return [ # types.TextContent( # type="text", # text=f""" # 标题: {news_content['title']} # 作者: {news_content['author_name']} # URL: {news_content['url']} # 新闻id: {news_content['uniquekey']} # 新闻内容: {news_content['content']} # """ # ) types.TextContent( type="text", text=f"{news_content}" ) ] else: return [ types.TextContent( type="text", text=f"Error: {data['reason']}" ) ]
- src/jnews_mcp_server/server.py:44-54 (registration)Registration of the 'get_news_content' tool in the @server.list_tools() handler, including the tool name, description, and input JSON schema requiring 'uniquekey'.types.Tool( name="get_news_content", description="根据新闻ID获取新闻的详细内容", inputSchema={ "type": "object", "properties": { "uniquekey": {"type": "string", "description": "新闻ID(gew_news_list中返回的uniquekey)"}, }, "required": ["uniquekey"], }, ),
- src/jnews_mcp_server/server.py:47-53 (schema)Input schema definition for the 'get_news_content' tool, specifying the required 'uniquekey' parameter.inputSchema={ "type": "object", "properties": { "uniquekey": {"type": "string", "description": "新闻ID(gew_news_list中返回的uniquekey)"}, }, "required": ["uniquekey"], },
- src/jnews_mcp_server/server.py:68-72 (handler)Dispatch logic in the @server.call_tool() handler that extracts the 'uniquekey' argument and invokes the get_news_content function.elif name == "get_news_content": uniquekey = arguments.get("uniquekey") if arguments else None if not uniquekey: raise ValueError("Missing name or content") return await get_news_content(uniquekey)