getUser
Retrieve a user profile by ID on Hacker News using the Hacker News MCP Server. Simplify access to user data for integration with LLM clients.
Instructions
Get a user profile by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the user |
Implementation Reference
- src/index.ts:465-489 (handler)The primary handler for the 'getUser' tool in the CallToolRequestSchema switch statement. Validates input, fetches user data from HN API, formats it, and constructs a response.case "getUser": { const validatedArgs = validateInput(UserRequestSchema, args); const { id } = validatedArgs; const user = await hnApi.getUser(id); if (!user) { throw new McpError( ErrorCode.InvalidParams, `User with ID ${id} not found` ); } const formattedUser = formatUser(user); const text = `User Profile:\n` + `Username: ${formattedUser.id}\n` + `Karma: ${formattedUser.karma}\n` + `Created: ${new Date(formattedUser.created * 1000).toISOString()}\n` + (formattedUser.about ? `\nAbout:\n${formattedUser.about}\n` : ""); return { content: [{ type: "text", text: text.trim() }], }; }
- src/index.ts:150-160 (registration)Tool registration in the ListToolsRequestSchema handler, defining name, description, and input schema for 'getUser'.{ name: "getUser", description: "Get a user profile by ID", inputSchema: { type: "object", properties: { id: { type: "string", description: "The ID of the user" }, }, required: ["id"], }, },
- src/schemas/index.ts:62-64 (schema)Zod schema (UserRequestSchema) used for input validation in the getUser handler and registration inputSchema.export const UserRequestSchema = z.object({ id: z.string(), });
- src/api/hn.ts:81-84 (helper)HackerNewsAPI.getUser method called by the handler to fetch raw user data from the Hacker News Firebase API.async getUser(id: string): Promise<any> { const response = await fetch(`${API_BASE_URL}/user/${id}.json`); return response.json(); }
- src/models/user.ts:9-17 (helper)formatUser function used by the handler to structure raw user data into a User interface.export function formatUser(user: any): User { return { id: user.id, created: user.created, karma: user.karma, about: user.about, submitted: user.submitted, }; }