Minecraft MCP Server

Erstellt vonPeterson047Peterson047

Minecraft-Serververwaltung über RCON. Integriert FastMCP für einfache Befehlsausführung, unterstützt die Interaktion mit Claude Desktop und anderen MCP-Clients und bietet eine flexible Architektur für lokale Entwicklung und Produktionsnutzung.

Übersicht

Minecraft-MCP-Server

Ein Python MCP-Server, der entwickelt wurde, um einen Minecraft-Server über RCON zu steuern, wobei FastMCP für nahtlose Integration und Befehlsausführung genutzt wird.

🔧 Funktionen

  • Befehlswörterbuch: Bietet eine umfassende Sammlung von Befehlen zur Verbesserung der Interaktion mit dem Minecraft-Server.
  • RCON-Ausführung: Führt Befehle direkt auf dem Minecraft-Server über RCON für die Echtzeitsteuerung aus.
  • Client-Integration: Kompatibel mit Claude Desktop oder jedem MCP-Client für eine einfache Verwaltung.
  • Flexible Struktur: Unterstützt sowohl die lokale Entwicklung über stdio als auch Produktionsumgebungen über HTTP/SSE.

📦 Projektstruktur

mcp_server/
├── commands.json         # Enthält Befehle und Beispiele zur Nutzung  
├── server.py             # Das Hauptserverskript für MCP  
├── commands.json         # Minecraft-Befehle für kontextuelles Verständnis  
└── (venv/)               # Optionale virtuelle Umgebung für Abhängigkeiten  

⚙️ Installation

  1. Klone das Repository:

    cd Minecraft-MCP-Server/mcp_server
    
  2. Richte die Umgebung ein und installiere die Abhängigkeiten:

    python -m venv venv
    venv\Scripts\activate
    pip install mcp[cli] mcrcon
    

📝 Einrichtung

In der Datei commands.json findest du eine Vielzahl von Befehlen wie /give, /weather und /gamemode, komplett mit Beschreibungen und Nutzungshinweisen.

Stelle sicher, dass RCON in deiner Minecraft server.properties-Datei aktiviert ist:

enable-rcon=true
rcon.password=minemcp
rcon.port=25575

🚀 Server starten

Um den Server zu starten, aktiviere die virtuelle Umgebung und führe aus:

venv\Scripts\activate
python server.py

Standardmäßig startet der MCP-Server im STDIO-Modus.

⚙️ Integration mit Claude Desktop

Um mit Claude Desktop zu integrieren, ändere die Datei claude_desktop_config.json (zu finden in %APPDATA%\Claude\):

{
  "mcpServers": {
    "minecraft-controller": {
      "type": "stdio",
      "command": "C:\\...\\venv\\Scripts\\python.exe",
      "args": ["C:\\...\\mcp_server\\server.py"],
      "env": {"PATH": "%PATH%"}
    }
  }
}

Starte Claude neu, um den Server „minecraft-controller“ aufgelistet zu sehen.

🧪 Lokale Tests mit Python

Du kannst den Server lokal mit folgendem Python-Skript testen:

from fastmcp import Client
import asyncio

async def test():
    client = Client("mcp_server/server.py")
    async with client:
        res = await client.call_tool("run_minecraft_command", {"command": "/list"})
        print("Spieler:", res)
        cmds = await client.read_resource("minecraft://commands")
        print("Befehle:", list(cmds.keys())[:5])

asyncio.run(test())

🧰 So funktioniert es

  • FastMCP-Funktionalität: Lädt automatisch Werkzeuge und Ressourcen für eine effiziente Befehlsverarbeitung.
  • Befehlsressource: Die Ressource minecraft://commands bietet ein Wörterbuch der verfügbaren Befehle.
  • Befehlsausführung: Das Werkzeug run_minecraft_command nutzt mcrcon, um Befehle an den Minecraft-Server zu senden.

📚 Referenzen

🛠 Nächste Schritte

  • Unterstützung für HTTP/SSE-Transport mit Docker implementieren.
  • Argumentvalidierung und Autocomplete-Funktionen über das Befehlswörterbuch verbessern.
  • Protokollierung zusätzlicher Aktionen wie /start, /stop, /backup und /whitelist hinzufügen.

Mach dich bereit, dein Minecraft-Servererlebnis zu verbessern! 🚀

Detail

Minecraft-MCP-Server

Python MCP Server to control a Minecraft server via RCON, using FastMCP.


🔧 Features

  • Exposes a set of commands (dictionary) to contextualize the LLM
  • Executes commands on the Minecraft server via RCON
  • Integration with Claude Desktop or any MCP client
  • Simple structure: stdio (local development) or HTTP/SSE (production)

📦 Project Structure

mcp_server/
├── commands.json         # Commands dictionary and examples  
├── server.py             # Main MCP server  
├── commands.json         # Minecraft commands for context  
└── (venv/)               # Virtual environment (optional)  

⚙️ Installation

  1. Clone the repository:

      cd Minecraft-MCP-Server/mcp_server
    
  2. Create an environment and install dependencies:

    python -m venv venv
    venv\Scripts\activate
    pip install mcp[cli] mcrcon
    

📝 Setup

In the commands.json file, you will have a list of commands like /give, /weather, /gamemode, etc., with descriptions and examples.

Don’t forget to enable RCON in the Minecraft server.properties file:

enable-rcon=true
rcon.password=minemcp
rcon.port=25575

🚀 Running

Activate the virtual environment and run:

venv\Scripts\activate
python server.py

Monkey patch: starts MCP server in STDIO by default (apidog.com, reddit.com, github.com)


⚙️ Integration with Claude Desktop

In claude_desktop_config.json (e.g., %APPDATA%\Claude\):

{
  "mcpServers": {
    "minecraft-controller": {
      "type": "stdio",
      "command": "C:\\...\\venv\\Scripts\\python.exe",
      "args": ["C:\\...\\mcp_server\\server.py"],
      "env": {"PATH": "%PATH%"}
    }
  }
}

Then restart Claude — the ‘minecraft-controller’ server will appear.


🧪 Local Test with Python

from fastmcp import Client
import asyncio

async def test():
    client = Client("mcp_server/server.py")
    async with client:
        res = await client.call_tool("run_minecraft_command", {"command": "/list"})
        print("Players:", res)
        cmds = await client.read_resource("minecraft://commands")
        print("Commands:", list(cmds.keys())[:5])

asyncio.run(test())

🧰 How It Works

  • 🎯 FastMCP automatically loads tools and resources (medium.com, github.com)
  • Resource minecraft://commands provides the commands dictionary
  • Tool run_minecraft_command uses mcrcon to send commands to Minecraft

📚 References

  • [FastMCP v2 – Sample README] (pypi.org)
  • [mcrcon – Python RCON client] (pypi.org)

🛠 Next Steps

  • Support for HTTP/SSE transport with Docker
  • Argument validation/autocomplete via commands dictionary
  • Logging extra actions: /start, /stop, /backup, /whitelist

Ready to make your server smart! 🚀


Serverkonfiguration

{
  "mcpServers": {
    "minecraft-controller": {
      "type": "stdio",
      "command": "C:\\...\\venv\\Scripts\\python.exe",
      "args": [
        "C:\\...\\mcp_server\\server.py"
      ],
      "env": {
        "PATH": "%PATH%"
      }
    }
  }
}

Projektinfo

Autor
Peterson047
Erstellt am
Jun 24, 2025
Stern
-
Sprache
Python
Tags
-