HackerNews MCP服务器
 ](https://nodejs.org) 
🚀 用于与HackerNews交互的模型上下文协议服务器
使AI代理和开发人员能够通过以下方式搜索、检索和分析HackerNews内容 模型上下文协议(MCP)此服务器提供用于高级搜索、首页检索、使用评论树的详细帖子访问和用户配置文件查找的工具。
______________________________________________________________________
✨ 特性
- 🔍 高级搜索 -使用关键字搜索、过滤器(作者、日期、点、评论)和灵活排序查找帖子
- 📰 首页访问 -使用分页检索当前HackerNews首页内容
- 💬 完整评论树 -使用嵌套评论结构访问完整的讨论线程
- 👤 用户档案 -查找用户信息,包括业力、账户年龄和个人信息
- ⚡ 速率限制 -符合HN API限制条件的自动速率限制(10000请求/小时)
- 🛡️ 类型安全 -采用TypeScript严格模式和全面验证构建
- 📚 证据充分的 -完整的API文档和使用示例
- ✅ 经过彻底测试 -合同、集成和单元测试的测试覆盖率超过90%
______________________________________________________________________
📋 目录
______________________________________________________________________
📦 安装
先决条件
- Node.js 22.0.0或更高
- npm 10.0.0或更高
通过npm安装
npm install -g hn-mcp-server从源代码安装
git clone https://github.com/yourusername/hn-mcp-server.git
cd hn-mcp-server
npm install
npm run build
npm link______________________________________________________________________
🚀 快速开始
使用克劳德桌面
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"hackernews": {
"command": "npx",
"args": ["-y", "hn-mcp-server"]
}
}
}配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 视窗:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
配置后,重新启动Claude Desktop。HackerNews工具将在您的对话中可用。
使用VS代码+GitHub副本
添加到您的VS代码 settings.json:
{
"github.copilot.chat.mcp.servers": {
"hackernews": {
"command": "npx",
"args": ["-y", "hn-mcp-server"]
}
}
}试验装置
# Verify server starts
hn-mcp-server
# Or via npx
npx hn-mcp-server服务器将启动并等待MCP客户端通过stdio连接。
______________________________________________________________________
💡 使用示例
示例1:搜索AI/ML帖子
自然语言 (克劳德语):
Search HackerNews for machine learning articles from the last month with more than 100 points示例2:浏览首页
自然语言:
Show me what's currently on the HackerNews front page示例3:阅读讨论
自然语言:
Get the full discussion for HackerNews post 39381647 including all comments示例4:研究用户
自然语言:
Tell me about the HackerNews user 'pg'示例5:高级过滤
自然语言:
Find Show HN posts by user 'todsacerdoti' from 2024 with at least 50 points有关更多详细示例,请参阅 快速入门指南.
______________________________________________________________________
🛠️ 可用工具
search_posts
使用高级过滤选项搜索HackerNews帖子。
参数:
query(字符串,可选)-搜索关键字tags(数组,可选)-内容类型筛选器:story,comment,poll,show_hn,ask_hn,front_pageauthor(字符串,可选)-按用户名筛选storyId(数字,可选)-按故事ID过滤评论minPoints,maxPoints(数字,可选)-积分阈值minComments,maxComments(数量,可选)-评论计数阈值dateAfter,dateBefore(字符串,可选)-日期范围过滤器(ISO 8601)sortByDate(布尔值,可选)-按日期(true)或相关性(false,默认)排序page(数字,可选)-页码(0索引,默认值:0)hitsPerPage(数字,可选)-每页结果(1-100,默认值:20)
get_front_page
检索当前HackerNews头版帖子。
参数:
page(数字,可选)-页码(0索引,默认值:0)hitsPerPage(数字,可选)-每页结果(1-30,默认值:30)
get_post
获取特定帖子的完整详细信息,包括评论树。
参数:
postId(字符串,必填)-HackerNews帖子ID
get_user
检索用户配置文件信息。
参数:
username(字符串,必填)-HackerNews用户名(1-15个字符)
______________________________________________________________________
⚙️ 配置
速率限制
服务器自动遵守HackerNews API的速率限制 每个IP地址每小时10000个请求.
- 使用令牌桶算法跟踪请求
- 在80%、90%、95%的使用率下记录警告
- 超过速率限制时返回错误
- 随着时间的推移自动重新填充令牌
错误处理
所有工具都返回结构化错误:
{
"error": "Human-readable error message",
"type": "validation_error | not_found | api_error | rate_limit | unknown",
"details": { "additional": "context" }
}______________________________________________________________________
👨💻 发展
设置
# Clone repository
git clone https://github.com/yourusername/hn-mcp-server.git
cd hn-mcp-server
# Install dependencies
npm install
# Build
npm run build开发工作流程
# Watch mode (auto-rebuild on changes)
npm run dev
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Lint code
npm run lint
# Fix lint issues
npm run lint:fix
# Format code
npm run format
# Type check without building
npm run typecheck测试
该项目遵循测试驱动开发(TDD),有三个测试层:
- 合同测试:验证外部API响应架构
- 集成测试:使用模拟API端到端测试工具工作流
- 单元测试:单独测试单个功能
保险范围要求:行、函数、分支和语句的最小值为90%。
# Run all tests
npm test
# View coverage report
npm run test:coverage
open coverage/index.html # macOS
start coverage/index.html # Windows项目结构
src/
├── index.ts # Main entry point, MCP server setup
├── types/ # TypeScript type definitions
│ ├── hn-api.ts # HackerNews API response types
│ └── mcp-tools.ts # MCP tool schemas
├── tools/ # MCP tool implementations
│ ├── search.ts # search_posts tool
│ ├── front-page.ts # get_front_page tool
│ ├── get-post.ts # get_post tool
│ ├── get-user.ts # get_user tool
│ └── index.ts # Tool registry
├── services/ # Business logic
│ ├── hn-api-client.ts # HackerNews API client
│ └── rate-limiter.ts # Rate limiting
└── lib/ # Utilities
├── validation.ts # Input validation helpers
└── error-handler.ts # Error handling utilities
tests/
├── contract/ # API contract tests
├── integration/ # Tool integration tests
└── unit/ # Unit tests代码的风格
- 语言:启用严格模式的TypeScript 5.x
- 过梁:生物特征(无ESLint或Prettier)
- 格式化:2空格缩进,100个字符线宽,双引号
- 类型安全:没有
any类型,导出函数的显式返回类型
______________________________________________________________________
🤝 贡献
欢迎投稿!请遵循以下指南:
- 分叉存储库
- 创建要素分支:
git checkout -b feature/my-feature - 遵循TDD:先写测试,然后实现
- 确保测试通过:
npm test - 确保棉绒通过:
npm run lint - 保持覆盖范围:保持在90%+
- 提交更改:
git commit -m "Add my feature" - 推送到分支:
git push origin feature/my-feature - 打开拉取请求
发展原则
该项目遵循严格的质量标准,记录在 .specify/memory/constitution.md:
- 代码质量第一:TypeScript严格模式,否
any类型 - 测试驱动开发:实施前的测试
- 文件优先:所有功能的完整文档
- 最新稳定版本:最新的依赖关系
- 重复使用而非再造:利用现有库
______________________________________________________________________
📚 文档
______________________________________________________________________
📝 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
🙏 致谢
- 黑客新闻 -社区和内容
- HN Algolia API公司 -搜索为该服务器供电的API
- 模型上下文协议 -MCP规范和SDK
- Anthropic -Claude和MCP开发
______________________________________________________________________
🐛 支持
- 问题:
- 讨论:
- HN API文件: hn.algolia.com/api
- MCP文件: 模型上下文协议.io
______________________________________________________________________
内置❤️ 使用TypeScript、MCP SDK和Biome
