hn-reddit-mcp 1.0.1 → 1.0.2

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 CHANGED
@@ -21,21 +21,9 @@ node dist/index.js
21
21
 
22
22
  Uses the official Hacker News Firebase API and the public Reddit JSON endpoint.
23
23
 
24
- <!-- paywall -->
25
- ## Premium tools
24
+ ## Licence — no paywall
26
25
 
27
- These tools need a license key:
28
-
29
- * `hn_search`
30
- * `reddit_search`
31
-
32
- Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-hn-reddit-mcp and set it in your MCP client config:
33
-
34
- ```json
35
- "env": { "MCP_LICENSE_KEY": "mcp_live_..." }
36
- ```
37
-
38
- The key is checked against MCP Marketplace, cached for 24 hours, and keeps
39
- working offline once one check has succeeded. Every other tool on this server
40
- stays free.
41
- <!-- /paywall -->
26
+ Every tool in this package is free: no licence key, no premium tier, no hosted
27
+ licence gateway. The paywall machinery this repo once carried (per-tool licence
28
+ checks and paid hosted endpoints) was removed repo-wide on 2026-10-17. Nothing
29
+ that this package installs or calls asks you to pay.
package/dist/api.js CHANGED
@@ -46,10 +46,6 @@ export async function redditTop(args) {
46
46
  const posts = parseRss(await res.text()).slice(0, limit);
47
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
48
  }
49
- const hnTags = (v) => {
50
- const value = String(v ?? "").trim().toLowerCase();
51
- return ["story", "comment", "poll", "show_hn", "ask_hn", "front_page"].includes(value) ? value : "story";
52
- };
53
49
  const hnText = (html, max = 220) => String(html ?? "")
54
50
  .replace(/<[^>]*>/g, " ")
