Skip to main content
Glama
leo4life2

Minecraft MCP Server

by leo4life2

joinGame

Spawn a bot into Minecraft using a username. Specify host and port to connect to any Minecraft server. Enables AI agents to join and control in-game actions for tasks like movement, crafting, and building.

Instructions

Spawn a bot into the Minecraft game

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostNoMinecraft server host (defaults to 'localhost' or command line option)
portNoMinecraft server port (defaults to 25565 or command line option)
usernameYesThe username for the bot

Implementation Reference

  • The main execution logic for the 'joinGame' tool. Creates a mineflayer bot instance, loads plugins (pathfinder, pvp, tool, collectblock), configures logging and properties, waits for the bot to spawn, and registers it with the BotManager.
    if (name === "joinGame") {
        try {
            const { username, host, port } = args as { username: string; host?: string; port?: number };
    
            // Use provided values, fall back to command line options, then defaults
            const serverHost = host || options.host || 'localhost';
            const serverPort = port || (options.port ? parseInt(options.port) : 25565);
    
            console.error(`[MCP] Attempting to spawn bot '${username}' on ${serverHost}:${serverPort}`);
    
            // Create a new bot
            const bot = mineflayerCreateBot({
                host: serverHost,
                port: serverPort,
                username: username
                // Auto-detect version by not specifying it
            }) as any; // Type assertion to allow adding custom properties
    
            // Dynamically import and load plugins
            const [pathfinderModule, pvpModule, toolModule, collectBlockModule] = await Promise.all([
                import('mineflayer-pathfinder'),
                import('mineflayer-pvp'),
                import('mineflayer-tool'),
                import('mineflayer-collectblock')
            ]);
    
            // Load plugins
            bot.loadPlugin(pathfinderModule.pathfinder);
            bot.loadPlugin(pvpModule.plugin);
            bot.loadPlugin(toolModule.plugin);
            bot.loadPlugin(collectBlockModule.plugin);
    
            // Add Movements constructor to bot for skills that create movement configurations
            bot.Movements = pathfinderModule.Movements;
    
            // Add a logger to the bot
            bot.logger = {
                info: (message: string) => {
                    const timestamp = new Date().toISOString();
                    console.error(`[${username}] ${timestamp} : ${message}`);
                },
                error: (message: string) => {
                    const timestamp = new Date().toISOString();
                    console.error(`[${username}] ${timestamp} : ERROR: ${message}`);
                },
                warn: (message: string) => {
                    const timestamp = new Date().toISOString();
                    console.error(`[${username}] ${timestamp} : WARN: ${message}`);
                },
                debug: (message: string) => {
                    const timestamp = new Date().toISOString();
                    console.error(`[${username}] ${timestamp} : DEBUG: ${message}`);
                }
            };
    
            // Register the bot
            const botId = botManager.addBot(username, bot);
    
            // Wait for spawn
            await Promise.race([
                new Promise<void>((resolve, reject) => {
                    bot.once('spawn', () => {
                        console.error(`[MCP] Bot ${username} spawned, initializing additional properties...`);
    
                        // Initialize properties that skills expect
                        bot.exploreChunkSize = 16; // INTERNAL_MAP_CHUNK_SIZE
                        bot.knownChunks = bot.knownChunks || {};
                        bot.currentSkillCode = '';
                        bot.currentSkillData = {};
    
                        // Set constants that skills use
                        bot.nearbyBlockXZRange = 20; // NEARBY_BLOCK_XZ_RANGE
                        bot.nearbyBlockYRange = 10; // NEARBY_BLOCK_Y_RANGE
                        bot.nearbyPlayerRadius = 10; // NEARBY_PLAYER_RADIUS
                        bot.hearingRadius = 30; // HEARING_RADIUS
                        bot.nearbyEntityRadius = 10; // NEARBY_ENTITY_RADIUS
    
                        // Initialize chat history tracking
                        initializeChatHistory(bot);
    
                        resolve();
                    });
                    bot.once('error', (err: Error) => reject(err));
                    bot.once('kicked', (reason: string) => reject(new Error(`Bot kicked: ${reason}`)));
                }),
                new Promise<never>((_, reject) =>
                    setTimeout(() => reject(new Error('Bot spawn timed out after 30 seconds')), 30000)
                )
            ]);
    
            return {
                content: [{
                    type: "text",
                    text: `Bot '${username}' successfully joined the game on ${serverHost}:${serverPort}. Bot ID: ${botId}`
                }]
            };
        } catch (error) {
            return {
                content: [{
                    type: "text",
                    text: `Failed to join game: ${error instanceof Error ? error.message : String(error)}`
                }],
                isError: true
            };
        }
    }
  • The input schema definition for the 'joinGame' tool, specifying parameters for username (required), host, and port.
    inputSchema: {
        type: "object",
        properties: {
            username: {
                type: "string",
                description: "The username for the bot"
            },
            host: {
                type: "string",
                description: "Minecraft server host (defaults to 'localhost' or command line option)"
            },
            port: {
                type: "number",
                description: "Minecraft server port (defaults to 25565 or command line option)"
            }
        },
        required: ["username"]
    }
  • Registration of the 'joinGame' tool in the ListToolsRequestSchema handler, defining its name, description, and input schema for discovery.
    {
        name: "joinGame",
        description: "Spawn a bot into the Minecraft game",
        inputSchema: {
            type: "object",
            properties: {
                username: {
                    type: "string",
                    description: "The username for the bot"
                },
                host: {
                    type: "string",
                    description: "Minecraft server host (defaults to 'localhost' or command line option)"
                },
                port: {
                    type: "number",
                    description: "Minecraft server port (defaults to 25565 or command line option)"
                }
            },
            required: ["username"]
        }
    },
Behavior2/5

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

With no annotations, the description carries full burden but only states the action ('spawn a bot'). It doesn't disclose behavioral traits such as whether this is a one-time connection, if it requires authentication, what happens on failure, or if it's idempotent. This is inadequate for a tool that likely involves network interaction.

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 waste. It's front-loaded and appropriately sized for the tool's purpose, earning its place without unnecessary elaboration.

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?

Given no annotations and no output schema, the description is incomplete. It doesn't explain what happens after spawning (e.g., bot state, return values, error handling) or address complexity like network dependencies. For a tool with potential side effects, more context is needed.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents parameters (host, port, username). The description adds no additional meaning beyond implying these are for server connection and bot identity, which is already clear from schema. Baseline 3 is appropriate as schema does the work.

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 'Spawn a bot into the Minecraft game' clearly states the action (spawn) and target (bot into game), distinguishing it from siblings like 'leaveGame' or 'readChat'. However, it doesn't explicitly differentiate from other entry-point tools (none in siblings), so it's not a perfect 5.

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 doesn't mention prerequisites (e.g., server must be running), when not to use it (e.g., if already in game), or relate to siblings like 'leaveGame'. This leaves usage context unclear.

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/leo4life2/minecraft-mcp-http'

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