systemprompt-mcp-reddit
Version:
A specialized Model Context Protocol (MCP) server that enables you to search, read, and interact with Reddit content, leveraging an AI Agent to help with each operation.
148 lines (147 loc) • 5.2 kB
TypeScript
import { RedditPost, RedditPostParams, RedditPostResponse, RedditReplyParams, RedditReplyResponse, FetchPostsOptions, RedditPostWithComments, RedditNotification as ApiRedditNotification, FetchNotificationsOptions, FetchSubscribedSubredditsOptions, SubscribedSubreddit, RedditComment, RedditCommentThread, SubredditFlair } from "../../types/reddit.js";
import type { RedditConfigData } from "../../types/config.js";
export interface RedditCommentParams {
id: string;
text: string;
sendreplies?: boolean;
}
export interface RedditCommentResponse {
id: string;
text: string;
permalink: string;
}
export interface RedditMessageParams {
recipient: string;
subject: string;
content: string;
}
export interface RedditMessageResponse {
id: string;
recipient: string;
subject: string;
body: string;
}
/**
* Main service for interacting with the Reddit API
* Implements facade pattern to coordinate between specialized services
*/
export declare class RedditService {
private static instance;
private readonly baseUrl;
private readonly rateLimitDelay;
private initialized;
private authService;
private postService;
private subredditService;
private constructor();
static getInstance(): RedditService;
/**
* Loads configuration from environment variables
* @throws {RedditError} if required environment variables are missing
*/
private loadConfig;
/**
* Initialize the service and authenticate
* @throws {RedditError} if initialization fails
*/
initialize(): Promise<void>;
/**
* Fetches posts based on provided options
*/
fetchPosts(options: FetchPostsOptions): Promise<RedditPost[]>;
/**
* Creates a new post on Reddit
* @throws {RedditError} if post creation fails or validation fails
*/
createPost(params: RedditPostParams): Promise<RedditPostResponse>;
/**
* Fetches subreddit information and rules
*/
getSubredditInfo(subreddit: string): Promise<import("../../types/reddit.js").SubredditRequirements>;
/**
* Fetches a single Reddit post by its ID
* @param id The ID of the post to fetch
* @returns The fetched post with comments
*/
fetchPostById(id: string): Promise<RedditPostWithComments>;
/**
* Fetches user notifications (inbox items) from Reddit
* @param options Options for fetching notifications
* @returns Array of notifications
*/
fetchNotifications(options?: FetchNotificationsOptions): Promise<ApiRedditNotification[]>;
/**
* Fetches the list of subreddits the authenticated user is subscribed to
* @param options Options for fetching subscribed subreddits
* @returns Array of subscribed subreddits
*/
fetchSubscribedSubreddits(options?: FetchSubscribedSubredditsOptions): Promise<SubscribedSubreddit[]>;
fetchUserInfo(): Promise<{
id: any;
name: any;
created_utc: any;
comment_karma: any;
link_karma: any;
is_gold: any;
is_mod: any;
has_verified_email: any;
}>;
fetchUserPreferences(): Promise<{
enable_notifications: any;
show_nsfw: any;
default_comment_sort: any;
theme: any;
language: any;
}>;
/**
* Formats a notification for the config response
*/
private formatNotification;
/**
* Formats subreddit info for the config response
*/
private formatSubredditInfo;
/**
* Gets the complete Reddit configuration including user info, notifications,
* and subscribed subreddits
*/
getRedditConfig(): Promise<RedditConfigData>;
/**
* Search Reddit posts
*/
searchReddit(options: {
query: string;
subreddit?: string;
sort?: "relevance" | "hot" | "new" | "top";
time?: "hour" | "day" | "week" | "month" | "year" | "all";
limit?: number;
}): Promise<RedditPost[]>;
/**
* Fetches a single comment by its ID
* @param id The ID of the comment to fetch
* @returns The fetched comment
*/
fetchCommentById(id: string): Promise<RedditComment>;
/**
* Fetches a comment thread (comment with all its replies)
* @param id The ID of the post containing the comment
* @param id The ID of the comment to fetch
* @returns The comment thread with all replies
*/
fetchCommentThread(parentId: string, id: string): Promise<RedditCommentThread>;
/**
* Sends a reply to a post or comment
* @param params Reply parameters including parent ID and text
* @throws {RedditError} if reply fails or validation fails
*/
sendReply(params: RedditReplyParams): Promise<RedditReplyResponse>;
/**
* Fetches available post flairs for a subreddit
* @param subreddit The subreddit name (without r/ prefix)
* @returns Array of available flairs
*/
getSubredditFlairs(subreddit: string): Promise<SubredditFlair[]>;
sendComment(params: RedditCommentParams): Promise<RedditCommentResponse>;
sendMessage(params: RedditMessageParams): Promise<RedditMessageResponse>;
private checkInitialized;
}