Hn Mcp Server

io.github.cyanheads由 GitHub 账号 cyanheads 发布v0.6.0更新于 Oct 29, 2026

Browse Hacker News feeds, threads, and user profiles with full-text search.

已验证Streamable HTTP可网页运行网页搜索与抓取沟通与协作

概览

AI 生成的概览

只读的 Hacker News 访问:浏览榜单、阅读评论串、查看用户资料,并全文搜索帖子、评论、投票和招聘信息。

可以做什么
  • 获取 top、new、best、ask、show、jobs 各榜单的帖子,支持分页并返回标题、链接、分数、作者和评论数
  • 读取某个条目及其评论树,可限制深度和评论数量,并用游标翻页读取长讨论串
  • 查看用户资料,包括 karma 和简介,可选解析一页最近的投稿
  • 按关键词搜索帖子、评论、投票和招聘,或仅用类型、作者、所属帖子、日期范围和最低分数等筛选条件搜索
适用场景
适合让助手调研或总结 Hacker News 上的讨论、跟踪某个话题或作者、确认某个链接是否被讨论过,或把完整评论串引入对话。
运行要求
可使用公开托管的 Streamable HTTP 端点,或通过 npx、bunx、Docker 在本地运行。本地运行需要 Bun 1.4.0 以上或 Node.js 24 以上。无需 API 密钥或账号,上游 API 均为公开接口。可选环境变量用于调整并发数、传输方式、HTTP 主机与端口以及日志级别。
安装前请注意
所有工具均为只读,不索取任何凭据。查询词、用户名和条目 ID 会发送给 Hacker News 的 Firebase API 和 Algolia 搜索;若使用公开托管端点,也会经过该实例的运营方。响应受大小和时间预算限制,长评论串和大范围搜索会分页或截断返回。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Hn Mcp Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Web executable,通过 Streamable HTTP。 远程服务在工作区中配置后即可从网页运行时运行。

交给智能体安装

把这段提示词粘贴到 Claude Code、Codex、Cursor 等智能体,或 SourceWeft 对话中。智能体会读取该服务器的安装指南,先向你展示发布者、端点和登录方式,经你同意后再把它添加到你的客户端。密钥不会写进任何命令。

阅读 https://sourceweft.com/mcp/io.github.cyanheads%2Fhn-mcp-server/install.md,并按其中说明把这个 MCP 服务器接入我的客户端。修改任何配置之前,先告诉我它的发布者、端点和登录方式,等我确认。不要把 API 密钥写进命令或我会提交的文件;问我密钥应从哪里获取。

查看智能体所依据的安装指南

其他 MCP 客户端

把它添加到你客户端的 mcpServers 配置中。

{
  "mcpServers": {
    "hn": {
      "type": "http",
      "url": "https://hn.caseyjhand.com/mcp"
    }
  }
}

README

@cyanheads/hn-mcp-server

Browse Hacker News feeds, threads, and user profiles with full-text search via MCP. STDIO or Streamable HTTP.

4 Tools

Public Hosted Server: https://hn.caseyjhand.com/mcp


Overview

Hacker News feeds, threads, and profiles. Browse ranked feeds, read full comment threads, look up users, and search stories, comments, polls, and jobs by keyword, author, date, or score.

Tools

ToolDescription
hn_get_storiesFetch stories from an HN feed (top, new, best, ask, show, jobs), with title, URL, score, author, and comment count
hn_get_threadGet an item and its comment tree as a threaded discussion, with depth and comment-count controls and a cursor to page through long threads
hn_get_userFetch a user profile with karma, about, and optionally a page of resolved submissions
hn_search_contentSearch stories, comments, polls, and jobs via Algolia by keyword, by filters alone, or both — type, author, parent story, date range, and minimum points

Agent skill

SkillDescription
hn-guideHow to find a link's thread, search without Algolia's fuzzy matches, read large comment trees in full, and search what one user said. Served over MCP as skill://hn-guide/SKILL.md and shipped in the npm package

Capability reference

hn_get_stories tool

  • Six feed types: top, new, best, ask, show, jobs; count (default 30) and offset for pagination. One call serves at most 100 stories; a count up to 1,000 is served at 100, with a notice naming the next offset
  • Returns id, type, title, url, domain, score, author, timestamp, comment count, and body text — each field omitted (not null) when HN doesn't provide it
  • Enrichment reports total, offset, and hasMore; while more stories remain, truncated is set and notice names the next offset, and a notice explains empty pages (empty feed, offset past end, or every item on the page deleted/flagged). The last page carries no truncation
  • Items whose fetch failed after retries, or ran past the call's 50-second time budget, are listed in failedIds with a notice naming the retry; a page where every item failed returns the classified upstream error instead of an empty list

