Skip to main content
Glama
tomwojcik

hn-mcp

by tomwojcik

hn-mcp

PyPI Python 3.12+ codecov License: MIT

HN threads have 500+ comments nested 10 levels deep. Your AI agent needs to read them without blowing its context window.

hn-mcp is an MCP server that gives AI agents full access to Hacker News — complete comment trees, search, and user profiles — with depth control so they can explore progressively instead of fetching everything at once.

Features

  • Full comment trees — no depth limits, no truncation

  • Depth control — fetch just top-level comments or the entire tree

  • Smart pruningreply_count at cut-off points so agents decide what to expand

  • Search — full-text search across stories and comments with filters

  • No API keys — uses the public Algolia HN API

  • 100% test coverage — tested with VCR cassettes, no network calls needed

Typical agent workflow

1. get_thread(42123456, depth=1)       → story + 85 top-level comments with reply_counts
2. Agent picks Comment A (47 replies)
3. get_comment_tree(comment_a_id)      → full 47-reply subtree
4. Agent summarizes branch, picks next

Or for smaller threads, just get_thread(id, depth=-1) to get the entire tree at once.

Getting started

Standard config works in most tools:

{
  "mcpServers": {
    "hn": {
      "command": "uvx",
      "args": ["hn-mcp"]
    }
  }
}
claude mcp add hn -- uvx hn-mcp

Add --scope user to make it available in all projects.

Follow the MCP install guide, use the standard config above.

Add to your Cursor MCP config (~/.cursor/mcp.json):

{
  "mcpServers": {
    "hn": {
      "command": "uvx",
      "args": ["hn-mcp"]
    }
  }
}

Follow the Windsurf MCP documentation, use the standard config above.

Add to your VS Code MCP config (.vscode/mcp.json):

{
  "mcpServers": {
    "hn": {
      "command": "uvx",
      "args": ["hn-mcp"]
    }
  }
}

If you want to run from a local clone instead:

claude mcp add hn -- uv run --directory /absolute/path/to/news-ycombinator-mcp hn-mcp

Prerequisites

  • Python 3.12+

  • uv (provides uvx)

Related MCP server: Hacker News MCP Server

Tools

Tool

Description

Key Inputs

Returns

get_thread

Fetch a story and its comment tree

story_id, depth (0=story only, 1=top-level, N=N levels, -1=full tree)

Story metadata + pruned comment tree

get_comment_tree

Dive into a specific comment's reply subtree

comment_id, depth (default: -1, full subtree)

Comment + nested replies

get_stories

Browse HN by category

category (top, new, ask_hn, show_hn), count

List of story summaries

search_stories

Full-text search for stories

query, sort_by (relevance/date), count, page

Paginated story results

search_comments

Full-text search for comments

query, sort_by, story_id, author, count, page

Paginated comment results

get_user

Fetch a user profile

username

Username, karma, about, created date

Depth parameter

The depth parameter on get_thread and get_comment_tree controls how much of the tree you get:

depth=0   (no comments — story metadata only)
depth=1   Comment A (reply_count=3)       ← just the comment + count
depth=2   Comment A                        ← comment + direct replies
            ├── Reply A1 (reply_count=2)
            ├── Reply A2 (reply_count=0)
            └── Reply A3 (reply_count=1)
depth=-1  Full tree, no pruning

Development

git clone https://github.com/tomwojcik/news-ycombinator-mcp
cd news-ycombinator-mcp
make venv
make install

Run tests

make test

Tests use vcrpy cassettes — no network calls needed. Coverage is reported automatically.

Re-record cassettes

If the Algolia API response format changes:

# In tests/conftest.py, temporarily change record_mode to "new_episodes"
uv run pytest
# Then change it back to "none"

Project structure

src/hn_mcp/
├── app.py               # FastMCP instance + tree pruning helpers
├── client.py            # HNClient — async Algolia API client
├── server.py            # Entrypoint
├── types.py             # TypedDict definitions for all responses
└── tools/
    ├── get_thread.py
    ├── get_comment_tree.py
    ├── get_stories.py
    ├── search_stories.py
    ├── search_comments.py
    └── get_user.py

License

MIT — see LICENSE.

Contributing

Contributions welcome. Please open an issue first to discuss what you'd like to change.

When submitting a PR:

  1. Add tests for new functionality

  2. Record VCR cassettes for any new API calls

  3. Ensure uv run pytest passes with 100% coverage

Available Tools

6 tools
get_comment_treeA

Fetch a specific comment and its reply subtree.

Use this to dive into a branch after scanning top-level comments
with get_thread(depth=1).

Args:
    comment_id: The HN comment ID.
    depth: How many levels of replies to include below this comment.
        0 = this comment only (with reply_count).
        N = N levels of replies.
        -1 = full subtree (default).
