feat: remove discord_login tool and update dockerfile

This commit is contained in:
IAPP-BY 2025-06-03 13:43:38 +08:00
parent 158b19cf58
commit 2758ce00fb
10 changed files with 31 additions and 75 deletions

View File

@ -19,5 +19,5 @@ RUN npm run build
# Expose HTTP port
EXPOSE 8080
# Default command to run the MCP server with HTTP transport
CMD ["node", "build/index.js", "--transport", "http", "--port", "8080"]
# Default command to run the MCP server with HTTP transport and Discord token
CMD ["node", "build/index.js", "--transport", "http", "--port", "8080", "--config", "{\"DISCORD_TOKEN\":\"${DISCORD_TOKEN}\"}"]

View File

@ -210,7 +210,6 @@ node build/index.js --transport http --port 3000 --config "your_discord_bot_toke
### Basic Functions
- `discord_login`: Login to Discord
- `discord_send`: Send a message to a specified channel (supports both channel ID and channel name)
- `discord_get_server_info`: Get Discord server information

View File

@ -83,11 +83,6 @@ export class DiscordMCPServer {
case "discord_delete_category":
toolResponse = await deleteCategoryHandler(args, this.toolContext);
return toolResponse;
case "discord_login":
toolResponse = await loginHandler(args, this.toolContext);
// Check the client state after login
this.logClientState("after discord_login handler");
return toolResponse;
case "discord_send":
this.logClientState("before discord_send handler");

View File

@ -39,17 +39,6 @@ export const toolList = [
required: ["categoryId"]
}
},
{
name: "discord_login",
description: "Logs in to Discord using the configured token",
inputSchema: {
type: "object",
properties: {
token: { type: "string" }
},
required: []
}
},
{
name: "discord_send",
description: "Sends a message to a specified Discord text channel",

View File

@ -21,7 +21,7 @@ export async function createCategoryHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -53,7 +53,7 @@ export async function editCategoryHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -86,7 +86,7 @@ export async function deleteCategoryHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -115,7 +115,7 @@ export async function createTextChannelHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -157,7 +157,7 @@ export async function deleteChannelHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -201,7 +201,7 @@ export async function readMessagesHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -270,7 +270,7 @@ export async function getServerInfoHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}

View File

@ -9,7 +9,7 @@ export const getForumChannelsHandler: ToolHandler = async (args, { client }) =>
try {
if (!client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -55,7 +55,7 @@ export const createForumPostHandler: ToolHandler = async (args, { client }) => {
try {
if (!client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -107,7 +107,7 @@ export const getForumPostHandler: ToolHandler = async (args, { client }) => {
try {
if (!client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -151,7 +151,7 @@ export const replyToForumHandler: ToolHandler = async (args, { client }) => {
try {
if (!client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -191,7 +191,7 @@ export const deleteForumPostHandler: ToolHandler = async (args, { client }) => {
try {
if (!client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}

View File

@ -17,7 +17,7 @@ export async function addReactionHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -61,7 +61,7 @@ export async function addMultipleReactionsHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -109,7 +109,7 @@ export async function removeReactionHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -176,7 +176,7 @@ export async function deleteMessageHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}

View File

@ -8,7 +8,7 @@ export const sendMessageHandler: ToolHandler = async (args, { client }) => {
try {
if (!client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}

View File

@ -17,7 +17,7 @@ export async function createWebhookHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -65,7 +65,7 @@ export async function sendWebhookMessageHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -106,7 +106,7 @@ export async function editWebhookHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}
@ -147,7 +147,7 @@ export async function deleteWebhookHandler(
try {
if (!context.client.isReady()) {
return {
content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }],
content: [{ type: "text", text: "Discord client not logged in." }],
isError: true
};
}

View File

@ -177,19 +177,6 @@ export class StreamableHttpTransport implements MCPTransport {
result = { tools: toolList };
break;
case 'discord_login':
result = await loginHandler(params, this.toolContext!);
// Log client state after login
info(`Client state after login: ${JSON.stringify({
isReady: this.toolContext!.client.isReady(),
hasToken: !!this.toolContext!.client.token,
user: this.toolContext!.client.user ? {
id: this.toolContext!.client.user.id,
tag: this.toolContext!.client.user.tag,
} : null
})}`);
break;
// Make sure Discord client is logged in for other Discord API tools
// but return a proper JSON-RPC error rather than throwing an exception
case 'discord_send':
@ -238,7 +225,7 @@ export class StreamableHttpTransport implements MCPTransport {
jsonrpc: '2.0',
error: {
code: -32603,
message: 'Discord client reconnect failed. Please use discord_login tool first.',
message: 'Discord client reconnect failed.',
},
id: req.body?.id || null,
});
@ -252,7 +239,7 @@ export class StreamableHttpTransport implements MCPTransport {
jsonrpc: '2.0',
error: {
code: -32603,
message: 'Discord client reconnect failed. Please use discord_login tool first.',
message: 'Discord client reconnect failed.',
},
id: req.body?.id || null,
});
@ -262,7 +249,7 @@ export class StreamableHttpTransport implements MCPTransport {
jsonrpc: '2.0',
error: {
code: -32603,
message: 'Discord client not logged in. Please use discord_login tool first.',
message: 'Discord client not logged in.',
},
id: req.body?.id || null,
});
@ -346,8 +333,7 @@ export class StreamableHttpTransport implements MCPTransport {
const toolArgs = params.arguments || {};
// Check if Discord client is logged in for Discord API tools
if (toolName !== 'discord_login' &&
toolName.startsWith('discord_') &&
if (toolName.startsWith('discord_') &&
!this.toolContext!.client.isReady()) {
error(`Client not ready for tool ${toolName}, client state: ${JSON.stringify({
isReady: this.toolContext!.client.isReady(),
@ -372,7 +358,7 @@ export class StreamableHttpTransport implements MCPTransport {
jsonrpc: '2.0',
error: {
code: -32603,
message: 'Discord client reconnect failed. Please use discord_login tool first.',
message: 'Discord client reconnect failed.',
},
id: req.body?.id || null,
});
@ -386,7 +372,7 @@ export class StreamableHttpTransport implements MCPTransport {
jsonrpc: '2.0',
error: {
code: -32603,
message: 'Discord client reconnect failed. Please use discord_login tool first.',
message: 'Discord client reconnect failed.',
},
id: req.body?.id || null,
});
@ -396,7 +382,7 @@ export class StreamableHttpTransport implements MCPTransport {
jsonrpc: '2.0',
error: {
code: -32603,
message: 'Discord client not logged in. Please use discord_login tool first.',
message: 'Discord client not logged in.',
},
id: req.body?.id || null,
});
@ -404,20 +390,7 @@ export class StreamableHttpTransport implements MCPTransport {
}
// Call the appropriate handler based on tool name
switch (toolName) {
case 'discord_login':
result = await loginHandler(toolArgs, this.toolContext!);
// Log client state after login
info(`Client state after login: ${JSON.stringify({
isReady: this.toolContext!.client.isReady(),
hasToken: !!this.toolContext!.client.token,
user: this.toolContext!.client.user ? {
id: this.toolContext!.client.user.id,
tag: this.toolContext!.client.user.tag,
} : null
})}`);
break;
switch (toolName) {
case 'discord_send':
result = await sendMessageHandler(toolArgs, this.toolContext!);
break;