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.
81 lines • 2.7 kB
JavaScript
import { formatToolResponse } from "./types.js";
import { RedditError } from "../../types/reddit.js";
import { sendRedditPostSuccessMessage } from "../../constants/tool/send-post.js";
const postResponseSchema = {
type: "object",
properties: {
status: { type: "string", enum: ["success", "error"] },
message: { type: "string" },
result: {
type: "object",
properties: {
response: {
type: "object",
properties: {
id: { type: "string" },
url: { type: "string" },
title: { type: "string" },
subreddit: { type: "string" },
permalink: { type: "string" },
},
required: ["id", "url", "title", "subreddit", "permalink"],
},
},
required: ["response"],
},
},
required: ["status", "message", "result"],
};
const responseSchema = {
type: "object",
properties: {
status: { type: "string", enum: ["success", "error"] },
message: { type: "string" },
result: {
type: "object",
properties: {
post: postResponseSchema,
},
required: ["post"],
},
},
required: ["status", "message", "result"],
};
export const handleSendPost = async (args, { redditService }) => {
if (!args.id) {
throw new RedditError("id is required for sending posts", "VALIDATION_ERROR");
}
try {
const { subreddit, title, content } = args;
if (!subreddit || !title || !content) {
throw new RedditError("Missing required fields", "VALIDATION_ERROR");
}
const postParams = {
subreddit,
title,
content,
};
const post = await redditService.createPost(postParams);
return formatToolResponse({
status: "success",
message: sendRedditPostSuccessMessage,
result: { post },
schema: responseSchema,
type: "server",
title: "Send Reddit Post",
});
}
catch (error) {
return formatToolResponse({
status: "error",
message: `Failed to send post: ${error instanceof Error ? error.message : "Unknown error"}`,
error: {
type: error instanceof RedditError ? error.type : "API_ERROR",
details: error,
},
type: "server",
title: "Error Sending Post",
});
}
};
//# sourceMappingURL=send-post.js.map