Add discord_list_guilds tool to list bot's guild memberships
Co-authored-by: SootyOwl <7614538+SootyOwl@users.noreply.github.com>
This commit is contained in:
parent
6310e9dadc
commit
9cdafc31c0
|
|
@ -130,3 +130,5 @@ export const DeleteWebhookSchema = z.object({
|
|||
webhookToken: z.string().optional(),
|
||||
reason: z.string().optional()
|
||||
});
|
||||
|
||||
export const ListGuildsSchema = z.object({});
|
||||
|
|
@ -29,7 +29,8 @@ import {
|
|||
deleteWebhookHandler,
|
||||
createCategoryHandler,
|
||||
editCategoryHandler,
|
||||
deleteCategoryHandler
|
||||
deleteCategoryHandler,
|
||||
listGuildsHandler
|
||||
} from './tools/tools.js';
|
||||
import { MCPTransport } from './transport.js';
|
||||
import { info, error } from './logger.js';
|
||||
|
|
@ -178,6 +179,11 @@ export class DiscordMCPServer {
|
|||
toolResponse = await deleteWebhookHandler(args, this.toolContext);
|
||||
return toolResponse;
|
||||
|
||||
case "discord_list_guilds":
|
||||
this.logClientState("before discord_list_guilds handler");
|
||||
toolResponse = await listGuildsHandler(args, this.toolContext);
|
||||
return toolResponse;
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown tool: ${name}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -292,5 +292,14 @@ export const toolList = [
|
|||
},
|
||||
required: ["webhookId"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "discord_list_guilds",
|
||||
description: "Lists all Discord servers (guilds) the bot is a member of",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: []
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
@ -8,7 +8,8 @@ import {
|
|||
GetServerInfoSchema,
|
||||
CreateCategorySchema,
|
||||
EditCategorySchema,
|
||||
DeleteCategorySchema
|
||||
DeleteCategorySchema,
|
||||
ListGuildsSchema
|
||||
} from "../schemas.js";
|
||||
import { handleDiscordError } from "../errorHandler.js";
|
||||
|
||||
|
|
@ -356,3 +357,39 @@ export async function getServerInfoHandler(
|
|||
return handleDiscordError(error);
|
||||
}
|
||||
}
|
||||
|
||||
// List guilds handler
|
||||
export async function listGuildsHandler(
|
||||
args: unknown,
|
||||
context: ToolContext
|
||||
): Promise<ToolResponse> {
|
||||
ListGuildsSchema.parse(args);
|
||||
try {
|
||||
if (!context.client.isReady()) {
|
||||
return {
|
||||
content: [{ type: "text", text: "Discord client not logged in." }],
|
||||
isError: true
|
||||
};
|
||||
}
|
||||
|
||||
const guilds = await context.client.guilds.fetch();
|
||||
|
||||
if (guilds.size === 0) {
|
||||
return {
|
||||
content: [{ type: "text", text: "No guilds found. The bot is not a member of any servers." }]
|
||||
};
|
||||
}
|
||||
|
||||
const guildsInfo = guilds.map(guild => ({
|
||||
id: guild.id,
|
||||
name: guild.name,
|
||||
icon: guild.iconURL()
|
||||
}));
|
||||
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(guildsInfo, null, 2) }]
|
||||
};
|
||||
} catch (error) {
|
||||
return handleDiscordError(error);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,8 @@ import {
|
|||
getServerInfoHandler,
|
||||
createCategoryHandler,
|
||||
editCategoryHandler,
|
||||
deleteCategoryHandler
|
||||
deleteCategoryHandler,
|
||||
listGuildsHandler
|
||||
} from './channel.js';
|
||||
import {
|
||||
addReactionHandler,
|
||||
|
|
@ -55,7 +56,8 @@ export {
|
|||
deleteWebhookHandler,
|
||||
createCategoryHandler,
|
||||
editCategoryHandler,
|
||||
deleteCategoryHandler
|
||||
deleteCategoryHandler,
|
||||
listGuildsHandler
|
||||
};
|
||||
|
||||
// Export common types
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ import {
|
|||
deleteWebhookHandler,
|
||||
editCategoryHandler,
|
||||
createCategoryHandler,
|
||||
deleteCategoryHandler
|
||||
deleteCategoryHandler,
|
||||
listGuildsHandler
|
||||
} from './tools/tools.js';
|
||||
import { Client, GatewayIntentBits } from "discord.js";
|
||||
import { info, error } from './logger.js';
|
||||
|
|
|
|||
Loading…
Reference in New Issue