Skip to main content
Glama

fetch_reddit_hot_threads

Retrieve trending posts from a specified subreddit using predefined parameters to fetch up to a custom number of threads.

Instructions

Fetch hot threads from a subreddit

Args: subreddit: Name of the subreddit limit: Number of posts to fetch (default: 10)

Returns: Human readable string containing list of post information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
subredditYes

Implementation Reference

  • The main handler for the 'fetch_reddit_hot_threads' tool. Decorated with @mcp.tool() for registration, fetches hot threads from the specified subreddit using redditwarp Client, formats post information (title, score, comments, author, type, content, link) using helpers, handles exceptions.
    @mcp.tool() async def fetch_reddit_hot_threads(subreddit: str, limit: int = 10) -> str: """ Fetch hot threads from a subreddit Args: subreddit: Name of the subreddit limit: Number of posts to fetch (default: 10) Returns: Human readable string containing list of post information """ try: posts = [] async for submission in client.p.subreddit.pull.hot(subreddit, limit): post_info = ( f"Title: {submission.title}\n" f"Score: {submission.score}\n" f"Comments: {submission.comment_count}\n" f"Author: {submission.author_display_name or '[deleted]'}\n" f"Type: {_get_post_type(submission)}\n" f"Content: {_get_content(submission)}\n" f"Link: https://reddit.com{submission.permalink}\n" f"---" ) posts.append(post_info) return "\n\n".join(posts) except Exception as e: logging.error(f"An error occurred: {str(e)}") return f"An error occurred: {str(e)}"
  • Helper function _get_post_type to determine Reddit post type (link, text, gallery, unknown) based on submission class.
    def _get_post_type(submission) -> str: """Helper method to determine post type""" if isinstance(submission, LinkPost): return 'link' elif isinstance(submission, TextPost): return 'text' elif isinstance(submission, GalleryPost): return 'gallery' return 'unknown'
  • Helper function _get_content to extract post content or permalink based on post type.
    def _get_content(submission) -> Optional[str]: """Helper method to extract post content based on type""" if isinstance(submission, LinkPost): return submission.permalink elif isinstance(submission, TextPost): return submission.body elif isinstance(submission, GalleryPost): return str(submission.gallery_link) return None
  • Initializes the FastMCP server instance named 'Reddit MCP' where the tool is registered via decorator.
    mcp = FastMCP("Reddit MCP")

Other Tools

Related 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/adhikasp/mcp-reddit'

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