Files
server-deploy/wsl-dev-stack/godot-mcp-pro-v1.14.1/server/build/tools/resource-tools.js
Joywayer dd3eb24d0f refactor: 拆分 claude-dev-stack 为 windows-dev-stack 和 wsl-dev-stack
将原 claude-dev-stack 目录拆分为独立的 Windows 和 WSL 部署栈,便于分别维护和使用。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-29 01:11:20 +08:00

69 lines
3.8 KiB
JavaScript

import { z } from "zod";
import { formatErrorForMcp } from "../utils/errors.js";
export function registerResourceTools(server, godot) {
server.tool("read_resource", "Read a .tres resource file and return its properties. Works with any Godot Resource type (StyleBox, Font, Theme, Material, etc.)", {
path: z.string().describe("Path to the resource file (e.g. 'res://themes/main_theme.tres')"),
}, async (params) => {
try {
const result = await godot.sendCommand("read_resource", params);
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
}
catch (e) {
return { content: [{ type: "text", text: formatErrorForMcp(e) }], isError: true };
}
});
server.tool("edit_resource", "Edit properties of an existing .tres resource file. Changes are saved to disk immediately.", {
path: z.string().describe("Path to the resource file (e.g. 'res://themes/main_theme.tres')"),
properties: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).describe("Properties to set as key-value pairs. Values auto-parsed for Vector2, Color, etc."),
}, async (params) => {
try {
const result = await godot.sendCommand("edit_resource", params);
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
}
catch (e) {
return { content: [{ type: "text", text: formatErrorForMcp(e) }], isError: true };
}
});
server.tool("create_resource", "Create a new .tres resource file of a given type with optional initial properties", {
path: z.string().describe("Path to save the resource (e.g. 'res://resources/player_stats.tres')"),
type: z.string().describe("Resource type to create (e.g. 'StyleBoxFlat', 'LabelSettings', 'Environment')"),
properties: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional().describe("Initial properties to set"),
overwrite: z.boolean().optional().describe("Overwrite if file exists (default: false)"),
}, async (params) => {
try {
const result = await godot.sendCommand("create_resource", params);
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
}
catch (e) {
return { content: [{ type: "text", text: formatErrorForMcp(e) }], isError: true };
}
});
server.tool("get_resource_preview", "Get a visual preview of an image or texture resource as a PNG. Works with .png, .jpg, .webp, .svg image files and Texture2D resources.", {
path: z.string().describe("Path to the resource (e.g. 'res://assets/player.png', 'res://icon.svg')"),
max_size: z.number().optional().describe("Maximum width/height in pixels, preserving aspect ratio (default: 256)"),
}, async (params) => {
try {
const result = await godot.sendCommand("get_resource_preview", params);
if (result && typeof result === "object" && "image_base64" in result) {
return {
content: [
{
type: "image",
data: result.image_base64,
mimeType: "image/png",
},
{
type: "text",
text: `Preview of ${result.path}: ${result.width}x${result.height}`,
},
],
};
}
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
}
catch (e) {
return { content: [{ type: "text", text: formatErrorForMcp(e) }], isError: true };
}
});
}
//# sourceMappingURL=resource-tools.js.map