get_top_articles
Retrieve trending Dev.to articles to discover popular developer content and insights.
Instructions
Get the top articles from Dev.to
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_top_articles"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:28-32 (handler)The handler function for the 'get_top_articles' tool. It fetches top articles from the Dev.to API endpoint '/articles' using the helper fetch_from_api and formats the first 10 using format_articles.
@mcp.tool() async def get_top_articles() -> str: """Get the top articles from Dev.to""" articles = await fetch_from_api("/articles") return format_articles(articles[:10]) # Limiting to 10 for readability - server.py:12-18 (helper)Helper function used by get_top_articles to make HTTP requests to the Dev.to API.
async def fetch_from_api(path: str, params: dict = None) -> dict: """Helper function to fetch data from Dev.to API""" async with httpx.AsyncClient() as client: url = f"{BASE_URL}{path}" response = await client.get(url, params=params, timeout=10.0) response.raise_for_status() return response.json() - server.py:168-188 (helper)Helper function used by get_top_articles to format the list of articles into a readable markdown string.
def format_articles(articles: list) -> str: """Format a list of articles for display""" if not articles: return "No articles found." result = "# Dev.to Articles\n\n" for article in articles: title = article.get("title", "Untitled") author = article.get("user", {}).get("name", "Unknown Author") published_date = article.get("readable_publish_date", "Unknown date") article_id = article.get("id", "") tags = article.get("tags", "") result += f"## {title}\n" result += f"ID: {article_id}\n" result += f"Author: {author}\n" result += f"Published: {published_date}\n" result += f"Tags: {tags}\n" result += f"Description: {article.get('description', 'No description available.')}\n\n" return result