Skip to main content
Glama
Hawstein

MCP Server Reddit

by Hawstein

get_subreddit_top_posts

Retrieve top posts from any subreddit using time filters and customizable limits to monitor trending discussions and content.

Instructions

Get top posts from a specific subreddit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subreddit_nameYesName of the subreddit (e.g. 'Python', 'news')
limitNoNumber of posts to return (default: 10)
timeNoTime filter for top posts (e.g. 'hour', 'day', 'week', 'month', 'year', 'all')

Implementation Reference

  • The core handler function in the RedditServer class that fetches the top posts from a subreddit using the redditwarp client, builds Post objects using the _build_post helper, and returns the list.
    def get_subreddit_top_posts(self, subreddit_name: str, limit: int = 10, time: str = '') -> list[Post]: """Get top posts from a specific subreddit""" posts = [] for subm in self.client.p.subreddit.pull.top(subreddit_name, limit, time=time): posts.append(self._build_post(subm)) return posts
  • Input JSON schema for the get_subreddit_top_posts tool, defining parameters subreddit_name (required), limit, and time filter.
    inputSchema={ "type": "object", "properties": { "subreddit_name": { "type": "string", "description": "Name of the subreddit (e.g. 'Python', 'news')", }, "limit": { "type": "integer", "description": "Number of posts to return (default: 10)", "default": 10, "minimum": 1, "maximum": 100 }, "time": { "type": "string", "description": "Time filter for top posts (e.g. 'hour', 'day', 'week', 'month', 'year', 'all')", "default": "", "enum": ["", "hour", "day", "week", "month", "year", "all"] } }, "required": ["subreddit_name"] }
  • Registration of the get_subreddit_top_posts tool in the list_tools() handler, including name, description, and input schema.
    Tool( name=RedditTools.GET_SUBREDDIT_TOP_POSTS.value, description="Get top posts from a specific subreddit", inputSchema={ "type": "object", "properties": { "subreddit_name": { "type": "string", "description": "Name of the subreddit (e.g. 'Python', 'news')", }, "limit": { "type": "integer", "description": "Number of posts to return (default: 10)", "default": 10, "minimum": 1, "maximum": 100 }, "time": { "type": "string", "description": "Time filter for top posts (e.g. 'hour', 'day', 'week', 'month', 'year', 'all')", "default": "", "enum": ["", "hour", "day", "week", "month", "year", "all"] } }, "required": ["subreddit_name"] } ),
  • Dispatch logic in the MCP server's call_tool handler that extracts arguments and calls the get_subreddit_top_posts method on the RedditServer instance.
    case RedditTools.GET_SUBREDDIT_TOP_POSTS.value: subreddit_name = arguments.get("subreddit_name") if not subreddit_name: raise ValueError("Missing required argument: subreddit_name") limit = arguments.get("limit", 10) time = arguments.get("time", "") result = reddit_server.get_subreddit_top_posts(subreddit_name, limit, time)
  • Helper function used by get_subreddit_top_posts to construct Post model instances from redditwarp submission objects.
    def _build_post(self, submission) -> Post: """Helper method to build Post object from submission""" return Post( id=submission.id36, title=submission.title, author=submission.author_display_name or '[deleted]', score=submission.score, subreddit=submission.subreddit.name, url=submission.permalink, created_at=submission.created_at.astimezone().isoformat(), comment_count=submission.comment_count, post_type=self._get_post_type(submission), content=self._get_post_content(submission) )

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/Hawstein/mcp-server-reddit'

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