Skip to main content
Glama

search_posts

Search for posts in a specific subreddit using customizable parameters such as query, sort options, and time filters, returning detailed results for matching content.

Instructions

Search for posts within a subreddit.

Args:
    params: Search parameters including subreddit name, query, and filters

Returns:
    List of matching posts with their details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • The main handler function that implements the search_posts tool logic, performing subreddit search via Reddit API and returning formatted PostResult objects.
    @validate_call(validate_return=True)
    def search_posts(params: SearchPostsParams) -> List[PostResult]:
        """
        Search for posts within a subreddit.
    
        Args:
            params: Search parameters including subreddit name, query, and filters
    
        Returns:
            List of matching posts with their details
        """
        client = RedditClient.get_instance()
        subreddit = client.reddit.subreddit(params.subreddit_name)
    
        posts = subreddit.search(
            query=params.query,
            sort=params.sort,
            syntax=params.syntax,
            time_filter=params.time_filter,
        )
    
        return [
            PostResult(
                id=post.id,
                title=post.title,
                url=post.url,
                score=post.score,
                num_comments=post.num_comments,
                created_utc=format_utc_timestamp(post.created_utc),
            )
            for post in posts
        ]
  • Pydantic input schema defining parameters for the search_posts tool.
    class SearchPostsParams(BaseModel):
        """Parameters for searching posts within a subreddit"""
    
        subreddit_name: str = Field(description="Name of the subreddit to search in")
        query: str = Field(description="Search query string")
        sort: Literal["relevance", "hot", "top", "new", "comments"] = Field(
            default="relevance", description="How to sort the results"
        )
        syntax: Literal["cloudsearch", "lucene", "plain"] = Field(
            default="lucene", description="Query syntax to use"
        )
        time_filter: Literal["all", "year", "month", "week", "day", "hour"] = Field(
            default="all", description="Time period to limit results to"
        )
  • Pydantic output schema for individual post results returned by search_posts.
    class PostResult(BaseModel):
        """Reddit post search result"""
    
        id: str = Field(description="Unique identifier of the post")
        title: str = Field(description="Title of the post")
        url: str = Field(description="URL of the post")
        score: int = Field(description="Number of upvotes minus downvotes")
        num_comments: int = Field(description="Number of comments on the post")
        created_utc: str = Field(description="UTC timestamp when post was created")
  • Code block that iterates over the tools list and registers each tool (including search_posts) with the FastMCP server.
    for tool in tools:
        logger.info(f"Registering tool: {tool.__name__}")
        mcp.tool()(tool)
  • Central registry list of all MCP tools, including search_posts, which is imported and used for registration in server.py.
    tools = [
        get_submission,
        get_subreddit,
        get_comments_by_submission,
        get_comment_by_id,
        search_posts,
        search_subreddits,
    ]
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states the basic action ('search') and return type ('List of matching posts with their details'), but lacks critical details such as whether this is a read-only operation, potential rate limits, authentication requirements, pagination behavior, or error handling. For a search tool with zero annotation coverage, this is insufficient.

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 appropriately concise with three sentences that cover purpose, parameters, and returns without unnecessary fluff. It's front-loaded with the core function. However, the structure could be slightly improved by integrating parameter details more seamlessly, but it remains efficient overall.

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 complexity of a search operation with multiple parameters (e.g., sort, syntax, time_filter), no annotations, and no output schema, the description is incomplete. It doesn't explain the return format beyond 'List of matching posts with their details,' nor does it cover behavioral aspects like rate limits or error cases. For a tool with rich input schema but no other structured data, more context is needed.

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 0%, so the description must compensate. It mentions 'Search parameters including subreddit name, query, and filters,' which adds some context beyond the schema by hinting at the parameters' roles. However, it doesn't detail specific filters or explain parameter interactions, leaving gaps. Given the low coverage, this partial compensation earns a baseline score.

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 tool's purpose: 'Search for posts within a subreddit.' It specifies the verb ('search') and resource ('posts within a subreddit'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'search_subreddits' or 'get_submission', which is why it doesn't achieve a perfect score.

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. It doesn't mention sibling tools like 'search_subreddits' (for searching subreddits themselves) or 'get_submission' (for retrieving a specific post), leaving the agent to infer usage context. This lack of explicit comparison or exclusion criteria results in a low score.

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

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

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