Skip to main content
Glama
liuyang1520

Reddit MCP Server

by liuyang1520

search_posts

Search for Reddit posts using keywords, filter by subreddit, sort by relevance or time, and retrieve specific results to find relevant discussions and content.

Instructions

Search for Reddit posts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of results to retrieve (1-100)
queryYesSearch query
sortNoSort order for search resultsrelevance
subredditNoOptional: restrict search to specific subreddit
timeNoTime period to filter results (works best with sort=top)

Implementation Reference

  • MCP tool handler for 'search_posts': parses arguments using SearchPostsSchema and calls redditClient.searchPosts to fetch and return search results as JSON.
    case 'search_posts': { const args = SearchPostsSchema.parse(request.params.arguments); const posts = await redditClient.searchPosts(args.query, args.subreddit, args.sort, args.time, args.limit); return { content: [ { type: 'text', text: JSON.stringify(posts, null, 2), }, ], }; }
  • Zod schema defining input validation for the search_posts tool parameters.
    const SearchPostsSchema = z.object({ query: z.string().min(1, "Search query is required"), subreddit: z.string().optional(), sort: z.enum(['relevance', 'hot', 'top', 'new', 'comments']).default('relevance'), time: z.enum(['hour', 'day', 'week', 'month', 'year', 'all']).optional(), limit: z.number().min(1).max(100).default(25), });
  • src/index.ts:232-267 (registration)
    Tool registration in ListTools response, including name, description, and JSON inputSchema for 'search_posts'.
    { name: 'search_posts', description: 'Search for Reddit posts', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query', }, subreddit: { type: 'string', description: 'Optional: restrict search to specific subreddit', }, sort: { type: 'string', enum: ['relevance', 'hot', 'top', 'new', 'comments'], description: 'Sort order for search results', default: 'relevance', }, time: { type: 'string', enum: ['hour', 'day', 'week', 'month', 'year', 'all'], description: 'Time period to filter results (works best with sort=top)', }, limit: { type: 'number', description: 'Number of results to retrieve (1-100)', minimum: 1, maximum: 100, default: 25, }, }, required: ['query'], }, },
  • Core implementation of post search using Reddit API search endpoint, mapping results to RedditPost interface.
    async searchPosts(query: string, subreddit?: string, sort: 'relevance' | 'hot' | 'top' | 'new' | 'comments' = 'relevance', time?: 'hour' | 'day' | 'week' | 'month' | 'year' | 'all', limit: number = 25): Promise<RedditPost[]> { const searchPath = subreddit ? `/r/${subreddit}/search` : '/search'; const params = new URLSearchParams({ q: query, sort, limit: limit.toString(), type: 'link', ...(subreddit && { restrict_sr: 'true' }), ...(time && { t: time }) }); const data = await this.makeRequest(`${searchPath}?${params}`); 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