Skip to main content
Glama

discord_login

Authenticate on Discord using a configured token to enable AI assistants to interact with servers, send messages, manage channels, and handle reactions via MCP-Discord.

Instructions

Logs in to Discord using the configured token

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenNo

Implementation Reference

  • The primary handler function for the 'discord_login' tool. It validates input with DiscordLoginSchema, checks if already logged in, uses provided or existing token to login the Discord client, waits for ready state using waitForReady helper, and returns success/error responses.
    export const loginHandler: ToolHandler = async (args, context) => {
      DiscordLoginSchema.parse(args);
      try {
            // Check if client is already logged in
            if (context.client.isReady()) {
              return {
                content: [{ type: "text", text: `Already logged in as: ${context.client.user?.tag}` }]
              };
            }
            
            // Use token from args if provided, otherwise fall back to the client's token
            const token = args.token || context.client.token;
            
            // Check if we have a token to use
            if (!token) {
              return {
                content: [{ type: "text", text: "Discord token not provided and not configured. Cannot log in. Please check the following: 1. Provide a token in the login command or make sure the token is correctly set in your config or environment variables. 2. Ensure all required privileged intents (Message Content, Server Members, Presence) are enabled in the Discord Developer Portal for your bot application." }],
                isError: true
              };
            }
            
            // If token is provided in args, update the client's token
            if (args.token) {
              context.client.token = args.token;
            }
            
            // Attempt to log in with the token and get the ready client
            const readyClient = await waitForReady(context.client, token);
            // Update the context client with the ready client
            context.client = readyClient;
            return {
              content: [{ type: "text", text: `Successfully logged in to Discord: ${context.client.user?.tag}` }]
            };
      } catch (err) {
        error(`Error in login handler: ${err instanceof Error ? err.message : String(err)}`);
        return handleDiscordError(err);
      }
    }; 
  • Zod schema defining the input parameters for the discord_login tool: an optional 'token' string.
    export const DiscordLoginSchema = z.object({
        token: z.string().optional()
    });
  • src/toolList.ts:42-51 (registration)
    Tool registration entry in the MCP tool list, providing the name 'discord_login', description, and JSON schema for inputs, used by ListToolsRequestHandler.
    {
      name: "discord_login",
      description: "Logs in to Discord using the configured token",
      inputSchema: {
        type: "object",
        properties: {
          token: { type: "string" }
        },
        required: []
      }
  • src/server.ts:89-91 (registration)
    Dispatch/registration in the CallToolRequestHandler switch statement, mapping 'discord_login' tool name to the loginHandler execution.
    case "discord_login": toolResponse = await loginHandler(args, this.toolContext);
      this.logClientState("after discord_login handler");
      return toolResponse;
  • Helper function to wait for Discord client to be ready after login, with timeout, error handling, and immediate resolution if already ready.
    async function waitForReady(client: Client, token: string, timeoutMs = 30000): Promise<Client> {
      return new Promise((resolve, reject) => {
        // Set a timeout to prevent hanging if ready event never fires
        const timeout = setTimeout(() => {
          reject(new Error(`Client ready event timed out after ${timeoutMs}ms`));
        }, timeoutMs);
        
        // If client is already ready, resolve immediately
        if (client.isReady()) {
          clearTimeout(timeout);
          resolve(client);
          return;
        }
        
        // Listen for ready event
        const readyHandler = () => {
          info('Client ready event received');
          clearTimeout(timeout);
          resolve(client);
        };
        
        // Listen for error event
        const errorHandler = (err: Error) => {
          clearTimeout(timeout);
          client.removeListener('ready', readyHandler);
          reject(err);
        };
        
        // Attach listeners
        client.once('ready', readyHandler);
        client.once('error', errorHandler);
        
        // Start login process
        info('Starting login process and waiting for ready event');
        client.login(token).catch((err: Error) => {
          clearTimeout(timeout);
          client.removeListener('ready', readyHandler);
          client.removeListener('error', errorHandler);
          reject(err);
        });
      });
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action but doesn't describe what 'logging in' entails operationally - whether it establishes a session, what permissions are required, whether it's idempotent, what happens on failure, or what the expected outcome looks like. For an authentication tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a simple authentication tool and front-loads the core purpose immediately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an authentication tool with no annotations, no output schema, and 0% schema description coverage, the description is incomplete. It doesn't explain the authentication mechanism, session management, error conditions, or what successful login enables. Given the complexity of authentication and the lack of structured documentation, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for the undocumented 'token' parameter. While it mentions 'using the configured token', it doesn't explain what format the token should be, where to obtain it, whether it's optional or required despite the schema saying required: [], or what happens if no token is provided. The description adds minimal value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Logs in') and resource ('to Discord'), specifying the action and target. It distinguishes from siblings by focusing on authentication rather than content manipulation. However, it doesn't explicitly differentiate from potential alternative login methods.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions 'using the configured token' but doesn't clarify if this is required before other Discord operations, what happens if already logged in, or whether there are other authentication methods available.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/barryyip0625/mcp-discord'

If you have feedback or need assistance with the MCP directory API, please join our Discord server