hn_get_thread tool

  • itemId plus depth (default 3; 0 returns the item with no comments) and maxComments (default 50) capping one response across all levels, alongside a fixed 64,000-byte budget on each response surface (all content[] text, nextCursor included, and the structuredContent JSON) that cuts only between comments and always returns a page's first comment whole. One call resolves at most 10 levels and 200 comments; a depth up to 100 is served at 10 and a maxComments up to 1,000 at 200, with a notice naming the comment to pass as itemId or the nextCursor that reaches the rest
  • Breadth-first traversal ranked like HN — top-ranked top-level comments resolve first, replies fill in only after the level above is exhausted
  • Resumable: a response stopped by maxComments, the byte budget, an upstream rate limit, or the call's 50-second time budget returns nextCursor; passing it back as cursor with the same itemId continues at the next unseen comment. The cursor carries the unvisited comments themselves, so re-ranked replies cannot shift it, and the server keeps no session state. A cursor the tool did not issue, an altered one, or one passed with a different itemId fails with invalid_cursor
  • The root carries its relationships and state: parent and storyId (the story or poll the discussion belongs to) for a comment, poll for a poll option, parts and resolved options (text and votes, at every depth) for a poll, and deleted/dead markers. The content[] heading names the type — a title, Comment by <author>, Poll option by <author> on poll <id> — and marks a deleted or dead root
  • Flat comment list carries depth/parentId for tree reconstruction, plus childCount and an isOp flag when the comment author submitted the thread's story — on a comment root, the story at storyId, never the comment's own author. Dead and deleted comments are left out, but their live replies are still returned at their true depth, with parentId naming the omitted comment
  • truncated and truncationReason (count, size, rate_limited, time, or depth when replies lie below the depth limit) are set only while comments remain unread — never on a terminal page, including a thread that loads in full at exactly the cap. notice reports deleted/dead comments omitted during traversal and the next step: the cursor, or a larger depth or a comment id as itemId, naming by ID any omitted comment whose replies the depth limit cut
  • Comments and poll options whose fetch failed after retries or ran past the call's time budget are listed in failedIds, and notice names them with the retry; failed comments ride in nextCursor, so paging on retries them rather than skipping them. The root item is still returned, and a failure is never passed off as a maxComments/depth limit

hn_get_user tool

  • username is case-sensitive and trimmed; includeSubmissions (default false) resolves recent submissions, with submissionCount (default 10) and submissionOffset paging through a long history. One call resolves at most 50 submissions; a submissionCount up to 1,000 is served at 50, with a notice naming the next submissionOffset
  • Profile includes karma, creation date, and about text (HTML stripped); submissions filter out dead/deleted items
  • A comment submission carries its parent and a poll-option submission its poll, so either links back to what it answered
  • Enrichment echoes submissionOffset and the offset to send next, or a notice when the requested offset is past the end of the history
  • Submissions whose fetch failed after retries, or that the call's 50-second time budget cut, are listed in failedIds with a notice naming the retry (and the budget, when it cut them); a window where every submission failed returns the classified upstream error — Timeout when the budget cut them all
  • Each response surface is held to a fixed 64,000-byte budget: an over-budget page keeps every submission and cuts the longest bodies to one shared length, flagging each with textTruncated and pointing to hn_get_thread for the whole text

