Skip to main content
Glama
liuyang1520

Reddit MCP Server

by liuyang1520

get_post_comments

Retrieve comments from a Reddit post by providing the post ID. Sort comments by best, top, new, controversial, or old to analyze discussions.

Instructions

Get comments from a Reddit post

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
postIdYesReddit post ID
sortNoSort order for commentsbest

Implementation Reference

  • Core handler function that fetches comments from Reddit API for a given post, extracts them recursively, and returns a flat list of RedditComment objects.
    async getPostComments(postId: string, sort: 'best' | 'top' | 'new' | 'controversial' | 'old' = 'best'): Promise<RedditComment[]> {
      const data = await this.makeRequest(`/comments/${postId}?sort=${sort}`);
      const comments: RedditComment[] = [];
      
      if (data[1] && data[1].data && data[1].data.children) {
        this.extractComments(data[1].data.children, comments);
      }
      
      return comments;
    }
  • MCP CallToolRequest handler case that validates input using Zod schema and delegates execution to RedditClient.getPostComments, formatting response as JSON text.
    case 'get_post_comments': {
      const args = GetPostCommentsSchema.parse(request.params.arguments);
      const comments = await redditClient.getPostComments(args.postId, args.sort);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(comments, null, 2),
          },
        ],
      };
    }
  • Zod schema defining and validating the tool's input parameters: postId (required string) and sort (enum with default 'best'). Used for parsing in handler.
    const GetPostCommentsSchema = z.object({
      postId: z.string().min(1, "Post ID is required"),
      sort: z.enum(['best', 'top', 'new', 'controversial', 'old']).default('best'),
    });
  • src/index.ts:130-149 (registration)
    Tool registration in ListTools response, specifying name, description, and JSON inputSchema advertised to MCP clients.
    {
      name: 'get_post_comments',
      description: 'Get comments from a Reddit post',
      inputSchema: {
        type: 'object',
        properties: {
          postId: {
            type: 'string',
            description: 'Reddit post ID',
          },
          sort: {
            type: 'string',
            enum: ['best', 'top', 'new', 'controversial', 'old'],
            description: 'Sort order for comments',
            default: 'best',
          },
        },
        required: ['postId'],
      },
    },
  • Recursive helper function to traverse Reddit's nested comment tree and collect all top-level and reply comments into a flat array.
    private extractComments(children: any[], comments: RedditComment[]): void {
      for (const child of children) {
        if (child.kind === 't1' && child.data) {
          comments.push(this.mapComment(child.data));
          if (child.data.replies && child.data.replies.data && child.data.replies.data.children) {
            this.extractComments(child.data.replies.data.children, comments);
          }
        }
      }
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. While 'Get comments' implies a read-only operation, it doesn't address critical aspects like authentication requirements, rate limits, pagination behavior, error conditions, or what the return format looks like (e.g., list of comments with metadata). This leaves significant gaps for a tool that interacts with an external API like Reddit.

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 directly states the tool's purpose without unnecessary words. It's front-loaded with the core action and resource, making it easy to parse quickly. There's no wasted verbiage or redundant information.

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 lack of annotations and output schema, the description is insufficient for a tool that fetches data from an external service like Reddit. It doesn't cover authentication needs, rate limits, return format, or error handling, which are crucial for an AI agent to use this tool effectively in real-world scenarios. The high schema coverage doesn't compensate for these behavioral gaps.

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?

The schema description coverage is 100%, with clear documentation for both parameters (postId and sort with enum values). The description doesn't add any meaningful semantic context beyond what the schema already provides, such as explaining what a 'Reddit post ID' looks like or how sorting affects comment retrieval. This meets the baseline for high schema coverage.

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 action ('Get comments') and resource ('from a Reddit post'), making the purpose immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'get_user_comments' or 'get_post' (which might return post details without comments), missing full sibling differentiation that would warrant a score of 5.

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. With sibling tools like 'get_post' (which might return post metadata) and 'get_user_comments' (which retrieves comments by user), there's no indication of when this specific tool is appropriate, leaving the agent to guess based on context alone.

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

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