Skip to main content
Glama
jordanburke

reddit-mcp-server

get_top_posts

Fetch top posts from any Reddit subreddit by specifying a time period and number of results to retrieve.

Instructions

Get top posts from a subreddit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of posts to fetch
subredditYesName of the subreddit
time_filterNoTime period to filter posts (e.g. 'day', 'week', 'month', 'year', 'all')week

Implementation Reference

  • Registration, schema definition, and handler (execute function) for the MCP tool 'get_top_posts'. Fetches top posts via RedditClient and formats the response.
    server.addTool({
      name: "get_top_posts",
      description: "Get top posts from a subreddit or from the Reddit home feed",
      parameters: z.object({
        subreddit: z.string().optional().describe("The subreddit name (without r/ prefix). Leave empty for home feed"),
        time_filter: z
          .enum(["hour", "day", "week", "month", "year", "all"])
          .default("week")
          .describe("Time period for top posts"),
        limit: z.number().min(1).max(100).default(10).describe("Number of posts to retrieve"),
      }),
      execute: async (args) => {
        const client = getRedditClient()
        if (!client) {
          throw new Error("Reddit client not initialized")
        }
    
        const posts = await client.getTopPosts(args.subreddit || "", args.time_filter, args.limit)
    
        if (posts.length === 0) {
          const location = args.subreddit ? `r/${args.subreddit}` : "home feed"
          return `No posts found in ${location} for the specified time period.`
        }
    
        const formattedPosts = posts.map(formatPostInfo)
        const postSummaries = formattedPosts
          .map(
            (post, index) => `### ${index + 1}. ${post.title}
    - Author: u/${post.author}
    - Score: ${post.stats.score.toLocaleString()} (${(post.stats.upvoteRatio * 100).toFixed(1)}% upvoted)
    - Comments: ${post.stats.comments.toLocaleString()}
    - Posted: ${post.metadata.posted}
    - Link: ${post.links.shortLink}`,
          )
          .join("\n\n")
    
        const location = args.subreddit ? `r/${args.subreddit}` : "Home Feed"
        return `# Top Posts from ${location} (${args.time_filter})
    
    ${postSummaries}`
      },
    })
  • Core helper function in RedditClient that implements the API call to retrieve top posts from a subreddit or the home feed using Reddit's /top.json endpoint.
    async getTopPosts(subreddit: string, timeFilter: string = "week", limit: number = 10): Promise<RedditPost[]> {
      await this.authenticate()
      try {
        const endpoint = subreddit ? `/r/${subreddit}/top.json` : "/top.json"
        const params = new URLSearchParams({
          t: timeFilter,
          limit: limit.toString(),
        })
    
        const response = await this.makeRequest(`${endpoint}?${params}`)
        if (!response.ok) {
          throw new Error(`HTTP ${response.status}`)
        }
    
        const json = (await response.json()) as RedditApiListingResponse<RedditApiPostData>
    
        return json.data.children.map((child) => {
          const post = child.data
          return {
            id: post.id,
            title: post.title,
            author: post.author,
            subreddit: post.subreddit,
            selftext: post.selftext,
            url: post.url,
            score: post.score,
            upvoteRatio: post.upvote_ratio,
            numComments: post.num_comments,
            createdUtc: post.created_utc,
            over18: post.over_18,
            spoiler: post.spoiler,
            edited: !!post.edited,
            isSelf: post.is_self,
            linkFlairText: post.link_flair_text ?? undefined,
            permalink: post.permalink,
          }
        })
      } catch {
        // Failed to get top posts
        throw new Error(`Failed to get top posts for ${subreddit || "home"}`)
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'gets' data, implying a read-only operation, but doesn't mention potential rate limits, authentication requirements, pagination, or what 'top' entails (e.g., sorting criteria). The description is minimal and misses key behavioral traits needed for safe and effective use.

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 a single, efficient sentence with no wasted words, making it easy to parse. However, it's front-loaded but overly brief, potentially sacrificing clarity for brevity. It earns a high score for conciseness but loses a point because the minimalism might hinder understanding without additional context.

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

Completeness2/5

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

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is incomplete. It lacks details on behavioral aspects like rate limits or authentication, doesn't explain the output format (e.g., what data is returned for posts), and offers no usage guidelines. While the schema covers parameters well, the overall context for an agent to use the tool effectively is insufficient.

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%, with clear descriptions for all parameters (limit, subreddit, time_filter) including defaults and enum values. The description adds no additional parameter semantics beyond what the schema provides, such as explaining 'top' in relation to parameters. Since the schema is comprehensive, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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

Purpose3/5

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

The description 'Get top posts from a subreddit' clearly states the action (get) and resource (top posts from a subreddit), but it's somewhat vague about what 'top' means (e.g., by upvotes, hotness) and doesn't explicitly distinguish this tool from siblings like 'get_reddit_post' (which might fetch a specific post) or 'search_reddit' (which might allow broader queries). It avoids tautology but lacks specificity for full differentiation.

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. It doesn't mention siblings like 'get_reddit_post' for individual posts or 'search_reddit' for custom searches, nor does it specify prerequisites or exclusions (e.g., whether it requires authentication). Usage is implied by the name but not explicitly stated, leaving gaps for an agent to infer context.

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

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