Skip to main content
Glama
Traves-Theberge

HackerNews MCP Server

Search HackerNews Posts

search_posts

Find relevant HackerNews posts by searching with keywords, filtering by author, score, or date range, and retrieving results within specified limits.

Instructions

Search and filter HackerNews posts by keywords, author, score, and date range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
authorNo
endTimeNo
limitNo
minScoreNo
queryNo
startTimeNo

Implementation Reference

  • The handler function that executes the 'search_posts' tool logic: constructs SearchParams, invokes hnClient.searchStories, formats results as structured JSON, and handles errors.
      async ({ query, author, minScore, startTime, endTime, limit }) => {
        try {
          const searchParams: SearchParams = {
            query,
            author,
            minScore,
            startTime,
            endTime,
            limit: limit || 20
          };
    
          const posts = await hnClient.searchStories(searchParams);
    
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                search_params: searchParams,
                result_count: posts.length,
                posts: posts.map(post => ({
                  id: post.id,
                  title: post.title,
                  by: post.by,
                  score: post.score,
                  time: post.time,
                  url: post.url,
                  descendants: post.descendants
                }))
              }, null, 2)
            }]
          };
        } catch (error) {
          logger.error("Failed to search posts:", error);
          return {
            content: [{
              type: "text",
              text: `Error searching posts: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Input schema using Zod for validating tool parameters: query, author, minScore, time ranges, and limit.
    {
      title: "Search HackerNews Posts",
      description: "Search and filter HackerNews posts by keywords, author, score, and date range",
      inputSchema: {
        query: z.string().optional(),
        author: z.string().optional(),
        minScore: z.number().optional(),
        startTime: z.number().optional(),
        endTime: z.number().optional(),
        limit: z.number().min(1).max(100).default(20).optional()
      }
  • Registers the 'search_posts' tool with the MCP server in setupTools, providing name, schema, and handler.
      "search_posts",
      {
        title: "Search HackerNews Posts",
        description: "Search and filter HackerNews posts by keywords, author, score, and date range",
        inputSchema: {
          query: z.string().optional(),
          author: z.string().optional(),
          minScore: z.number().optional(),
          startTime: z.number().optional(),
          endTime: z.number().optional(),
          limit: z.number().min(1).max(100).default(20).optional()
        }
      },
      async ({ query, author, minScore, startTime, endTime, limit }) => {
        try {
          const searchParams: SearchParams = {
            query,
            author,
            minScore,
            startTime,
            endTime,
            limit: limit || 20
          };
    
          const posts = await hnClient.searchStories(searchParams);
    
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                search_params: searchParams,
                result_count: posts.length,
                posts: posts.map(post => ({
                  id: post.id,
                  title: post.title,
                  by: post.by,
                  score: post.score,
                  time: post.time,
                  url: post.url,
                  descendants: post.descendants
                }))
              }, null, 2)
            }]
          };
        } catch (error) {
          logger.error("Failed to search posts:", error);
          return {
            content: [{
              type: "text",
              text: `Error searching posts: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Supporting method in HackerNewsClient that performs the actual story search: fetches top stories, retrieves items, filters by parameters, and limits results. Called by the tool handler.
    async searchStories(params: SearchParams): Promise<HackerNewsItem[]> {
      const topStories = await this.getTopStories();
      const storyLimit = Math.min(params.limit || 50, 100); // Limit to avoid too many API calls
      
      const stories = await Promise.all(
        topStories.slice(0, storyLimit * 2).map(id => this.getItem(id))
      );
    
      const validStories = stories.filter((story): story is HackerNewsItem => 
        story !== null && story.type === "story"
      );
    
      return this.filterStories(validStories, params).slice(0, storyLimit);
    }
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 offers minimal behavioral insight. It mentions filtering capabilities but doesn't disclose whether this is a read-only operation, if it requires authentication, rate limits, pagination behavior (beyond the 'limit' parameter in schema), or what the output format looks like. For a search tool with 6 parameters, this leaves significant gaps.

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 front-loads the core functionality ('search and filter HackerNews posts') followed by the key filter criteria. Every word earns its place with no redundancy or fluff.

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 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'keywords' means versus the 'query' parameter, how date ranges work (Unix timestamps?), what 'score' represents, or what the tool returns. The agent lacks critical 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 description lists the filterable fields (keywords, author, score, date range), which maps to 4 of the 6 parameters (query, author, minScore, startTime/endTime). However, with 0% schema description coverage, the 'limit' parameter remains undocumented in both schema and description. The description adds some value but doesn't fully compensate for the coverage gap.

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 verb ('search and filter') and resource ('HackerNews posts'), making the purpose immediately understandable. It distinguishes from siblings like 'get_post' (single post retrieval) and 'search_comments' (different resource type), though it doesn't explicitly contrast with 'search_trending' or 'search_user'.

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 is provided about when to use this tool versus alternatives. While the description implies it's for searching posts, it doesn't mention when to choose this over 'search_trending' (which might find trending posts) or 'get_post' (for retrieving specific posts by ID). The agent must infer usage from tool names alone.

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/Traves-Theberge/Hackernews-MCP-Typescript'

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