Skip to main content
Glama

get_subreddit_info

Retrieve key details about any Reddit community, including rules, member counts, and activity metrics, to understand its purpose and engagement.

Instructions

Get information about a subreddit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subreddit_nameYesName of the subreddit

Implementation Reference

  • Main tool handler that fetches subreddit data via RedditClient, formats it using formatSubredditInfo, and returns a formatted Markdown response.
    export async function getSubredditInfo(params: { subreddit_name: string }) {
      const { subreddit_name } = params;
      const client = getRedditClient();
    
      if (!client) {
        throw new McpError(
          ErrorCode.InternalError,
          "Reddit client not initialized"
        );
      }
    
      try {
        console.log(`[Tool] Getting info for r/${subreddit_name}`);
        const subreddit = await client.getSubredditInfo(subreddit_name);
        const formattedSubreddit = formatSubredditInfo(subreddit);
    
        return {
          content: [
            {
              type: "text",
              text: `
    # Subreddit Information: r/${formattedSubreddit.name}
    
    ## Overview
    - Name: r/${formattedSubreddit.name}
    - Title: ${formattedSubreddit.title}
    - Subscribers: ${formattedSubreddit.stats.subscribers.toLocaleString()}
    - Active Users: ${
                typeof formattedSubreddit.stats.activeUsers === "number"
                  ? formattedSubreddit.stats.activeUsers.toLocaleString()
                  : formattedSubreddit.stats.activeUsers
              }
    
    ## Description
    ${formattedSubreddit.description.short}
    
    ## Detailed Description
    ${formattedSubreddit.description.full}
    
    ## Metadata
    - Created: ${formattedSubreddit.metadata.created}
    - Flags: ${formattedSubreddit.metadata.flags.join(", ")}
    
    ## Links
    - Subreddit: ${formattedSubreddit.links.subreddit}
    - Wiki: ${formattedSubreddit.links.wiki}
    
    ## Community Analysis
    - ${formattedSubreddit.communityAnalysis.replace(/\n  - /g, "\n- ")}
    
    ## Engagement Tips
    - ${formattedSubreddit.engagementTips.replace(/\n  - /g, "\n- ")}
              `,
            },
          ],
        };
      } catch (error) {
        console.error(`[Error] Error getting subreddit info: ${error}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to fetch subreddit data: ${error}`
        );
      }
    }
  • Input schema definition for the get_subreddit_info tool, specifying subreddit_name as required string parameter.
      name: "get_subreddit_info",
      description: "Get information about a subreddit",
      inputSchema: {
        type: "object",
        properties: {
          subreddit_name: {
            type: "string",
            description: "Name of the subreddit",
          },
        },
        required: ["subreddit_name"],
      },
    },
  • src/index.ts:446-449 (registration)
    Tool call routing in the switch statement that invokes the getSubredditInfo handler from the tools module.
    case "get_subreddit_info":
      return await tools.getSubredditInfo(
        toolParams as { subreddit_name: string }
      );
  • RedditClient method that performs the actual API call to fetch raw subreddit data from Reddit.
    async getSubredditInfo(subredditName: string): Promise<RedditSubreddit> {
      await this.authenticate();
      try {
        const response = await this.api.get(`/r/${subredditName}/about.json`);
        const data = response.data.data;
    
        return {
          displayName: data.display_name,
          title: data.title,
          description: data.description || "",
          publicDescription: data.public_description || "",
          subscribers: data.subscribers,
          activeUserCount: data.active_user_count,
          createdUtc: data.created_utc,
          over18: data.over18,
          subredditType: data.subreddit_type,
          url: data.url,
        };
      } catch (error) {
        console.error(
          `[Error] Failed to get subreddit info for ${subredditName}:`,
          error
        );
        throw new Error(`Failed to get subreddit info for ${subredditName}`);
      }
    }
  • Helper function that formats raw RedditSubreddit data into a structured FormattedSubredditInfo object with analysis and tips.
    export function formatSubredditInfo(
      subreddit: RedditSubreddit
    ): FormattedSubredditInfo {
      const flags: string[] = [];
      if (subreddit.over18) flags.push("NSFW");
      if (subreddit.subredditType) flags.push(`Type: ${subreddit.subredditType}`);
    
      const ageDays = (Date.now() / 1000 - subreddit.createdUtc) / (24 * 3600);
    
      return {
        name: subreddit.displayName,
        title: subreddit.title,
        stats: {
          subscribers: subreddit.subscribers,
          activeUsers:
            subreddit.activeUserCount !== undefined
              ? subreddit.activeUserCount
              : "Unknown",
        },
        description: {
          short: subreddit.publicDescription,
          full:
            subreddit.description.length > 300
              ? subreddit.description.substring(0, 297) + "..."
              : subreddit.description,
        },
        metadata: {
          created: formatTimestamp(subreddit.createdUtc),
          flags: flags.length ? flags : ["None"],
        },
        links: {
          subreddit: `https://reddit.com${subreddit.url}`,
          wiki: `https://reddit.com/r/${subreddit.displayName}/wiki`,
        },
        communityAnalysis: analyzeSubredditHealth(
          subreddit.subscribers,
          subreddit.activeUserCount,
          ageDays
        ),
        engagementTips: getSubredditEngagementTips(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/samy-clivolt/reddit-mcp-server'

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