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.
74 lines • 3.48 kB
JavaScript
import { RedditService } from "../services/reddit/reddit-service.js";
import { TOOLS } from "../constants/tools.js";
import { TOOL_ERROR_MESSAGES } from "../constants/tools.js";
import { SystemPromptService } from "../services/systemprompt-service.js";
import { validateWithErrors } from "../utils/validation.js";
import { handleGetChannelPosts, handleGetNotifications, handleAnalyseSubreddit, handleCreateRedditPost, handleCreateRedditComment, handleSendPost, handleGetPost, handleConfigureInstructions, handleSearchReddit, handleSendComment, handleGetComment, handleDeleteContent, handleEditContent, } from "./tools/index.js";
import { handleCreateRedditMessage } from "./tools/create-message.js";
import { handleSendMessage } from "./tools/send-message.js";
export async function handleListTools(request) {
try {
let tools = [...TOOLS].sort((a, b) => a.name.localeCompare(b.name));
return { tools, _meta: { required: ["configure_instructions"] } };
}
catch (error) {
return { tools: TOOLS };
}
}
export async function handleToolCall(request) {
const redditService = RedditService.getInstance();
const systemPromptService = SystemPromptService.getInstance();
const context = {
redditService,
systemPromptService,
};
try {
if (!request.params.arguments) {
throw new Error("Arguments are required");
}
const tool = TOOLS.find((t) => t.name === request.params.name);
if (!tool) {
throw new Error(`${TOOL_ERROR_MESSAGES.UNKNOWN_TOOL} ${request.params.name}`);
}
validateWithErrors(request.params.arguments, tool.inputSchema);
const args = request.params.arguments;
switch (request.params.name) {
case "analyse_subreddit":
return await handleAnalyseSubreddit(args, context);
case "create_post":
return await handleCreateRedditPost(args, context);
case "create_comment":
return await handleCreateRedditComment(args, context);
case "create_message":
return await handleCreateRedditMessage(args, context);
case "configure_instructions":
return await handleConfigureInstructions(args, context);
case "delete_content":
return await handleDeleteContent(args, context);
case "edit_content":
return await handleEditContent(args, context);
case "get_post":
return await handleGetPost(args, context);
case "get_posts":
return await handleGetChannelPosts(args, context);
case "get_notifications":
return await handleGetNotifications(args, context);
case "get_comment":
return await handleGetComment(args, context);
case "send_comment":
return await handleSendComment(args, context);
case "send_post":
return await handleSendPost(args, context);
case "send_message":
return await handleSendMessage(args, context);
case "search_reddit":
return await handleSearchReddit(args, context);
default:
throw new Error(`${TOOL_ERROR_MESSAGES.UNKNOWN_TOOL} ${request.params.name}`);
}
}
catch (error) {
throw error;
}
}
//# sourceMappingURL=tool-handlers.js.map