godot tilemap mcp
允许AI代理的MCP(模型上下文协议)服务器 阅读、检查、可视化和绘画 在Godot 4 TileMapLayer/TileSet资源上。
AI编码助手(Cursor、Codex、Claude等)通常看不到tilemap数据——它以不透明的二进制形式存储在内部 .tscn 文件夹。该服务器对其进行解码并公开9个工具,以便AI能够理解您的地图并以编程方式进行编辑。
工具
检查(只读)
| 工具 | 说明 |
|---|---|
list_tilemaps | 扫描项目中的所有内容 .tscn 包含TileMapLayer节点的场景 |
inspect_tileset | 解析a .tres TileSet:源、自定义数据层、地形、物理 |
get_tilemap_info | 边界、图块计数、图块集参考、z_index、每层可见性 |
read_tiles | 解码一个层中的所有图块(使用可选的区域过滤器) |
render_tilemap | ASCII艺术可视化——源ID或图集坐标 |
绘图(书写)
| 工具 | 说明 |
|---|---|
set_tiles | 在特定坐标处放置或覆盖图块 |
fill_rect | 用单个图块类型填充矩形区域 |
erase_tiles | 移除特定位置的瓷砖 |
erase_rect | 清除矩形区域中的所有瓷砖 |
快速开始
cd godot-tilemap-mcp
npm install光标
添加 ~/.cursor/mcp.json:
{
"mcpServers": {
"godot-tilemap": {
"command": "node",
"args": ["/absolute/path/to/godot-tilemap-mcp/src/index.js"],
"env": {
"GODOT_PROJECT_PATH": "/absolute/path/to/your/godot/project"
}
}
}
}Codex/其他MCP客户
任何支持stdio传输的MCP客户端都可以使用此服务器。设置 GODOT_PROJECT_PATH 将环境变量添加到Godot项目根目录并运行:
GODOT_PROJECT_PATH=/path/to/project node src/index.js路径分辨率
所有工具都接受三种形式的路径:
- 绝对的:
/home/user/project/Scenes/World.tscn - 相对的:
Scenes/World.tscn(从GODOT_PROJECT_PATH) - Godot风格:
res://Scenes/World.tscn(条纹res://,与项目路径连接)
二进制格式
戈多4 tile_map_data 是一个 PackedByteArray 以base64格式存储在 .tscn 文本场景:
Header (2 bytes):
uint16 LE format version
Per cell (12 bytes):
int16 LE cell X
int16 LE cell Y
uint16 LE source_id
uint16 LE atlas_coords.x
uint16 LE atlas_coords.y
uint16 LE alternative_tile参考: godotengine/godot — scene/2d/tile_map_layer.cpp
示例用法(AI)
配置后,AI代理可以:
> list_tilemaps
4 scenes found. World.tscn has layers: Base (258 tiles), Overlay (12 tiles)...
> render_tilemap scene:World.tscn layer:TileMapLayer_Base mode:source
-4 -3 -2 -1 0 1 2 3 4 5
0 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 0 0 0 1 1 1
...
> set_tiles scene:World.tscn layer:TileMapLayer_Base tiles:[{x:5,y:3,source_id:2,atlas_x:1,atlas_y:0}]
Success: 1 tile set, 259 total需求
- Node.js 18+
- Godot 4.x项目
.tscn使用TileMapLayer节点的场景
许可证
麻省理工学院
