Hacker News MCP Server

Hacker News MCP Server

Enables AI assistants to fetch top, new, best, Ask HN, Show HN, and job stories, as well as specific posts, comments, and user information from Hacker News through the Model Context Protocol.

Category
访问服务器

README

Hacker News MCP Server for Netlify

This is a Model Context Protocol (MCP) server that integrates with the official Hacker News API, designed to be deployed to Netlify. The MCP server exposes tools and resources that enable AI assistants to access and interact with Hacker News content through the Model Context Protocol.

This project also includes a FastAPI client that provides a REST API for interacting with the MCP server, making it easy to test and integrate with other applications.

Features

MCP Server

  • Serverless MCP server implementation integrating with the Hacker News API
  • Deployed on Netlify
  • Includes tools to fetch top, new, best, Ask HN, Show HN, and job stories
  • Provides tools to get specific posts, comments, and user information
  • Includes resources with documentation on using the Hacker News API

MCP Client

  • FastAPI REST API for interacting with the MCP server
  • Interactive API documentation (Swagger UI)
  • Easy testing and integration
  • Python script for automated testing

Getting Started

Local Development

  1. Clone this repository
  2. Install dependencies:
    npm install
    
  3. Start the development server:
    npm run dev
    

The MCP server will be available locally at http://localhost:8888/mcp

Testing Your MCP Server

You can test your MCP server using either the MCP Inspector or directly with curl commands.

Using MCP Inspector

While the development server is running, you can test your MCP server using the MCP inspector:

npx @modelcontextprotocol/inspector npx mcp-remote@next http://localhost:8888/mcp

After deployment, you can test your deployed version:

npx @modelcontextprotocol/inspector npx mcp-remote@next https://your-site-name.netlify.app/mcp

Then open http://localhost:6274/ in your browser to interact with the MCP inspector.

Using curl

You can also test the MCP server directly using curl commands:

  1. Initialize the MCP server:

    curl -X POST http://localhost:8888/mcp \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"mcp/init","params":{},"id":"1"}'
    
  2. List available tools:

    curl -X POST http://localhost:8888/mcp \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"mcp/listTools","params":{},"id":"2"}'
    
  3. Call a tool to get top Hacker News stories:

    curl -X POST http://localhost:8888/mcp \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"mcp/callTool","params":{"name":"hn-get-top-stories","args":{"limit":5}},"id":"3"}'
    

    Call a tool to get a specific Hacker News item:

    curl -X POST http://localhost:8888/mcp \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"mcp/callTool","params":{"name":"hn-get-item","args":{"id":8863}},"id":"3"}'
    
  4. List available resources:

    curl -X POST http://localhost:8888/mcp \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"mcp/listResources","params":{},"id":"4"}'
    
  5. Read a resource about the Hacker News API:

    curl -X POST http://localhost:8888/mcp \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"mcp/readResource","params":{"uri":"docs://hacker-news-api-overview"},"id":"5"}'
    

Deployment

Deploying to Netlify

  1. Push this repository to GitHub
  2. Connect your repository to Netlify
  3. Configure the build settings:
    • Build command: leave empty (no build required)
    • Publish directory: public

After deployment, your MCP server will be available at https://your-site-name.netlify.app/mcp

Using with Claude Desktop

To use this Hacker News MCP server with Claude Desktop:

  1. Go to Claude Desktop settings
  2. Enable the MCP Server configuration
  3. Edit the configuration file:
    {
      "mcpServers": {
        "hacker-news": {
          "command": "npx",
          "args": [
            "mcp-remote@next",
            "https://your-site-name.netlify.app/mcp"
          ]
        }
      }
    }
    
  4. Restart Claude Desktop

Once configured, you can ask Claude to interact with Hacker News content, for example:

  • "Show me the top 5 stories from Hacker News right now"
  • "Get me the details of a specific Hacker News post"
  • "Search for Ask HN posts about programming"
  • "Find information about a specific Hacker News user"

Using the MCP Client

The MCP client provides a REST API interface for interacting with the MCP server. It's built with FastAPI and offers a clean, modern API with automatic documentation.

Starting the Client

cd mcp-client
pip install -r requirements.txt
uvicorn main:app --reload

This will start the FastAPI server at http://localhost:8001. You can access the API documentation at http://localhost:8001/docs.

Managing the MCP Server and FastAPI Client

The template includes several scripts to manage both the MCP server and FastAPI client:

cd mcp-client
./start.sh    # Start both services in the background
./stop.sh     # Stop both services gracefully
./check_status.sh  # Check if services are running and view logs
./test_client.py   # Test the FastAPI client endpoints

These scripts ensure processes keep running in the background even after you close your terminal, properly manage log files, and provide clear status information.

Testing the Client

You can test the client using the provided test script:

cd mcp-client
./test_client.py

This will run a series of tests against the API endpoints and display the results.

API Endpoints

  • GET /server - Get server information
  • GET /tools - List available tools
  • POST /tools/call - Call a tool
  • GET /resources - List available resources
  • POST /resources/read - Read a resource

For more details, refer to the MCP Client README.

Hacker News API Tools

This MCP server provides the following tools for interacting with the Hacker News API:

  1. hn-get-top-stories: Fetches the current top stories from Hacker News

    • Parameters: limit (optional, number of stories to return, default: 10, max: 500)
  2. hn-get-new-stories: Fetches the newest stories from Hacker News

    • Parameters: limit (optional, number of stories to return, default: 10, max: 500)
  3. hn-get-best-stories: Fetches the best stories from Hacker News

    • Parameters: limit (optional, number of stories to return, default: 10, max: 500)
  4. hn-get-ask-stories: Fetches Ask HN stories from Hacker News

    • Parameters: limit (optional, number of stories to return, default: 10, max: 200)
  5. hn-get-show-stories: Fetches Show HN stories from Hacker News

    • Parameters: limit (optional, number of stories to return, default: 10, max: 200)
  6. hn-get-job-stories: Fetches job stories from Hacker News

    • Parameters: limit (optional, number of stories to return, default: 10, max: 200)
  7. hn-get-item: Fetches a specific item (story, comment, job, poll, etc.) from Hacker News by ID

    • Parameters: id (required, the ID of the item to fetch)
  8. hn-get-user: Fetches information about a specific user from Hacker News by username

    • Parameters: id (required, the username of the user to fetch)

Documentation Resources

The MCP server provides the following documentation resources:

  1. docs://hacker-news-api-overview: Overview of the Hacker News API and the tools available in this MCP server
  2. docs://hacker-news-item-types: Information about the different types of items in the Hacker News API and their properties
  3. docs://hacker-news-usage-examples: Examples of how to use the Hacker News MCP tools with sample requests and responses

Extending

Extending the MCP Server

You can extend this MCP server by adding more tools and resources to the getServer function in netlify/functions/mcp-server.js. Follow the existing examples and refer to the Model Context Protocol documentation for more information.

Extending the MCP Client

To add new endpoints to the MCP client, edit the main.py file in the mcp-client directory. The client is built with FastAPI, which makes it easy to add new routes and functionality.

Learn More

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选