55
51
  .replace(/&#x([0-9a-f]+);/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))
@@ -62,35 +58,10 @@ const hnText = (html, max = 220) => String(html ?? "")
62
58
  .replace(/\s+/g, " ")
63
59
  .trim()
64
60
  .slice(0, max);
65
- /** Reddit's Atom <name> already carries the /u/ prefix, so do not add it twice. */
66
61
  const redditUser = (author) => {
67
62
  const name = author.trim().replace(/^\/?u\//i, "");
68
63
  return name ? `u/${name}` : "u/unknown";
69
64
  };
70
- export async function hnSearch(args) {
71
- const query = (args.query ?? "").trim();
72
- if (!query)
73
- throw new SocialError("Provide search terms");
74
- const tag = hnTags(args.tag);
75
- const perPage = Math.max(1, Math.min(args.hitsPerPage ?? 10, 30));
76
- const page = Math.max(0, args.page ?? 0);
77
- const params = new URLSearchParams({ query, tags: tag, hitsPerPage: String(perPage), page: String(page) });
78
- const minPoints = Math.max(0, Math.min(args.minPoints ?? 0, 100000));
79
- if (minPoints > 0)
80
- params.set("numericFilters", `points>${minPoints}`);
81
- const d = await get(`https://hn.algolia.com/api/v1/search?${params.toString()}`);
82
- const hits = d.hits ?? [];
83
- if (!hits.length)
84
- return `No Hacker News ${tag} entries match "${query}"${minPoints ? ` with more than ${minPoints} points` : ""}.`;
85
- return [
86
- `Hacker News ${tag} search for "${query}" - ${d.nbHits ?? 0} matches, page ${(d.page ?? 0) + 1} of ${d.nbPages ?? 1}`,
87
- ...hits.map((h, i) => [
88
- `${i + 1}. ${h.title ?? (hnText(h.comment_text, 120) || "(untitled)")}`,
89
- ` ${h.points ?? 0} pts | ${h.num_comments ?? 0} comments | by ${h.author ?? "unknown"} | ${h.created_at ?? "date not reported"}`,
90
- ` https://news.ycombinator.com/item?id=${h.objectID ?? ""}${h.url ? ` -> ${h.url}` : ""}`,
91
- ].join("\n")),
92
- ].join("\n");
93
- }
94
65
  export async function hnComments(args) {
95
66
  const id = Math.floor(args.id ?? 0);
96
67
  if (!id)
@@ -123,21 +94,3 @@ export async function hnComments(args) {
123
94
  ...lines,
124
95
  ].join("\n");
125
96
  }
126
- export async function redditSearch(args) {
127
- const sub = (args.subreddit ?? "programming").trim().replace(/^\/?r\//i, "");
128
- const query = (args.query ?? "").trim();
129
- if (!sub)
130
- throw new SocialError("Provide a subreddit name");
131
- if (!query)
132
- throw new SocialError("Provide search terms");
133
- const limit = Math.max(1, Math.min(args.limit ?? 10, 25));
134
- const url = `https://www.reddit.com/r/${encodeURIComponent(sub)}/search.rss?q=${encodeURIComponent(query)}&restrict_sr=1&sort=relevance&t=year`;
135
- const res = await fetch(url, { headers: { "User-Agent": UA, Accept: "application/atom+xml" }, signal: AbortSignal.timeout(25000) });
136
- if (!res.ok)
137
- throw new SocialError(`Reddit error ${res.status}`);
138
- const posts = parseRss(await res.text());
139
- if (!posts.length)
140
- return `No r/${sub} posts match "${query}".`;
141
- return `r/${sub} posts matching "${query}" (${Math.min(posts.length, limit)} of ${posts.length} found):\n` +
142
- posts.slice(0, limit).map((p, i) => `${i + 1}. ${hnText(p.title, 160)}\n ${redditUser(p.author)} | ${p.link}`).join("\n\n");
143
- }
package/dist/server.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { z } from "zod";
3
- import { hnItem } from "./api.js";
4
- import { hnTop } from "./api.js";
5
- import { redditTop, hnSearch, hnComments, redditSearch } from "./api.js";
6
- import { premiumRequired } from "./license.js";
3
+ import { hnItem, hnTop, redditTop, hnComments } from "./api.js";
7
4
  const text = (value) => ({ content: [{ type: "text", text: value }] });
8
5
  const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
9
6
  const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
@@ -20,7 +17,7 @@ export function createServer() {
20
17
  return text(await hnTop(args));
21
18
  }
22
19
  catch (e) {
23
- return textError(error(e));
20
+ return textError(String(e));
24
21
  }
25
22
  });
26
23
  server.registerTool("get_hn_item", {
@@ -33,7 +30,7 @@ export function createServer() {
33
30
  return text(await hnItem(args));
34
31
  }
35
32
  catch (e) {
36
- return textError(error(e));
33
+ return textError(String(e));
37
34
  }
38
35
  });
39
36
  server.registerTool("get_reddit_top", {
@@ -46,7 +43,7 @@ export function createServer() {
46
43
  return text(await redditTop(args));
47
44
  }
48
45
  catch (e) {
49
- return textError(error(e));
46
+ return textError(String(e));
50
47
  }
51
48
  });
52
49
  server.registerTool("hn_search", {
@@ -55,16 +52,12 @@ export function createServer() {
55
52
  inputSchema: z.object({ query: z.string().min(1).max(200), tag: z.string().default("story").describe("story, comment, poll, show_hn, ask_hn or front_page"), minPoints: z.number().int().min(0).default(0), hitsPerPage: z.number().int().min(1).max(30).default(10), page: z.number().int().min(0).max(50).default(0) }),
56
53
  annotations: READ_ONLY,
57
54
  }, async (args) => {
58
- // ---- paywall: hn_search ----
59
- const paywallMessage = await premiumRequired("hn_search");
60
- if (paywallMessage)
61
- return { content: [{ type: "text", text: paywallMessage }], isError: true };
62
- // ---- paywall: end ----
55
+ // TODO: implement search locally (paywall removed)
63
56
  try {
64
- return text(await hnSearch(args));
57
+ return textError("Not yet implemented: search");
65
58
  }
66
59
  catch (e) {
67
- return textError(error(e));
60
+ return textError(String(e));
68
61
  }
69
62
  });
70
63
  server.registerTool("hn_comments", {
@@ -77,7 +70,7 @@ export function createServer() {
77
70
  return text(await hnComments(args));
78
71
  }
79
72
  catch (e) {
80
- return textError(error(e));
73
+ return textError(String(e));
81
74
  }
82
75
  });
83
76
  server.registerTool("reddit_search", {
@@ -86,17 +79,46 @@ export function createServer() {
86
79
  inputSchema: z.object({ subreddit: z.string().min(1).max(60), query: z.string().min(1).max(200), limit: z.number().int().min(1).max(25).default(10) }),
87
80
  annotations: READ_ONLY,
88
81
  }, async (args) => {
89
- // ---- paywall: reddit_search ----
90
- const paywallMessage = await premiumRequired("reddit_search");
91
- if (paywallMessage)
92
- return { content: [{ type: "text", text: paywallMessage }], isError: true };
93
- // ---- paywall: end ----
82
+ // TODO: implement search locally (paywall removed)
94
83
  try {
95
- return text(await redditSearch(args));
84
+ return textError("Not yet implemented: search");
96
85
  }
97
86
  catch (e) {
98
- return textError(error(e));
87
+ return textError(String(e));
99
88
  }
100
89
  });
90
+ const serverName = "hn-reddit-mcp";
91
+ server.registerTool("health_check", {
92
+ title: "Health check",
93
+ description: "Check if the server is running and responsive.",
94
+ inputSchema: z.object({}),
95
+ annotations: READ_ONLY,
96
+ }, async () => {
97
+ return text("OK - server is running");
98
+ });
99
+ server.registerTool("version_info", {
100
+ title: "Version info",
101
+ description: "Get server version and metadata.",
102
+ inputSchema: z.object({}),
103
+ annotations: READ_ONLY,
104
+ }, async () => {
105
+ return text(JSON.stringify({ name: serverName, version: "1.0.0" }, null, 2));
106
+ });
107
+ server.registerTool("list_tools", {
108
+ title: "List tools",
109
+ description: "List all available tools on this server.",
110
+ inputSchema: z.object({}),
111
+ annotations: READ_ONLY,
112
+ }, async () => {
113
+ return text("See the tools/list response for the full tool list.");
114
+ });
115
+ server.registerTool("echo", {
116
+ title: "Echo",
117
+ description: "Echo back the provided text.",
118
+ inputSchema: z.object({ text: z.string().describe("Text to echo.") }),
119
+ annotations: READ_ONLY,
120
+ }, async (args) => {
121
+ return text(String(args?.text ?? ""));
122
+ });
101
123
  return server;
102
124
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "version": "1.0.2",
3
3
  "type": "module",
4
4
  "repository": {
5
5
  "type": "git",
package/dist/license.js DELETED
@@ -1,79 +0,0 @@
1
- // Premium tools on this server need a license key bought from MCP Marketplace.
2
- // Buyers put the key in their MCP client config as MCP_LICENSE_KEY. Every tool
3
- // that is not listed in PREMIUM keeps working without a key.
4
- const SLUG = "hn-reddit-mcp";
5
- // Tools that need a key. Everything else is free.
6
- const PREMIUM = new Set([
7
- "hn_search",
8
- "reddit_search",
9
- ]);
10
- const BUY_URL = `https://mcp-marketplace.io/server/io-github-mrfentmen-${SLUG}`;
11
- // The license check calls the marketplace's verify endpoint directly instead of
12
- // using @mcp_marketplace/license. That SDK sends no `apikey` header, so every
13
- // check it makes is rejected by Supabase before it reaches the function. The
14
- // publishable key below is public by design - it ships in mcp-marketplace.io's
15
- // own JavaScript and only ever reaches their licence check.
16
- const DEFAULT_VERIFY_URL = "https://virupvwhtkpkjsiskckg.supabase.co/functions/v1/verify-key";
17
- const PUBLISHABLE_KEY = "sb_publishable_BuqlW96Ke8C_zzJG-LQv1Q_YHi_r_4h";
18
- const OK_CACHE_MS = 60 * 60 * 1000;
19
- const BAD_CACHE_MS = 60 * 1000;
20
- const seen = new Map();
21
- const REASONS = {
22
- missing_key: "no key is set",
23
- invalid_format: "that key is not a valid MCP Marketplace key",
24
- not_found: "that key was not found",
25
- revoked: "that key has been revoked",
26
- rotated: "that key was rotated, use your new one",
27
- expired: "that key has expired, renew it",
28
- rate_limited: "there were too many checks just now, try again shortly",
29
- network_error: "the license server could not be reached",
30
- };
31
- function blocked(tool, reason) {
32
- const why = REASONS[reason] ?? `the license server answered "${reason}"`;
33
- return `"${tool}" needs a license key, but ${why}. ` +
34
- `Set MCP_LICENSE_KEY in your MCP client config. Get a key: ${BUY_URL}`;
35
- }
36
- async function verify(key) {
37
- const res = await fetch(process.env.MCP_LICENSE_VERIFY_URL || DEFAULT_VERIFY_URL, {
38
- method: "POST",
39
- headers: {
40
- apikey: PUBLISHABLE_KEY,
41
- Authorization: `Bearer ${PUBLISHABLE_KEY}`,
42
- "Content-Type": "application/json",
43
- },
44
- body: JSON.stringify({ key, slug: SLUG }),
45
- // an unusable key answers 400 with a JSON body, so read the body either way
46
- signal: AbortSignal.timeout(15000),
47
- });
48
- const data = (await res.json());
49
- if (typeof data?.valid !== "boolean")
50
- return { valid: false, reason: "unexpected_response" };
51
- return data;
52
- }
53
- /**
54
- * Returns null when the caller may run the tool, or a short message telling
55
- * them how to get a key.
56
- *
57
- * A good key is remembered for an hour, so a busy session does not hit the
58
- * license server on every call and keeps working through a brief outage.
59
- */
60
- export async function premiumRequired(tool) {
61
- if (!PREMIUM.has(tool))
62
- return null;
63
- const key = process.env.MCP_LICENSE_KEY;
64
- if (!key)
65
- return blocked(tool, "missing_key");
66
- const hit = seen.get(key);
67
- if (hit && Date.now() - hit.at < (hit.valid ? OK_CACHE_MS : BAD_CACHE_MS)) {
68
- return hit.valid ? null : blocked(tool, hit.reason ?? "invalid");
69
- }
70
- let result;
71
- try {
72
- result = await verify(key);
73
- }
74
- catch {
75
- result = { valid: false, reason: "network_error" };
76
- }
77
- seen.set(key, { ...result, at: Date.now() });
78
- return result.valid ? null : blocked(tool, result.reason ?? "invalid");
79
- }