Skip to main content
Glama

search_reddit_posts

Search Reddit posts using keywords, sort by relevance or time, and filter results by date range to find specific discussions and content.

Instructions

Search for Reddit posts with various filters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYesMax result count
queryYesMain search query
sortNoType of search results sortingrelevance
time_filterNoTime filter for search resultsall
timeoutNoMax scrapping execution timeout (in seconds)

Implementation Reference

  • The handler function that executes the tool: constructs request data, calls the Reddit search API endpoint via makeRequest, logs progress, returns formatted JSON response or error.
    async ({ query, count, timeout, sort, time_filter }) => {
      const requestData = { timeout, query, sort, time_filter, count };
      log("Starting Reddit posts search with:", JSON.stringify(requestData));
      try {
        const response = await makeRequest(API_CONFIG.ENDPOINTS.REDDIT_SEARCH_POSTS, requestData);
        log(`Search complete, found ${response.length} results`);
        return {
          content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
        };
      } catch (error) {
        log("Reddit search posts error:", error);
        return {
          content: [{ type: "text", text: `Reddit search posts API error: ${formatError(error)}` }],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the search_reddit_posts tool, including query, count, timeout, sort, and time_filter with descriptions and defaults.
    {
      query: z.string().describe("Search query"),
      count: z.number().default(10).describe("Max results"),
      timeout: z.number().default(300).describe("Timeout in seconds"),
      sort: z.string().default("relevance").describe("Sort order"),
      time_filter: z.string().default("all").describe("Time filter")
    },
  • src/index.ts:745-772 (registration)
    The MCP server.tool registration call that defines and registers the search_reddit_posts tool with its name, description, input schema, and handler function.
    server.tool(
      "search_reddit_posts",
      "Search Reddit posts",
      {
        query: z.string().describe("Search query"),
        count: z.number().default(10).describe("Max results"),
        timeout: z.number().default(300).describe("Timeout in seconds"),
        sort: z.string().default("relevance").describe("Sort order"),
        time_filter: z.string().default("all").describe("Time filter")
      },
      async ({ query, count, timeout, sort, time_filter }) => {
        const requestData = { timeout, query, sort, time_filter, count };
        log("Starting Reddit posts search with:", JSON.stringify(requestData));
        try {
          const response = await makeRequest(API_CONFIG.ENDPOINTS.REDDIT_SEARCH_POSTS, requestData);
          log(`Search complete, found ${response.length} results`);
          return {
            content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
          };
        } catch (error) {
          log("Reddit search posts error:", error);
          return {
            content: [{ type: "text", text: `Reddit search posts API error: ${formatError(error)}` }],
            isError: true
          };
        }
      }
    );
  • API endpoint constant used by the handler to route the request to the Reddit posts search backend.
    REDDIT_SEARCH_POSTS: "/api/reddit/search/posts",
  • Generic helper function makeRequest used by the tool handler to perform authenticated HTTPS POST requests to the AnySite API endpoints.
    const makeRequest = (endpoint: string, data: any, method: string = "POST"): Promise<any> => {
      return new Promise((resolve, reject) => {
        const url = new URL(endpoint, API_CONFIG.BASE_URL);
        const postData = JSON.stringify(data);
    
        const options = {
          hostname: url.hostname,
          port: url.port || 443,
          path: url.pathname,
          method: method,
          headers: {
            "Content-Type": "application/json",
            "Content-Length": Buffer.byteLength(postData),
            "access-token": API_KEY,
            ...(ACCOUNT_ID && { "x-account-id": ACCOUNT_ID })
          }
        };
    
        const req = https.request(options, (res) => {
          let responseData = "";
          res.on("data", (chunk) => {
            responseData += chunk;
          });
    
          res.on("end", () => {
            try {
              const parsed = JSON.parse(responseData);
              if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
                resolve(parsed);
              } else {
                reject(new Error(`API error ${res.statusCode}: ${JSON.stringify(parsed)}`));
              }
            } catch (e) {
              reject(new Error(`Failed to parse response: ${responseData}`));
            }
          });
        });
    
        req.on("error", (error) => {
          reject(error);
        });
    
        req.write(postData);
        req.end();
      });
    };
Behavior2/5

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

With no annotations provided, the description carries full burden but only mentions 'various filters' without detailing behavioral traits like rate limits, authentication needs, or potential side effects (e.g., scraping implications from the 'timeout' parameter). This leaves significant gaps in understanding how the tool behaves.

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 that directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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?

For a search tool with 5 parameters, no annotations, and no output schema, the description is inadequate. It lacks details on return values, error handling, or operational constraints (e.g., the 'timeout' hinting at scraping), leaving the agent with incomplete context for effective use.

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%, so parameters are well-documented in the schema. The description adds minimal value by mentioning 'various filters' but doesn't elaborate on parameter meanings beyond what the schema provides, aligning with 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 clearly states the action ('search') and resource ('Reddit posts'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'search_linkedin_posts' or 'google_search' beyond mentioning Reddit specifically, which is why it doesn't reach a 5.

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 'google_search' or other search tools in the sibling list. It mentions 'various filters' but doesn't specify contexts or exclusions, leaving the agent without usage direction.

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/anysiteio/hdw-mcp-server'

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