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.
54 lines • 1.91 kB
JavaScript
import { PROMPTS } from "../constants/sampling/index.js";
import { injectVariablesIntoText } from "../utils/message-handlers.js";
export async function handleListPrompts(request) {
try {
if (!PROMPTS || !Array.isArray(PROMPTS)) {
throw new Error("Failed to fetch prompts");
}
return {
prompts: PROMPTS.map(({ messages, ...rest }) => rest),
};
}
catch (error) {
throw error;
}
}
export async function handleGetPrompt(request) {
try {
if (!PROMPTS || !Array.isArray(PROMPTS)) {
throw new Error("Failed to fetch prompts");
}
const foundPrompt = PROMPTS.find((p) => p.name === request.params.name);
if (!foundPrompt) {
throw new Error(`Prompt not found: ${request.params.name}`);
}
if (!foundPrompt.messages ||
!Array.isArray(foundPrompt.messages) ||
foundPrompt.messages.length === 0) {
throw new Error(`Messages not found for prompt: ${request.params.name}`);
}
const injectedMessages = foundPrompt.messages.map((message) => {
if (message.role === "user" && message.content.type === "text" && request.params.arguments) {
return {
role: message.role,
content: {
type: "text",
text: injectVariablesIntoText(message.content.text, request.params.arguments),
},
};
}
return message;
});
return {
name: foundPrompt.name,
description: foundPrompt.description,
arguments: foundPrompt.arguments || [],
messages: injectedMessages,
_meta: foundPrompt._meta,
};
}
catch (error) {
throw error;
}
}
//# sourceMappingURL=prompt-handlers.js.map