reddit-mcp-server 2.0.1 โ 2.0.3
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/CHANGELOG.md +16 -0
- package/README.md +7 -0
- package/dist/bin.js +2 -2
- package/dist/index.js +67 -59
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.0.3] - 2026-11-26
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Every dependency is updated to its latest release: functype 2.2.2, somamcp 2.11.1, ts-builds 5.0.0, `@types/node` 26 and the latest patches of dotenv, fast-xml-parser, msw, rimraf and tsdown
|
|
10
|
+
- From somamcp, over HTTP the server advertises only the `logging` and `tools` capabilities. `prompts/list`, `resources/list` and `resources/templates/list`, which returned empty lists, now answer "method not found". The server registers no prompts or resources, and stdio is unchanged
|
|
11
|
+
- From somamcp, an invalid-argument error names the argument, as in `limit: Too big: expected number to be <=100`
|
|
12
|
+
- The random HTTP bearer token is built only when `OAUTH_TOKEN` is unset, instead of on every start
|
|
13
|
+
|
|
14
|
+
## [2.0.2] - 2026-11-14
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- In `auto` mode, a failed startup credential check (Reddit rejects the client id or secret, or can't be reached) no longer stops the server. It logs a warning and starts, so registries that start it with placeholder credentials, such as Glama, can list its tools. Each tool call that needs OAuth retries authentication and reports the error. `REDDIT_AUTH_MODE=authenticated` still exits at startup
|
|
19
|
+
- Startup logs say "User credentials set for" instead of "User authenticated as", since the username and password are not checked at startup, and the keyless message notes that Reddit said it would end RSS feeds on 2026-11-13
|
|
20
|
+
|
|
5
21
|
## [2.0.1] - 2026-10-31
|
|
6
22
|
|
|
7
23
|
### Fixed
|
package/README.md
CHANGED
|
@@ -264,6 +264,8 @@ Reddit closed self-service OAuth app creation in November 2025, and as of 2026-1
|
|
|
264
264
|
| `auto` (no creds) | Shared, free | None | Most read tools ([Keyless Mode](#keyless-mode)) | New users |
|
|
265
265
|
| `anonymous` | Shared, free | None | Same as `auto` without credentials | Legacy alias |
|
|
266
266
|
|
|
267
|
+
If Reddit rejects your credentials at startup, `auto` logs a warning and starts anyway, and each tool call reports the error. `authenticated` exits instead.
|
|
268
|
+
|
|
267
269
|
### Keyless Mode
|
|
268
270
|
|
|
269
271
|
Without OAuth credentials, reads come from two free sources:
|
|
@@ -324,6 +326,7 @@ pnpm build # Build TypeScript
|
|
|
324
326
|
pnpm dev # Rebuild on every change
|
|
325
327
|
pnpm inspect # Build and open the MCP inspector
|
|
326
328
|
pnpm validate # Format, lint, typecheck, test and build
|
|
329
|
+
pnpm run ci # validate's checks without fixing, as CI runs them (type `run`: `pnpm ci` is a clean install)
|
|
327
330
|
pnpm test # Run tests
|
|
328
331
|
pnpm lint # Lint code
|
|
329
332
|
pnpm format # Format code
|
|
@@ -429,3 +432,7 @@ This server is designed with [Reddit's Responsible Builder Policy](https://suppo
|
|
|
429
432
|
|
|
430
433
|
- Fork of [reddit-mcp-server](https://github.com/alexandros-lekkas/reddit-mcp-server) by Alexandros Lekkas
|
|
431
434
|
- Inspired by [Python Reddit MCP Server](https://github.com/Arindam200/reddit-mcp) by Arindam200
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
Maintained by [Jordan Burke](https://github.com/jordanburke) ยท **Affiliated with <a href="https://sapientsai.com/"><img src="https://sapientsai.com/images/logo.svg" alt="SapientsAI logo" width="18" align="absmiddle"></a> <a href="https://sapientsai.com/">SapientsAI</a>**
|
package/dist/bin.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
if ((process.env.TRANSPORT_TYPE ?? "").trim() === "") process.env.TRANSPORT_TYPE = "stdio";
|
|
4
4
|
const args = process.argv.slice(2);
|
|
5
5
|
if (args.includes("--version") || args.includes("-v")) {
|
|
6
|
-
console.log("2.0.
|
|
6
|
+
console.log("2.0.3");
|
|
7
7
|
process.exit(0);
|
|
8
8
|
}
|
|
9
9
|
if (args.includes("--help") || args.includes("-h")) {
|
|
10
10
|
console.log(`
|
|
11
|
-
Reddit MCP Server v2.0.
|
|
11
|
+
Reddit MCP Server v2.0.3
|
|
12
12
|
|
|
13
13
|
Usage: reddit-mcp-server [options]
|
|
14
14
|
|
package/dist/index.js
CHANGED
|
@@ -348,10 +348,10 @@ var ArcticShiftClient = class {
|
|
|
348
348
|
...cached,
|
|
349
349
|
resetSeconds: Option.none()
|
|
350
350
|
} : await this.fetchBody(url);
|
|
351
|
-
const json = Try(() => JSON.parse(body)).
|
|
351
|
+
const json = Try(() => JSON.parse(body)).getOrElse(() => ({
|
|
352
352
|
data: null,
|
|
353
353
|
error: `HTTP ${status}`
|
|
354
|
-
});
|
|
354
|
+
}));
|
|
355
355
|
if (status < 200 || status >= 300 || json.error !== void 0 || json.data === null) {
|
|
356
356
|
const detail = (json.error ?? `HTTP ${status}`).slice(0, ERROR_TEXT_MAX_LENGTH);
|
|
357
357
|
if (status === 429 || /timeout|timed out/i.test(detail)) {
|
|
@@ -595,8 +595,8 @@ function decodeHtmlEntities(text) {
|
|
|
595
595
|
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'").replace(/ /g, " ").replace(/&/g, "&");
|
|
596
596
|
}
|
|
597
597
|
function extractLinkUrl(contentHtml) {
|
|
598
|
-
|
|
599
|
-
return (match === null || match === void 0 ? void 0 : match[1])
|
|
598
|
+
var _contentHtml$match;
|
|
599
|
+
return Option((_contentHtml$match = contentHtml.match(/href="([^"]+)">\[link\]/)) === null || _contentHtml$match === void 0 ? void 0 : _contentHtml$match[1]).filter((href) => href !== "").map(decodeHtmlEntities);
|
|
600
600
|
}
|
|
601
601
|
function extractSelfText(contentHtml) {
|
|
602
602
|
const match = contentHtml.match(/<!-- SC_OFF -->(.*?)<!-- SC_ON -->/s);
|
|
@@ -607,8 +607,8 @@ function atomEntryToRedditPost(entry) {
|
|
|
607
607
|
var _entry$link, _entry$author, _entry$category;
|
|
608
608
|
const permalink = ((_entry$link = entry.link) === null || _entry$link === void 0 ? void 0 : _entry$link["@_href"]) ?? "";
|
|
609
609
|
const contentHtml = contentText(entry.content);
|
|
610
|
-
const externalUrl = extractLinkUrl(contentHtml);
|
|
611
|
-
const isSelf =
|
|
610
|
+
const externalUrl = extractLinkUrl(contentHtml).filter((href) => !href.includes("/comments/"));
|
|
611
|
+
const isSelf = externalUrl.isNone();
|
|
612
612
|
const author = (((_entry$author = entry.author) === null || _entry$author === void 0 ? void 0 : _entry$author.name) ?? "").replace(/^\/u\//, "");
|
|
613
613
|
const subreddit = ((_entry$category = entry.category) === null || _entry$category === void 0 ? void 0 : _entry$category["@_term"]) ?? "";
|
|
614
614
|
return {
|
|
@@ -617,7 +617,7 @@ function atomEntryToRedditPost(entry) {
|
|
|
617
617
|
author,
|
|
618
618
|
subreddit,
|
|
619
619
|
selftext: extractSelfText(contentHtml),
|
|
620
|
-
url:
|
|
620
|
+
url: externalUrl.getOrElse(() => permalink),
|
|
621
621
|
score: 0,
|
|
622
622
|
upvoteRatio: 0,
|
|
623
623
|
numComments: 0,
|
|
@@ -635,6 +635,10 @@ var RssClient = class {
|
|
|
635
635
|
constructor(userAgent) {
|
|
636
636
|
this.userAgent = userAgent;
|
|
637
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* @interop Same boundary as reddit-client.ts: the `throw`s are control flow inside this method's
|
|
640
|
+
* `Try.async`, which `classifyRedditError` turns into the returned `Either`; none escapes the method.
|
|
641
|
+
*/
|
|
638
642
|
async fetchSubredditPosts(subreddit, sort, timeFilter, limit, after) {
|
|
639
643
|
return (await Try.async(async () => {
|
|
640
644
|
const sub = normalizeSubreddit(subreddit);
|
|
@@ -752,7 +756,7 @@ var RedditClient = class {
|
|
|
752
756
|
if (cached !== void 0) return new Response(cached.body, { status: cached.status });
|
|
753
757
|
}
|
|
754
758
|
const requiresAuth = this.authMode === "authenticated" || this.authMode === "auto" && this.hasCredentials;
|
|
755
|
-
if (requiresAuth && (Date.now() >= this.tokenExpiry || !this.authenticated)) (await this.authenticate()).orThrow();
|
|
759
|
+
if (requiresAuth && (Date.now() >= this.tokenExpiry || !this.authenticated)) (await this.authenticate()).orThrow((e) => e);
|
|
756
760
|
const headers = {
|
|
757
761
|
"User-Agent": this.userAgent,
|
|
758
762
|
...options.headers
|
|
@@ -842,15 +846,14 @@ var RedditClient = class {
|
|
|
842
846
|
if (subreddit !== void 0 && duplicate.subreddit !== "" && subreddit !== duplicate.subreddit) throw new ValidationError("Cross-subreddit duplicate detected. Reddit's Responsible Builder Policy prohibits posting identical or substantially similar content across multiple subreddits. Please create unique content for each subreddit.");
|
|
843
847
|
throw new ValidationError("Duplicate content detected. Reddit's spam filter may ban your account for posting identical content. Please modify your content and try again.");
|
|
844
848
|
}
|
|
845
|
-
this.recentContentRecords.
|
|
849
|
+
this.recentContentRecords = [...this.recentContentRecords, {
|
|
846
850
|
hash,
|
|
847
851
|
subreddit: subreddit ?? "",
|
|
848
852
|
timestamp: Date.now()
|
|
849
|
-
});
|
|
850
|
-
this.recentContentRecords = this.recentContentRecords.slice(-this.safeMode.maxRecentHashes);
|
|
853
|
+
}].slice(-this.safeMode.maxRecentHashes);
|
|
851
854
|
}
|
|
852
855
|
async reauthorize() {
|
|
853
|
-
(await this.authenticate()).orThrow();
|
|
856
|
+
(await this.authenticate()).orThrow((e) => e);
|
|
854
857
|
return `Bearer ${this.accessToken}`;
|
|
855
858
|
}
|
|
856
859
|
async fetchWithRetry(url, options, headers, path, attempt) {
|
|
@@ -897,7 +900,7 @@ var RedditClient = class {
|
|
|
897
900
|
if (rssProblem.isEmpty || !archivable || !cursorFitsArchive) return rss;
|
|
898
901
|
return (await this.arctic.listSubredditPosts(subreddit, limit, after)).map((page) => ({
|
|
899
902
|
...page,
|
|
900
|
-
notice: `The RSS feed ${rssProblem.
|
|
903
|
+
notice: `The RSS feed ${rssProblem.getOrElse(() => "failed")}, so these are the newest posts from the Arctic Shift archive, not "${sort}" ranking.`
|
|
901
904
|
}));
|
|
902
905
|
}
|
|
903
906
|
async keylessSearch(query, type, options) {
|
|
@@ -909,7 +912,7 @@ var RedditClient = class {
|
|
|
909
912
|
if (this.keyless) return this.arctic.getUser(username);
|
|
910
913
|
const context = `Failed to get user info for ${username}`;
|
|
911
914
|
return (await Try.async(async () => {
|
|
912
|
-
const response = (await this.makeRequest(`/user/${normalizeUsername(username)}/about.json`)).orThrow();
|
|
915
|
+
const response = (await this.makeRequest(`/user/${normalizeUsername(username)}/about.json`)).orThrow((e) => e);
|
|
913
916
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
914
917
|
const { data } = await response.json();
|
|
915
918
|
return {
|
|
@@ -928,7 +931,7 @@ var RedditClient = class {
|
|
|
928
931
|
}
|
|
929
932
|
async getUserContent(path, context) {
|
|
930
933
|
return (await Try.async(async () => {
|
|
931
|
-
const response = (await this.makeRequest(path)).orThrow();
|
|
934
|
+
const response = (await this.makeRequest(path)).orThrow((e) => e);
|
|
932
935
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
933
936
|
const json = await response.json();
|
|
934
937
|
return {
|
|
@@ -959,7 +962,7 @@ var RedditClient = class {
|
|
|
959
962
|
if (this.username === void 0) return Left(new NotAuthenticatedError("Fetching your account requires REDDIT_USERNAME"));
|
|
960
963
|
const context = "Failed to get authenticated user info";
|
|
961
964
|
return (await Try.async(async () => {
|
|
962
|
-
const response = (await this.makeRequest("/api/v1/me")).orThrow();
|
|
965
|
+
const response = (await this.makeRequest("/api/v1/me")).orThrow((e) => e);
|
|
963
966
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
964
967
|
const data = await response.json();
|
|
965
968
|
return {
|
|
@@ -980,7 +983,7 @@ var RedditClient = class {
|
|
|
980
983
|
if (this.keyless) return this.arctic.getSubredditInfo(subredditName);
|
|
981
984
|
const context = `Failed to get subreddit info for ${subredditName}`;
|
|
982
985
|
return (await Try.async(async () => {
|
|
983
|
-
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subredditName)}/about.json`)).orThrow();
|
|
986
|
+
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subredditName)}/about.json`)).orThrow((e) => e);
|
|
984
987
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
985
988
|
return parseSubredditData((await response.json()).data);
|
|
986
989
|
})).toEither((error) => classifyRedditError(error, context));
|
|
@@ -989,7 +992,7 @@ var RedditClient = class {
|
|
|
989
992
|
if (this.keyless) return this.arctic.getSubredditRules(subreddit);
|
|
990
993
|
const context = `Failed to get rules for r/${subreddit}`;
|
|
991
994
|
return (await Try.async(async () => {
|
|
992
|
-
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subreddit)}/about/rules.json`)).orThrow();
|
|
995
|
+
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subreddit)}/about/rules.json`)).orThrow((e) => e);
|
|
993
996
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
994
997
|
return (await response.json()).rules.map(parseRuleData);
|
|
995
998
|
})).toEither((error) => classifyRedditError(error, context));
|
|
@@ -998,7 +1001,7 @@ var RedditClient = class {
|
|
|
998
1001
|
if (this.keyless) return this.requiresOAuthError("get_post_flairs");
|
|
999
1002
|
const context = `Failed to get post flairs for r/${subreddit}`;
|
|
1000
1003
|
return (await Try.async(async () => {
|
|
1001
|
-
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subreddit)}/api/link_flair_v2.json`)).orThrow();
|
|
1004
|
+
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subreddit)}/api/link_flair_v2.json`)).orThrow((e) => e);
|
|
1002
1005
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
1003
1006
|
return (await response.json()).map((flair) => ({
|
|
1004
1007
|
id: flair.id,
|
|
@@ -1019,7 +1022,7 @@ var RedditClient = class {
|
|
|
1019
1022
|
return (await Try.async(async () => {
|
|
1020
1023
|
const name = normalizeSubreddit(subreddit);
|
|
1021
1024
|
const endpoint = name !== "" ? `/r/${name}/top.json` : "/top.json";
|
|
1022
|
-
const response = (await this.makeRequest(`${endpoint}?${params}`)).orThrow();
|
|
1025
|
+
const response = (await this.makeRequest(`${endpoint}?${params}`)).orThrow((e) => e);
|
|
1023
1026
|
if (!response.ok) throw new HttpError(response.status, `Failed to get top posts: HTTP ${response.status}`);
|
|
1024
1027
|
const json = await response.json();
|
|
1025
1028
|
return {
|
|
@@ -1046,7 +1049,7 @@ var RedditClient = class {
|
|
|
1046
1049
|
return (await Try.async(async () => {
|
|
1047
1050
|
const name = normalizeSubreddit(subreddit);
|
|
1048
1051
|
const endpoint = name !== "" ? `/r/${name}/${sort}.json` : `/${sort}.json`;
|
|
1049
|
-
const response = (await this.makeRequest(`${endpoint}?${params}`)).orThrow();
|
|
1052
|
+
const response = (await this.makeRequest(`${endpoint}?${params}`)).orThrow((e) => e);
|
|
1050
1053
|
if (!response.ok) throw new HttpError(response.status, `Failed to browse r/${home}: HTTP ${response.status}`);
|
|
1051
1054
|
const json = await response.json();
|
|
1052
1055
|
return {
|
|
@@ -1061,7 +1064,7 @@ var RedditClient = class {
|
|
|
1061
1064
|
return (await Try.async(async () => {
|
|
1062
1065
|
const id = normalizeThingId(postId);
|
|
1063
1066
|
const endpoint = Option(subreddit).fold(() => `/api/info.json?id=t3_${id}`, (sr) => `/r/${normalizeSubreddit(sr)}/comments/${id}.json`);
|
|
1064
|
-
const response = (await this.makeRequest(endpoint)).orThrow();
|
|
1067
|
+
const response = (await this.makeRequest(endpoint)).orThrow((e) => e);
|
|
1065
1068
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
1066
1069
|
if (subreddit !== void 0) return parsePostData((await response.json())[0].data.children[0].data);
|
|
1067
1070
|
const json = await response.json();
|
|
@@ -1074,7 +1077,7 @@ var RedditClient = class {
|
|
|
1074
1077
|
const params = new URLSearchParams({ limit: limit.toString() });
|
|
1075
1078
|
const context = `Failed to get trending subreddits`;
|
|
1076
1079
|
return (await Try.async(async () => {
|
|
1077
|
-
const response = (await this.makeRequest(`/subreddits/popular.json?${params}`)).orThrow();
|
|
1080
|
+
const response = (await this.makeRequest(`/subreddits/popular.json?${params}`)).orThrow((e) => e);
|
|
1078
1081
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
1079
1082
|
return (await response.json()).data.children.map((child) => child.data.display_name);
|
|
1080
1083
|
})).toEither((error) => classifyRedditError(error, context));
|
|
@@ -1101,21 +1104,21 @@ var RedditClient = class {
|
|
|
1101
1104
|
method: "POST",
|
|
1102
1105
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1103
1106
|
body: params.toString()
|
|
1104
|
-
})).orThrow();
|
|
1107
|
+
})).orThrow((e) => e);
|
|
1105
1108
|
if (!response.ok) throw new HttpError(response.status, `Failed to create post: HTTP ${response.status}`);
|
|
1106
1109
|
const json = await response.json();
|
|
1107
1110
|
if (json.json.errors !== void 0 && json.json.errors.length > 0) throw new ApiError(`Reddit API errors: ${json.json.errors.map((e) => e[1]).join(", ")}`);
|
|
1108
1111
|
const postId = ((_json$json$data = json.json.data) === null || _json$json$data === void 0 ? void 0 : _json$json$data.id) ?? ((_json$json$data2 = json.json.data) === null || _json$json$data2 === void 0 || (_json$json$data2 = _json$json$data2.name) === null || _json$json$data2 === void 0 ? void 0 : _json$json$data2.replace("t3_", ""));
|
|
1109
1112
|
if (postId === void 0) throw new ApiError("No post ID returned from Reddit");
|
|
1110
|
-
return (await this.getPost(postId, targetSubreddit)).orThrow();
|
|
1113
|
+
return (await this.getPost(postId, targetSubreddit)).orThrow((e) => e);
|
|
1111
1114
|
})).toEither((error) => classifyRedditError(error));
|
|
1112
1115
|
}
|
|
1113
1116
|
async checkPostExists(postId) {
|
|
1114
1117
|
return (await Try.async(async () => {
|
|
1115
|
-
const response = (await this.makeRequest(`/api/info.json?id=t3_${normalizeThingId(postId)}`)).orThrow();
|
|
1118
|
+
const response = (await this.makeRequest(`/api/info.json?id=t3_${normalizeThingId(postId)}`)).orThrow((e) => e);
|
|
1116
1119
|
if (!response.ok) return false;
|
|
1117
1120
|
return (await response.json()).data.children.length > 0;
|
|
1118
|
-
})).
|
|
1121
|
+
})).getOrElse(() => false);
|
|
1119
1122
|
}
|
|
1120
1123
|
async replyToPost(postId, content) {
|
|
1121
1124
|
return (await Try.async(async () => {
|
|
@@ -1136,7 +1139,7 @@ var RedditClient = class {
|
|
|
1136
1139
|
method: "POST",
|
|
1137
1140
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1138
1141
|
body: params.toString()
|
|
1139
|
-
})).orThrow();
|
|
1142
|
+
})).orThrow((e) => e);
|
|
1140
1143
|
if (!response.ok) throw new HttpError(response.status, `Failed to reply: HTTP ${response.status}`);
|
|
1141
1144
|
const json = await response.json();
|
|
1142
1145
|
if (((_json$json$data3 = json.json.data) === null || _json$json$data3 === void 0 ? void 0 : _json$json$data3.things) !== void 0 && json.json.data.things.length > 0) {
|
|
@@ -1169,7 +1172,7 @@ var RedditClient = class {
|
|
|
1169
1172
|
method: "POST",
|
|
1170
1173
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1171
1174
|
body: params.toString()
|
|
1172
|
-
})).orThrow();
|
|
1175
|
+
})).orThrow((e) => e);
|
|
1173
1176
|
if (!response.ok) {
|
|
1174
1177
|
const errorText = await response.text();
|
|
1175
1178
|
console.error(`[Reddit API] Delete failed: ${response.status} ${response.statusText}`);
|
|
@@ -1204,7 +1207,7 @@ var RedditClient = class {
|
|
|
1204
1207
|
method: "POST",
|
|
1205
1208
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1206
1209
|
body: params.toString()
|
|
1207
|
-
})).orThrow();
|
|
1210
|
+
})).orThrow((e) => e);
|
|
1208
1211
|
if (!response.ok) throw new HttpError(response.status, `Failed to edit: HTTP ${response.status}`);
|
|
1209
1212
|
const json = await response.json();
|
|
1210
1213
|
if (json.json.errors !== void 0 && json.json.errors.length > 0) throw new ApiError(`Reddit API errors: ${json.json.errors.map((e) => e[1]).join(", ")}`);
|
|
@@ -1228,7 +1231,7 @@ var RedditClient = class {
|
|
|
1228
1231
|
method: "POST",
|
|
1229
1232
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1230
1233
|
body: params.toString()
|
|
1231
|
-
})).orThrow();
|
|
1234
|
+
})).orThrow((e) => e);
|
|
1232
1235
|
if (!response.ok) throw new HttpError(response.status, `Failed to ${saved ? "save" : "unsave"}: HTTP ${response.status}`);
|
|
1233
1236
|
return true;
|
|
1234
1237
|
})).toEither((error) => classifyRedditError(error));
|
|
@@ -1263,7 +1266,7 @@ var RedditClient = class {
|
|
|
1263
1266
|
const context = `Failed to search Reddit for: ${query}`;
|
|
1264
1267
|
return (await Try.async(async () => {
|
|
1265
1268
|
const endpoint = Option(subreddit).fold(() => "/search.json", (sr) => `/r/${normalizeSubreddit(sr)}/search.json`);
|
|
1266
|
-
const response = (await this.makeRequest(`${endpoint}?${params}`)).orThrow();
|
|
1269
|
+
const response = (await this.makeRequest(`${endpoint}?${params}`)).orThrow((e) => e);
|
|
1267
1270
|
if (!response.ok) throw new HttpError(response.status, `Failed to search Reddit: HTTP ${response.status}`);
|
|
1268
1271
|
const json = await response.json();
|
|
1269
1272
|
return {
|
|
@@ -1286,11 +1289,10 @@ var RedditClient = class {
|
|
|
1286
1289
|
});
|
|
1287
1290
|
const context = `Failed to get comments for post ${postId}`;
|
|
1288
1291
|
return (await Try.async(async () => {
|
|
1289
|
-
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subreddit)}/comments/${normalizeThingId(postId)}.json?${params}`)).orThrow();
|
|
1292
|
+
const response = (await this.makeRequest(`/r/${normalizeSubreddit(subreddit)}/comments/${normalizeThingId(postId)}.json?${params}`)).orThrow((e) => e);
|
|
1290
1293
|
if (!response.ok) throw new HttpError(response.status, `Failed to get comments: HTTP ${response.status}`);
|
|
1291
1294
|
const json = await response.json();
|
|
1292
|
-
const
|
|
1293
|
-
const post = parsePostData(postData);
|
|
1295
|
+
const post = parsePostData(json[0].data.children[0].data);
|
|
1294
1296
|
return {
|
|
1295
1297
|
post,
|
|
1296
1298
|
comments: parseCommentTree(json[1].data.children, post.title),
|
|
@@ -1308,7 +1310,7 @@ var RedditClient = class {
|
|
|
1308
1310
|
link_id: normalizeFullname(linkId, "t3"),
|
|
1309
1311
|
children: commentIds.map((id) => normalizeThingId(id)).join(",")
|
|
1310
1312
|
});
|
|
1311
|
-
const response = (await this.makeRequest(`/api/morechildren?${params}`)).orThrow();
|
|
1313
|
+
const response = (await this.makeRequest(`/api/morechildren?${params}`)).orThrow((e) => e);
|
|
1312
1314
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
1313
1315
|
return (((_json$json$data4 = (await response.json()).json.data) === null || _json$json$data4 === void 0 ? void 0 : _json$json$data4.things) ?? []).filter((thing) => thing.kind === "t1" && thing.data.body !== void 0).map((thing) => parseCommentData(thing.data));
|
|
1314
1316
|
})).toEither((error) => classifyRedditError(error, context));
|
|
@@ -1324,7 +1326,7 @@ var RedditClient = class {
|
|
|
1324
1326
|
if (after !== void 0) params.set("after", after);
|
|
1325
1327
|
const context = `Failed to get posts for user ${username}`;
|
|
1326
1328
|
return (await Try.async(async () => {
|
|
1327
|
-
const response = (await this.makeRequest(`/user/${normalizeUsername(username)}/submitted.json?${params}`)).orThrow();
|
|
1329
|
+
const response = (await this.makeRequest(`/user/${normalizeUsername(username)}/submitted.json?${params}`)).orThrow((e) => e);
|
|
1328
1330
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
1329
1331
|
const json = await response.json();
|
|
1330
1332
|
return {
|
|
@@ -1344,7 +1346,7 @@ var RedditClient = class {
|
|
|
1344
1346
|
if (after !== void 0) params.set("after", after);
|
|
1345
1347
|
const context = `Failed to get comments for user ${username}`;
|
|
1346
1348
|
return (await Try.async(async () => {
|
|
1347
|
-
const response = (await this.makeRequest(`/user/${normalizeUsername(username)}/comments.json?${params}`)).orThrow();
|
|
1349
|
+
const response = (await this.makeRequest(`/user/${normalizeUsername(username)}/comments.json?${params}`)).orThrow((e) => e);
|
|
1348
1350
|
if (!response.ok) throw new HttpError(response.status, `${context}: HTTP ${response.status}`);
|
|
1349
1351
|
const json = await response.json();
|
|
1350
1352
|
return {
|
|
@@ -1383,7 +1385,7 @@ function hasUserCredentials(env = process.env) {
|
|
|
1383
1385
|
function formatTimestamp(timestamp) {
|
|
1384
1386
|
return Try(() => {
|
|
1385
1387
|
return (/* @__PURE__ */ new Date(timestamp * 1e3)).toISOString().replace("T", " ").replace(/\.\d+Z$/, " UTC");
|
|
1386
|
-
}).
|
|
1388
|
+
}).getOrElse(() => String(timestamp));
|
|
1387
1389
|
}
|
|
1388
1390
|
function analyzeUserActivity(karmaRatio, isMod, accountAgeDays) {
|
|
1389
1391
|
return [
|
|
@@ -1548,7 +1550,7 @@ function formatCommentInfo(comment, maxLength = COMMENT_CONTENT_MAX_LENGTH) {
|
|
|
1548
1550
|
}
|
|
1549
1551
|
// src/index.ts
|
|
1550
1552
|
dotenv.config({ quiet: true });
|
|
1551
|
-
const VERSION = "2.0.
|
|
1553
|
+
const VERSION = "2.0.3";
|
|
1552
1554
|
function validateUserAgent(userAgent, username) {
|
|
1553
1555
|
if (!/^[\w-]+:[\w-]+:[\d.]+ \(by \/u\/\w+\)$/.test(userAgent)) {
|
|
1554
1556
|
console.error("[Warning] User-Agent does not follow Reddit's recommended format");
|
|
@@ -1673,8 +1675,8 @@ async function setupRedditClient() {
|
|
|
1673
1675
|
const customUserAgent = readEnv("REDDIT_USER_AGENT").orUndefined();
|
|
1674
1676
|
const username = readEnv("REDDIT_USERNAME").orUndefined();
|
|
1675
1677
|
const password = readEnv("REDDIT_PASSWORD").orUndefined();
|
|
1676
|
-
const authMode = readEnv("REDDIT_AUTH_MODE").
|
|
1677
|
-
const safeMode = readEnv("REDDIT_SAFE_MODE").
|
|
1678
|
+
const authMode = readEnv("REDDIT_AUTH_MODE").getOrElse(() => "auto");
|
|
1679
|
+
const safeMode = readEnv("REDDIT_SAFE_MODE").getOrElse(() => "standard");
|
|
1678
1680
|
if (";
|
|
1704
1707
|
const botDisclosureConfig = {
|
|
1705
1708
|
enabled: botDisclosureMode === "auto",
|
|
1706
|
-
footer: botDisclosureMode === "auto" ? readEnv("REDDIT_BOT_FOOTER").
|
|
1709
|
+
footer: botDisclosureMode === "auto" ? readEnv("REDDIT_BOT_FOOTER").getOrElse(() => defaultFooter) : ""
|
|
1707
1710
|
};
|
|
1708
|
-
const cacheEnabled = readEnv("REDDIT_CACHE").
|
|
1709
|
-
const cacheMaxMb = Number(readEnv("REDDIT_CACHE_MAX_MB").
|
|
1711
|
+
const cacheEnabled = readEnv("REDDIT_CACHE").getOrElse(() => "on") !== "off";
|
|
1712
|
+
const cacheMaxMb = Number(readEnv("REDDIT_CACHE_MAX_MB").getOrElse(() => "50"));
|
|
1710
1713
|
const cacheConfig = {
|
|
1711
1714
|
enabled: cacheEnabled,
|
|
1712
1715
|
maxBytes: (Number.isFinite(cacheMaxMb) && cacheMaxMb > 0 ? cacheMaxMb : 50) * 1024 * 1024
|
|
1713
1716
|
};
|
|
1714
|
-
const maxRetriesRaw = Number(readEnv("REDDIT_MAX_RETRIES").
|
|
1717
|
+
const maxRetriesRaw = Number(readEnv("REDDIT_MAX_RETRIES").getOrElse(() => "3"));
|
|
1715
1718
|
const client = initializeRedditClient({
|
|
1716
1719
|
clientId: clientId ?? "",
|
|
1717
1720
|
clientSecret: clientSecret ?? "",
|
|
@@ -1733,23 +1736,28 @@ async function setupRedditClient() {
|
|
|
1733
1736
|
if (authMode === "anonymous") console.error("[Warning] REDDIT_AUTH_MODE=anonymous is deprecated; it is now an alias for auto without credentials.");
|
|
1734
1737
|
if (authMode === "anonymous" || !hasCredentials) {
|
|
1735
1738
|
console.error("[Setup] Keyless mode โ no OAuth credentials detected.");
|
|
1736
|
-
console.error("[Setup] Reads come from RSS feeds (ranked listings
|
|
1739
|
+
console.error("[Setup] Reads come from RSS feeds (ranked listings; Reddit said it would end them 2026-11-13)");
|
|
1737
1740
|
console.error("[Setup] and the Arctic Shift archive (a free third-party Reddit archive; scores lag).");
|
|
1738
1741
|
console.error("[Setup] Existing REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET still give live data (60-100 req/min).");
|
|
1739
1742
|
console.error("[Setup] Reddit takes no new API access requests and closes its public API in March 2027.");
|
|
1740
1743
|
console.error("[Setup] See: https://github.com/jordanburke/reddit-mcp-server#reddit-is-closing-its-public-api");
|
|
1741
1744
|
} else {
|
|
1742
1745
|
console.error("[Setup] Testing Reddit API connection...");
|
|
1743
|
-
if (
|
|
1746
|
+
if (await client.checkAuthentication()) {
|
|
1747
|
+
console.error("[Setup] โ Reddit API connection successful");
|
|
1748
|
+
console.error("[Setup] Using OAuth Reddit API (60-100 req/min)");
|
|
1749
|
+
} else if (authMode === "authenticated") {
|
|
1744
1750
|
console.error("[Error] โ Failed to connect to Reddit API");
|
|
1745
1751
|
console.error("[Error] Please check your REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET");
|
|
1746
1752
|
process.exit(1);
|
|
1753
|
+
} else {
|
|
1754
|
+
console.error("[Warning] โ Could not authenticate with the Reddit API; starting anyway");
|
|
1755
|
+
console.error("[Warning] Check REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET. Tool calls retry and report the error");
|
|
1756
|
+
console.error("[Warning] Set REDDIT_AUTH_MODE=authenticated to exit on this instead");
|
|
1747
1757
|
}
|
|
1748
|
-
console.error("[Setup] โ Reddit API connection successful");
|
|
1749
|
-
console.error("[Setup] Using OAuth Reddit API (60-100 req/min)");
|
|
1750
1758
|
}
|
|
1751
1759
|
if (username !== void 0 && password !== void 0) {
|
|
1752
|
-
console.error(`[Setup] โ User
|
|
1760
|
+
console.error(`[Setup] โ User credentials set for: ${username}`);
|
|
1753
1761
|
console.error("[Setup] Write operations enabled (posting, replying, editing, deleting)");
|
|
1754
1762
|
} else {
|
|
1755
1763
|
console.error("[Setup] Read-only mode (no user credentials)");
|
|
@@ -1767,8 +1775,8 @@ async function setupRedditClient() {
|
|
|
1767
1775
|
}
|
|
1768
1776
|
}
|
|
1769
1777
|
const configuredOauthToken = readEnv("OAUTH_TOKEN");
|
|
1770
|
-
const oauthToken = configuredOauthToken.
|
|
1771
|
-
if (readEnv("OAUTH_ENABLED").
|
|
1778
|
+
const oauthToken = configuredOauthToken.getOrElse(() => crypto.randomBytes(32).toString("hex"));
|
|
1779
|
+
if (readEnv("OAUTH_ENABLED").getOrElse(() => "false") === "true" && configuredOauthToken.isNone()) console.error(`[Auth] Generated OAuth token: ${oauthToken}`);
|
|
1772
1780
|
function authenticateBearer(request) {
|
|
1773
1781
|
const authHeader = getRequestHeader(request, "authorization");
|
|
1774
1782
|
if (!(authHeader === null || authHeader === void 0 ? void 0 : authHeader.startsWith("Bearer "))) return Promise.reject(new Response(null, { status: 401 }));
|
|
@@ -1777,7 +1785,7 @@ function authenticateBearer(request) {
|
|
|
1777
1785
|
if (!crypto.timingSafeEqual(tokenHash, expectedHash)) return Promise.reject(new Response(null, { status: 403 }));
|
|
1778
1786
|
return Promise.resolve({ authenticated: true });
|
|
1779
1787
|
}
|
|
1780
|
-
const transportType = readEnv("TRANSPORT_TYPE").
|
|
1788
|
+
const transportType = readEnv("TRANSPORT_TYPE").getOrElse(() => "stdio");
|
|
1781
1789
|
const useHttp = transportType === "httpStream" || transportType === "http";
|
|
1782
1790
|
const server = createServer({
|
|
1783
1791
|
name: "reddit-mcp-server",
|
|
@@ -1805,7 +1813,7 @@ IMPORTANT - Reddit Responsible Builder Policy compliance:
|
|
|
1805
1813
|
- All bot-generated content must clearly disclose its automated nature
|
|
1806
1814
|
- Bots must NOT send private/direct messages without explicit user consent
|
|
1807
1815
|
For details: https://support.reddithelp.com/hc/en-us/articles/42728983564564-Responsible-Builder-Policy`,
|
|
1808
|
-
...useHttp && readEnv("OAUTH_ENABLED").
|
|
1816
|
+
...useHttp && readEnv("OAUTH_ENABLED").getOrElse(() => "false") === "true" ? { authenticate: authenticateBearer } : {},
|
|
1809
1817
|
enableIntrospection: false,
|
|
1810
1818
|
enableInfoEndpoint: false,
|
|
1811
1819
|
enableDashboard: false,
|
|
@@ -2375,7 +2383,7 @@ server.addTool({
|
|
|
2375
2383
|
|
|
2376
2384
|
## Comment Details
|
|
2377
2385
|
- Posted to: ${args.post_id}
|
|
2378
|
-
- Author: u/${readEnv("REDDIT_USERNAME").
|
|
2386
|
+
- Author: u/${readEnv("REDDIT_USERNAME").getOrElse(() => "")}
|
|
2379
2387
|
- Comment ID: ${comment.id}
|
|
2380
2388
|
|
|
2381
2389
|
Your reply has been successfully posted.`);
|
|
@@ -2603,8 +2611,8 @@ ${commentList}${archiveDisclaimer(client)}`;
|
|
|
2603
2611
|
});
|
|
2604
2612
|
async function main() {
|
|
2605
2613
|
await setupRedditClient();
|
|
2606
|
-
const port = parseInt(readEnv("PORT").
|
|
2607
|
-
const host = readEnv("HOST").
|
|
2614
|
+
const port = parseInt(readEnv("PORT").getOrElse(() => "3000"));
|
|
2615
|
+
const host = readEnv("HOST").getOrElse(() => "127.0.0.1");
|
|
2608
2616
|
if (useHttp) {
|
|
2609
2617
|
console.error(`[Setup] Starting HTTP server on ${host}:${port}`);
|
|
2610
2618
|
await server.start({
|