Skip to main content
Glama
devabdultech

Hacker News MCP Server

getUser

Retrieve Hacker News user profiles by ID to access karma, about sections, and submission history.

Instructions

Get a user profile by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID of the user

Implementation Reference

  • Main handler for the 'getUser' tool: validates input using UserRequestSchema, fetches user data via hnApi.getUser, formats it with formatUser, constructs response text with user profile details.
    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)
    Registers the 'getUser' tool in the ListTools response, specifying name, description, and input schema.
    {
      name: "getUser",
      description: "Get a user profile by ID",
      inputSchema: {
        type: "object",
        properties: {
          id: { type: "string", description: "The ID of the user" },
        },
        required: ["id"],
      },
    },
  • Zod schema for validating the input parameters of the 'getUser' tool (user ID as string).
    export const UserRequestSchema = z.object({
      id: z.string(),
    });
  • HackerNewsAPI method that fetches user profile data from the official HN Firebase API endpoint.
    async getUser(id: string): Promise<any> {
      const response = await fetch(`${API_BASE_URL}/user/${id}.json`);
      return response.json();
    }
  • Helper function to format raw user data from HN API into a structured User interface.
    export function formatUser(user: any): User {
      return {
        id: user.id,
        created: user.created,
        karma: user.karma,
        about: user.about,
        submitted: user.submitted,
      };
    }

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/devabdultech/hn-mcp'

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