Skip to main content
Glama
wei
by wei

Search Posts by Time Range

search-by-time-range

Find HackerNews posts from specific time periods using Unix timestamps to filter results by date range.

Instructions

Search for posts within a specific time range (Unix timestamps)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endTimeYesEnd time in Unix timestamp (seconds)
hitsPerPageNoNumber of results per page (default: 20)
pageNoPage number for pagination (default: 0)
queryNoSearch query text (optional)
startTimeYesStart time in Unix timestamp (seconds)
tagsNoFilter tags (e.g., "story", "comment")

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsYes
pageYes
nbHitsYes
nbPagesYes
hitsPerPageYes

Implementation Reference

  • The handler function that implements the core logic for the 'search-by-time-range' tool. It constructs URLSearchParams with numericFilters for the time range using created_at_i field, calls fetchHN on the /search_by_date endpoint, and returns both text and structured content.
    async ({ query, tags, startTime, endTime, page, hitsPerPage }) => {
      const params = new URLSearchParams();
      if (query) params.append('query', query);
      if (tags) params.append('tags', tags);
      params.append('numericFilters', `created_at_i>${startTime},created_at_i<${endTime}`);
      if (page !== undefined) params.append('page', page.toString());
      if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString());
      
      const endpoint = `/search_by_date?${params.toString()}`;
      const result = await fetchHN(endpoint);
      
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
        structuredContent: result
      };
    }
  • The input and output schemas for the tool, defined with Zod. Input includes startTime and endTime as required Unix timestamps, optional query, tags, and pagination.
      title: 'Search Posts by Time Range',
      description: 'Search for posts within a specific time range (Unix timestamps)',
      inputSchema: {
        query: z.string().optional().describe('Search query text (optional)'),
        tags: z.string().optional().describe('Filter tags (e.g., "story", "comment")'),
        startTime: z.number().describe('Start time in Unix timestamp (seconds)'),
        endTime: z.number().describe('End time in Unix timestamp (seconds)'),
        page: z.number().optional().describe('Page number for pagination (default: 0)'),
        hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)')
      },
      outputSchema: {
        hits: z.array(z.any()),
        nbHits: z.number(),
        nbPages: z.number(),
        page: z.number(),
        hitsPerPage: z.number()
      }
    },
  • src/index.ts:475-512 (registration)
    The server.registerTool call that registers the 'search-by-time-range' tool with its schema and handler function.
    server.registerTool(
      'search-by-time-range',
      {
        title: 'Search Posts by Time Range',
        description: 'Search for posts within a specific time range (Unix timestamps)',
        inputSchema: {
          query: z.string().optional().describe('Search query text (optional)'),
          tags: z.string().optional().describe('Filter tags (e.g., "story", "comment")'),
          startTime: z.number().describe('Start time in Unix timestamp (seconds)'),
          endTime: z.number().describe('End time in Unix timestamp (seconds)'),
          page: z.number().optional().describe('Page number for pagination (default: 0)'),
          hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)')
        },
        outputSchema: {
          hits: z.array(z.any()),
          nbHits: z.number(),
          nbPages: z.number(),
          page: z.number(),
          hitsPerPage: z.number()
        }
      },
      async ({ query, tags, startTime, endTime, page, hitsPerPage }) => {
        const params = new URLSearchParams();
        if (query) params.append('query', query);
        if (tags) params.append('tags', tags);
        params.append('numericFilters', `created_at_i>${startTime},created_at_i<${endTime}`);
        if (page !== undefined) params.append('page', page.toString());
        if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString());
        
        const endpoint = `/search_by_date?${params.toString()}`;
        const result = await fetchHN(endpoint);
        
        return {
          content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
          structuredContent: result
        };
      }
    );
  • Shared helper utility function used by the tool handler to perform HTTP fetches to the HackerNews Algolia API endpoints.
    async function fetchHN(endpoint: string): Promise<any> {
      const response = await fetch(`${HN_API_BASE}${endpoint}`);
      if (!response.ok) {
        throw new Error(`HN API error: ${response.status} ${response.statusText}`);
      }
      return await response.json();
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'Search for posts' but doesn't describe what constitutes a post, whether results are paginated (though schema hints at it), what the output format looks like, rate limits, authentication requirements, or error conditions. The description is minimal and lacks important operational context.

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 extremely concise - a single sentence that states the core purpose without any fluff. It's front-loaded with the essential information and wastes no words, making it efficient for an agent to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the existence of an output schema (which handles return values) and 100% schema description coverage, the description doesn't need to explain parameters or return format. However, for a search tool with 6 parameters and multiple sibling alternatives, the description should provide more context about when to use it and what behavioral expectations exist beyond the basic 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?

Schema description coverage is 100%, so parameters are well-documented in the schema itself. The description adds only that the time range uses 'Unix timestamps,' which is already stated in the schema for startTime and endTime. No additional semantic context is provided beyond what's in the structured fields.

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 resource ('Posts') with the specific constraint 'by Time Range', which distinguishes it from generic search tools. However, it doesn't explicitly differentiate from sibling tools like 'search-posts-by-date' or 'search-posts', leaving some ambiguity about when to choose this specific time-range search.

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. With multiple sibling search tools available (e.g., 'search-posts', 'search-posts-by-date', 'search-by-url'), there's no indication of when this time-range search is preferred or what distinguishes it from other filtering mechanisms.

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/wei/hn-mcp-server-vibe'

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