Skip to main content
Glama
6551Team

OpenNews MCP

by 6551Team

get_news_by_engine

Retrieve cryptocurrency news articles filtered by specific content types including news, listings, onchain data, memes, and market updates.

Instructions

Get news articles filtered by engine type.

Engine types: "news", "listing", "onchain", "meme", "market".

Args: engine_type: The engine type code. limit: Maximum results (default 10, max 100).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
engine_typeYes
limitNo

Implementation Reference

  • The main handler function get_news_by_engine that filters news articles by engine type. It uses the @mcp.tool() decorator for registration, retrieves the API client from context, calls api.search_news with the engine_type filter, and returns a standardized response with success status, data, count, and total.
    @mcp.tool()
    async def get_news_by_engine(engine_type: str, ctx: Context, limit: int = 10) -> dict:
        """Get news articles filtered by engine type.
    
        Engine types: "news", "listing", "onchain", "meme", "market".
    
        Args:
            engine_type: The engine type code.
            limit: Maximum results (default 10, max 100).
        """
        api = ctx.request_context.lifespan_context.api
        limit = clamp_limit(limit)
        try:
            result = await api.search_news(engine_types={engine_type: []}, limit=limit, page=1)
            data = result.get("data", [])[:limit]
            return make_serializable({
                "success": True, "engine_type": engine_type, "data": data,
                "count": len(data), "total": result.get("total", 0),
            })
        except Exception as e:
            return {"success": False, "error": str(e) or repr(e)}
  • The @mcp.tool() decorator registers the get_news_by_engine function as an MCP tool, making it available to clients via the Model Context Protocol.
    @mcp.tool()
  • The clamp_limit helper function validates and clamps the user-supplied limit parameter to the range [1, MAX_ROWS], ensuring safe API queries.
    def clamp_limit(limit: int) -> int:
        """Clamp user-supplied limit to [1, MAX_ROWS]."""
        return min(max(1, limit), MAX_ROWS)
  • The make_serializable helper function recursively converts non-JSON-serializable types (datetime, Decimal, bytes) to JSON-compatible formats, ensuring clean API responses.
    def make_serializable(obj):
        """Recursively convert non-JSON-serializable types."""
        if obj is None:
            return None
        if isinstance(obj, dict):
            return {k: make_serializable(v) for k, v in obj.items()}
        if isinstance(obj, (list, tuple)):
            return [make_serializable(item) for item in obj]
        if isinstance(obj, (datetime, date)):
            return obj.isoformat()
        if isinstance(obj, Decimal):
            return float(obj)
        if isinstance(obj, bytes):
            return obj.decode("utf-8", errors="replace")
        return obj
  • The search_news method in NewsAPIClient performs the actual REST API call to POST /open/news_search, accepting engine_types as a filter and returning raw article data from the 6551 news platform.
    async def search_news(
        self,
        coins: Optional[list[str]] = None,
        query: Optional[str] = None,
        engine_types: Optional[dict[str, list[str]]] = None,
        has_coin: bool = False,
        limit: int = 20,
        page: int = 1,
    ) -> dict:
        """POST /open/news_search — 搜索新闻文章"""
        body: dict[str, Any] = {"limit": limit, "page": page}
        if coins:
            body["coins"] = coins
        if query:
            body["q"] = query
        if engine_types:
            body["engineTypes"] = engine_types
        if has_coin:
            body["hasCoin"] = has_coin
    
        resp = await self._request("POST", f"{self.base_url}/open/news_search", json=body)
        return resp.json()

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/6551Team/opennews-mcp'

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