Skip to main content
Glama
wei
by wei

get-posts-by-author

Retrieve all posts, stories, and comments from a specific HackerNews author. Filter results by content type and manage pagination to browse user contributions efficiently.

Instructions

Get all posts (stories, comments, etc.) by a specific author

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsPerPageNoNumber of results per page (default: 20)
pageNoPage number for pagination (default: 0)
tagsNoFilter by type (e.g., "story", "comment")
usernameYesThe username of the author

Implementation Reference

  • Handler function that constructs a HackerNews API search query using the 'author_USERNAME' tag combined with optional tags filter, paginates if specified, fetches from /search_by_date endpoint using shared fetchHN helper, and returns structured results.
    async ({ username, tags, page, hitsPerPage }) => {
      const params = new URLSearchParams();
      const authorTag = `author_${username}`;
      const combinedTags = tags ? `${authorTag},${tags}` : authorTag;
      params.append('tags', combinedTags);
      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
      };
    }
  • Input schema requires username, optional tags filter, page, hitsPerPage. Output schema defines search result structure with hits array, pagination info.
    {
      title: 'Get Posts by Author',
      description: 'Get all posts (stories, comments, etc.) by a specific author',
      inputSchema: {
        username: z.string().describe('The username of the author'),
        tags: z.string().optional().describe('Filter by type (e.g., "story", "comment")'),
        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:331-367 (registration)
    Full registration of the 'get-posts-by-author' tool on the MCP server, including name, metadata, schemas, and handler reference.
    // Tool 10: Get posts by author
    server.registerTool(
      'get-posts-by-author',
      {
        title: 'Get Posts by Author',
        description: 'Get all posts (stories, comments, etc.) by a specific author',
        inputSchema: {
          username: z.string().describe('The username of the author'),
          tags: z.string().optional().describe('Filter by type (e.g., "story", "comment")'),
          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 ({ username, tags, page, hitsPerPage }) => {
        const params = new URLSearchParams();
        const authorTag = `author_${username}`;
        const combinedTags = tags ? `${authorTag},${tags}` : authorTag;
        params.append('tags', combinedTags);
        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 utility function to make HTTP requests to the HackerNews Algolia API, handles errors and JSON parsing, used by the get-posts-by-author handler.
    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();
    }

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