mcp-discord-agent-comm
Version:
An MCP server enabling async communication between AI agents and users via Discord - perfect for long-running tasks requiring remote interaction
56 lines (55 loc) ⢠1.44 kB
JavaScript
import { z } from "zod";
import { getChannel } from "../utils.js";
export function requestInputTool(
server,
discord,
defaultChannelId,
defaultTimeout,
pendingRequests,
) {
server.tool(
"discord_request_input",
"Send a message and wait for a user response",
{
question: z.string().describe("The question to ask"),
timeout_seconds: z
.number()
.optional()
.describe("Timeout in seconds (default: 60)"),
channel_id: z
.string()
.optional()
.describe("Discord channel ID (optional)"),
},
async ({ question, timeout_seconds, channel_id }) => {
const timeout = (timeout_seconds || defaultTimeout) * 1000;
const channel = await getChannel(discord, channel_id, defaultChannelId);
const message = await channel.send(
`š **${question}**\n*Reply to this message to respond*`,
);
// Wait for response
const response = await new Promise((resolve, reject) => {
const timer = setTimeout(() => {
pendingRequests.delete(message.id);
message
.edit(`${message.content}\n\nā **Timed out**`)
.catch(() => {});
reject(new Error("Timeout"));
}, timeout);
pendingRequests.set(message.id, (value) => {
clearTimeout(timer);
resolve(value);
});
});
return {
content: [
{
type: "text",
text: JSON.stringify({ success: true, response }),
},
],
};
},
);
}
//# sourceMappingURL=request-input.js.map