get_subreddit_posts
Retrieve posts from any subreddit using sort options like hot, new, top, or rising to access Reddit content programmatically.
Instructions
Get posts from a specific subreddit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subreddit | Yes | Name of the subreddit (without r/ prefix) | |
| sort | No | Sort order for posts | hot |
| limit | No | Number of posts to retrieve (1-100) |
Implementation Reference
- src/index.ts:296-307 (handler)MCP tool handler for 'get_subreddit_posts' that validates arguments with Zod schema and delegates to RedditClient.getSubredditPosts, returning JSON-formatted posts.case 'get_subreddit_posts': { const args = GetSubredditPostsSchema.parse(request.params.arguments); const posts = await redditClient.getSubredditPosts(args.subreddit, args.sort, args.limit); return { content: [ { type: 'text', text: JSON.stringify(posts, null, 2), }, ], }; }
- src/index.ts:38-42 (schema)Zod schema defining input parameters for the get_subreddit_posts tool: subreddit (required), sort (enum with default), limit (1-100 with default).const GetSubredditPostsSchema = z.object({ subreddit: z.string().min(1, "Subreddit name is required"), sort: z.enum(['hot', 'new', 'top', 'rising']).default('hot'), limit: z.number().min(1).max(100).default(25), });
- src/index.ts:90-115 (registration)Tool registration metadata including name, description, and JSON schema for inputs, provided in response to ListToolsRequest.name: 'get_subreddit_posts', description: 'Get posts from a specific subreddit', inputSchema: { type: 'object', properties: { subreddit: { type: 'string', description: 'Name of the subreddit (without r/ prefix)', }, sort: { type: 'string', enum: ['hot', 'new', 'top', 'rising'], description: 'Sort order for posts', default: 'hot', }, limit: { type: 'number', description: 'Number of posts to retrieve (1-100)', minimum: 1, maximum: 100, default: 25, }, }, required: ['subreddit'], }, },
- src/reddit-client.ts:129-132 (helper)Core helper method in RedditClient that makes authenticated API request to fetch subreddit posts and maps Reddit API response to RedditPost objects.async getSubredditPosts(subreddit: string, sort: 'hot' | 'new' | 'top' | 'rising' = 'hot', limit: number = 25): Promise<RedditPost[]> { const data = await this.makeRequest(`/r/${subreddit}/${sort}?limit=${limit}`); return data.data.children.map((child: any) => this.mapPost(child.data)); }