Skip to main content
Glama
Rahii123

Advanced MCP Server

by Rahii123

search_news

Find recent news articles on specific topics to stay informed about current events and developments.

Instructions

Search for recent news articles on a specific topic.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • server.py:38-64 (handler)
    This is the main handler function for the 'search_news' tool. It fetches recent news articles using the NewsAPI based on the query parameter, handles API key validation, and formats the top 5 results.
    @mcp.tool() async def search_news(query: str) -> str: """Search for recent news articles on a specific topic.""" query = query.strip() api_key = os.getenv("NEWS_API_KEY") if not api_key or api_key.strip() == "your_api_key_here": return "Error: NEWS_API_KEY not set. Please add it to your .env file." api_key = api_key.strip() url = f"https://newsapi.org/v2/everything?q={query}&pageSize=5&apiKey={api_key}" async with httpx.AsyncClient() as client: response = await client.get(url) if response.status_code != 200: return f"Error fetching news: {response.status_code}" data = response.json() articles = data.get("articles", []) if not articles: return f"No news found for '{query}'." news_list = [] for art in articles: news_list.append(f"- {art.get('title')} (Source: {art.get('source', {}).get('name')})") return "\n".join(news_list)
Install Server

Other 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/Rahii123/mcp'

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