hn-reddit-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/api.js +48 -0
- package/dist/index.js +4 -0
- package/dist/server.js +52 -0
- package/package.json +44 -0
- package/server.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# HN Reddit MCP
|
|
2
|
+
|
|
3
|
+
Read top stories from Hacker News and top posts from any subreddit. No API key is required.
|
|
4
|
+
|
|
5
|
+
This file is self contained. It reads public data only and never writes to the machine. All output is bounded and honest about what could not be fetched.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
* `get_hn_top` Top Hacker News stories with scores.
|
|
11
|
+
* `get_hn_item` One story or comment by id.
|
|
12
|
+
* `get_reddit_top` Top posts from a subreddit.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install
|
|
18
|
+
npm run build
|
|
19
|
+
node dist/index.js
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Uses the official Hacker News Firebase API and the public Reddit JSON endpoint.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const UA = "mrfentmen-hn-reddit-mcp/1.0 (https://github.com/mrfentmen)";
|
|
2
|
+
export class SocialError extends Error {
|
|
3
|
+
}
|
|
4
|
+
async function get(url, headers = {}) {
|
|
5
|
+
const res = await fetch(url, { headers: { "User-Agent": UA, ...headers }, signal: AbortSignal.timeout(25000) });
|
|
6
|
+
if (!res.ok)
|
|
7
|
+
throw new SocialError(`API error ${res.status}`);
|
|
8
|
+
return (await res.json());
|
|
9
|
+
}
|
|
10
|
+
export async function hnTop(args) {
|
|
11
|
+
const limit = Math.min(args.limit ?? 15, 30);
|
|
12
|
+
const ids = await get("https://hacker-news.firebaseio.com/v0/topstories.json");
|
|
13
|
+
const items = await Promise.all(ids.slice(0, limit).map((id) => get(`https://hacker-news.firebaseio.com/v0/item/${id}.json`)));
|
|
14
|
+
return items.map((it, i) => `${i + 1}. ${it.title ?? ""} (${it.score ?? 0} pts)\n ${it.url ?? `https://news.ycombinator.com/item?id=${it.id}`}`).join("\n\n");
|
|
15
|
+
}
|
|
16
|
+
export async function hnItem(args) {
|
|
17
|
+
const id = args.item_id ?? 0;
|
|
18
|
+
if (!id)
|
|
19
|
+
throw new SocialError("Provide an item id");
|
|
20
|
+
const it = await get(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
|
|
21
|
+
return `${it.title ?? "item"} (${it.score ?? 0} pts, ${it.descendants ?? 0} comments)\n${it.url ?? `https://news.ycombinator.com/item?id=${it.id}`}\n\n${(it.text ?? "").slice(0, 2000)}`;
|
|
22
|
+
}
|
|
23
|
+
function parseRss(xml) {
|
|
24
|
+
const out = [];
|
|
25
|
+
const entryRe = /<entry>([\s\S]*?)<\/entry>/g;
|
|
26
|
+
let m;
|
|
27
|
+
while ((m = entryRe.exec(xml)) !== null) {
|
|
28
|
+
const e = m[1];
|
|
29
|
+
const title = /<title>([\s\S]*?)<\/title>/.exec(e)?.[1] ?? "";
|
|
30
|
+
const link = /<link[^>]*href="([^"]+)"/.exec(e)?.[1] ?? "";
|
|
31
|
+
const author = /<name>([\s\S]*?)<\/name>/.exec(e)?.[1] ?? "";
|
|
32
|
+
if (title)
|
|
33
|
+
out.push({ title, link, author });
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
export async function redditTop(args) {
|
|
38
|
+
const sub = encodeURIComponent(args.subreddit ?? "programming");
|
|
39
|
+
const limit = Math.min(args.limit ?? 10, 25);
|
|
40
|
+
const res = await fetch(`https://www.reddit.com/r/${sub}/top/.rss?t=week`, {
|
|
41
|
+
headers: { "User-Agent": UA, Accept: "application/atom+xml" },
|
|
42
|
+
signal: AbortSignal.timeout(25000),
|
|
43
|
+
});
|
|
44
|
+
if (!res.ok)
|
|
45
|
+
throw new SocialError(`Reddit error ${res.status}`);
|
|
46
|
+
const posts = parseRss(await res.text()).slice(0, limit);
|
|
47
|
+
return posts.map((p, i) => `${i + 1}. ${p.title}\n u/${p.author || "unknown"} | r/${sub}\n ${p.link}`).join("\n\n") || "No posts found";
|
|
48
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
|
+
import { createServer } from "./server.js";
|
|
3
|
+
const main = async () => { const server = createServer(); await server.connect(new StdioServerTransport()); };
|
|
4
|
+
main().catch((error) => { console.error("Fatal error:", error); process.exit(1); });
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { hnItem } from "./api.js";
|
|
4
|
+
import { hnTop } from "./api.js";
|
|
5
|
+
import { redditTop } from "./api.js";
|
|
6
|
+
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
7
|
+
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
8
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
9
|
+
const error = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
10
|
+
export function createServer() {
|
|
11
|
+
const server = new McpServer({ name: "hn-reddit-mcp", version: "1.0.0" });
|
|
12
|
+
server.registerTool("get_hn_top", {
|
|
13
|
+
title: "Get hn top",
|
|
14
|
+
description: "Get top Hacker News stories.",
|
|
15
|
+
inputSchema: z.object({ limit: z.number().describe("Max stories.").optional() }),
|
|
16
|
+
annotations: READ_ONLY,
|
|
17
|
+
}, async (args) => {
|
|
18
|
+
try {
|
|
19
|
+
return text(await hnTop(args));
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return textError(error(e));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
server.registerTool("get_hn_item", {
|
|
26
|
+
title: "Get hn item",
|
|
27
|
+
description: "Get one Hacker News item by id.",
|
|
28
|
+
inputSchema: z.object({ item_id: z.number().describe("Hacker News item id.") }),
|
|
29
|
+
annotations: READ_ONLY,
|
|
30
|
+
}, async (args) => {
|
|
31
|
+
try {
|
|
32
|
+
return text(await hnItem(args));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
return textError(error(e));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
server.registerTool("get_reddit_top", {
|
|
39
|
+
title: "Get reddit top",
|
|
40
|
+
description: "Get top posts from a subreddit.",
|
|
41
|
+
inputSchema: z.object({ subreddit: z.string().describe("Subreddit name without the r slash."), limit: z.number().describe("Max posts.").optional() }),
|
|
42
|
+
annotations: READ_ONLY,
|
|
43
|
+
}, async (args) => {
|
|
44
|
+
try {
|
|
45
|
+
return text(await redditTop(args));
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
return textError(error(e));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return server;
|
|
52
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/mrfentmen/hn-reddit-mcp.git"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"hn-reddit-mcp": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"server.json",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"start": "node dist/index.js",
|
|
20
|
+
"dev": "npm run build && node dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
25
|
+
"zod": "^3.23.8"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"typescript": "^5.6.0"
|
|
30
|
+
},
|
|
31
|
+
"name": "hn-reddit-mcp",
|
|
32
|
+
"description": "Hacker News top stories and Reddit top posts by subreddit. No key required.",
|
|
33
|
+
"mcpName": "io.github.mrfentmen/hn-reddit-mcp",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"mcp",
|
|
36
|
+
"hackernews",
|
|
37
|
+
"reddit",
|
|
38
|
+
"news",
|
|
39
|
+
"trending"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.mrfentmen/hn-reddit-mcp",
|
|
4
|
+
"description": "Hacker News top stories and Reddit top posts by subreddit. No key required.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/mrfentmen/hn-reddit-mcp",
|
|
7
|
+
"source": "github"
|
|
8
|
+
},
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"packages": [
|
|
11
|
+
{
|
|
12
|
+
"registryType": "npm",
|
|
13
|
+
"identifier": "hn-reddit-mcp",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"transport": {
|
|
16
|
+
"type": "stdio"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|