Minecraft MCP 服务器
通过RCON管理Minecraft服务器。集成了FastMCP以便于命令执行,支持与Claude Desktop及其他MCP客户端的交互,并提供灵活的架构以便于本地开发和生产使用。
概览
Minecraft-MCP-Server
一个用Python编写的MCP服务器,旨在通过RCON控制Minecraft服务器,利用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! 🚀
Server配置
{
"mcpServers": {
"minecraft-controller": {
"type": "stdio",
"command": "C:\\...\\venv\\Scripts\\python.exe",
"args": [
"C:\\...\\mcp_server\\server.py"
],
"env": {
"PATH": "%PATH%"
}
}
}
}