Hacker News MCP 服务器
一个提供Hacker News API访问的模型上下文协议(MCP)服务器。此服务器允许像Claude这样的AI助手从Hacker News获取故事、评论、用户资料和其他内容。
使用Claude技能mcp-builder通过Claude Code创建。
特点
- 9款综合工具 用于访问Hacker News数据:
- hn_get_item - 通过ID获取任意项目(故事、评论、工作、调查) - hn_get_top_stories - 获取当前首页的新闻故事 - hn_get_new_stories - 获取最新故事 - hn_get_best_stories - 获取有史以来最棒的故事 - hn_get_ask_stories - 获取Ask HN帖子 - hn_get_show_stories - 获取Show HN帖子 - hn_get_job_stories - 获取职位招聘信息 - hn_get_user - 获取用户资料信息 - hn_get_max_item_id - 获取最新的项目ID
- 灵活的输出格式Markdown(人类可读)和JSON(机器可读)两者都支持
- 分页支持高效浏览大型结果集
- 细节级别选择简洁的总结或详细的信息
- 速率限制处理优雅的错误处理,附带有用的信息
- 字符限制对大型响应进行自动截断
- 并行获取高效批量请求多个项目
要求
- Python 3.8或更高版本 (在 Python 3.10+ 上测试)
- Windows 10/11 (兼容 PowerShell 和 Git Bash)
安装
第一步:安装Python
如果你还没有安装Python:
- 从(某处)下载Python python.org
- 重要的在安装过程中,勾选“将 Python 添加到 PATH”
- 验证安装:
python --version步骤2:创建虚拟环境(推荐)
使用虚拟环境可以保持依赖项的隔离:
PowerShell:
cd /path/to/claude_skill_create_hn_mcp_server
python -m venv venv
.\venv\Scripts\Activate.ps1Git Bash:
cd /path/to/claude_skill_create_hn_mcp_server
python -m venv venv
source venv/Scripts/activate你应该看到 (venv) 激活后,在您的终端提示符下。
步骤3:安装依赖项
pip install --upgrade pip
pip install mcp httpx pydantic验证安装:
python -c "from mcp.server.fastmcp import FastMCP; print('MCP installed successfully')"步骤4:测试服务器
验证服务器能否运行:
python hackernews_mcp.py --help你应该能看到FastMCP的帮助输出。服务器可能会看起来卡住——这是正常的!按下 Ctrl+C 阻止它。
配置
对于Claude Desktop(Windows版)
- 找到您的Claude Desktop配置文件:
%APPDATA%\Claude\claude_desktop_config.json- 在文本编辑器中打开它,并添加Hacker News MCP服务器:
PowerShell 用户:
{
"mcpServers": {
"hackernews": {
"command": "/path/to/python.exe",
"args": [
"/path/to/hackernews_mcp.py"
]
}
}
}Git Bash 用户:
{
"mcpServers": {
"hackernews": {
"command": "/path/to/python.exe",
"args": [
"/path/to/hackernews_mcp.py"
]
}
}
}重要提示:
- 使用双反斜杠(
\\在JSON文件路径中(有)) - 使用两个文件的完整绝对路径
python.exe和hackernews_mcp.py - 如果您有其他MCP服务器,请将此作为另一项条目添加进去
mcpServers
- 重启Claude桌面版
- 验证连接:
- 打开Claude桌面版 - 寻找“锤子”或“工具”图标,表示MCP服务器已连接 - 问Claude:“你有哪些可用的Hacker News工具?”
对于其他MCP客户端
服务器默认使用stdio传输方式。请配置您的MCP客户端以运行:
python /path/to/hackernews_mcp.py使用示例
配置完成后,您可以要求Claude使用Hacker News工具:
获取头条新闻
Show me the top 10 stories on Hacker News right now获取故事详情
Get details about HN story with ID 8863搜索用户
What's the profile for HN user 'pg'?获取 Ask HN 帖子
Show me the latest Ask HN questions with at least 50 comments浏览职位发布
What are the latest 5 job postings on HN?工具参考
\hn_get_item\ 翻译成中文可以是“获取项目/条目”。不过,具体的翻译可能还需要根据上下文来确定,因为“hn”可能是一个特定系统或应用的缩写,而“get_item”通常表示获取某个项目或条目的操作。在没有具体上下文的情况下,“获取项目/条目”是一个比较通用的翻译
获取任何HN项目(故事、评论、工作、投票)的完整详情。
参数:
item_id(必填):物品ID编号response_format“markdown”(默认)或“json”detail_level“详细”(默认)或“简洁”
示例:
{
"item_id": 8863,
"response_format": "markdown",
"detail_level": "detailed"
}获取热门故事
获取当前首页的新闻故事。
参数:
limit返回的最大故事数(1-100,默认:30)offset跳过这么多故事(默认:0)response_format“markdown”(默认)或“json”detail_level“简洁”(默认)或“详细”
获取新故事(hn_get_new_stories)
按时间顺序获取最新故事。
参数: 与……相同 hn_get_top_stories
获取最佳故事(hn_get_best_stories)
通过HN的算法获取最佳故事。
参数: 与……相同 hn_get_top_stories
获取未回答的问题故事(或:获取待解答的故事提问)
获取最新的Ask HN帖子。
参数: 与……相同 hn_get_top_stories
获取展示故事(或:获取要展示的故事列表)
获取最新的Show HN帖子。
参数: 与……相同 hn_get_top_stories
获取工作故事(或:获取职位相关经历)
获取最新的职位招聘信息。
参数: 与……相同 hn_get_top_stories
\hn_get_user\ 翻译成中文是“获取用户信息”或“获取用户数据”。具体翻译可能根据上下文有所调整,但基本意思是获取与用户相关的数据或信息
获取用户资料信息。
参数:
username(必填):区分大小写的用户名response_format“markdown”(默认)或“json”include_submissions包含完整的提交列表(默认:false)
示例:
{
"username": "pg",
"response_format": "markdown",
"include_submissions": false
}\hn_get_max_item_id\ 可以翻译为“获取最大项目ID”或“获取最高项目编号”
获取当前最大的项目ID。
参数: 无
故障排除
“python: command not found” 翻译成中文是:“python:命令未找到”
解决方案: Python 不在你的系统路径中。
PowerShell:
# Find Python installation
Get-Command python
# If not found, reinstall Python with "Add to PATH" checkedGit Bash:
# Check if Python is installed
which python
# Add Python to PATH temporarily
export PATH="/c/Users/YourUsername/AppData/Local/Programs/Python/Python311:$PATH"“没有名为 'mcp' 的模块”
解决方案: 在虚拟环境中安装依赖项:
# Make sure virtual environment is activated (you should see (venv) in prompt)
source venv/Scripts/activate # Git Bash
# or
.\venv\Scripts\Activate.ps1 # PowerShell
# Install dependencies
pip install mcp httpx pydantic在激活虚拟环境时出现“权限被拒绝”(PowerShell)
解决方案: 启用脚本执行:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser服务器在运行时似乎卡住了
这是 正常行为!MCP服务器是长时间运行的进程,它们通过标准输入输出等待请求。它们不会立即退出。要测试其是否正常工作:
- 跑
python hackernews_mcp.py --help- 应该显示帮助 - 在Claude桌面应用中进行配置,并通过Claude使用它
- 使用
Ctrl+C如果手动运行服务器,则停止服务器
Claude Desktop 不显示HN工具
检查清单:
- 验证JSON语法
claude_desktop_config.json(使用JSON验证器) - 在Windows路径中使用双反斜杠:
C:\\Users\\... - 使用完整的绝对路径,而非相对路径
- 配置更改后重启Claude桌面版
- 检查Claude Desktop的日志(通常位于
%APPDATA%\Claude\logs)
“速率限制已超出”错误
The Hacker News API没有官方的速率限制,但如果你请求过多:
- 使用
limit参数用于获取更少的项目 - 使用
detail_level: "concise"减少API调用 - 如有需要,在请求之间添加延迟
API 文档
这个服务器使用的是官方的Hacker News Firebase API:
- 基本URL:
https://hacker-news.firebaseio.com/v0/ - 文档:参见
docs/README.md在这个仓库中 - 来源:
建筑学
- 框架FastMCP(官方MCP Python SDK)
- HTTP 客户端httpx(异步)
- 验证Pydantic v2
- 交通stdio(标准输入/输出)
主要特点:
- 对所有I/O操作使用Async/await
- 并行批量获取以提高效率
- 全面的错误处理
- 字符限制执行(25,000个字符)
- 分页支持
- 带有详细约束的输入验证
发展
运行测试
# Activate virtual environment first
source venv/Scripts/activate # Git Bash
# or
.\venv\Scripts\Activate.ps1 # PowerShell
# Test imports
python -c "from hackernews_mcp import mcp; print('Import successful')"
# Test server help
python hackernews_mcp.py --help代码结构
hackernews_mcp.py
├── Constants (API_BASE_URL, CHARACTER_LIMIT, etc.)
├── Enums (ResponseFormat, DetailLevel)
├── Pydantic Models (ItemInput, StoryListInput, UserInput)
├── Shared Utilities
│ ├── _fetch_from_api() - HTTP requests
│ ├── _fetch_items_batch() - Parallel fetching
│ ├── _format_timestamp() - Time formatting
│ ├── _format_item_markdown() - Markdown output
│ ├── _format_item_json() - JSON output
│ ├── _handle_api_error() - Error handling
│ └── _check_truncation() - Character limit enforcement
└── Tools (9 @mcp.tool decorated functions)许可证
此MCP服务器按原样提供,用于与Hacker News API配合使用。Hacker News API由Y Combinator提供。
功劳/学分
- Hacker News API:Y Combinator
- MCP协议:人类中心主义(或“以人为本”)
- 服务器实现:使用Claude代码工具,凭借mcp-builder技能创建
支持
对于问题或疑问:
- 查看上方的故障排除部分
- 请查看API文档中的内容
docs/README.md - 验证您的Python版本和依赖项版本
- 检查Claude Desktop的日志以获取详细的错误信息
版本
版本:1.0.0 最后更新时间:2025年10月18日
