Skip to main content
Glama
jordanburke

reddit-mcp-server

get_user_posts

Retrieve posts submitted by a specific Reddit user with options to sort by new, hot, top, or controversial content and filter by time period.

Instructions

Get posts submitted by a specific user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of posts to return
sortNoSort order: new, hot, top, controversialnew
time_filterNoTime filter for top/controversial: hour, day, week, month, year, allall
usernameYesThe username to get posts for

Implementation Reference

  • src/index.ts:179-224 (registration)
    Registration of the 'get_user_posts' tool in the FastMCP server, including name, description, Zod input schema, and the inline execute handler function.
    server.addTool({
      name: "get_user_posts",
      description: "Get recent posts by a Reddit user with sorting and filtering options",
      parameters: z.object({
        username: z.string().describe("The Reddit username (without u/ prefix)"),
        sort: z.enum(["new", "hot", "top"]).default("new").describe("Sort order for posts"),
        time_filter: z
          .enum(["hour", "day", "week", "month", "year", "all"])
          .default("all")
          .describe("Time filter 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.getUserPosts(args.username, {
          sort: args.sort,
          timeFilter: args.time_filter,
          limit: args.limit,
        })
    
        if (posts.length === 0) {
          return `No posts found for u/${args.username} with the specified filters.`
        }
    
        const postSummaries = posts
          .map((post, index) => {
            const flags = [...(post.over18 ? ["**NSFW**"] : []), ...(post.spoiler ? ["**Spoiler**"] : [])]
    
            return `### ${index + 1}. ${post.title} ${flags.join(" ")}
    - Subreddit: r/${post.subreddit}
    - Score: ${post.score.toLocaleString()} (${(post.upvoteRatio * 100).toFixed(1)}% upvoted)
    - Comments: ${post.numComments.toLocaleString()}
    - Posted: ${new Date(post.createdUtc * 1000).toLocaleString()}
    - Link: https://reddit.com${post.permalink}`
          })
          .join("\n\n")
    
        return `# Posts by u/${args.username} (${args.sort} - ${args.time_filter})
    
    ${postSummaries}`
      },
    })
  • The handler function (execute callback) that implements the core logic: gets Reddit client, fetches user posts, formats them into a markdown summary, and returns the response.
      execute: async (args) => {
        const client = getRedditClient()
        if (!client) {
          throw new Error("Reddit client not initialized")
        }
    
        const posts = await client.getUserPosts(args.username, {
          sort: args.sort,
          timeFilter: args.time_filter,
          limit: args.limit,
        })
    
        if (posts.length === 0) {
          return `No posts found for u/${args.username} with the specified filters.`
        }
    
        const postSummaries = posts
          .map((post, index) => {
            const flags = [...(post.over18 ? ["**NSFW**"] : []), ...(post.spoiler ? ["**Spoiler**"] : [])]
    
            return `### ${index + 1}. ${post.title} ${flags.join(" ")}
    - Subreddit: r/${post.subreddit}
    - Score: ${post.score.toLocaleString()} (${(post.upvoteRatio * 100).toFixed(1)}% upvoted)
    - Comments: ${post.numComments.toLocaleString()}
    - Posted: ${new Date(post.createdUtc * 1000).toLocaleString()}
    - Link: https://reddit.com${post.permalink}`
          })
          .join("\n\n")
    
        return `# Posts by u/${args.username} (${args.sort} - ${args.time_filter})
    
    ${postSummaries}`
      },
  • Zod schema defining the input parameters for the get_user_posts tool.
    parameters: z.object({
      username: z.string().describe("The Reddit username (without u/ prefix)"),
      sort: z.enum(["new", "hot", "top"]).default("new").describe("Sort order for posts"),
      time_filter: z
        .enum(["hour", "day", "week", "month", "year", "all"])
        .default("all")
        .describe("Time filter for top posts"),
      limit: z.number().min(1).max(100).default(10).describe("Number of posts to retrieve"),
    }),
  • Supporting method in RedditClient class that performs the actual API call to fetch user's submitted posts from Reddit.
    async getUserPosts(
      username: string,
      options: {
        sort?: string
        timeFilter?: string
        limit?: number
      } = {},
    ): Promise<RedditPost[]> {
      await this.authenticate()
      try {
        const { sort = "new", timeFilter = "all", limit = 25 } = options
        const params = new URLSearchParams({
          sort,
          t: timeFilter,
          limit: limit.toString(),
        })
    
        const response = await this.makeRequest(`/user/${username}/submitted.json?${params}`)
        if (!response.ok) {
          throw new Error(`HTTP ${response.status}`)
        }
    
        const json = (await response.json()) as { data: { children: any[] } }
    
        return json.data.children
          .filter((child: any) => child.kind === "t3")
          .map((child: any) => {
            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 {
        throw new Error(`Failed to get posts for user ${username}`)
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe important behaviors: whether this is a read-only operation, if there are rate limits, what authentication is required, what happens with invalid usernames, or the format/structure of returned posts. For a tool with 4 parameters and no annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is a single, efficient sentence that states the core purpose without any wasted words. It's appropriately sized for a straightforward retrieval tool and front-loads the essential information. Every word earns its place.

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 has 4 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what kind of posts are returned (e.g., titles, content, metadata), whether results are paginated, error conditions, or authentication requirements. For a data retrieval tool with multiple filtering options, more context is needed.

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 already fully documents all 4 parameters with descriptions, defaults, enums, and constraints. The description adds no additional parameter semantics beyond implying the 'username' parameter is required (which is already in the schema). Baseline 3 is appropriate when the schema does all the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb 'Get' and resource 'posts submitted by a specific user', making the purpose immediately understandable. It distinguishes from siblings like get_user_comments (which gets comments) and get_top_posts (which gets posts by popularity rather than by user). However, it doesn't specify whether this includes all types of posts or just certain categories, which prevents a perfect score.

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 when to choose get_user_posts over get_user_info (which might include post summaries) or search_reddit (which could filter by user), nor does it specify prerequisites like needing a valid username. Usage is implied but not explicitly stated.

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