Minecraft MCP 伺服器
Minecraft 伺服器管理透過 RCON。整合 FastMCP 以便於命令執行,支援與 Claude Desktop 及其他 MCP 客戶端的互動,並提供靈活的架構以供本地開發和生產使用。
概覽
Minecraft-MCP-Server
一個用於通過 RCON 控制 Minecraft 伺服器的 Python MCP 伺服器,利用 FastMCP 進行無縫集成和命令執行。
🔧 功能
- 命令字典:提供一套全面的命令,以增強與 Minecraft 伺服器的互動。
- RCON 執行:使用 RCON 直接在 Minecraft 伺服器上執行命令,以實現實時控制。
- 客戶端集成:與 Claude Desktop 或任何 MCP 客戶端兼容,便於管理。
- 靈活結構:支持通過
stdio
的本地開發和通過 HTTP/SSE 的生產環境。
📦 項目結構
mcp_server/
├── commands.json # 包含命令和用法示例
├── server.py # MCP 的主要伺服器腳本
├── commands.json # 用於上下文理解的 Minecraft 命令
└── (venv/) # 可選的依賴項虛擬環境
⚙️ 安裝
-
克隆倉庫:
cd Minecraft-MCP-Server/mcp_server
-
設置環境並安裝依賴項:
python -m venv venv venv\Scripts\activate pip install mcp[cli] mcrcon
📝 設置
在 commands.json
文件中,您將找到各種命令,例如 /give
、/weather
和 /gamemode
,並附有描述和用法示例。
確保在您的 Minecraft server.properties
文件中啟用 RCON:
enable-rcon=true
rcon.password=minemcp
rcon.port=25575
🚀 運行伺服器
要啟動伺服器,請激活虛擬環境並執行:
venv\Scripts\activate
python server.py
默認情況下,MCP 伺服器以 STDIO 模式啟動。
⚙️ 與 Claude Desktop 的集成
要與 Claude Desktop 集成,請修改 claude_desktop_config.json
文件(位於 %APPDATA%\Claude\
):
{
"mcpServers": {
"minecraft-controller": {
"type": "stdio",
"command": "C:\\...\\venv\\Scripts\\python.exe",
"args": ["C:\\...\\mcp_server\\server.py"],
"env": {"PATH": "%PATH%"}
}
}
}
重新啟動 Claude 以查看列出的 ‘minecraft-controller’ 伺服器。
🧪 使用 Python 進行本地測試
您可以使用以下 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("玩家:", res)
cmds = await client.read_resource("minecraft://commands")
print("命令:", list(cmds.keys())[:5])
asyncio.run(test())
🧰 工作原理
- FastMCP 功能:自動加載工具和資源,以高效處理命令。
- 命令資源:資源
minecraft://commands
提供可用命令的字典。 - 命令執行:工具
run_minecraft_command
使用mcrcon
將命令發送到 Minecraft 伺服器。
📚 參考資料
🛠 下一步
- 實現使用 Docker 的 HTTP/SSE 傳輸支持。
- 通過命令字典增強參數驗證和自動完成功能。
- 為額外操作(如
/start
、/stop
、/backup
和/whitelist
)添加日誌記錄。
準備好提升您的 Minecraft 伺服器體驗! 🚀
詳細
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
-
Clone the repository:
cd Minecraft-MCP-Server/mcp_server
-
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
usesmcrcon
to send commands to Minecraft
📚 References
🛠 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! 🚀
伺服器配置
{
"mcpServers": {
"minecraft-controller": {
"type": "stdio",
"command": "C:\\...\\venv\\Scripts\\python.exe",
"args": [
"C:\\...\\mcp_server\\server.py"
],
"env": {
"PATH": "%PATH%"
}
}
}
}