使用说明
FastMCP GDMC网桥
之间的桥梁 FastMCP 和 GDPC Minecraft生成设计。
概述
该项目提供了 FastMCP 服务器,通过标准化的API公开GDPC(生成设计Python客户端)功能。这允许AI助手和其他应用程序使用GDMC HTTP接口与Minecraft世界进行交互。
特性
- 映像规则:放置单个块或几何形状
- 地形分析:分析地形特征和高度图
- 结构建筑:通过转换构建各种结构
- 模型创建:创建和放置复杂模型
- 实体放置:世界上的新生实体
- 命令执行:运行Minecraft命令
- 世界信息:访问块、生物组和玩家数据
先决条件
- Minecraft Java版 GDMC HTTP接口模块 (v1.6.0+)
- Python 3.8+
安装
# Clone the repository
git clone https://github.com/natea/fastmcp-gdmc-bridge.git
cd fastmcp-gdmc-bridge
# Create and activate a virtualenv
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -e .
用法
启动服务器
# Start the server with stdio transport (for AI assistants)
python -m gdmc_mcp.server
# Or start with SSE transport (for web applications)
fastmcp run gdmc_mcp.server --transport sse
客户端示例
import asyncio
from fastmcp import Client
async def main():
# Connect to the server
async with Client() as client:
# Get the build area
build_area = await client.access_resource("gdmc://build_area")
print(f"Build area: {build_area}")
# Place a block
result = await client.use_tool(
"place_block",
{
"position": {"coords": [0, 65, 0]},
"block": {"id": "stone"}
}
)
print(f"Block placed: {result}")
# Build a house with transformation
result = await client.use_tool(
"build_with_transform",
{
"position": {"coords": [10, 65, 10]},
"rotation": 1,
"flip": [False, False, False],
"build_function": "house",
"size": 7,
"block": "oak_planks"
}
)
print(f"House built: {result}")
if __name__ == "__main__":
asyncio.run(main())
看 src/client_example.py 举一个更全面的例子。
api参考
工具
- 地点块:在指定坐标处放置块
- 运行命令:执行Minecraft命令
- 地点_立方体:放置实心或空心长方体
- 分析表:分析地形特征
- 构建与转换:使用转换构建结构
- 创建和放置模型:创建和放置复杂模型
- 地点:将实体放置在世界各地
资源
- gdmc://build_area:返回当前构建区域
- gdmc://players:返回有关在线玩家的信息
- gdmc://minecraft_version:返回Minecraft服务器版本
- gdmc://block/{x} /{y}/{z}:返回坐标处的块信息
- gdmc://biome/{x} /{y}/{z}:返回坐标处的生物群落信息
发展
项目结构
fastmcp-gdmc-bridge/
├── src/
│ ├── gdmc_mcp/
│ │ ├── __init__.py
│ │ ├── server.py
│ │ ├── models.py
│ │ ├── gdpc_utils.py
│ │ ├── tutorial_tools.py
│ │ └── py.typed
│ ├── client.py
│ └── client_example.py
├── tests/
│ ├── conftest.py
│ ├── test_models.py
│ ├── test_place_block_tool.py
│ ├── test_run_command_tool.py
│ ├── test_place_cuboid_tool.py
│ ├── test_place_entities_tool.py
│ ├── test_place_structure_tool.py
│ ├── test_resources.py
│ ├── test_server_lifespan.py
│ ├── run_tests.py
│ └── README.md
├── pyproject.toml
└── README.md
运行测试
该项目包括一个全面的测试套件,该套件使用mocking来测试功能,而不需要运行Minecraft服务器。
# Install test dependencies
pip install pytest pytest-asyncio pytest-cov
# Run all tests
cd fastmcp-gdmc-bridge
./tests/run_tests.py
# Run with coverage report
./tests/run_tests.py --cov
# Run specific test file
./tests/run_tests.py --test-file test_place_block_tool.py
# Run with verbose output
./tests/run_tests.py --verbose
看 tests/README.md 有关测试套件的更多详细信息。
添加新工具
要向服务器添加新工具,请向添加新功能 server.py 随着 @mcp.tool() 装饰师:
@mcp.tool()
async def my_new_tool(
param1: Annotated[str, Field(description="Description of param1")],
ctx: Context
) -> dict[str, Any]:
"""Tool description."""
editor = _get_editor(ctx)
# Implement tool functionality
return {"result": "success"}
添加新工具时,请务必在 tests/ 目录。
许可证
麻省理工学院
致谢
- GDPC -生成式设计Python客户端
- FastMCP -构建MCP服务器的框架
- GDMC HTTP接口 -用于HTTP交互的Minecraft mod