get-user
Retrieve detailed information about specific HackerNews users including their profile data, karma score, and account activity.
Instructions
Get information about a specific HackerNews user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username to look up |
Implementation Reference
- src/index.ts:320-328 (handler)The asynchronous handler function for the 'get-user' tool. It constructs the HN API endpoint for the given username, fetches the user data using the shared fetchHN helper, and returns both a textual JSON representation and the structured data.async ({ username }) => { const endpoint = `/users/${username}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; }
- src/index.ts:308-319 (schema)The tool configuration including title, description, inputSchema (username: string), and outputSchema (username, about, karma) using Zod validation for the 'get-user' tool.{ title: 'Get HackerNews User Info', description: 'Get information about a specific HackerNews user', inputSchema: { username: z.string().describe('The username to look up') }, outputSchema: { username: z.string(), about: z.string().optional(), karma: z.number() } },
- src/index.ts:306-329 (registration)The complete registration of the 'get-user' tool via server.registerTool, specifying the tool name, schema/configuration, and handler function.server.registerTool( 'get-user', { title: 'Get HackerNews User Info', description: 'Get information about a specific HackerNews user', inputSchema: { username: z.string().describe('The username to look up') }, outputSchema: { username: z.string(), about: z.string().optional(), karma: z.number() } }, async ({ username }) => { const endpoint = `/users/${username}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; } );
- src/index.ts:11-17 (helper)Shared helper function fetchHN used by all HN API tools, including 'get-user', to perform API requests to the HackerNews Algolia API and handle errors.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(); }