hn_search_content tool

  • Free-text query — typo-tolerant, with the last term also matching as a prefix; wrap a term in double quotes to match it exactly and put - before one to exclude it — plus tags (story/comment/poll/job/ask_hn/show_hn/front_page), author (the exact, case-sensitive username), storyId, dateRange, and minPoints filters; sort by relevance or date; count (default 30) and page for pagination. One call serves at most 50 hits; a count up to 1,000 is served as the page of 50 starting at the requested page's first hit, with a notice naming the count: 50 page to pass next; a non-zero page whose first hit begins no page of 50 fails with count_page_unaligned, naming a count and page that start there and, when that count is under 25, the page of 50 that holds that hit
  • tags: "front_page" is the front page right now (about 30 stories), never past front pages; for an earlier window, use tags: "story" with dateRange and minPoints
  • query is optional when a filter is set — list Ask HN, Show HN, polls, or jobs on their own, or pass a story's storyId with tags: "comment" to search within one thread. No query and no filter fails with missing_query_or_filter
  • To check whether a page was discussed, pass its URL alone as query: the leading http://, https://, or www. is dropped before searching, so submissions under either scheme, with or without www., all match. The output query and the notice show what was searched
  • dateRange bounds take ISO 8601 (YYYY, YYYY-MM, YYYY-MM-DD, or a date-time with optional offset), read as UTC and both exclusive; an empty or out-of-order range fails with invalid_date_range
  • minPoints applies to stories and polls — comments and jobs carry no points, so pairing it with tags: "comment" or "job" fails with min_points_unscored_type
  • view: "compact" drops the two body-text fields (text, highlights.text), which otherwise repeat a long comment twice per hit — pass a hit id to hn_get_thread to read the body. In full, a page over 64,000 bytes per response surface drops highlights.text from every hit (highlightsTextOmitted), then cuts the longest bodies to one shared length (textTruncated, with an hn_get_thread pointer) — every hit stays
  • Each hit carries its type (story, comment, poll, pollopt, job) when Algolia records one. Untagged searches also return poll options, which carry only an id, author, vote count, and date — hn_get_thread reads an option's text and poll. A poll hit has no storyId; its own id is the discussion root
  • Job descriptions come back as text, though keywords don't search them
  • Highlight metadata (highlights.title, highlights.text, matchedWords) shows which terms matched and where; highlights.text is the matched body in full with <em> markers
  • Enrichment echoes the applied criteria — each filter set (author trimmed, dateRange as the exclusive UTC bounds applied, to the second), plus sort, count, and view with defaults filled — so a saved result says what it answers
  • Enrichment reports totalHits, page, and the actual reachable totalPages — not derived from totalHits, since broad queries report far more hits than Algolia will serve. totalHitsExact: false marks totalHits as an estimate, and reachableHits: 1000 marks a search that matches more than Algolia's 1,000-hit ceiling; the last page of such a search gets a notice naming the ceiling and narrower dateRange windows to reach the rest. While more pages remain, truncated is set and notice names the next page; a page past the end gets a notice naming the last valid page (or page: 0 past the ceiling)

Features

Built on @cyanheads/mcp-ts-core: stdio and Streamable HTTP transports, pluggable auth (none / jwt / oauth), swappable storage (in-memory, filesystem, Supabase, Cloudflare KV/R2/D1), structured logging with optional OpenTelemetry tracing.

HN-specific:

  • Two upstream APIs: HN's Firebase API for feeds, items, and users; Algolia's HN Search API for full-text search
  • Concurrent batch fetching with configurable parallelism for item resolution (HN_CONCURRENCY_LIMIT)
  • HTML bodies stripped to plain text — entities decoded once, code blocks kept verbatim, each link rendered once as its full URL — while titles, which are not HTML though some carry entities, are entity-decoded and never tag-stripped
  • Server-level instructions forwarded to LLM clients on initialize — item types, ID reuse across tools, case-sensitive usernames, field sparsity
  • No API keys required — both upstream APIs are public

