Skip to main content
Glama

search_subreddits

Find Reddit subreddits by name or description, retrieving detailed matches based on specific search parameters and preferences for NSFW or full descriptions.

Instructions

Search for subreddits using either name-based or description-based search.

Args:
    by: Search parameters, either SearchByName or SearchByDescription

Returns:
    List of matching subreddits with their details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYes

Implementation Reference

  • The core handler function that implements the search_subreddits tool logic. It uses the RedditClient to search subreddits by name or description based on input parameters and maps results to SubredditResult models.
    def search_subreddits(by: SearchParams) -> List[SubredditResult]:
        """
        Search for subreddits using either name-based or description-based search.
    
        Args:
            by: Search parameters, either SearchByName or SearchByDescription
    
        Returns:
            List of matching subreddits with their details
        """
        client = RedditClient.get_instance()
    
        if by.type == "name":
            subreddits = client.reddit.subreddits.search_by_name(
                by.query, exact=by.exact_match, include_nsfw=by.include_nsfw
            )
        else:  # by.type == "description"
            subreddits = client.reddit.subreddits.search(by.query)
    
        return [
            SubredditResult(
                name=subreddit.display_name,
                public_description=subreddit.public_description,
                description=(
                    subreddit.description
                    if (by.type == "description" and by.include_full_description)
                    else None
                ),
                url=subreddit.url,
                subscribers=subreddit.subscribers,
                created_utc=format_utc_timestamp(subreddit.created_utc),
            )
            for subreddit in subreddits
        ]
  • Input schema definitions for the tool, discriminating union between SearchByName and SearchByDescription parameters.
    class SearchByName(BaseModel):
        """Parameters for searching subreddits by name"""
    
        type: Literal["name"]
        query: str
        include_nsfw: bool = Field(
            default=False,
            description="Whether to include NSFW subreddits in search results",
        )
        exact_match: bool = Field(
            default=False, description="If True, only return exact name matches"
        )
    
    
    class SearchByDescription(BaseModel):
        """Parameters for searching subreddits by description"""
    
        type: Literal["description"]
        query: str
        include_full_description: bool = Field(
            default=False,
            description="Whether to include the full subreddit description (aka sidebar description) in results -- can be very long and contain markdown formatting",
        )
    
    
    SearchParams = Union[SearchByName, SearchByDescription]
  • Output schema model defining the structure of each subreddit result returned by the tool.
    class SubredditResult(BaseModel):
        """Subreddit search result"""
    
        name: str = Field(description="Display name of the subreddit")
        public_description: str = Field(description="Short description shown publicly")
        url: str = Field(description="URL of the subreddit")
        subscribers: int | None = Field(default=None, description="Number of subscribers")
        created_utc: str = Field(description="UTC date when subreddit was created")
        description: str | None = Field(
            default=None,
            description="Full subreddit description with markdown formatting",
        )
  • The search_subreddits tool function is included in the central tools registry list, which is imported and used by the MCP server for registration.
    tools = [
        get_submission,
        get_subreddit,
        get_comments_by_submission,
        get_comment_by_id,
        search_posts,
        search_subreddits,
    ]
  • Generic registration loop in the MCP server that applies mcp.tool() decorator to each function in the tools list, including search_subreddits.
    for tool in tools:
        logger.info(f"Registering tool: {tool.__name__}")
        mcp.tool()(tool)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It only notes it returns a list of matching subreddits with details, but omits important traits like auth requirements, rate limits, or any side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is short and includes a structured Args and Returns section. It is efficient, though perhaps too brief for full clarity.

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 tool has a complex parameter (union type), no output schema, and no annotations, the description is insufficient. It does not explain return structure or how to choose between search modes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, yet the description only says 'by: Search parameters, either SearchByName or SearchByDescription', which adds little beyond the schema. It fails to explain how the union discriminator works or hint at intended usage.

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 tool searches for subreddits using two methods (name-based or description-based), which distinguishes it from sibling tools like get_comment_by_id or search_posts.

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?

No guidance on when to use this tool versus other search tools, nor when to choose name vs. description search. The description lacks explicit context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools

Related Tools