Skip to main content
Glama
liuyang1520

Reddit MCP Server

by liuyang1520

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
NameRequiredDescriptionDefault
usernameYesReddit username (without u/ prefix)
sortNoSort order for commentsnew
limitNoNumber of comments to retrieve (1-100)

Implementation Reference

  • 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),
          },
        ],
      };
    }
  • 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'],
      },
    },
  • 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));
    }
  • 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,
      };
    }

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

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