Skip to main content
Glama
karanb192

Reddit Buddy MCP

by karanb192

search_reddit

Find Reddit posts by keywords, subreddits, or filters to gather insights and information from discussions across the platform.

Instructions

Search for posts across Reddit or specific subreddits. Returns matching posts with content and metadata.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
authorNoFilter by specific username (e.g., "spez")
flairNoFilter by post flair/tag (e.g., "Discussion", "News")
limitNoNumber of results (1-100, default: 25)
queryYesSearch terms (e.g., "machine learning", "climate change")
sortNoResult ordering: "relevance" (best match), "hot", "top", "new", "comments" (most discussed)
subredditsNoList of subreddits to search in. Leave empty to search all of Reddit (e.g., ["science", "technology"])
timeNoTime range filter: "hour", "day", "week", "month", "year", "all"

Implementation Reference

  • The main handler function implementing the search_reddit tool logic: performs Reddit search via API, handles multiple subreddits, applies filters for author and flair, extracts and formats post data.
    async searchReddit(params: z.infer<typeof searchRedditSchema>) {
      // Handle multiple subreddits
      let results: RedditListing<RedditPost>;
      
      if (params.subreddits && params.subreddits.length > 0) {
        if (params.subreddits.length === 1) {
          // Single subreddit - direct search
          results = await this.api.search(params.query, {
            subreddit: params.subreddits[0],
            sort: params.sort,
            time: params.time,
            limit: params.limit,
          });
        } else {
          // Multiple subreddits - parallel search
          const searchPromises = params.subreddits.map(sub => 
            this.api.search(params.query, {
              subreddit: sub,
              sort: params.sort,
              time: params.time,
              limit: Math.ceil(params.limit! / params.subreddits!.length),
            })
          );
          
          const allResults = await Promise.all(searchPromises);
          
          // Combine results
          results = {
            kind: 'Listing',
            data: {
              children: allResults.flatMap(r => r.data.children),
              after: null,
              before: null,
            }
          };
        }
      } else {
        // Search all of Reddit
        results = await this.api.search(params.query, {
          subreddit: undefined,
          sort: params.sort,
          time: params.time,
          limit: params.limit,
        });
      }
    
      // Filter by author if specified
      if (params.author) {
        results.data.children = results.data.children.filter(
          child => child.data.author.toLowerCase() === params.author!.toLowerCase()
        );
      }
    
      // Filter by flair if specified
      if (params.flair) {
        results.data.children = results.data.children.filter(
          child => child.data.link_flair_text?.toLowerCase().includes(params.flair!.toLowerCase())
        );
      }
    
      // Extract just the essential fields from Reddit's verbose response
      const posts = results.data.children.map(child => ({
        id: child.data.id,
        title: child.data.title,
        author: child.data.author,
        score: child.data.score,
        upvote_ratio: child.data.upvote_ratio,
        num_comments: child.data.num_comments,
        created_utc: child.data.created_utc,
        url: child.data.url,
        permalink: `https://reddit.com${child.data.permalink}`,
        subreddit: child.data.subreddit,
        is_video: child.data.is_video,
        is_text_post: child.data.is_self,
        content: child.data.selftext?.substring(0, 500), // Limit text preview
        nsfw: child.data.over_18,
        link_flair_text: child.data.link_flair_text,
      }));
    
      return {
        results: posts,
        total_results: posts.length
      };
    }
  • Zod schema defining the input parameters and validation for the search_reddit tool.
    export const searchRedditSchema = z.object({
      query: z.string().describe('Search query'),
      subreddits: z.array(z.string()).optional().describe('Subreddits to search in (leave empty for all)'),
      sort: z.enum(['relevance', 'hot', 'top', 'new', 'comments']).optional().default('relevance'),
      time: z.enum(['hour', 'day', 'week', 'month', 'year', 'all']).optional().default('all'),
      limit: z.number().min(1).max(100).optional().default(25).describe('Default 25, range (1-100). Override ONLY IF user requests.'),
      author: z.string().optional(),
      flair: z.string().optional(),
    });
  • Registration of the search_reddit tool in the MCP server toolDefinitions array, specifying name, description, and input schema.
    name: 'search_reddit',
    description: 'Search for posts across Reddit or specific subreddits. Returns matching posts with content and metadata.',
    inputSchema: zodToJsonSchema(searchRedditSchema) as any,
    readOnlyHint: true
  • Dispatch case in the tools/call handler that routes search_reddit calls to the searchReddit method.
    case 'search_reddit':
      result = await tools.searchReddit(
        searchRedditSchema.parse(args)
      );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states it 'returns matching posts with content and metadata.' It doesn't disclose rate limits, authentication needs, pagination behavior, error conditions, or what specific metadata is included, leaving significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with two clear sentences that efficiently convey core functionality and return value. It's front-loaded with the main purpose and avoids unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a search tool with 7 parameters, 100% schema coverage, and no output schema, the description adequately covers basic purpose but lacks behavioral context and usage guidance. It's minimally viable but has clear gaps in transparency and guidelines.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 7 parameters. The description adds no parameter-specific information beyond what's in the schema, meeting the baseline of 3 where schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verb ('Search for posts') and resource ('across Reddit or specific subreddits'), and distinguishes it from siblings by focusing on search functionality rather than browsing, getting details, explaining, or analyzing users.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like browse_subreddit or get_post_details. It mentions searching 'across Reddit or specific subreddits' but doesn't clarify when to choose this over other tools for similar tasks.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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