Minecraft Mineflayer MCP server

Integrates Mineflayer API to enable control of Minecraft bots for navigation, block manipulation, inventory management, and game state monitoring.
Back to servers
Provider
Dennis Traub
Release date
Dec 23, 2024
Language
TypeScript
Stats
8 stars

The Model Context Protocol (MCP) server for Minecraft provides AI systems a way to interact with Minecraft through the Mineflayer API. This implementation allows AI assistants to receive game data and send commands to control a Minecraft character, enabling interesting AI-driven gameplay experiences.

Installation

Prerequisites

  • Node.js (v16 or newer)
  • A Minecraft Java Edition account
  • Minecraft Java Edition server (vanilla or with support for offline mode)

Setup

  1. Clone the repository and install dependencies:
git clone https://github.com/yourusername/minecraft-mcp-server.git
cd minecraft-mcp-server
npm install
  1. Create a configuration file by copying the example:
cp config.example.json config.json
  1. Edit the config.json file with your Minecraft server details:
{
  "host": "localhost",
  "port": 25565,
  "username": "your_minecraft_username",
  "password": "your_password",
  "auth": "microsoft",
  "version": "1.19.3"
}

For offline mode servers, you can use:

{
  "host": "localhost",
  "port": 25565,
  "username": "Bot",
  "version": "1.19.3"
}

Running the Server

Start the MCP server with the following command:

npm start

You should see output confirming the server is running, typically on port 8000.

Connecting to the MCP Server

The MCP server exposes WebSocket endpoints that clients can connect to:

Endpoints

  • Main WebSocket endpoint: ws://localhost:8000/
  • Event stream: ws://localhost:8000/events

Basic Usage

Sending Commands

Connect to the WebSocket endpoint and send JSON messages in the MCP format:

{
  "type": "command",
  "data": {
    "command": "move",
    "args": {
      "direction": "forward",
      "distance": 5
    }
  }
}

Available Commands

Movement Commands

  • move: Move in a direction

    {
      "type": "command",
      "data": {
        "command": "move",
        "args": {
          "direction": "forward|backward|left|right",
          "distance": 5
        }
      }
    }
    
  • lookAt: Turn to face a specific coordinate

    {
      "type": "command",
      "data": {
        "command": "lookAt",
        "args": {
          "x": 100,
          "y": 64,
          "z": 200
        }
      }
    }
    

Interaction Commands

  • dig: Mine a block at specific coordinates

    {
      "type": "command",
      "data": {
        "command": "dig",
        "args": {
          "x": 100,
          "y": 64,
          "z": 200
        }
      }
    }
    
  • placeBlock: Place a block from inventory

    {
      "type": "command",
      "data": {
        "command": "placeBlock",
        "args": {
          "x": 100,
          "y": 64,
          "z": 200,
          "blockType": "dirt"
        }
      }
    }
    

Receiving Game Data

Connect to the events endpoint to receive a stream of game updates:

wscat -c ws://localhost:8000/events

Example event data:

{
  "type": "gameState",
  "data": {
    "player": {
      "position": {"x": 100, "y": 64, "z": 200},
      "health": 20,
      "food": 20,
      "inventory": [...]
    },
    "world": {
      "blocks": [...],
      "entities": [...]
    }
  }
}

Troubleshooting

Common Issues

  • Connection Refused: Verify the Minecraft server is running and the IP/port are correct
  • Authentication Failed: Check your Minecraft account credentials in config.json
  • Version Mismatch: Ensure your client version matches the server version

If the bot disconnects unexpectedly, check the console for error messages that may indicate what went wrong.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later