reddit-mcp-server 1.0.2 → 1.0.4
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/.claude/settings.local.json +4 -1
- package/dist/bin.js +45 -52
- package/dist/index.js +45 -52
- package/package.json +4 -4
- package/src/bin.ts +3 -3
- package/src/client/reddit-client.ts +19 -19
- package/src/index.ts +45 -15
- package/src/tools/post-tools.ts +12 -12
- package/src/tools/subreddit-tools.ts +6 -6
- package/src/tools/user-tools.ts +3 -3
package/dist/bin.js
CHANGED
|
@@ -74,12 +74,10 @@ var RedditClient = class {
|
|
|
74
74
|
const authUrl = "https://www.reddit.com/api/v1/access_token";
|
|
75
75
|
const authData = new URLSearchParams();
|
|
76
76
|
if (this.username && this.password) {
|
|
77
|
-
console.log(`[Auth] Authenticating with user credentials for ${this.username}`);
|
|
78
77
|
authData.append("grant_type", "password");
|
|
79
78
|
authData.append("username", this.username);
|
|
80
79
|
authData.append("password", this.password);
|
|
81
80
|
} else {
|
|
82
|
-
console.log("[Auth] Authenticating with client credentials (read-only)");
|
|
83
81
|
authData.append("grant_type", "client_credentials");
|
|
84
82
|
}
|
|
85
83
|
const response = await import_axios.default.post(authUrl, authData, {
|
|
@@ -96,9 +94,7 @@ var RedditClient = class {
|
|
|
96
94
|
this.tokenExpiry = now + response.data.expires_in * 1e3;
|
|
97
95
|
this.authenticated = true;
|
|
98
96
|
this.api.defaults.headers.common["Authorization"] = `Bearer ${this.accessToken}`;
|
|
99
|
-
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.error("[Auth] Authentication error:", error);
|
|
97
|
+
} catch {
|
|
102
98
|
throw new Error("Failed to authenticate with Reddit API");
|
|
103
99
|
}
|
|
104
100
|
}
|
|
@@ -130,8 +126,7 @@ var RedditClient = class {
|
|
|
130
126
|
createdUtc: data.created_utc,
|
|
131
127
|
profileUrl: `https://reddit.com/user/${data.name}`
|
|
132
128
|
};
|
|
133
|
-
} catch
|
|
134
|
-
console.error(`[Error] Failed to get user info for ${username}:`, error);
|
|
129
|
+
} catch {
|
|
135
130
|
throw new Error(`Failed to get user info for ${username}`);
|
|
136
131
|
}
|
|
137
132
|
}
|
|
@@ -152,8 +147,7 @@ var RedditClient = class {
|
|
|
152
147
|
subredditType: data.subreddit_type,
|
|
153
148
|
url: data.url
|
|
154
149
|
};
|
|
155
|
-
} catch
|
|
156
|
-
console.error(`[Error] Failed to get subreddit info for ${subredditName}:`, error);
|
|
150
|
+
} catch {
|
|
157
151
|
throw new Error(`Failed to get subreddit info for ${subredditName}`);
|
|
158
152
|
}
|
|
159
153
|
}
|
|
@@ -188,8 +182,7 @@ var RedditClient = class {
|
|
|
188
182
|
permalink: post.permalink
|
|
189
183
|
};
|
|
190
184
|
});
|
|
191
|
-
} catch
|
|
192
|
-
console.error(`[Error] Failed to get top posts for ${subreddit || "home"}:`, error);
|
|
185
|
+
} catch {
|
|
193
186
|
throw new Error(`Failed to get top posts for ${subreddit || "home"}`);
|
|
194
187
|
}
|
|
195
188
|
}
|
|
@@ -225,8 +218,7 @@ var RedditClient = class {
|
|
|
225
218
|
linkFlairText: post.link_flair_text,
|
|
226
219
|
permalink: post.permalink
|
|
227
220
|
};
|
|
228
|
-
} catch
|
|
229
|
-
console.error(`[Error] Failed to get post with ID ${postId}:`, error);
|
|
221
|
+
} catch {
|
|
230
222
|
throw new Error(`Failed to get post with ID ${postId}`);
|
|
231
223
|
}
|
|
232
224
|
}
|
|
@@ -237,8 +229,7 @@ var RedditClient = class {
|
|
|
237
229
|
params: { limit }
|
|
238
230
|
});
|
|
239
231
|
return response.data.data.children.map((child) => child.data.display_name);
|
|
240
|
-
} catch
|
|
241
|
-
console.error("[Error] Failed to get trending subreddits:", error);
|
|
232
|
+
} catch {
|
|
242
233
|
throw new Error("Failed to get trending subreddits");
|
|
243
234
|
}
|
|
244
235
|
}
|
|
@@ -265,8 +256,7 @@ var RedditClient = class {
|
|
|
265
256
|
} else {
|
|
266
257
|
throw new Error("Failed to create post");
|
|
267
258
|
}
|
|
268
|
-
} catch
|
|
269
|
-
console.error(`[Error] Failed to create post in ${subreddit}:`, error);
|
|
259
|
+
} catch {
|
|
270
260
|
throw new Error(`Failed to create post in ${subreddit}`);
|
|
271
261
|
}
|
|
272
262
|
}
|
|
@@ -310,8 +300,7 @@ var RedditClient = class {
|
|
|
310
300
|
isSubmitter: false,
|
|
311
301
|
permalink: commentData.permalink
|
|
312
302
|
};
|
|
313
|
-
} catch
|
|
314
|
-
console.error(`[Error] Failed to reply to post ${postId}:`, error);
|
|
303
|
+
} catch {
|
|
315
304
|
throw new Error(`Failed to reply to post ${postId}`);
|
|
316
305
|
}
|
|
317
306
|
}
|
|
@@ -569,7 +558,6 @@ async function getUserInfo(params) {
|
|
|
569
558
|
throw new import_types.McpError(import_types.ErrorCode.InternalError, "Reddit client not initialized");
|
|
570
559
|
}
|
|
571
560
|
try {
|
|
572
|
-
console.log(`[Tool] Getting info for u/${username}`);
|
|
573
561
|
const user = await client.getUser(username);
|
|
574
562
|
const formattedUser = formatUserInfo(user);
|
|
575
563
|
return {
|
|
@@ -599,8 +587,7 @@ async function getUserInfo(params) {
|
|
|
599
587
|
]
|
|
600
588
|
};
|
|
601
589
|
} catch (error) {
|
|
602
|
-
|
|
603
|
-
throw new import_types.McpError(import_types.ErrorCode.InternalError, `Failed to fetch user data: ${error}`);
|
|
590
|
+
throw new import_types.McpError(import_types.ErrorCode.InternalError, `Failed to fetch user data: ${String(error)}`);
|
|
604
591
|
}
|
|
605
592
|
}
|
|
606
593
|
|
|
@@ -613,7 +600,6 @@ async function getRedditPost(params) {
|
|
|
613
600
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
614
601
|
}
|
|
615
602
|
try {
|
|
616
|
-
console.log(`[Tool] Getting post ${post_id} from r/${subreddit}`);
|
|
617
603
|
const post = await client.getPost(post_id, subreddit);
|
|
618
604
|
const formattedPost = formatPostInfo(post);
|
|
619
605
|
return {
|
|
@@ -655,8 +641,7 @@ ${formattedPost.bestTimeToEngage}
|
|
|
655
641
|
]
|
|
656
642
|
};
|
|
657
643
|
} catch (error) {
|
|
658
|
-
|
|
659
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch post data: ${error}`);
|
|
644
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch post data: ${String(error)}`);
|
|
660
645
|
}
|
|
661
646
|
}
|
|
662
647
|
async function getTopPosts(params) {
|
|
@@ -666,7 +651,6 @@ async function getTopPosts(params) {
|
|
|
666
651
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
667
652
|
}
|
|
668
653
|
try {
|
|
669
|
-
console.log(`[Tool] Getting top posts from r/${subreddit}`);
|
|
670
654
|
const posts = await client.getTopPosts(subreddit, time_filter, limit);
|
|
671
655
|
const formattedPosts = posts.map(formatPostInfo);
|
|
672
656
|
const postSummaries = formattedPosts.map(
|
|
@@ -692,8 +676,7 @@ ${postSummaries}
|
|
|
692
676
|
]
|
|
693
677
|
};
|
|
694
678
|
} catch (error) {
|
|
695
|
-
|
|
696
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch top posts: ${error}`);
|
|
679
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch top posts: ${String(error)}`);
|
|
697
680
|
}
|
|
698
681
|
}
|
|
699
682
|
async function createPost(params) {
|
|
@@ -703,7 +686,6 @@ async function createPost(params) {
|
|
|
703
686
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
704
687
|
}
|
|
705
688
|
try {
|
|
706
|
-
console.log(`[Tool] Creating ${is_self ? "text" : "link"} post in r/${subreddit}`);
|
|
707
689
|
const post = await client.createPost(subreddit, title, content, is_self);
|
|
708
690
|
const formattedPost = formatPostInfo(post);
|
|
709
691
|
return {
|
|
@@ -725,8 +707,7 @@ Your post has been successfully submitted to r/${formattedPost.subreddit}.
|
|
|
725
707
|
]
|
|
726
708
|
};
|
|
727
709
|
} catch (error) {
|
|
728
|
-
|
|
729
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to create post: ${error}`);
|
|
710
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to create post: ${String(error)}`);
|
|
730
711
|
}
|
|
731
712
|
}
|
|
732
713
|
async function replyToPost(params) {
|
|
@@ -736,7 +717,6 @@ async function replyToPost(params) {
|
|
|
736
717
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
737
718
|
}
|
|
738
719
|
try {
|
|
739
|
-
console.log(`[Tool] Replying to post ${post_id}`);
|
|
740
720
|
const comment = await client.replyToPost(post_id, content);
|
|
741
721
|
const formattedComment = formatCommentInfo(comment);
|
|
742
722
|
return {
|
|
@@ -758,8 +738,7 @@ Your reply has been successfully posted.
|
|
|
758
738
|
]
|
|
759
739
|
};
|
|
760
740
|
} catch (error) {
|
|
761
|
-
|
|
762
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to reply to post: ${error}`);
|
|
741
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to reply to post: ${String(error)}`);
|
|
763
742
|
}
|
|
764
743
|
}
|
|
765
744
|
|
|
@@ -772,7 +751,6 @@ async function getSubredditInfo(params) {
|
|
|
772
751
|
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, "Reddit client not initialized");
|
|
773
752
|
}
|
|
774
753
|
try {
|
|
775
|
-
console.log(`[Tool] Getting info for r/${subreddit_name}`);
|
|
776
754
|
const subreddit = await client.getSubredditInfo(subreddit_name);
|
|
777
755
|
const formattedSubreddit = formatSubredditInfo(subreddit);
|
|
778
756
|
return {
|
|
@@ -812,8 +790,7 @@ ${formattedSubreddit.description.full}
|
|
|
812
790
|
]
|
|
813
791
|
};
|
|
814
792
|
} catch (error) {
|
|
815
|
-
|
|
816
|
-
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch subreddit data: ${error}`);
|
|
793
|
+
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch subreddit data: ${String(error)}`);
|
|
817
794
|
}
|
|
818
795
|
}
|
|
819
796
|
async function getTrendingSubreddits() {
|
|
@@ -822,7 +799,6 @@ async function getTrendingSubreddits() {
|
|
|
822
799
|
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, "Reddit client not initialized");
|
|
823
800
|
}
|
|
824
801
|
try {
|
|
825
|
-
console.log("[Tool] Getting trending subreddits");
|
|
826
802
|
const trendingSubreddits = await client.getTrendingSubreddits();
|
|
827
803
|
return {
|
|
828
804
|
content: [
|
|
@@ -837,8 +813,7 @@ ${trendingSubreddits.map((subreddit, index) => `${index + 1}. r/${subreddit}`).j
|
|
|
837
813
|
]
|
|
838
814
|
};
|
|
839
815
|
} catch (error) {
|
|
840
|
-
|
|
841
|
-
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch trending subreddits: ${error}`);
|
|
816
|
+
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch trending subreddits: ${String(error)}`);
|
|
842
817
|
}
|
|
843
818
|
}
|
|
844
819
|
|
|
@@ -848,8 +823,6 @@ import_dotenv.default.config();
|
|
|
848
823
|
var RedditServer = class {
|
|
849
824
|
server;
|
|
850
825
|
constructor() {
|
|
851
|
-
console.log("[Setup] Initializing Reddit Server...");
|
|
852
|
-
this.initializeRedditClient();
|
|
853
826
|
this.server = new import_server.Server(
|
|
854
827
|
{
|
|
855
828
|
name: "reddit-mcp-server",
|
|
@@ -861,8 +834,15 @@ var RedditServer = class {
|
|
|
861
834
|
}
|
|
862
835
|
}
|
|
863
836
|
);
|
|
837
|
+
this.initializeRedditClient();
|
|
864
838
|
this.setupToolHandlers();
|
|
865
|
-
this.server.onerror = (error) =>
|
|
839
|
+
this.server.onerror = async (error) => {
|
|
840
|
+
await this.server.sendLoggingMessage({
|
|
841
|
+
level: "error",
|
|
842
|
+
logger: "reddit-server",
|
|
843
|
+
data: `Server error: ${error}`
|
|
844
|
+
});
|
|
845
|
+
};
|
|
866
846
|
process.on("SIGINT", async () => {
|
|
867
847
|
await this.server.close();
|
|
868
848
|
process.exit(0);
|
|
@@ -888,12 +868,6 @@ var RedditServer = class {
|
|
|
888
868
|
username,
|
|
889
869
|
password
|
|
890
870
|
});
|
|
891
|
-
console.log("[Setup] Reddit client initialized");
|
|
892
|
-
if (username && password) {
|
|
893
|
-
console.log(`[Setup] Authenticated as user: ${username}`);
|
|
894
|
-
} else {
|
|
895
|
-
console.log("[Setup] Running in read-only mode (no user authentication)");
|
|
896
|
-
}
|
|
897
871
|
} catch (error) {
|
|
898
872
|
console.error("[Error] Failed to initialize Reddit client:", error);
|
|
899
873
|
process.exit(1);
|
|
@@ -1046,7 +1020,11 @@ var RedditServer = class {
|
|
|
1046
1020
|
try {
|
|
1047
1021
|
const toolName = request.params.name;
|
|
1048
1022
|
const toolParams = request.params.arguments || {};
|
|
1049
|
-
|
|
1023
|
+
await this.server.sendLoggingMessage({
|
|
1024
|
+
level: "debug",
|
|
1025
|
+
logger: "reddit-server",
|
|
1026
|
+
data: `Tool call: ${toolName}`
|
|
1027
|
+
});
|
|
1050
1028
|
switch (toolName) {
|
|
1051
1029
|
case "test_reddit_mcp_server":
|
|
1052
1030
|
return {
|
|
@@ -1082,7 +1060,11 @@ var RedditServer = class {
|
|
|
1082
1060
|
}
|
|
1083
1061
|
} catch (error) {
|
|
1084
1062
|
if (error instanceof Error) {
|
|
1085
|
-
|
|
1063
|
+
await this.server.sendLoggingMessage({
|
|
1064
|
+
level: "error",
|
|
1065
|
+
logger: "reddit-server",
|
|
1066
|
+
data: `Error calling tool: ${error.message}`
|
|
1067
|
+
});
|
|
1086
1068
|
throw new import_types4.McpError(import_types4.ErrorCode.InternalError, `Failed to fetch data: ${error.message}`);
|
|
1087
1069
|
}
|
|
1088
1070
|
throw error;
|
|
@@ -1092,7 +1074,18 @@ var RedditServer = class {
|
|
|
1092
1074
|
async run() {
|
|
1093
1075
|
const transport = new import_stdio.StdioServerTransport();
|
|
1094
1076
|
await this.server.connect(transport);
|
|
1095
|
-
|
|
1077
|
+
await this.server.sendLoggingMessage({
|
|
1078
|
+
level: "info",
|
|
1079
|
+
logger: "reddit-server",
|
|
1080
|
+
data: "Reddit MCP Server is running"
|
|
1081
|
+
});
|
|
1082
|
+
const username = process.env.REDDIT_USERNAME;
|
|
1083
|
+
const password = process.env.REDDIT_PASSWORD;
|
|
1084
|
+
await this.server.sendLoggingMessage({
|
|
1085
|
+
level: "info",
|
|
1086
|
+
logger: "reddit-server",
|
|
1087
|
+
data: username && password ? `Authenticated as user: ${username}` : "Running in read-only mode (no user authentication)"
|
|
1088
|
+
});
|
|
1096
1089
|
}
|
|
1097
1090
|
};
|
|
1098
1091
|
if (require.main === module) {
|
package/dist/index.js
CHANGED
|
@@ -83,12 +83,10 @@ var RedditClient = class {
|
|
|
83
83
|
const authUrl = "https://www.reddit.com/api/v1/access_token";
|
|
84
84
|
const authData = new URLSearchParams();
|
|
85
85
|
if (this.username && this.password) {
|
|
86
|
-
console.log(`[Auth] Authenticating with user credentials for ${this.username}`);
|
|
87
86
|
authData.append("grant_type", "password");
|
|
88
87
|
authData.append("username", this.username);
|
|
89
88
|
authData.append("password", this.password);
|
|
90
89
|
} else {
|
|
91
|
-
console.log("[Auth] Authenticating with client credentials (read-only)");
|
|
92
90
|
authData.append("grant_type", "client_credentials");
|
|
93
91
|
}
|
|
94
92
|
const response = await import_axios.default.post(authUrl, authData, {
|
|
@@ -105,9 +103,7 @@ var RedditClient = class {
|
|
|
105
103
|
this.tokenExpiry = now + response.data.expires_in * 1e3;
|
|
106
104
|
this.authenticated = true;
|
|
107
105
|
this.api.defaults.headers.common["Authorization"] = `Bearer ${this.accessToken}`;
|
|
108
|
-
|
|
109
|
-
} catch (error) {
|
|
110
|
-
console.error("[Auth] Authentication error:", error);
|
|
106
|
+
} catch {
|
|
111
107
|
throw new Error("Failed to authenticate with Reddit API");
|
|
112
108
|
}
|
|
113
109
|
}
|
|
@@ -139,8 +135,7 @@ var RedditClient = class {
|
|
|
139
135
|
createdUtc: data.created_utc,
|
|
140
136
|
profileUrl: `https://reddit.com/user/${data.name}`
|
|
141
137
|
};
|
|
142
|
-
} catch
|
|
143
|
-
console.error(`[Error] Failed to get user info for ${username}:`, error);
|
|
138
|
+
} catch {
|
|
144
139
|
throw new Error(`Failed to get user info for ${username}`);
|
|
145
140
|
}
|
|
146
141
|
}
|
|
@@ -161,8 +156,7 @@ var RedditClient = class {
|
|
|
161
156
|
subredditType: data.subreddit_type,
|
|
162
157
|
url: data.url
|
|
163
158
|
};
|
|
164
|
-
} catch
|
|
165
|
-
console.error(`[Error] Failed to get subreddit info for ${subredditName}:`, error);
|
|
159
|
+
} catch {
|
|
166
160
|
throw new Error(`Failed to get subreddit info for ${subredditName}`);
|
|
167
161
|
}
|
|
168
162
|
}
|
|
@@ -197,8 +191,7 @@ var RedditClient = class {
|
|
|
197
191
|
permalink: post.permalink
|
|
198
192
|
};
|
|
199
193
|
});
|
|
200
|
-
} catch
|
|
201
|
-
console.error(`[Error] Failed to get top posts for ${subreddit || "home"}:`, error);
|
|
194
|
+
} catch {
|
|
202
195
|
throw new Error(`Failed to get top posts for ${subreddit || "home"}`);
|
|
203
196
|
}
|
|
204
197
|
}
|
|
@@ -234,8 +227,7 @@ var RedditClient = class {
|
|
|
234
227
|
linkFlairText: post.link_flair_text,
|
|
235
228
|
permalink: post.permalink
|
|
236
229
|
};
|
|
237
|
-
} catch
|
|
238
|
-
console.error(`[Error] Failed to get post with ID ${postId}:`, error);
|
|
230
|
+
} catch {
|
|
239
231
|
throw new Error(`Failed to get post with ID ${postId}`);
|
|
240
232
|
}
|
|
241
233
|
}
|
|
@@ -246,8 +238,7 @@ var RedditClient = class {
|
|
|
246
238
|
params: { limit }
|
|
247
239
|
});
|
|
248
240
|
return response.data.data.children.map((child) => child.data.display_name);
|
|
249
|
-
} catch
|
|
250
|
-
console.error("[Error] Failed to get trending subreddits:", error);
|
|
241
|
+
} catch {
|
|
251
242
|
throw new Error("Failed to get trending subreddits");
|
|
252
243
|
}
|
|
253
244
|
}
|
|
@@ -274,8 +265,7 @@ var RedditClient = class {
|
|
|
274
265
|
} else {
|
|
275
266
|
throw new Error("Failed to create post");
|
|
276
267
|
}
|
|
277
|
-
} catch
|
|
278
|
-
console.error(`[Error] Failed to create post in ${subreddit}:`, error);
|
|
268
|
+
} catch {
|
|
279
269
|
throw new Error(`Failed to create post in ${subreddit}`);
|
|
280
270
|
}
|
|
281
271
|
}
|
|
@@ -319,8 +309,7 @@ var RedditClient = class {
|
|
|
319
309
|
isSubmitter: false,
|
|
320
310
|
permalink: commentData.permalink
|
|
321
311
|
};
|
|
322
|
-
} catch
|
|
323
|
-
console.error(`[Error] Failed to reply to post ${postId}:`, error);
|
|
312
|
+
} catch {
|
|
324
313
|
throw new Error(`Failed to reply to post ${postId}`);
|
|
325
314
|
}
|
|
326
315
|
}
|
|
@@ -578,7 +567,6 @@ async function getUserInfo(params) {
|
|
|
578
567
|
throw new import_types.McpError(import_types.ErrorCode.InternalError, "Reddit client not initialized");
|
|
579
568
|
}
|
|
580
569
|
try {
|
|
581
|
-
console.log(`[Tool] Getting info for u/${username}`);
|
|
582
570
|
const user = await client.getUser(username);
|
|
583
571
|
const formattedUser = formatUserInfo(user);
|
|
584
572
|
return {
|
|
@@ -608,8 +596,7 @@ async function getUserInfo(params) {
|
|
|
608
596
|
]
|
|
609
597
|
};
|
|
610
598
|
} catch (error) {
|
|
611
|
-
|
|
612
|
-
throw new import_types.McpError(import_types.ErrorCode.InternalError, `Failed to fetch user data: ${error}`);
|
|
599
|
+
throw new import_types.McpError(import_types.ErrorCode.InternalError, `Failed to fetch user data: ${String(error)}`);
|
|
613
600
|
}
|
|
614
601
|
}
|
|
615
602
|
|
|
@@ -622,7 +609,6 @@ async function getRedditPost(params) {
|
|
|
622
609
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
623
610
|
}
|
|
624
611
|
try {
|
|
625
|
-
console.log(`[Tool] Getting post ${post_id} from r/${subreddit}`);
|
|
626
612
|
const post = await client.getPost(post_id, subreddit);
|
|
627
613
|
const formattedPost = formatPostInfo(post);
|
|
628
614
|
return {
|
|
@@ -664,8 +650,7 @@ ${formattedPost.bestTimeToEngage}
|
|
|
664
650
|
]
|
|
665
651
|
};
|
|
666
652
|
} catch (error) {
|
|
667
|
-
|
|
668
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch post data: ${error}`);
|
|
653
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch post data: ${String(error)}`);
|
|
669
654
|
}
|
|
670
655
|
}
|
|
671
656
|
async function getTopPosts(params) {
|
|
@@ -675,7 +660,6 @@ async function getTopPosts(params) {
|
|
|
675
660
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
676
661
|
}
|
|
677
662
|
try {
|
|
678
|
-
console.log(`[Tool] Getting top posts from r/${subreddit}`);
|
|
679
663
|
const posts = await client.getTopPosts(subreddit, time_filter, limit);
|
|
680
664
|
const formattedPosts = posts.map(formatPostInfo);
|
|
681
665
|
const postSummaries = formattedPosts.map(
|
|
@@ -701,8 +685,7 @@ ${postSummaries}
|
|
|
701
685
|
]
|
|
702
686
|
};
|
|
703
687
|
} catch (error) {
|
|
704
|
-
|
|
705
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch top posts: ${error}`);
|
|
688
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to fetch top posts: ${String(error)}`);
|
|
706
689
|
}
|
|
707
690
|
}
|
|
708
691
|
async function createPost(params) {
|
|
@@ -712,7 +695,6 @@ async function createPost(params) {
|
|
|
712
695
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
713
696
|
}
|
|
714
697
|
try {
|
|
715
|
-
console.log(`[Tool] Creating ${is_self ? "text" : "link"} post in r/${subreddit}`);
|
|
716
698
|
const post = await client.createPost(subreddit, title, content, is_self);
|
|
717
699
|
const formattedPost = formatPostInfo(post);
|
|
718
700
|
return {
|
|
@@ -734,8 +716,7 @@ Your post has been successfully submitted to r/${formattedPost.subreddit}.
|
|
|
734
716
|
]
|
|
735
717
|
};
|
|
736
718
|
} catch (error) {
|
|
737
|
-
|
|
738
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to create post: ${error}`);
|
|
719
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to create post: ${String(error)}`);
|
|
739
720
|
}
|
|
740
721
|
}
|
|
741
722
|
async function replyToPost(params) {
|
|
@@ -745,7 +726,6 @@ async function replyToPost(params) {
|
|
|
745
726
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Reddit client not initialized");
|
|
746
727
|
}
|
|
747
728
|
try {
|
|
748
|
-
console.log(`[Tool] Replying to post ${post_id}`);
|
|
749
729
|
const comment = await client.replyToPost(post_id, content);
|
|
750
730
|
const formattedComment = formatCommentInfo(comment);
|
|
751
731
|
return {
|
|
@@ -767,8 +747,7 @@ Your reply has been successfully posted.
|
|
|
767
747
|
]
|
|
768
748
|
};
|
|
769
749
|
} catch (error) {
|
|
770
|
-
|
|
771
|
-
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to reply to post: ${error}`);
|
|
750
|
+
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, `Failed to reply to post: ${String(error)}`);
|
|
772
751
|
}
|
|
773
752
|
}
|
|
774
753
|
|
|
@@ -781,7 +760,6 @@ async function getSubredditInfo(params) {
|
|
|
781
760
|
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, "Reddit client not initialized");
|
|
782
761
|
}
|
|
783
762
|
try {
|
|
784
|
-
console.log(`[Tool] Getting info for r/${subreddit_name}`);
|
|
785
763
|
const subreddit = await client.getSubredditInfo(subreddit_name);
|
|
786
764
|
const formattedSubreddit = formatSubredditInfo(subreddit);
|
|
787
765
|
return {
|
|
@@ -821,8 +799,7 @@ ${formattedSubreddit.description.full}
|
|
|
821
799
|
]
|
|
822
800
|
};
|
|
823
801
|
} catch (error) {
|
|
824
|
-
|
|
825
|
-
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch subreddit data: ${error}`);
|
|
802
|
+
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch subreddit data: ${String(error)}`);
|
|
826
803
|
}
|
|
827
804
|
}
|
|
828
805
|
async function getTrendingSubreddits() {
|
|
@@ -831,7 +808,6 @@ async function getTrendingSubreddits() {
|
|
|
831
808
|
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, "Reddit client not initialized");
|
|
832
809
|
}
|
|
833
810
|
try {
|
|
834
|
-
console.log("[Tool] Getting trending subreddits");
|
|
835
811
|
const trendingSubreddits = await client.getTrendingSubreddits();
|
|
836
812
|
return {
|
|
837
813
|
content: [
|
|
@@ -846,8 +822,7 @@ ${trendingSubreddits.map((subreddit, index) => `${index + 1}. r/${subreddit}`).j
|
|
|
846
822
|
]
|
|
847
823
|
};
|
|
848
824
|
} catch (error) {
|
|
849
|
-
|
|
850
|
-
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch trending subreddits: ${error}`);
|
|
825
|
+
throw new import_types3.McpError(import_types3.ErrorCode.InternalError, `Failed to fetch trending subreddits: ${String(error)}`);
|
|
851
826
|
}
|
|
852
827
|
}
|
|
853
828
|
|
|
@@ -857,8 +832,6 @@ import_dotenv.default.config();
|
|
|
857
832
|
var RedditServer = class {
|
|
858
833
|
server;
|
|
859
834
|
constructor() {
|
|
860
|
-
console.log("[Setup] Initializing Reddit Server...");
|
|
861
|
-
this.initializeRedditClient();
|
|
862
835
|
this.server = new import_server.Server(
|
|
863
836
|
{
|
|
864
837
|
name: "reddit-mcp-server",
|
|
@@ -870,8 +843,15 @@ var RedditServer = class {
|
|
|
870
843
|
}
|
|
871
844
|
}
|
|
872
845
|
);
|
|
846
|
+
this.initializeRedditClient();
|
|
873
847
|
this.setupToolHandlers();
|
|
874
|
-
this.server.onerror = (error) =>
|
|
848
|
+
this.server.onerror = async (error) => {
|
|
849
|
+
await this.server.sendLoggingMessage({
|
|
850
|
+
level: "error",
|
|
851
|
+
logger: "reddit-server",
|
|
852
|
+
data: `Server error: ${error}`
|
|
853
|
+
});
|
|
854
|
+
};
|
|
875
855
|
process.on("SIGINT", async () => {
|
|
876
856
|
await this.server.close();
|
|
877
857
|
process.exit(0);
|
|
@@ -897,12 +877,6 @@ var RedditServer = class {
|
|
|
897
877
|
username,
|
|
898
878
|
password
|
|
899
879
|
});
|
|
900
|
-
console.log("[Setup] Reddit client initialized");
|
|
901
|
-
if (username && password) {
|
|
902
|
-
console.log(`[Setup] Authenticated as user: ${username}`);
|
|
903
|
-
} else {
|
|
904
|
-
console.log("[Setup] Running in read-only mode (no user authentication)");
|
|
905
|
-
}
|
|
906
880
|
} catch (error) {
|
|
907
881
|
console.error("[Error] Failed to initialize Reddit client:", error);
|
|
908
882
|
process.exit(1);
|
|
@@ -1055,7 +1029,11 @@ var RedditServer = class {
|
|
|
1055
1029
|
try {
|
|
1056
1030
|
const toolName = request.params.name;
|
|
1057
1031
|
const toolParams = request.params.arguments || {};
|
|
1058
|
-
|
|
1032
|
+
await this.server.sendLoggingMessage({
|
|
1033
|
+
level: "debug",
|
|
1034
|
+
logger: "reddit-server",
|
|
1035
|
+
data: `Tool call: ${toolName}`
|
|
1036
|
+
});
|
|
1059
1037
|
switch (toolName) {
|
|
1060
1038
|
case "test_reddit_mcp_server":
|
|
1061
1039
|
return {
|
|
@@ -1091,7 +1069,11 @@ var RedditServer = class {
|
|
|
1091
1069
|
}
|
|
1092
1070
|
} catch (error) {
|
|
1093
1071
|
if (error instanceof Error) {
|
|
1094
|
-
|
|
1072
|
+
await this.server.sendLoggingMessage({
|
|
1073
|
+
level: "error",
|
|
1074
|
+
logger: "reddit-server",
|
|
1075
|
+
data: `Error calling tool: ${error.message}`
|
|
1076
|
+
});
|
|
1095
1077
|
throw new import_types4.McpError(import_types4.ErrorCode.InternalError, `Failed to fetch data: ${error.message}`);
|
|
1096
1078
|
}
|
|
1097
1079
|
throw error;
|
|
@@ -1101,7 +1083,18 @@ var RedditServer = class {
|
|
|
1101
1083
|
async run() {
|
|
1102
1084
|
const transport = new import_stdio.StdioServerTransport();
|
|
1103
1085
|
await this.server.connect(transport);
|
|
1104
|
-
|
|
1086
|
+
await this.server.sendLoggingMessage({
|
|
1087
|
+
level: "info",
|
|
1088
|
+
logger: "reddit-server",
|
|
1089
|
+
data: "Reddit MCP Server is running"
|
|
1090
|
+
});
|
|
1091
|
+
const username = process.env.REDDIT_USERNAME;
|
|
1092
|
+
const password = process.env.REDDIT_PASSWORD;
|
|
1093
|
+
await this.server.sendLoggingMessage({
|
|
1094
|
+
level: "info",
|
|
1095
|
+
logger: "reddit-server",
|
|
1096
|
+
data: username && password ? `Authenticated as user: ${username}` : "Running in read-only mode (no user authentication)"
|
|
1097
|
+
});
|
|
1105
1098
|
}
|
|
1106
1099
|
};
|
|
1107
1100
|
if (require.main === module) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reddit-mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A Model Context Protocol (MCP) that provides tools for fetching and creating Reddit content. Fork of the alexandros-lekkas/reddit-mcp-server.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"author": "Jordan Burke <jordan.burke@gmail.com>",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@modelcontextprotocol/sdk": "^1.13.
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1.13.2",
|
|
19
19
|
"axios": "^1.10.0",
|
|
20
|
-
"dotenv": "^16.
|
|
20
|
+
"dotenv": "^16.6.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@eslint/js": "^9.29.0",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"eslint": "^9.29.0",
|
|
28
28
|
"eslint-config-prettier": "^10.1.5",
|
|
29
29
|
"eslint-plugin-prettier": "^5.5.1",
|
|
30
|
-
"prettier": "^3.6.
|
|
30
|
+
"prettier": "^3.6.2",
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
32
|
"typescript": "^5.8.3"
|
|
33
33
|
},
|
package/src/bin.ts
CHANGED
|
@@ -52,12 +52,12 @@ export class RedditClient {
|
|
|
52
52
|
const authData = new URLSearchParams()
|
|
53
53
|
|
|
54
54
|
if (this.username && this.password) {
|
|
55
|
-
|
|
55
|
+
// Authenticating with user credentials
|
|
56
56
|
authData.append("grant_type", "password")
|
|
57
57
|
authData.append("username", this.username)
|
|
58
58
|
authData.append("password", this.password)
|
|
59
59
|
} else {
|
|
60
|
-
|
|
60
|
+
// Authenticating with client credentials (read-only)
|
|
61
61
|
authData.append("grant_type", "client_credentials")
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -77,9 +77,9 @@ export class RedditClient {
|
|
|
77
77
|
this.authenticated = true
|
|
78
78
|
this.api.defaults.headers.common["Authorization"] = `Bearer ${this.accessToken}`
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
} catch
|
|
82
|
-
|
|
80
|
+
// Successfully authenticated with Reddit API
|
|
81
|
+
} catch {
|
|
82
|
+
// Authentication error occurred
|
|
83
83
|
throw new Error("Failed to authenticate with Reddit API")
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -114,8 +114,8 @@ export class RedditClient {
|
|
|
114
114
|
createdUtc: data.created_utc,
|
|
115
115
|
profileUrl: `https://reddit.com/user/${data.name}`,
|
|
116
116
|
}
|
|
117
|
-
} catch
|
|
118
|
-
|
|
117
|
+
} catch {
|
|
118
|
+
// Failed to get user info
|
|
119
119
|
throw new Error(`Failed to get user info for ${username}`)
|
|
120
120
|
}
|
|
121
121
|
}
|
|
@@ -138,8 +138,8 @@ export class RedditClient {
|
|
|
138
138
|
subredditType: data.subreddit_type,
|
|
139
139
|
url: data.url,
|
|
140
140
|
}
|
|
141
|
-
} catch
|
|
142
|
-
|
|
141
|
+
} catch {
|
|
142
|
+
// Failed to get subreddit info
|
|
143
143
|
throw new Error(`Failed to get subreddit info for ${subredditName}`)
|
|
144
144
|
}
|
|
145
145
|
}
|
|
@@ -176,8 +176,8 @@ export class RedditClient {
|
|
|
176
176
|
permalink: post.permalink,
|
|
177
177
|
}
|
|
178
178
|
})
|
|
179
|
-
} catch
|
|
180
|
-
|
|
179
|
+
} catch {
|
|
180
|
+
// Failed to get top posts
|
|
181
181
|
throw new Error(`Failed to get top posts for ${subreddit || "home"}`)
|
|
182
182
|
}
|
|
183
183
|
}
|
|
@@ -219,8 +219,8 @@ export class RedditClient {
|
|
|
219
219
|
linkFlairText: post.link_flair_text,
|
|
220
220
|
permalink: post.permalink,
|
|
221
221
|
}
|
|
222
|
-
} catch
|
|
223
|
-
|
|
222
|
+
} catch {
|
|
223
|
+
// Failed to get post
|
|
224
224
|
throw new Error(`Failed to get post with ID ${postId}`)
|
|
225
225
|
}
|
|
226
226
|
}
|
|
@@ -233,8 +233,8 @@ export class RedditClient {
|
|
|
233
233
|
})
|
|
234
234
|
|
|
235
235
|
return response.data.data.children.map((child: any) => child.data.display_name)
|
|
236
|
-
} catch
|
|
237
|
-
|
|
236
|
+
} catch {
|
|
237
|
+
// Failed to get trending subreddits
|
|
238
238
|
throw new Error("Failed to get trending subreddits")
|
|
239
239
|
}
|
|
240
240
|
}
|
|
@@ -267,8 +267,8 @@ export class RedditClient {
|
|
|
267
267
|
} else {
|
|
268
268
|
throw new Error("Failed to create post")
|
|
269
269
|
}
|
|
270
|
-
} catch
|
|
271
|
-
|
|
270
|
+
} catch {
|
|
271
|
+
// Failed to create post
|
|
272
272
|
throw new Error(`Failed to create post in ${subreddit}`)
|
|
273
273
|
}
|
|
274
274
|
}
|
|
@@ -320,8 +320,8 @@ export class RedditClient {
|
|
|
320
320
|
isSubmitter: false,
|
|
321
321
|
permalink: commentData.permalink,
|
|
322
322
|
}
|
|
323
|
-
} catch
|
|
324
|
-
|
|
323
|
+
} catch {
|
|
324
|
+
// Failed to reply to post
|
|
325
325
|
throw new Error(`Failed to reply to post ${postId}`)
|
|
326
326
|
}
|
|
327
327
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,11 +12,6 @@ class RedditServer {
|
|
|
12
12
|
private server: Server
|
|
13
13
|
|
|
14
14
|
constructor() {
|
|
15
|
-
console.error("[Setup] Initializing Reddit Server...")
|
|
16
|
-
|
|
17
|
-
// Initialize the Reddit client
|
|
18
|
-
this.initializeRedditClient()
|
|
19
|
-
|
|
20
15
|
this.server = new Server(
|
|
21
16
|
{
|
|
22
17
|
name: "reddit-mcp-server",
|
|
@@ -29,9 +24,19 @@ class RedditServer {
|
|
|
29
24
|
},
|
|
30
25
|
)
|
|
31
26
|
|
|
27
|
+
// Initialize the Reddit client
|
|
28
|
+
this.initializeRedditClient()
|
|
29
|
+
|
|
32
30
|
this.setupToolHandlers()
|
|
33
31
|
|
|
34
|
-
this.server.onerror = (error) =>
|
|
32
|
+
this.server.onerror = async (error) => {
|
|
33
|
+
await this.server.sendLoggingMessage({
|
|
34
|
+
level: "error",
|
|
35
|
+
logger: "reddit-server",
|
|
36
|
+
data: `Server error: ${error}`,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
process.on("SIGINT", async () => {
|
|
36
41
|
await this.server.close()
|
|
37
42
|
process.exit(0)
|
|
@@ -46,6 +51,8 @@ class RedditServer {
|
|
|
46
51
|
const password = process.env.REDDIT_PASSWORD
|
|
47
52
|
|
|
48
53
|
if (!clientId || !clientSecret) {
|
|
54
|
+
// Can't use server logging here as server isn't initialized yet
|
|
55
|
+
// Using console.error is OK for startup failures
|
|
49
56
|
console.error(
|
|
50
57
|
"[Error] Missing required Reddit API credentials. Please set REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET environment variables.",
|
|
51
58
|
)
|
|
@@ -61,13 +68,9 @@ class RedditServer {
|
|
|
61
68
|
password,
|
|
62
69
|
})
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
if (username && password) {
|
|
66
|
-
console.error(`[Setup] Authenticated as user: ${username}`)
|
|
67
|
-
} else {
|
|
68
|
-
console.error("[Setup] Running in read-only mode (no user authentication)")
|
|
69
|
-
}
|
|
71
|
+
// Client initialized successfully
|
|
70
72
|
} catch (error) {
|
|
73
|
+
// Can't use server logging here as server isn't connected yet
|
|
71
74
|
console.error("[Error] Failed to initialize Reddit client:", error)
|
|
72
75
|
process.exit(1)
|
|
73
76
|
}
|
|
@@ -222,7 +225,12 @@ class RedditServer {
|
|
|
222
225
|
const toolName = request.params.name
|
|
223
226
|
const toolParams = request.params.arguments || {}
|
|
224
227
|
|
|
225
|
-
|
|
228
|
+
// Log tool call
|
|
229
|
+
await this.server.sendLoggingMessage({
|
|
230
|
+
level: "debug",
|
|
231
|
+
logger: "reddit-server",
|
|
232
|
+
data: `Tool call: ${toolName}`,
|
|
233
|
+
})
|
|
226
234
|
|
|
227
235
|
switch (toolName) {
|
|
228
236
|
case "test_reddit_mcp_server":
|
|
@@ -280,7 +288,11 @@ class RedditServer {
|
|
|
280
288
|
}
|
|
281
289
|
} catch (error: unknown) {
|
|
282
290
|
if (error instanceof Error) {
|
|
283
|
-
|
|
291
|
+
await this.server.sendLoggingMessage({
|
|
292
|
+
level: "error",
|
|
293
|
+
logger: "reddit-server",
|
|
294
|
+
data: `Error calling tool: ${error.message}`,
|
|
295
|
+
})
|
|
284
296
|
|
|
285
297
|
throw new McpError(ErrorCode.InternalError, `Failed to fetch data: ${error.message}`)
|
|
286
298
|
}
|
|
@@ -293,7 +305,25 @@ class RedditServer {
|
|
|
293
305
|
async run() {
|
|
294
306
|
const transport = new StdioServerTransport()
|
|
295
307
|
await this.server.connect(transport)
|
|
296
|
-
|
|
308
|
+
|
|
309
|
+
// Log server startup
|
|
310
|
+
await this.server.sendLoggingMessage({
|
|
311
|
+
level: "info",
|
|
312
|
+
logger: "reddit-server",
|
|
313
|
+
data: "Reddit MCP Server is running",
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
// Log authentication status
|
|
317
|
+
const username = process.env.REDDIT_USERNAME
|
|
318
|
+
const password = process.env.REDDIT_PASSWORD
|
|
319
|
+
await this.server.sendLoggingMessage({
|
|
320
|
+
level: "info",
|
|
321
|
+
logger: "reddit-server",
|
|
322
|
+
data:
|
|
323
|
+
username && password
|
|
324
|
+
? `Authenticated as user: ${username}`
|
|
325
|
+
: "Running in read-only mode (no user authentication)",
|
|
326
|
+
})
|
|
297
327
|
}
|
|
298
328
|
}
|
|
299
329
|
|
package/src/tools/post-tools.ts
CHANGED
|
@@ -11,7 +11,7 @@ export async function getRedditPost(params: { subreddit: string; post_id: string
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
// Getting post
|
|
15
15
|
const post = await client.getPost(post_id, subreddit)
|
|
16
16
|
const formattedPost = formatPostInfo(post)
|
|
17
17
|
|
|
@@ -54,8 +54,8 @@ ${formattedPost.bestTimeToEngage}
|
|
|
54
54
|
],
|
|
55
55
|
}
|
|
56
56
|
} catch (error) {
|
|
57
|
-
|
|
58
|
-
throw new McpError(ErrorCode.InternalError, `Failed to fetch post data: ${error}`)
|
|
57
|
+
// Error will be logged by the server
|
|
58
|
+
throw new McpError(ErrorCode.InternalError, `Failed to fetch post data: ${String(error)}`)
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ export async function getTopPosts(params: { subreddit: string; time_filter?: str
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
try {
|
|
71
|
-
|
|
71
|
+
// Getting top posts
|
|
72
72
|
const posts = await client.getTopPosts(subreddit, time_filter, limit)
|
|
73
73
|
const formattedPosts = posts.map(formatPostInfo)
|
|
74
74
|
|
|
@@ -98,8 +98,8 @@ ${postSummaries}
|
|
|
98
98
|
],
|
|
99
99
|
}
|
|
100
100
|
} catch (error) {
|
|
101
|
-
|
|
102
|
-
throw new McpError(ErrorCode.InternalError, `Failed to fetch top posts: ${error}`)
|
|
101
|
+
// Error will be logged by the server
|
|
102
|
+
throw new McpError(ErrorCode.InternalError, `Failed to fetch top posts: ${String(error)}`)
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -112,7 +112,7 @@ export async function createPost(params: { subreddit: string; title: string; con
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
try {
|
|
115
|
-
|
|
115
|
+
// Creating post
|
|
116
116
|
const post = await client.createPost(subreddit, title, content, is_self)
|
|
117
117
|
const formattedPost = formatPostInfo(post)
|
|
118
118
|
|
|
@@ -135,8 +135,8 @@ Your post has been successfully submitted to r/${formattedPost.subreddit}.
|
|
|
135
135
|
],
|
|
136
136
|
}
|
|
137
137
|
} catch (error) {
|
|
138
|
-
|
|
139
|
-
throw new McpError(ErrorCode.InternalError, `Failed to create post: ${error}`)
|
|
138
|
+
// Error will be logged by the server
|
|
139
|
+
throw new McpError(ErrorCode.InternalError, `Failed to create post: ${String(error)}`)
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -149,7 +149,7 @@ export async function replyToPost(params: { post_id: string; content: string; su
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
try {
|
|
152
|
-
|
|
152
|
+
// Replying to post
|
|
153
153
|
const comment = await client.replyToPost(post_id, content)
|
|
154
154
|
const formattedComment = formatCommentInfo(comment)
|
|
155
155
|
|
|
@@ -172,7 +172,7 @@ Your reply has been successfully posted.
|
|
|
172
172
|
],
|
|
173
173
|
}
|
|
174
174
|
} catch (error) {
|
|
175
|
-
|
|
176
|
-
throw new McpError(ErrorCode.InternalError, `Failed to reply to post: ${error}`)
|
|
175
|
+
// Error will be logged by the server
|
|
176
|
+
throw new McpError(ErrorCode.InternalError, `Failed to reply to post: ${String(error)}`)
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -11,7 +11,7 @@ export async function getSubredditInfo(params: { subreddit_name: string }) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
// Getting subreddit info
|
|
15
15
|
const subreddit = await client.getSubredditInfo(subreddit_name)
|
|
16
16
|
const formattedSubreddit = formatSubredditInfo(subreddit)
|
|
17
17
|
|
|
@@ -56,8 +56,8 @@ ${formattedSubreddit.description.full}
|
|
|
56
56
|
],
|
|
57
57
|
}
|
|
58
58
|
} catch (error) {
|
|
59
|
-
|
|
60
|
-
throw new McpError(ErrorCode.InternalError, `Failed to fetch subreddit data: ${error}`)
|
|
59
|
+
// Error will be logged by the server
|
|
60
|
+
throw new McpError(ErrorCode.InternalError, `Failed to fetch subreddit data: ${String(error)}`)
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -69,7 +69,7 @@ export async function getTrendingSubreddits() {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
try {
|
|
72
|
-
|
|
72
|
+
// Getting trending subreddits
|
|
73
73
|
const trendingSubreddits = await client.getTrendingSubreddits()
|
|
74
74
|
|
|
75
75
|
return {
|
|
@@ -85,7 +85,7 @@ ${trendingSubreddits.map((subreddit, index) => `${index + 1}. r/${subreddit}`).j
|
|
|
85
85
|
],
|
|
86
86
|
}
|
|
87
87
|
} catch (error) {
|
|
88
|
-
|
|
89
|
-
throw new McpError(ErrorCode.InternalError, `Failed to fetch trending subreddits: ${error}`)
|
|
88
|
+
// Error will be logged by the server
|
|
89
|
+
throw new McpError(ErrorCode.InternalError, `Failed to fetch trending subreddits: ${String(error)}`)
|
|
90
90
|
}
|
|
91
91
|
}
|
package/src/tools/user-tools.ts
CHANGED
|
@@ -11,7 +11,7 @@ export async function getUserInfo(params: { username: string }) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
// Getting user info
|
|
15
15
|
const user = await client.getUser(username)
|
|
16
16
|
const formattedUser = formatUserInfo(user)
|
|
17
17
|
|
|
@@ -42,7 +42,7 @@ export async function getUserInfo(params: { username: string }) {
|
|
|
42
42
|
],
|
|
43
43
|
}
|
|
44
44
|
} catch (error) {
|
|
45
|
-
|
|
46
|
-
throw new McpError(ErrorCode.InternalError, `Failed to fetch user data: ${error}`)
|
|
45
|
+
// Error will be logged by the server
|
|
46
|
+
throw new McpError(ErrorCode.InternalError, `Failed to fetch user data: ${String(error)}`)
|
|
47
47
|
}
|
|
48
48
|
}
|