get_frontpage_posts
Retrieve trending posts from the Reddit frontpage to monitor popular discussions and content.
Instructions
Get hot posts from Reddit frontpage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of posts to return (default: 10) |
Implementation Reference
- src/mcp_server_reddit/server.py:109-114 (handler)The core handler function implementing get_frontpage_posts. Fetches hot posts from Reddit's frontpage using redditwarp.Client, builds Post models using _build_post helper, and returns a list of them.def get_frontpage_posts(self, limit: int = 10) -> list[Post]: """Get hot posts from Reddit frontpage""" posts = [] for subm in self.client.p.front.pull.hot(limit): posts.append(self._build_post(subm)) return posts
- Pydantic BaseModel schema defining the structure of a Reddit Post, used in the return type of get_frontpage_posts.class Post(BaseModel): id: str title: str author: str score: int subreddit: str url: str created_at: str comment_count: int post_type: PostType content: str | None
- src/mcp_server_reddit/server.py:203-217 (registration)Registers the get_frontpage_posts tool with the MCP server in the list_tools handler, specifying name, description, and input JSON schema.name=RedditTools.GET_FRONTPAGE_POSTS.value, description="Get hot posts from Reddit frontpage", inputSchema={ "type": "object", "properties": { "limit": { "type": "integer", "description": "Number of posts to return (default: 10)", "default": 10, "minimum": 1, "maximum": 100 } } } ),
- Key helper function that converts a redditwarp submission object into a structured Post model, called by get_frontpage_posts.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) )
- src/mcp_server_reddit/server.py:380-382 (registration)In the MCP call_tool handler, matches on tool name and dispatches to the get_frontpage_posts method with parsed arguments.case RedditTools.GET_FRONTPAGE_POSTS.value: limit = arguments.get("limit", 10) result = reddit_server.get_frontpage_posts(limit)