Skip to main content
Glama
liuyang1520

Reddit MCP Server

by liuyang1520

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
NameRequiredDescriptionDefault
subredditYesName of the subreddit (without r/ prefix)
sortNoSort order for postshot
limitNoNumber of posts to retrieve (1-100)

Implementation Reference

  • 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), }, ], }; }
  • 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'], }, },
  • 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)); }

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

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