Skip to main content
Glama
jeebus87

reddirect

by jeebus87

Browse Subreddit

browse_subreddit

Browse posts from any subreddit using sort options like hot, new, top, rising, or controversial. Filter by time range for top and controversial results.

Instructions

Browse posts from a subreddit with sort options (hot, new, top, rising, controversial). For top and controversial, you can specify a time range.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subredditYesSubreddit name without r/ prefix
sortNoSort order for postshot
timeNoTime range filter (only for top and controversial)
limitNoNumber of posts to return

Implementation Reference

  • The handler function that executes the 'browse_subreddit' tool logic. It takes subreddit, sort, time, and limit parameters, calls the Reddit API client to fetch posts from /r/{subreddit}/{sort}.json, formats the posts using formatPost(), and returns the result as JSON text. Includes error handling.
    async ({ subreddit, sort, time, limit }) => {
      try {
        const params = new URLSearchParams({ limit: String(limit) });
        if (time && (sort === "top" || sort === "controversial")) {
          params.set("t", time);
        }
        const data = await client.getJson(
          `/r/${subreddit}/${sort}.json?${params}`
        );
        const posts = (data?.data?.children || []).map((c: any) =>
          formatPost(c.data)
        );
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(
                { subreddit, sort, time: time ?? null, posts },
                null,
                2
              ),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error browsing r/${subreddit}: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • The input schema (Zod validation) for browse_subreddit. Defines: subreddit (string), sort (enum: hot/new/top/rising/controversial, default hot), time (enum: hour/day/week/month/year/all, optional, only for top/controversial), limit (int 1-100, default 25).
    {
      title: "Browse Subreddit",
      description:
        "Browse posts from a subreddit with sort options (hot, new, top, rising, controversial). For top and controversial, you can specify a time range.",
      inputSchema: z.object({
        subreddit: z.string().describe("Subreddit name without r/ prefix"),
        sort: z
          .enum(["hot", "new", "top", "rising", "controversial"])
          .default("hot")
          .describe("Sort order for posts"),
        time: z
          .enum(["hour", "day", "week", "month", "year", "all"])
          .optional()
          .describe("Time range filter (only for top and controversial)"),
        limit: z
          .number()
          .int()
          .min(1)
          .max(100)
          .default(25)
          .describe("Number of posts to return"),
      }),
  • Registration call: server.registerTool('browse_subreddit', ...) inside the exported register() function of src/tools/browse.ts. The register function itself is invoked in src/index.ts (line 27) as registerBrowseTools(server, client).
    export function register(server: McpServer, client: RedditClient): void {
      server.registerTool(
        "browse_subreddit",
        {
          title: "Browse Subreddit",
          description:
            "Browse posts from a subreddit with sort options (hot, new, top, rising, controversial). For top and controversial, you can specify a time range.",
          inputSchema: z.object({
            subreddit: z.string().describe("Subreddit name without r/ prefix"),
            sort: z
              .enum(["hot", "new", "top", "rising", "controversial"])
              .default("hot")
              .describe("Sort order for posts"),
            time: z
              .enum(["hour", "day", "week", "month", "year", "all"])
              .optional()
              .describe("Time range filter (only for top and controversial)"),
            limit: z
              .number()
              .int()
              .min(1)
              .max(100)
              .default(25)
              .describe("Number of posts to return"),
          }),
        },
        async ({ subreddit, sort, time, limit }) => {
          try {
            const params = new URLSearchParams({ limit: String(limit) });
            if (time && (sort === "top" || sort === "controversial")) {
              params.set("t", time);
            }
            const data = await client.getJson(
              `/r/${subreddit}/${sort}.json?${params}`
            );
            const posts = (data?.data?.children || []).map((c: any) =>
              formatPost(c.data)
            );
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify(
                    { subreddit, sort, time: time ?? null, posts },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error browsing r/${subreddit}: ${error instanceof Error ? error.message : String(error)}`,
                },
              ],
              isError: true,
            };
          }
        }
      );
  • formatPost helper function used by browse_subreddit to transform raw Reddit API post data into a structured object with fields: id, title, author, subreddit, score, numComments, url, permalink, createdUtc, isSelf, flair, selfText.
    function formatPost(p: any) {
      return {
        id: p.name || `t3_${p.id}`,
        title: p.title,
        author: p.author,
        subreddit: p.subreddit,
        score: p.score,
        numComments: p.num_comments,
        url: p.url,
        permalink: `${BASE_URL}${p.permalink}`,
        createdUtc: p.created_utc,
        isSelf: p.is_self,
        flair: p.link_flair_text || null,
        selfText: p.selftext || undefined,
      };
    }
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 does not mention read-only nature, authentication requirements, rate limits, or error handling. Only parameter behavior (sort/time link) is hinted, leaving significant gaps.

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?

Two sentences, no redundancy, essential information front-loaded. Every word earns its place. Highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers main purpose and parameter dependency but omits details about return structure, pagination behavior (limit parameter described), and edge cases. For a simple listing tool with no output schema, it is minimally adequate but not comprehensive.

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?

Input schema has 100% coverage with clear parameter descriptions. The description adds minor value by explicitly noting that time range is only for 'top' and 'controversial', but this is already inferable from the schema's enum and description. Baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states the action ('browse posts'), the resource ('from a subreddit'), and the available options (sort orders, time range). It effectively distinguishes from sibling tools like get_post (specific post) and search_reddit (search across Reddit).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives like get_subreddit_info or search_reddit. The description implies usage for browsing posts with sorting but does not provide exclusions or comparative context.

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/jeebus87/reddirect'

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