get_post
Retrieve complete HackerNews post details including title, author, points, URL, and the full hierarchical comment tree with nested replies and metadata.
Instructions
Retrieve full details of a specific HackerNews post by its ID. Returns the complete post data including title, URL, author, points, and the entire comment tree with nested replies. Comments are returned in hierarchical structure preserving parent-child relationships. Includes metadata like total comment count and nesting depth.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| postId | Yes |
Implementation Reference
- src/tools/get-post.ts:19-51 (handler)The primary handler function for the 'get_post' tool. It validates the input using GetPostInputSchema, fetches the post data via apiClient.getPost, builds the comment tree, calculates metadata (total comments and nesting depth), and formats the response for the MCP tool protocol.export async function handleGetPost(args: unknown) { // Validate input const parseResult = GetPostInputSchema.safeParse(args); if (!parseResult.success) { throw new ValidationError("Invalid post ID", parseResult.error.errors); } const input: GetPostInput = parseResult.data; // Get post from API const post = await apiClient.getPost(input.postId); // Build comment tree (already nested from API) const postWithTree = buildCommentTree(post); // Calculate metadata const totalComments = countComments(postWithTree); const nestingDepth = calculateNestingDepth(postWithTree); // Format response const response = { post: postWithTree, metadata: { totalComments, nestingDepth, hasComments: totalComments > 0, }, remainingQuota: apiClient.getRemainingQuota(), }; return formatToolResponse(response); }
- src/schemas/index.ts:106-112 (schema)Zod schema for validating the input to the get_post tool, ensuring postId is a numeric string. Also exports the inferred TypeScript type.* Schema for get_post tool input */ export const GetPostInputSchema = z.object({ postId: z.string().regex(/^\d+$/, "Post ID must be a numeric string"), }); export type GetPostInput = z.infer<typeof GetPostInputSchema>;
- src/tools/index.ts:38-42 (registration)Tool registration in the MCP tools list, including name, description, and input schema converted to JSON schema for the protocol.{ name: "get_post", description: "Retrieve full details of a specific HackerNews post by its ID. Returns the complete post data including title, URL, author, points, and the entire comment tree with nested replies. Comments are returned in hierarchical structure preserving parent-child relationships. Includes metadata like total comment count and nesting depth.", inputSchema: zodToJsonSchema(GetPostInputSchema),
- src/index.ts:58-59 (registration)Handler dispatch registration in the main MCP server request handler switch statement, mapping 'get_post' tool calls to the handleGetPost function.case "get_post": return await handleGetPost(args);
- API client method used by the handler to fetch the specific post data from the HackerNews Algolia API.async getPost(postId: string): Promise<HackerNewsPost> { return this.request<HackerNewsPost>(`items/${postId}`); }