getUser
Retrieve detailed user profile information from Hacker News by specifying a username. This tool integrates with MCP Hacker News to fetch live data efficiently.
Instructions
Get user profile information
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username to look up |
Input Schema (JSON Schema)
{
"properties": {
"username": {
"description": "The username to look up",
"type": "string"
}
},
"required": [
"username"
],
"type": "object"
}
Implementation Reference
- src/tools.ts:427-462 (handler)The execute handler function for the getUser tool. Fetches user profile from HackerNews API using fetchFromAPI, formats the data including karma, created time (using formatTime helper), about text, and recent submissions, then returns a JSON-formatted text content response.execute: async (args: any) => { const user = await fetchFromAPI<HackerNewsUser>(`/user/${args.username}`); if (!user) { return { content: [ { type: "text", text: JSON.stringify({ error: "User not found" }) }, ], }; } const formattedUser = { id: user.id, karma: user.karma, created: user.created ? formatTime(user.created) : "unknown", about: user.about, submittedCount: user.submitted?.length || 0, recentSubmissions: user.submitted?.slice(0, 10) || [], }; return { content: [ { type: "text", text: JSON.stringify( { message: `User profile for ${args.username}`, user: formattedUser, }, null, 2 ), }, ], }; },
- src/tools.ts:417-426 (schema)Input schema for getUser tool, defining an object with required 'username' string property.inputSchema: { type: "object", properties: { username: { type: "string", description: "The username to look up", }, }, required: ["username"], },
- src/tools.ts:414-463 (registration)Registration of the getUser tool as an object in the exported tools array from tools.ts. This array is imported into index.ts and used to list tools and dispatch calls to the execute handler.{ name: "getUser", description: "Get user profile information", inputSchema: { type: "object", properties: { username: { type: "string", description: "The username to look up", }, }, required: ["username"], }, execute: async (args: any) => { const user = await fetchFromAPI<HackerNewsUser>(`/user/${args.username}`); if (!user) { return { content: [ { type: "text", text: JSON.stringify({ error: "User not found" }) }, ], }; } const formattedUser = { id: user.id, karma: user.karma, created: user.created ? formatTime(user.created) : "unknown", about: user.about, submittedCount: user.submitted?.length || 0, recentSubmissions: user.submitted?.slice(0, 10) || [], }; return { content: [ { type: "text", text: JSON.stringify( { message: `User profile for ${args.username}`, user: formattedUser, }, null, 2 ), }, ], }; }, },