Skip to main content
Glama

get_user_comments

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

Instructions

Get comments made by a specific user

Input Schema

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

Implementation Reference

  • src/index.ts:226-275 (registration)
    Tool registration for 'get_user_comments' including name, description, input schema, and the full handler implementation.
    server.addTool({ name: "get_user_comments", description: "Get recent comments 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 comments"), time_filter: z .enum(["hour", "day", "week", "month", "year", "all"]) .default("all") .describe("Time filter for top comments"), limit: z.number().min(1).max(100).default(10).describe("Number of comments to retrieve"), }), execute: async (args) => { const client = getRedditClient() if (!client) { throw new Error("Reddit client not initialized") } const comments = await client.getUserComments(args.username, { sort: args.sort, timeFilter: args.time_filter, limit: args.limit, }) if (comments.length === 0) { return `No comments found for u/${args.username} with the specified filters.` } const commentSummaries = comments .map((comment, index) => { const truncatedBody = comment.body.length > 300 ? comment.body.substring(0, 300) + "..." : comment.body const flags = [...(comment.edited ? ["*(edited)*"] : []), ...(comment.isSubmitter ? ["**OP**"] : [])] return `### ${index + 1}. Comment ${flags.join(" ")} In r/${comment.subreddit} on "${comment.submissionTitle}" > ${truncatedBody} - Score: ${comment.score.toLocaleString()} - Posted: ${new Date(comment.createdUtc * 1000).toLocaleString()} - Link: https://reddit.com${comment.permalink}` }) .join("\n\n") return `# Comments by u/${args.username} (${args.sort} - ${args.time_filter}) ${commentSummaries}` }, })
  • Zod schema defining input parameters for the get_user_comments 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 comments"), time_filter: z .enum(["hour", "day", "week", "month", "year", "all"]) .default("all") .describe("Time filter for top comments"), limit: z.number().min(1).max(100).default(10).describe("Number of comments to retrieve"), }),
  • The execute handler function that implements the core logic: fetches comments via RedditClient, formats them, and returns a markdown summary.
    execute: async (args) => { const client = getRedditClient() if (!client) { throw new Error("Reddit client not initialized") } const comments = await client.getUserComments(args.username, { sort: args.sort, timeFilter: args.time_filter, limit: args.limit, }) if (comments.length === 0) { return `No comments found for u/${args.username} with the specified filters.` } const commentSummaries = comments .map((comment, index) => { const truncatedBody = comment.body.length > 300 ? comment.body.substring(0, 300) + "..." : comment.body const flags = [...(comment.edited ? ["*(edited)*"] : []), ...(comment.isSubmitter ? ["**OP**"] : [])] return `### ${index + 1}. Comment ${flags.join(" ")} In r/${comment.subreddit} on "${comment.submissionTitle}" > ${truncatedBody} - Score: ${comment.score.toLocaleString()} - Posted: ${new Date(comment.createdUtc * 1000).toLocaleString()} - Link: https://reddit.com${comment.permalink}` }) .join("\n\n") return `# Comments by u/${args.username} (${args.sort} - ${args.time_filter}) ${commentSummaries}` },
  • Supporting method in RedditClient class that performs the actual API call to fetch user comments from Reddit.
    async getUserComments( username: string, options: { sort?: string timeFilter?: string limit?: number } = {}, ): Promise<RedditComment[]> { 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}/comments.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 === "t1") .map((child: any) => { const comment = child.data return { id: comment.id, author: comment.author, body: comment.body, score: comment.score, controversiality: comment.controversiality, subreddit: comment.subreddit, submissionTitle: comment.link_title || "", createdUtc: comment.created_utc, edited: !!comment.edited, isSubmitter: comment.is_submitter, permalink: comment.permalink, } }) } catch { throw new Error(`Failed to get comments for user ${username}`) } }

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