get_user_comments
Retrieve comments posted by a specific Reddit user, with options to sort by hot, new, or top and limit results from 1 to 100 comments.
Instructions
Get comments made by a user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | Reddit username (without u/ prefix) | |
| sort | No | Sort order for comments | new |
| limit | No | Number of comments to retrieve (1-100) |
Implementation Reference
- src/index.ts:374-385 (handler)MCP CallToolRequest handler implementation for the 'get_user_comments' tool. Parses arguments using Zod schema, calls RedditClient.getUserComments, and formats response as JSON text.case 'get_user_comments': { const args = GetUserCommentsSchema.parse(request.params.arguments); const comments = await redditClient.getUserComments(args.username, args.sort, args.limit); return { content: [ { type: 'text', text: JSON.stringify(comments, null, 2), }, ], }; }
- src/index.ts:67-71 (schema)Zod schema for validating input parameters of the get_user_comments tool: username (required string), sort (enum: hot/new/top, default 'new'), limit (1-100, default 25).const GetUserCommentsSchema = z.object({ username: z.string().min(1, "Username is required"), sort: z.enum(['hot', 'new', 'top']).default('new'), limit: z.number().min(1).max(100).default(25), });
- src/index.ts:205-231 (registration)Tool registration in ListToolsResponse: defines name, description, and inputSchema matching the Zod schema.{ name: 'get_user_comments', description: 'Get comments made by a user', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'Reddit username (without u/ prefix)', }, sort: { type: 'string', enum: ['hot', 'new', 'top'], description: 'Sort order for comments', default: 'new', }, limit: { type: 'number', description: 'Number of comments to retrieve (1-100)', minimum: 1, maximum: 100, default: 25, }, }, required: ['username'], }, },
- src/reddit-client.ts:165-168 (helper)Core implementation in RedditClient: makes authenticated API request to Reddit's /user/{username}/comments endpoint and maps responses to RedditComment objects using mapComment helper.async getUserComments(username: string, sort: 'hot' | 'new' | 'top' = 'new', limit: number = 25): Promise<RedditComment[]> { const data = await this.makeRequest(`/user/${username}/comments?sort=${sort}&limit=${limit}`); return data.data.children.map((child: any) => this.mapComment(child.data)); }
- src/reddit-client.ts:219-230 (helper)Helper method to transform raw Reddit API comment data into structured RedditComment interface.private mapComment(data: any): RedditComment { return { id: data.id, author: data.author, body: data.body, created_utc: data.created_utc, score: data.score, permalink: `https://reddit.com${data.permalink}`, parent_id: data.parent_id, subreddit: data.subreddit, }; }