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,
    ]

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?

No annotations provided. Description only states it searches and returns posts, but does not disclose behavioral traits such as rate limits, authentication needs, or whether it is a read-only operation. Name implies read-only, but not explicit.

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?

Description is three lines: title, args summary, returns summary. Compact and front-loaded. Could be slightly more structured but no wasted words.

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?

No output schema provided, yet return description is vague ('List of matching posts with their details'). No mention of pagination, result limits, or sorting behavior despite these being important for a search tool. Incomplete for a search operation.

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 rich descriptions for all nested fields (subreddit_name, query, sort, syntax, time_filter). The description adds only a generic summary ('params: Search parameters including subreddit name, query, and filters'), which is mostly redundant. With high schema coverage, baseline 3 is appropriate.

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?

Clearly states 'Search for posts within a subreddit' – a specific verb (search) and resource (posts) with scope. However, no differentiation from sibling tools like get_submission or search_subreddits.

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 vs alternatives (e.g., get_submission for single post, search_subreddits for subreddits). No when-not-to-use or context information.

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