Metadata-Version: 2.4
Name: hacker-news-mcp-py
Version: 0.2.0
Summary: MCP server for searching Hacker News stories via Algolia
Project-URL: Homepage, https://github.com/m-higuchi/hacker-news-mcp
Project-URL: Repository, https://github.com/m-higuchi/hacker-news-mcp
Project-URL: Issues, https://github.com/m-higuchi/hacker-news-mcp/issues
Author: hacker-news-mcp contributors
License: MIT License
        
        Copyright (c) 2026 hacker-news-mcp contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: algolia,hacker-news,mcp,model-context-protocol
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Requires-Dist: mcp>=1.0
Requires-Dist: pydantic>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Description-Content-Type: text/markdown

# Hacker News MCP

MCP server for searching Hacker News stories through the Algolia Hacker News Search API.

The server is read-only and is designed to run through `uvx`.

The PyPI distribution name is `mcp-hacker-news` (the name `hacker-news-mcp` is rejected as too similar to existing projects).

## Install and Run

Install from PyPI with pip:

```bash
pip install mcp-hacker-news
hacker-news-mcp
```

(`mcp-hacker-news` is also installed as a command.)

Or run with uv:

```bash
uvx mcp-hacker-news
```

During local development:

```bash
uv run hacker-news-mcp
```

## MCP Configuration

```json
{
  "mcpServers": {
    "hacker-news": {
      "command": "uvx",
      "args": ["mcp-hacker-news"]
    }
  }
}
```

## Running from a Local Source Copy

If you want to run a local copy of this repository instead of resolving the package
through `uvx`, clone the source code and install dependencies:

```bash
git clone https://github.com/m-higuchi/hacker-news-mcp
cd hacker-news-mcp
uv sync
```

Then use the following MCP configuration:

```json
{
  "mcpServers": {
    "hacker-news": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/hacker-news-mcp",
        "run",
        "hacker-news-mcp"
      ]
    }
  }
}
```

Replace `/path/to/hacker-news-mcp` with the **absolute path** to the directory where you cloned this repository (the folder that contains `pyproject.toml`).

## Backend API

This server uses Algolia's Hacker News Search API as the primary backend:

```text
https://hn.algolia.com/api/v1
```

Story searches always include `tags=story`. Date range searches call `/search_by_date` and convert ISO dates into Algolia `created_at_i` numeric filters.

## Tools

### `search_stories_by_date`

Search stories within a date range.

Input:

```json
{
  "query": "AI",
  "start_date": "2026-04-01",
  "end_date": "2026-04-27",
  "limit": 20,
  "page": 0
}
```

Behavior:

- `start_date` and `end_date` accept `YYYY-MM-DD` or ISO datetime strings.
- Date-only `start_date` is interpreted as `00:00:00Z`.
- Date-only `end_date` is interpreted as `23:59:59Z`.
- `limit` defaults to 20 and is capped at 100.
- `page` is zero-based.

### `search_stories`

Search stories by relevance or date.

Input:

```json
{
  "query": "AI",
  "sort": "relevance",
  "limit": 20,
  "page": 0
}
```

`sort` can be `relevance` or `date`.

### `get_story`

Fetch a story by Hacker News item ID.

Input:

```json
{
  "story_id": 123456
}
```

### `get_user`

Fetch a Hacker News user profile by username.

Input:

```json
{
  "username": "pg"
}
```

## Example Prompts

Once the MCP server is connected, you can ask the AI questions like the following.

**Searching by keyword:**

- "Search Hacker News for recent stories about Rust."
- "Find the most relevant Hacker News stories about LLM fine-tuning."
- "Show me the latest 5 Hacker News stories mentioning WebAssembly."

**Searching by date range:**

- "What were the top Hacker News stories about OpenAI in April 2026?"
- "Find Hacker News stories about Kubernetes from March 1 to March 31, 2026."

**Fetching a specific story:**

- "Get the Hacker News story with ID 12345678."

**Looking up a user:**

- "Show me the Hacker News profile of pg."
- "What is the account info for the user tptacek on Hacker News?"

## Development

### Dev Container

Open this repository in a Dev Container to get Python 3.12 and `uv` preinstalled.

The container runs this setup command after creation:

```bash
uv sync --extra dev
```

Tests can be run with:

```bash
uv run pytest
```

### Local

```bash
uv sync --extra dev
uv run pytest
```
