Hacker News 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.
伺服器配置
{
"mcpServers": {
"hn-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/metorial/mcp-container--pskill9--hn-server--hn-server",
"node ./build/index.js"
],
"env": {}
}
}
}