pskill9/hn-server
简介
核心亮点
- 将 Hacker News 网页内容实时结构化
- 支持快速检索 Top/New 等多种故事类型
- 让 AI 助手具备实时追踪技术热点能力
- 无需 API Key,通过解析 HTML 直接获取
完整文档
Hacker News MCP Server
一个 Model Context Protocol (MCP) 服务器,提供获取 Hacker News 故事的工具。该服务器解析来自 news.ycombinator.com 的 HTML 内容,并为不同类型的故事(top, new, ask, show, jobs)提供结构化数据。
<a href="https://glama.ai/mcp/servers/oge85xl22f"><img width="380" height="200" src="https://glama.ai/mcp/servers/oge85xl22f/badge" alt="Hacker News MCP server" /></a>
Features
- 获取不同类型的故事 (top, new, ask, show, jobs)
- 获取包含标题、URL、分数、作者、时间戳和评论数的结构化数据
- 可配置返回的故事数量限制
- 完善的错误处理和验证
Installation
1. Clone 仓库:
git clone https://github.com/pskill9/hn-server
cd hn-servernpm installnpm run build对于 VSCode Claude 扩展:
{
"mcpServers": {
"hacker-news": {
"command": "node",
"args": ["/path/to/hn-server/build/index.js"]
}
}
}该服务器提供了一个名为 get_stories 的工具,用于从 Hacker News 获取故事。
工具:get_stories
参数:
type(string):要获取的故事类型
- 选项:'top', 'new', 'ask', 'show', 'jobs'
- 默认值:'top'
limit(number):返回的故事数量
- 范围:1-30
- 默认值:10
使用示例:
use_mcp_tool with:
server_name: "hacker-news"
tool_name: "get_stories"
arguments: {
"type": "top",
"limit": 5
}[
{
"title": "Example Story Title",
"url": "https://example.com/story",
"points": 100,
"author": "username",
"time": "2024-12-28T00:03:05",
"commentCount": 50,
"rank": 1
},
// ... more stories
]要将此 MCP server 与 Claude 配合使用,您需要:
1. 安装 Claude 桌面应用或 VSCode Claude 扩展
2. 在设置中配置 MCP server
3. 使用 Claude 的自然语言界面与 Hacker News 交互
配置
对于 Claude 桌面应用,请将 server 配置添加到:
// ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
// %APPDATA%\Claude\claude_desktop_config.json (Windows)
{
"mcpServers": {
"hacker-news": {
"command": "node",
"args": ["/path/to/hn-server/build/index.js"]
}
}
}// VSCode Settings JSON
{
"mcpServers": {
"hacker-news": {
"command": "node",
"args": ["/path/to/hn-server/build/index.js"]
}
}
}配置完成后,你可以使用自然语言与 Claude 交互来获取 Hacker News 故事。示例:
- "Show me the top 5 stories from Hacker News"
- "What are the latest Ask HN posts?"
- "Get me the top Show HN submissions from today"
Claude 将自动使用相应的参数来获取你想要的故事。
!Claude using the Hacker News MCP server
Story 对象结构
每个 story 对象包含:
title(string):故事标题
url(string, optional):故事的 URL(对于文本帖子可能是内部 HN URL)
points(number):点赞数
author(string):发布者的用户名
time(string):故事发布的时间戳
commentCount(number):评论数
rank(number):在列表中的位置
开发
该服务器使用以下技术构建:
- TypeScript
- Model Context Protocol SDK
- Axios 用于 HTTP 请求
- Cheerio 用于 HTML 解析
如需修改服务器:
1. 修改 src/index.ts
2. 重新构建:
npm run build服务器包含针对以下情况的鲁棒错误处理:
- 无效的 story 类型
- 网络故障
- HTML 解析错误
- 无效的参数值
错误将随相应的错误代码和描述性消息一起返回。
贡献
欢迎贡献!请随时提交 Pull Request。
许可证
MIT License - 欢迎在您自己的项目中使用。