黑客新闻 Mcp 服务器
概览
什么是 hn-server?
hn-server 是由用户 ### pskill9 在 GitHub 上创建的公共存储库。它作为 Hacker News 的服务器实现,Hacker News 是一个专注于计算机科学和创业的热门社交新闻网站。该项目允许用户通过服务器端应用程序与 Hacker News 进行交互,启用获取新闻文章、提交故事和评论等功能,同时遵循 Hacker News API。
hn-server 的特点
- 公共访问:该存储库对公众开放,允许任何人查看、分叉或为项目做出贡献。
- MIT 许可证:该项目根据 MIT 许可证授权,允许用户使用、复制、修改和分发软件。
- 活跃社区:该存储库获得了 35 个星标和 8 次分叉,表明了日益增长的兴趣和社区参与。
- 易于集成:该服务器可以轻松与各种应用程序集成,为希望利用 Hacker News 数据的开发者提供无缝体验。
- 文档:提供全面的文档,帮助用户理解如何有效地设置和使用服务器。
如何使用 hn-server
-
克隆存储库:首先使用以下命令将 hn-server 存储库克隆到本地计算机:
git clone https://github.com/pskill9/hn-server.git
-
安装依赖:导航到项目目录并安装必要的依赖。这通常可以使用 npm 或 yarn 等包管理器完成,具体取决于项目的设置。
-
运行服务器:安装依赖后,可以使用文档中指定的命令(通常类似于
npm start
)来运行服务器。 -
与 API 交互:服务器运行后,可以与 Hacker News API 端点进行交互,以获取新闻文章、提交故事等。
-
贡献:如果您想为项目做出贡献,请随意分叉存储库,进行更改并提交拉取请求。
常见问题解答
hn-server 使用了哪些技术?
hn-server 通常使用 JavaScript 和 Node.js 构建,利用各种库和框架来促进服务器端操作。
我可以为 hn-server 项目做贡献吗?
可以!欢迎贡献。您可以分叉存储库,进行更改,并提交拉取请求以供审核。
有办法在本地运行 hn-server 吗?
当然可以!您可以克隆存储库并按照文档中的设置说明在本地计算机上运行它。
MIT 许可证的目的是什么?
MIT 许可证允许用户自由使用、修改和分发软件,促进开源协作和创新。
我该如何报告问题或错误?
您可以通过导航到 hn-server GitHub 存储库中的“问题”选项卡,提交新问题并详细说明您遇到的问题来报告问题。
详情
Hacker News MCP Server
A Model Context Protocol (MCP) server that provides tools for fetching stories from Hacker News. This server parses the HTML content from news.ycombinator.com and provides structured data for different types of stories (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
- Fetch different types of stories (top, new, ask, show, jobs)
- Get structured data including titles, URLs, points, authors, timestamps, and comment counts
- Configurable limit on number of stories returned
- Clean error handling and validation
Installation
- Clone the repository:
git clone https://github.com/pskill9/hn-server
cd hn-server
- Install dependencies:
npm install
- Build the server:
npm run build
- Add to your MCP settings configuration file (location depends on your system):
For VSCode Claude extension:
{
"mcpServers": {
"hacker-news": {
"command": "node",
"args": ["/path/to/hn-server/build/index.js"]
}
}
}
Usage
The server provides a tool called get_stories
that can be used to fetch stories from Hacker News.
Tool: get_stories
Parameters:
type
(string): Type of stories to fetch- Options: 'top', 'new', 'ask', 'show', 'jobs'
- Default: 'top'
limit
(number): Number of stories to return- Range: 1-30
- Default: 10
Example usage:
use_mcp_tool with:
server_name: "hacker-news"
tool_name: "get_stories"
arguments: {
"type": "top",
"limit": 5
}
Sample output:
[
{
"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
]
Integrating with Claude
To use this MCP server with Claude, you'll need to:
- Have the Claude desktop app or VSCode Claude extension installed
- Configure the MCP server in your settings
- Use Claude's natural language interface to interact with Hacker News
Configuration
For the Claude desktop app, add the server configuration to:
// ~/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"]
}
}
}
For the VSCode Claude extension, add to:
// VSCode Settings JSON
{
"mcpServers": {
"hacker-news": {
"command": "node",
"args": ["/path/to/hn-server/build/index.js"]
}
}
}
Example Interactions
Once configured, you can interact with Claude using natural language to fetch Hacker News stories. Examples:
- "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 will automatically use the appropriate parameters to fetch the stories you want.
Story Object Structure
Each story object contains:
title
(string): The story titleurl
(string, optional): URL of the story (may be internal HN URL for text posts)points
(number): Number of upvotesauthor
(string): Username of the postertime
(string): Timestamp of when the story was postedcommentCount
(number): Number of commentsrank
(number): Position in the list
Development
The server is built using:
- TypeScript
- Model Context Protocol SDK
- Axios for HTTP requests
- Cheerio for HTML parsing
To modify the server:
- Make changes to
src/index.ts
- Rebuild:
npm run build
Error Handling
The server includes robust error handling for:
- Invalid story types
- Network failures
- HTML parsing errors
- Invalid parameter values
Errors are returned with appropriate error codes and descriptive messages.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - feel free to use this in your own projects.
Server配置
{
"mcpServers": {
"hn-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--pskill9--hn-server--hn-server",
"node ./build/index.js"
],
"env": {}
}
}
}