Skip to main content
Glama

search_subreddits

Find Reddit communities by name or description using targeted search queries to discover relevant subreddits for specific topics or interests.

Instructions

Rechercher des subreddits par nom ou description

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesLa requête de recherche
limitNoNombre de résultats à retourner

Implementation Reference

  • The main handler function for the 'search_subreddits' tool. It destructures query and optional limit from params, retrieves the Reddit client, searches for subreddits, formats them using formatSubredditInfo, generates markdown summaries, and returns a structured text content response.
    export async function searchSubreddits(params: {
      query: string;
      limit?: number;
    }) {
      const { query, limit = 25 } = params;
      const client = getRedditClient();
    
      if (!client) {
        throw new McpError(
          ErrorCode.InternalError,
          "Reddit client not initialized"
        );
      }
    
      try {
        console.log(`[Tool] Searching subreddits for "${query}"`);
        const subreddits = await client.searchSubreddits(query, limit);
        const formattedSubreddits = subreddits.map(formatSubredditInfo);
    
        const subredditSummaries = formattedSubreddits
          .map(
            (subreddit, index) => `
    ### ${index + 1}. r/${subreddit.name}
    - Titre: ${subreddit.title}
    - Abonnés: ${subreddit.stats.subscribers.toLocaleString()}
    - Description: ${subreddit.description.short.substring(0, 150)}${subreddit.description.short.length > 150 ? "..." : ""}
    - Lien: ${subreddit.links.subreddit}
        `
          )
          .join("\n");
    
        return {
          content: [
            {
              type: "text",
              text: `
    # Résultats de recherche de subreddits
    
    **Requête:** "${query}"
    **Résultats trouvés:** ${subreddits.length}
    
    ${subredditSummaries}
              `,
            },
          ],
        };
      } catch (error) {
        console.error(`[Error] Error searching subreddits: ${error}`);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to search subreddits: ${error}`
        );
      }
    } 
  • The input schema and metadata for the 'search_subreddits' tool as registered in the ListTools response, defining the expected parameters: query (string, required) and limit (integer, optional default 25).
    {
      name: "search_subreddits",
      description: "Rechercher des subreddits par nom ou description",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "La requête de recherche",
          },
          limit: {
            type: "integer",
            description: "Nombre de résultats à retourner",
            default: 25,
          },
        },
        required: ["query"],
      },
    },
  • src/index.ts:498-501 (registration)
    The dispatch registration in the CallToolRequest handler's switch statement that routes calls to 'search_subreddits' to the tools.searchSubreddits function with typed parameters.
    case "search_subreddits":
      return await tools.searchSubreddits(
        toolParams as { query: string; limit?: number }
      );
  • Supporting helper method in RedditClient class that authenticates, makes API call to Reddit's /subreddits/search.json endpoint, parses the response, and returns an array of formatted RedditSubreddit objects. Called by the tool handler.
    async searchSubreddits(query: string, limit: number = 25): Promise<RedditSubreddit[]> {
      await this.authenticate();
      try {
        const response = await this.api.get("/subreddits/search.json", {
          params: {
            q: query,
            limit,
            type: "sr",
          },
        });
    
        return response.data.data.children.map((child: any) => {
          const subreddit = child.data;
          return {
            displayName: subreddit.display_name,
            title: subreddit.title,
            description: subreddit.description || "",
            publicDescription: subreddit.public_description || "",
            subscribers: subreddit.subscribers,
            activeUserCount: subreddit.active_user_count,
            createdUtc: subreddit.created_utc,
            over18: subreddit.over18,
            subredditType: subreddit.subreddit_type,
            url: subreddit.url,
          };
        });
      } catch (error) {
        console.error(`[Error] Failed to search subreddits:`, error);
        throw new Error(`Failed to search subreddits: ${error}`);
      }
    }
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 only states the search functionality without mentioning any behavioral traits such as rate limits, authentication requirements, pagination behavior, or what happens when no results are found. This leaves significant gaps for a search tool.

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 in French that directly states the tool's purpose without any unnecessary words or structural complexity. It's appropriately sized and front-loaded with the essential 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 incomplete. It doesn't explain what the search returns (e.g., list of subreddit objects with what fields), how results are ordered, or any limitations. For a search tool with 2 parameters and no structured output documentation, this leaves too many unanswered questions.

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 both parameters ('query' and 'limit') well-documented in the schema. The description adds no additional parameter semantics beyond what's already in the structured schema, so it 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 'Rechercher des subreddits par nom ou description' clearly states the action (search) and target resource (subreddits) with specific search criteria (by name or description). However, it doesn't explicitly differentiate from sibling tools like 'search_posts' or 'get_trending_subreddits' which also involve subreddit-related searches.

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 like 'search_posts', 'get_trending_subreddits', or 'get_subreddit_info'. It simply states what the tool does without context about appropriate use cases or exclusions.

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/samy-clivolt/reddit-mcp-server'

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