ParametersJSON Schema
NameRequiredDescriptionDefault
depthNo
comment_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It thoroughly explains depth semantics: 0 means only the comment with reply_count, N means N levels, -1 means full subtree. This goes beyond schema defaults and gives the agent essential knowledge about response behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and front-loaded: a one-line summary, a usage sentence, then a structured Args list. Every element serves a purpose, with no redundant fluff. The format is easy to scan and parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has an output schema, so return structure is available elsewhere. The description covers the critical contextual points: how to use it relative to get_thread, how the depth parameter behaves, and what depth=0 returns. For a relatively simple two-parameter tool, this is complete and actionable.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, meaning no parameter descriptions exist in the schema. The description compensates fully: comment_id is identified as 'The HN comment ID' and depth is detailed with all three modes (0, N, -1) and the default behavior. This adds significant meaning beyond the raw schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Fetch a specific comment and its reply subtree.' This clearly distinguishes it from sibling tools like get_thread (top-level comments) and search_comments. The purpose is unambiguous and immediately understood.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The second sentence explicitly states when to use this tool: 'dive into a branch after scanning top-level comments with get_thread(depth=1).' It names the alternative tool and provides a concrete use case, giving the agent clear decision guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_storiesA

Browse HN stories by category. Returns metadata only (no comments).

Args:
    category: One of: top, new, ask_hn, show_hn.
    count: Number of stories to return (default 20, max 100).
ParametersJSON Schema
NameRequiredDescriptionDefault
countNo
categoryYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the transparency burden. It states that only metadata is returned (no comments), defines count limits, and implies a read-only operation through 'Browse' and 'Returns.' It does not discuss rate limits or authentication, but for this simple HN read tool, the core behavioral traits are covered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely efficient: two purpose/behavior sentences plus a clean, well-formatted argument list. Every sentence carries meaningful information and there is no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple browse tool with an output schema present, the description covers purpose, return type, parameter semantics, and constraints. No critical context is missing for selection or invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaning beyond the schema: it explains count as 'Number of stories to return' with default and max values, and enumerates category options in plain language. The schema provides enum/default but no descriptions; the description compensates well, though it could slightly expand on what each category signifies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Browse HN stories by category.' It further clarifies scope with 'Returns metadata only (no comments),' which distinguishes it from comment- and thread-focused sibling tools. This is clear and non-tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description clearly frames the tool as a category-based story browser and notes it returns metadata only, implying it is not for comment retrieval or searching. However, it does not explicitly name alternatives or provide when-not-to-use guidance relative to search_stories or get_thread.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_threadA

Fetch a story and its comment tree from Hacker News.

Args:
    story_id: The HN story ID.
    depth: How many levels of comment nesting to include.
        0 = story metadata only, no comments.
        1 = top-level comments only (each includes reply_count).
        2 = top-level + their direct replies.
        N = N levels deep.
        -1 = entire tree, no limits.
ParametersJSON Schema
NameRequiredDescriptionDefault
depthNo
story_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.1/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does well by explaining the depth parameter's exact behavior (0, 1, 2, N, -1) and noting that top-level comments include reply_count. It doesn't mention potential side effects or rate limits, but for a read-only fetch the depth detail is substantive transparency beyond the schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized, opening with a clear one-sentence purpose and then using a structured list for arguments. Every line adds meaningful information, with no fluff or repetition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has a simple parameter set and an output schema, the description covers the essential behavior well, especially the depth options. It misses only an explicit note on how this relates to sibling get_comment_tree, which would strengthen completeness in the sibling context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description meticulously defines both parameters: story_id as 'The HN story ID' and depth with level-by-level semantics including special value -1. This fully compensates for the schema's lack of descriptions, going beyond mere names and types.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool fetches 'a story and its comment tree from Hacker News,' with a specific verb and resource. It doesn't explicitly differentiate from the sibling get_comment_tree, which could be ambiguous, but the mention of 'story and its comment tree' gives a distinct scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when the agent needs story metadata and nested comments, and the depth parameter provides guidance on how much of the tree to retrieve. However, it doesn't explicitly state when to prefer this over get_comment_tree or other sibling tools, leaving the when-to-use guidance implicit rather than direct.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_userB

Fetch a Hacker News user profile.

Args:
    username: The HN username.
ParametersJSON Schema
NameRequiredDescriptionDefault
usernameYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It only says 'Fetch a Hacker News user profile' with no mention of return format, error handling, rate limits, or permission requirements. It discloses the basic action but little else.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences and front-loads the purpose. It is concise and to the point, though extremely terse with no additional structure or context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With a single parameter and an output schema present, the description doesn't need to explain return values. However, it lacks any usage context or behavioral caveats. Given its simplicity, it is barely adequate but not fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has no parameter descriptions (0% coverage), so the description's 'Args: username: The HN username' adds minimal but necessary meaning. It confirms the required parameter's semantics beyond the schema's title alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Fetch a Hacker News user profile' with a clear verb and resource. This distinguishes it from sibling tools that fetch threads, comment trees, stories, or search results.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance is provided about when to use this tool versus alternatives. The description only states what it does, leaving the agent to infer usage from the tool name and sibling context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_commentsA

