search_news
Search recent news articles using Lightning Network or Arbitrum ETH micropayments. Pay per query for current information without API keys or subscriptions.
Instructions
Search recent news. Pay with Lightning (payment_hash) or Arbitrum ETH (tx_hash).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| payment_hash | No | ||
| tx_hash | No | ||
| max_results | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:127-139 (handler)The main handler function for the search_news tool. Validates payment (either Lightning payment_hash or Arbitrum tx_hash) and returns news results by calling do_news().
def search_news(query: str, payment_hash: str = "", tx_hash: str = "", max_results: int = 5) -> str: """Search recent news. Pay with Lightning (payment_hash) or Arbitrum ETH (tx_hash).""" if payment_hash: if not check_invoice(payment_hash): return "Lightning payment not settled. Call get_invoice first." elif tx_hash: ok, pid = arb_pay.verify_tx(tx_hash, "search") if not ok: return "Arbitrum payment not found or already used. Call get_arbitrum_invoice first." arb_pay.mark_used(pid) else: return "Provide payment_hash (Lightning) or tx_hash (Arbitrum)." return do_news(query, max_results) - server.py:65-70 (helper)Helper function that performs the actual DuckDuckGo news search using the DDGS library. Returns formatted news results with title, URL, and body.
def do_news(query: str, max_results: int = 5) -> str: with DDGS() as ddgs: results = list(ddgs.news(query, max_results=max_results)) if not results: return "No news found." return "\n---\n".join(f"**{r['title']}**\n{r['url']}\n{r['body']}" for r in results) - server.py:126-127 (registration)The @mcp.tool() decorator registers the search_news function as an MCP tool with the FastMCP server.
@mcp.tool() def search_news(query: str, payment_hash: str = "", tx_hash: str = "", max_results: int = 5) -> str: - server.py:127-128 (schema)Input schema for search_news tool defined via function signature type hints. Parameters: query (str), payment_hash (str, optional), tx_hash (str, optional), max_results (int, optional, default=5). Returns string.
def search_news(query: str, payment_hash: str = "", tx_hash: str = "", max_results: int = 5) -> str: """Search recent news. Pay with Lightning (payment_hash) or Arbitrum ETH (tx_hash)."""