get_frontpage_posts
Retrieve trending Reddit posts from the frontpage using a specified limit, facilitating quick access to popular content. Integrates with MCP Server Reddit for seamless Reddit API interaction.
Instructions
Get hot posts from Reddit frontpage
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of posts to return (default: 10) |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"default": 10,
"description": "Number of posts to return (default: 10)",
"maximum": 100,
"minimum": 1,
"type": "integer"
}
},
"type": "object"
}
Implementation Reference
- src/mcp_server_reddit/server.py:109-114 (handler)The main handler function that fetches hot posts from Reddit's frontpage using the redditwarp client, builds Post objects using a helper, and returns the list.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 model defining the structure of a Post, which is the primary output type of the get_frontpage_posts tool.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:202-217 (registration)Tool registration in list_tools(), specifying the tool name, description, and JSON input schema.Tool( 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 } } } ),
- src/mcp_server_reddit/server.py:379-383 (registration)Dispatch logic in the call_tool() handler that matches the tool name and invokes the specific get_frontpage_posts method with parsed arguments.match name: case RedditTools.GET_FRONTPAGE_POSTS.value: limit = arguments.get("limit", 10) result = reddit_server.get_frontpage_posts(limit)
- Key helper function used by the handler to construct Post instances from raw Reddit submission data.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) )