Full-text search for HN comments.

Args:
    query: Search terms.
    sort_by: "relevance" or "date".
    story_id: Optional — only search comments on this story.
    author: Optional — only search comments by this author.
    count: Results per page (default 20, max 100).
    page: Page number, 0-indexed.
ParametersJSON Schema
NameRequiredDescriptionDefault
pageNo
countNo
queryYes
authorNo
sort_byNorelevance
story_idNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry the burden. It discloses search behavior and sort options ('relevance' or 'date'), but does not explicitly state read-only nature, output format, or potential side effects. The output schema covers return shape, but the description adds limited behavioral context beyond the parameter list.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a brief summary followed by a tight, structured parameter list. Every sentence is informative and there is no redundant content. It is appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has an output schema, so not explaining return values is fine. The description covers all parameters, defaults, and constraints (e.g., count max, page 0-indexed), making it complete for successful invocation. It lacks explicit rate limit or auth info, but these are not critical for a public HN search tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With schema description coverage at 0%, the description fully compensates by explaining every parameter: 'story_id: Optional — only search comments on this story,' 'count: Results per page (default 20, max 100),' 'page: Page number, 0-indexed.' This adds meaning well beyond the schema's bare types and defaults.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with 'Full-text search for HN comments,' a specific verb+resource that clearly distinguishes it from sibling tools like search_stories and get_thread. The parameter list further clarifies its comment-specific scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description clearly implies when to use this tool (searching comments) through its title and 'Full-text search' context, but it does not explicitly name alternatives or provide exclusions. This is clear context without explicit 'do not use if' guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_storiesA

Full-text search for HN stories.

Args:
    query: Search terms.
    sort_by: "relevance" or "date".
    count: Results per page (default 20, max 100).
    page: Page number, 0-indexed.
ParametersJSON Schema
NameRequiredDescriptionDefault
pageNo
countNo
queryYes
sort_byNorelevance

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the transparency burden. It does disclose useful operational details like count default (20), max limit (100), and 0-indexed page numbers, but it does not describe response behavior, empty-result handling, or potential search caveats. This is adequate but not rich.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact: a one-sentence purpose followed by a clean argument list. Every line provides useful information, with no redundant or filler content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the output schema covers return values and the tool is relatively simple, the description is fairly complete. It covers pagination, sorting, and result count constraints. It lacks explicit sibling-tool guidance, but that is a usage-guidelines concern rather than a completeness gap here.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has zero description coverage, but the description documents all four parameters. It adds meaningful semantics beyond the schema, especially count's max value and page's 0-indexing. Some entries like 'query: Search terms' are minimal, but overall it compensates well for the schema gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with 'Full-text search for HN stories', which clearly names the action (search) and the target resource (HN stories). This also differentiates it from siblings like search_comments, get_stories, and get_thread by resource type and search behavior.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance is given about when to use this tool versus alternatives such as search_comments or get_stories. The intended use is implied by the word 'search' and the parameter list, but there are no clear exclusions or 'use this instead' hints.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 6 tool updatesv0.1.0
    • First observedget_comment_tree
    • First observedget_stories
    • First observedget_thread
    • First observedget_user
    • First observedsearch_comments
    • First observedsearch_stories

TDQS

A4.2/5.0

Scored across 6 tools

Disambiguation5/5

Each tool addresses a distinct purpose: browsing story lists, fetching a story with comments, drilling into a comment subtree, retrieving user profiles, and searching stories/comments. No overlap in core functionality.

Naming Consistency5/5

All retrieval tools follow a consistent 'get_' prefix, while search tools use 'search_', making the naming pattern predictable and easy to navigate.

Tool Count5/5

Six tools cover the essential read-only operations for Hacker News without excessive granularity or unnecessary overlap, which is well-scoped for the domain.

Completeness5/5

The toolkit provides comprehensive coverage for browsing HN: story feeds, story/comment retrieval with configurable depth, user profiles, and full-text search for both stories and comments. No obvious gaps for a read-only client.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    A Model Context Protocol server that enables AI tools like Claude and Cursor to fetch and interact with live Hacker News data (posts, comments, users) via standardized MCP endpoints.
    11
    47
    33
    MIT
  • A
    license
    D
    quality
    D
    maintenance
    An MCP server that enables AI assistants to access real-time Hacker News data including top stories, story details, comments, and search functionality.
    1
    14
    3
    MIT