Skip to main content
Glama
wei

HackerNews MCP Server

by wei

get-item

Retrieve detailed HackerNews stories, comments, polls, and discussion threads with full nested comment trees and metadata by providing an item ID.

Instructions

Retrieve detailed information about a specific HackerNews item by ID.

Returns complete item details including the full nested comment tree. Use this to:

  • View a story with all comments

  • Read a specific comment with its replies

  • Explore discussion threads in depth

  • Get complete metadata for any item

Features:

  • Full nested comment tree (all levels)

  • Complete item metadata (title, url, text, points, author, etc.)

  • Works for stories, comments, polls, and poll options

  • Includes creation time and item type

Examples:

  • Get story with comments: { "itemId": "38456789" }

  • Get specific comment: { "itemId": "38456790" }

  • Get poll: { "itemId": "126809" }

Note: Large comment threads (>500 comments) may take 2-3 seconds to load due to nested fetching. Returns error if item doesn't exist or has been deleted.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemIdYesHackerNews item ID (e.g., '38456789')

Implementation Reference

  • The primary handler function that executes the 'get-item' tool logic: validates input, fetches the HackerNews item by ID using HNAPIClient (including full nested comment tree), checks existence, validates output, and returns success or error result.
    export async function getItemHandler(input: unknown): Promise<CallToolResult> {
    	try {
    		// Validate input
    		const validatedParams = GetItemInputSchema.parse(input);
    
    		// Create API client
    		const client = new HNAPIClient();
    
    		// Call items API to get item with nested children
    		const result = await client.getItem(validatedParams.itemId);
    
    		// Check if item exists
    		const notFoundError = checkItemExists(result, "Item", validatedParams.itemId);
    		if (notFoundError) {
    			return notFoundError;
    		}
    
    		// Validate output
    		const validatedResult = GetItemOutputSchema.parse(result);
    
    		return createSuccessResult(validatedResult);
    	} catch (error) {
    		return handleAPIError(error, "get-item");
    	}
    }
  • Zod schemas defining input (GetItemInputSchema: itemId string) and output (GetItemOutputSchema: full item fields including nested children) for validation in the get-item tool.
    export const GetItemInputSchema = z.object({
    	itemId: z.string().min(1, "itemId must not be empty").describe("HackerNews item ID"),
    });
    
    /**
     * Output schema for get-item tool (ItemResult with nested children)
     */
    export const GetItemOutputSchema = z.object({
    	id: z.string(),
    	created_at: z.string().datetime(),
    	created_at_i: z.number().int().positive(),
    	type: z.enum(["story", "comment", "poll", "pollopt"]),
    	author: z.string(),
    	title: z.string().nullable(),
    	url: z.string().url().nullable(),
    	text: z.string().nullable(),
    	points: z.number().int().nonnegative().nullable(),
    	parent_id: z.number().int().positive().nullable(),
    	story_id: z.number().int().positive(),
    	options: z.array(z.number().int()),
    	children: z.array(z.any()), // Recursive type, validated at runtime
    });
  • Tool metadata (getItemTool) for MCP registration: name, detailed description, and JSON schema for input validation.
    export const getItemTool = {
    	name: "get-item",
    	description: `Retrieve detailed information about a specific HackerNews item by ID.
    
    Returns complete item details including the full nested comment tree. Use this to:
    - View a story with all comments
    - Read a specific comment with its replies
    - Explore discussion threads in depth
    - Get complete metadata for any item
    
    Features:
    - Full nested comment tree (all levels)
    - Complete item metadata (title, url, text, points, author, etc.)
    - Works for stories, comments, polls, and poll options
    - Includes creation time and item type
    
    Examples:
    - Get story with comments: { "itemId": "38456789" }
    - Get specific comment: { "itemId": "38456790" }
    - Get poll: { "itemId": "126809" }
    
    Note: Large comment threads (>500 comments) may take 2-3 seconds to load due to nested fetching.
    Returns error if item doesn't exist or has been deleted.`,
    	inputSchema: {
    		type: "object",
    		properties: {
    			itemId: {
    				type: "string",
    				description: "HackerNews item ID (e.g., '38456789')",
    			},
    		},
    		required: ["itemId"],
    	},
    };
  • src/index.ts:45-55 (registration)
    Registration of getItemTool in the server's ListToolsRequestHandler response, making it discoverable by MCP clients.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
    	return {
    		tools: [
    			searchPostsToolMetadata,
    			getFrontPageTool,
    			getLatestPostsTool,
    			getItemTool,
    			getUserTool,
    		],
    	};
    });
  • src/index.ts:75-76 (registration)
    Dispatch registration in the central CallToolRequestHandler switch statement, routing 'get-item' calls to getItemHandler.
    case "get-item":
    	return await getItemHandler(args);
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It does well by specifying performance characteristics ('Large comment threads (>500 comments) may take 2-3 seconds to load due to nested fetching'), error conditions ('Returns error if item doesn't exist or has been deleted'), and what the tool returns ('complete item details including the full nested comment tree'). However, it doesn't mention rate limits or authentication requirements, which would be helpful for a public API tool.

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?

The description is well-structured with clear sections (purpose, use cases, features, examples, notes) and front-loads the core purpose. While comprehensive, it could be slightly more concise by combining some bullet points or reducing redundancy between 'Features' and the opening description. Every sentence adds value, but there's minor room for tightening.

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

Completeness4/5

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

For a single-parameter read operation with no output schema, the description provides excellent context about what information is returned (full nested comment tree, complete metadata), performance characteristics, error conditions, and supported item types. The main gap is the lack of output format details (structure of returned data), which would be helpful since there's no output schema. However, it covers most other aspects well.

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 input schema has 100% description coverage, with the single parameter 'itemId' well-documented in the schema. The description adds minimal value beyond the schema by providing examples of item IDs in the 'Examples' section, but doesn't explain parameter semantics beyond what's already in the schema description. This meets the baseline of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Retrieve detailed information') and resource ('specific HackerNews item by ID'), distinguishing it from sibling tools like get-front-page (list of stories), get-latest-posts (recent posts), get-user (user profiles), and search-posts (search functionality). It explicitly mentions what types of items it works for (stories, comments, polls, poll options).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool through bullet points: 'View a story with all comments', 'Read a specific comment with its replies', 'Explore discussion threads in depth', and 'Get complete metadata for any item'. It also implicitly distinguishes from siblings by focusing on single-item retrieval rather than lists or searches.

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'

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