search_articles
Find relevant articles on Dev.to by entering a search query and specifying a page number for pagination. Streamline content discovery with this tool.
Instructions
Search for articles on Dev.to
Args:
query: Search term to find articles
page: Page number for pagination (default: 1)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | ||
| query | Yes |
Implementation Reference
- server.py:48-65 (handler)The handler function for the 'search_articles' MCP tool. It fetches articles from Dev.to API for the given page, filters them based on the query matching title or description (case-insensitive), limits to 10, and formats the output.@mcp.tool() async def search_articles(query: str, page: int = 1) -> str: """ Search for articles on Dev.to Args: query: Search term to find articles page: Page number for pagination (default: 1) """ articles = await fetch_from_api("/articles", params={"page": page}) filtered_articles = [ article for article in articles if query.lower() in article.get("title", "").lower() or query.lower() in article.get("description", "").lower() ] return format_articles(filtered_articles[:10])
- server.py:12-18 (helper)Helper function used by search_articles to fetch paginated articles from 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 search_articles to format the filtered 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