Agent-friendly output:

  • Graceful partial failure — an item whose fetch fails after retries is reported by ID in failedIds, apart from deleted, dead, or nonexistent items, rather than silently shrinking the result; each hn_get_thread, hn_get_stories, and hn_get_user call runs under one 50-second time budget, so hung fetches cannot hold it past an MCP client's 60-second timeout; hn_get_thread also counts the deleted and dead comments it drops, and a rate-limited item stops the batch instead of sending every remaining item through its own retry ladder
  • Discriminated output contracts — typed error reasons (item_not_found, upstream_rate_limited, upstream_html, …) with per-reason recovery text (a rate limit passes on the upstream's Retry-After as retryAfter), and a depth/parentId pair on every comment so callers reconstruct the tree without guessing nesting
  • Pagination provenance — every paged listing echoes the offset it used (offset, submissionOffset, page) plus the exact next-offset value in notice, hn_search_content also echoes the criteria it searched with, and hn_get_thread returns a self-contained nextCursor, so an agent can resume without recomputing state
  • Response shaping — HTML stripping, URL normalization, and domain extraction remove upstream markup noise; hn_search_content's view: "compact" drops the two body-text fields that otherwise duplicate a hit's full text, and a 64,000-byte budget on each response surface cuts the longest bodies of an over-budget page
  • Fenced upstream text — in content[], every line of a body is block-quoted and titles are escaped only where they could break the surrounding Markdown, so a comment cannot pass for a server-authored line

Getting started

Public Hosted Instance

A public instance is available at https://hn.caseyjhand.com/mcp — no installation required. Point any MCP client at it via Streamable HTTP:

json
{  "mcpServers": {    "hn-mcp-server": {      "type": "streamable-http",      "url": "https://hn.caseyjhand.com/mcp"    }  }}

Self-Hosted / Local

Add to your MCP client configuration file:

json
{  "mcpServers": {    "hn-mcp-server": {      "type": "stdio",      "command": "bunx",      "args": ["@cyanheads/hn-mcp-server@latest"],      "env": {        "MCP_TRANSPORT_TYPE": "stdio",        "MCP_LOG_LEVEL": "info"      }    }  }}

Or with npx (no Bun required):

json
{  "mcpServers": {    "hn-mcp-server": {      "type": "stdio",      "command": "npx",      "args": ["-y", "@cyanheads/hn-mcp-server"],      "env": {        "MCP_TRANSPORT_TYPE": "stdio",        "MCP_LOG_LEVEL": "info"      }    }  }}

Or with Docker:

json
{  "mcpServers": {    "hn-mcp-server": {      "type": "stdio",      "command": "docker",      "args": [        "run", "-i", "--rm",        "-e", "MCP_TRANSPORT_TYPE=stdio",        "ghcr.io/cyanheads/hn-mcp-server:latest"      ]    }  }}

Prerequisites

Installation

sh
git clone https://github.com/cyanheads/hn-mcp-server.gitcd hn-mcp-serverbun install

Configuration

All configuration is via environment variables. No API keys required — HN APIs are public.

VariableDescriptionDefault
HN_CONCURRENCY_LIMITMax concurrent HTTP requests for batch item fetches (integer, 1–50).10
MCP_TRANSPORT_TYPETransport: stdio or http.stdio
MCP_HTTP_PORTHTTP server port.3010
MCP_HTTP_HOSTHTTP server host.127.0.0.1
MCP_SESSION_MODEHTTP session handling: stateful, stateless, or auto (resolves to stateful). The server declares stateless in source, and the published Docker image and .env.example set it too; a meaningful env value still overrides.stateless
MCP_LOG_LEVELLog level: debug, info, notice, warning, error.info
LOGS_DIRDirectory for log files (Node.js only).<project-root>/logs

See .env.example for the full list of optional overrides.

Running the server

Local development

  • Dev mode (auto-reload):

    sh
    MCP_TRANSPORT_TYPE=stdio bun --watch src/index.ts   # stdioMCP_TRANSPORT_TYPE=http bun --watch src/index.ts    # HTTP
  • Build and run:

    sh
    bun run rebuildbun run start:stdio   # or start:http
  • Run checks and tests:

    sh
    bun run devcheck   # Lint, format, typecheck, securitybun run test       # Vitest test suite

Docker

sh
docker build -t hn-mcp-server .docker run --rm -p 3010:3010 hn-mcp-server

The Dockerfile defaults to HTTP transport, stateless session mode, and logs to /var/log/hn-mcp-server. OpenTelemetry peer dependencies are installed by default — build with --build-arg OTEL_ENABLED=false to omit them.

Project structure

DirectoryPurpose
src/index.tscreateApp() entry point — registers tools and inits the HN service.
src/config/Server-specific environment variable parsing and validation with Zod.
src/mcp-server/tools/definitions/Tool definitions (*.tool.ts).
src/services/hn/HN Firebase + Algolia API client and domain types.
tests/Unit and integration tests mirroring src/.

Development guide

See CLAUDE.md for development guidelines and architectural rules. The short version:

  • Handlers throw, framework catches — no try/catch in tool logic
  • Use ctx.log for request-scoped logging
  • All tools are read-only — no auth scopes required
  • Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields

Contributing

Issues are welcome. Run checks before submitting:

sh
bun run devcheckbun run test

License

Apache-2.0 — see LICENSE for details.

来源:README.md,提交 a02e940

工具

4

hn_get_stories

Hn Get Stories

Fetch stories from an HN feed (top, new, best, ask, show, jobs), with title, URL, score, author, and comment count for each story.

输入参数feed必填countoffset

hn_get_thread

Hn Get Thread

Get an item and its comment tree as a threaded discussion, with child comments resolved recursively. Use depth 0 for an item-only lookup. A long thread comes back in pages: pass the returned nextCursor as cursor to continue.

输入参数depthcursoritemId必填maxComments

hn_get_user

Hn Get User

Get an HN user profile with karma, about, and optionally their most recent submissions resolved into full items.

输入参数username必填submissionCountsubmissionOffsetincludeSubmissions

hn_search_content

Hn Search Content

Search Hacker News stories, comments, polls, and jobs via Algolia — by keyword, by filters alone, or both. Filterable by content type, author, parent story, date range, and minimum points.

输入参数pagesorttagsviewcountqueryauthorstoryIddateRangeminPoints

版本历史

6
  1. v0.6.0最新Oct 29, 2026
  2. v0.5.22Oct 18, 2026
  3. v0.5.21Oct 5, 2026
  4. v0.5.20Sep 24, 2026
  5. v0.5.17Sep 19, 2026
  6. v0.5.16Sep 16, 2026

评分

已满足适用检查项的 100%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通必需25 分
  • 已声明认证方式必需10 分
  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分