MCP for FairyGUI logo

MCP for FairyGUI

Community
kaohum

MCP toolset for FairyGUI editor automation - let AI assistants operate FairyGUI

Publisherkaohum
RepositoryFairyGUI-MCP
LanguagePython
Forks
7
Stars
40
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    MCP for FairyGUI exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    40 stars and 7 forks from the linked repository.

MCP for FairyGUI

让 AI 助手直接操作 FairyGUI 编辑器,实现 UI 开发自动化

MIT License Python 3.10+ MCP

English | 中文


概述

MCP for FairyGUI 是一个基于 Model Context Protocol (MCP) 的工具集,让 AI 编程助手(如 Claude Code、Cursor 等)能够直接与 FairyGUI 编辑器交互。

AI 助手可以浏览 UI 资源、打开和预览组件、截图验证、切换控制器状态、发布 UI 包——全程无需手动操作编辑器。

工作原理

┌───────────────┐   MCP (stdio)   ┌─────────────────┐   文件轮询    ┌─────────────────┐
│   AI 助手      │◄──────────────► │  Python MCP 服务 │◄───────────►│  FairyGUI 编辑器 │
│ (Claude Code) │                 │   (fastmcp)     │    JSON     │   (Lua 插件)     │
└───────────────┘                 └─────────────────┘             └─────────────────┘

通信流程:

  1. AI 助手调用 MCP 工具 → Python MCP 服务接收请求
  2. MCP 服务将 JSON 命令写入 bridge/commands/ 目录
  3. FairyGUI 编辑器中的 Lua 插件每 100ms 轮询命令文件
  4. 插件在编辑器内执行命令,将结果写入 bridge/results/
  5. MCP 服务读取结果,返回给 AI 助手

功能特性

包与资源管理

工具说明
fg_list_packages列出项目中所有 UI 包(包名、ID、资源数)
fg_get_package_info获取包详情(组件/图片/字体/文件夹列表)
fg_list_resources按类型过滤列出包内资源
fg_search_component跨包模糊搜索组件
fg_move_resource移动或重命名包内资源
fg_delete_resource删除资源(自动扫描引用,支持强制删除)

组件分析

工具说明
fg_read_component读取组件原始 XML 内容
fg_parse_component解析 XML 为结构化自然语言描述(含控制器、Gear、Relation、动画)
fg_validate_component验证组件规范(XML 格式、属性完整性、命名规范、ID 唯一性)

编辑器交互

工具说明
fg_editor_status检查编辑器和插件连接状态
fg_editor_activate激活编辑器窗口到前台
fg_editor_reload刷新项目或指定包的资源
fg_editor_open_component在编辑器中打开组件进行编辑
fg_editor_save保存当前打开的组件
fg_editor_close关闭当前组件
fg_editor_get_selection获取编辑器中当前选中的元素

预览与截图

工具说明
fg_editor_preview在预览窗口中显示组件
fg_editor_start_test启动 F5 预览测试(支持指定设备分辨率,如 iPhone X、iPad Pro)
fg_editor_stop_test停止 F5 预览
fg_editor_capture_preview截取预览运行中的截图(支持切换设备分辨率)
fg_editor_screenshot截取编辑器全屏或组件画布截图

控制器操作

工具说明
fg_editor_list_controllers列出当前组件的所有控制器(含页面名称和当前选中页)
fg_editor_switch_controller切换控制器页面(按索引或名称)

发布

工具说明
fg_editor_publish_package发布指定 UI 包
fg_editor_publish_all发布所有 UI 包

插件管理

工具说明
fg_editor_reload_plugin热重载命令处理器(无需重启插件)
fg_editor_reload_all_plugins重载所有 FairyGUI 插件

系统要求

  • Python 3.10+
  • FairyGUI 编辑器(Windows 版本)
  • MCP 客户端(Claude Code / Cursor / 其他支持 MCP 的工具)
  • Windows 操作系统(窗口截图功能依赖 Win32 API)

快速开始

1. 安装 Python MCP 服务

bash
cd fairyGUI-MCP
pip install -e .

Windows 用户也可以双击 install.bat。

2. 安装 FairyGUI 编辑器插件

将 plugin/MCPBridge/ 目录复制到你的 FairyGUI 项目的 plugins/ 目录下:

your-fairygui-project/
└── plugins/
    └── MCPBridge/          ← 复制整个目录
        ├── package.json
        ├── main.lua
        ├── src/
        │   └── command_handler.lua
        └── bridge/
            ├── commands/
            ├── results/
            └── screenshots/

打开 FairyGUI 编辑器,控制台出现 [MCPBridge] 插件已启动 即表示成功。

3. 配置 MCP 客户端

Claude Code (~/.claude/settings.json 或项目 .mcp.json):

json
{
  "mcpServers": {
    "fairygui-tools": {
      "command": "python",
      "args": ["-m", "mcp_fairygui.server"],
      "cwd": "/path/to/fairyGUI-MCP",
      "env": {
        "UI_PROJECT_PATH": "/path/to/your/fairygui-project"
      }
    }
  }
}

Cursor (.cursor/mcp.json):

json
{
  "mcpServers": {
    "fairygui-tools": {
      "command": "python",
      "args": ["-m", "mcp_fairygui.server"],
      "cwd": "/path/to/fairyGUI-MCP",
      "env": {
        "UI_PROJECT_PATH": "/path/to/your/fairygui-project"
      }
    }
  }
}

UI_PROJECT_PATH 是你的 FairyGUI 工程根目录(包含 assets/ 和 package.xml 的目录)。

4. 验证连接

在 AI 助手中调用:

fg_editor_status

应返回:

编辑器: 运行中
通信目录: 正常
插件通信: 正常
已加载 X 个 UI 包

环境变量

变量必填说明
UI_PROJECT_PATH是FairyGUI UI 工程根目录
PROJECT_ROOT否项目根目录(自动检测的兜底)

项目结构

fairyGUI-MCP/
├── README.md
├── LICENSE
├── pyproject.toml                      # Python 包配置
├── install.bat                         # Windows 安装脚本
├── claude_settings_example.json        # MCP 配置示例
│
├── src/mcp_fairygui/                   # Python MCP 服务
│   ├── server.py                       #   服务入口(路径自动检测)
│   ├── tools/
│   │   ├── package_tools.py            #   包与资源查询
│   │   ├── component_tools.py          #   组件分析(读取/解析/验证)
│   │   ├── editor_tools.py             #   编辑器交互(预览/截图/控制器/发布)
│   │   └── file_tools.py              #   文件管理(移动/删除)
│   ├── parsers/
│   │   ├── xml_parser.py               #   FairyGUI XML 结构化解析器
│   │   └── description_gen.py          #   组件自然语言描述生成器
│   ├── bridge/
│   │   └── command_queue.py            #   命令队列管理器
│   └── utils/
│       └── window_manager.py           #   Windows 窗口管理(激活/截图)
│
└── plugin/MCPBridge/                   # FairyGUI 编辑器插件
    ├── package.json                    #   插件配置
    ├── main.lua                        #   插件入口(定时器轮询 + 日志缓冲)
    ├── src/
    │   └── command_handler.lua         #   命令处理器(编辑器操作实际实现)
    └── bridge/                         #   通信目录
        ├── commands/                   #   MCP → 编辑器
        ├── results/                    #   编辑器 → MCP
        └── screenshots/                #   截图输出

技术细节

通信协议

项目说明
传输层文件系统 JSON 命令/结果队列
命令格式{ "id": "cmd_xxx", "action": "...", "params": {...} }
结果格式{ "id": "cmd_xxx", "status": "success"|"error", "data": {...} }
轮询间隔100ms(Lua 端 FairyGUI Timers)
默认超时5 秒(发布操作 60-300 秒)

Lua 插件

  • 基于 FairyGUI 插件系统,随编辑器启动自动加载
  • 拦截 fprint 全局函数,维护环形日志缓冲区(最多 500 条)
  • 持续重置 runInBackground,防止窗口失焦后定时器暂停
  • 支持热重载信号文件机制,更新 command_handler.lua 无需重启

Python MCP 服务

  • 基于 fastmcp 框架
  • 自动检测项目路径(环境变量 → CWD 向上搜索 → 兜底)
  • Windows 窗口管理:Win32 API 自动激活编辑器 + PrintWindow 截图

XML 解析

  • 完整 FairyGUI 组件 Schema(控制器、显示列表、Gear、Relation、Transition、扩展属性)
  • 结构化 dataclass 模型(Component、Controller、DisplayElement 等)
  • 自然语言描述生成器,将组件结构转化为 AI 友好的文档

使用示例

AI 辅助 UI 开发

用户:帮我查看 Common 包里有哪些按钮组件

AI 调用: fg_list_resources("Common", "component")
AI 调用: fg_search_component("Button")
→ 列出所有匹配组件,包含 ID、路径、导出状态

自动化 UI 验证

AI 调用: fg_editor_open_component("Build", "BuildLevelUp")
AI 调用: fg_editor_list_controllers()
→ 获取所有控制器和页面

AI 调用: fg_editor_switch_controller("state", page_index=0)
AI 调用: fg_editor_screenshot(target="preview")
→ 截图验证正常状态

AI 调用: fg_editor_switch_controller("state", page_index=1)
AI 调用: fg_editor_screenshot(target="preview")
→ 截图验证 MAX 状态

组件分析与校验

AI 调用: fg_parse_component("Common", "ButtonItem")
→ 生成结构化描述:尺寸、控制器、元素列表、Gear/Relation 配置、动画定义

AI 调用: fg_validate_component("Common", "ButtonItem")
→ 验证:XML 格式、属性完整性、命名规范、ID 唯一性

批量发布

AI 调用: fg_editor_publish_all()
→ 发布所有 UI 包到 Unity 项目

依赖

Python(必填)

包版本说明
fastmcp>=0.1.0MCP 服务框架
pydantic>=2.0.0数据校验

Python(可选,Windows 截图功能)

包说明
pywin32Win32 API(窗口管理/截图)
Pillow图像处理(PrintWindow 截图转 PNG)

安装可选依赖:pip install -e ".[windows]"

常见问题

Q:显示"插件通信: 超时"

确保 MCPBridge 插件已加载。检查 FairyGUI 编辑器控制台是否有 [MCPBridge] 插件已启动。如果插件未加载,检查 plugins/MCPBridge/ 目录是否正确放置。

Q:截图功能不可用

编辑器全屏截图需要 pywin32 和 Pillow:pip install pywin32 Pillow。组件画布截图由 Lua 插件通过 GetScreenShot API 实现,不需要额外依赖。

Q:F5 预览模式下命令超时

F5 模式会将 runInBackground 设为 false。插件会持续重置此标志,但如果编辑器被其他全屏窗口遮挡,仍可能超时。确保编辑器在前台可见。

Q:支持 macOS/Linux 吗?

MCP 服务本身跨平台。Lua 插件运行在 FairyGUI 编辑器内(Unity),与操作系统无关。但窗口管理和全屏截图功能依赖 Windows API(pywin32),其他平台需要自行实现对应功能。欢迎贡献!

贡献

欢迎提交 Issue 和 Pull Request!

  1. Fork 本仓库
  2. 创建特性分支:git checkout -b feature/amazing-feature
  3. 提交更改:git commit -m 'Add amazing feature'
  4. 推送分支:git push origin feature/amazing-feature
  5. 提交 Pull Request

致谢

许可证

MIT License


Overview

MCP for FairyGUI is a Model Context Protocol (MCP) toolset that enables AI coding assistants (Claude Code, Cursor, etc.) to interact directly with the FairyGUI editor — browse UI resources, open and preview components, capture screenshots, switch controller states, and publish packages, all without manual editor operations.

How It Works

┌───────────────┐   MCP (stdio)   ┌─────────────────┐   File Polling  ┌─────────────────┐
│  AI Client    │◄──────────────► │  Python MCP Srv │◄──────────────► │  FairyGUI Editor│
│ (Claude Code) │                 │   (fastmcp)     │     JSON        │   (Lua Plugin)  │
└───────────────┘                 └─────────────────┘                 └─────────────────┘
  1. AI assistant calls an MCP tool → Python MCP server receives the request
  2. MCP server writes a JSON command to bridge/commands/
  3. Lua plugin inside FairyGUI editor polls for commands every 100ms
  4. Plugin executes the command in editor context, writes result to bridge/results/
  5. MCP server reads the result and returns it to the AI assistant

Features

  • Package & Resource Management — List, search, move, and delete UI resources
  • Component Analysis — Read, parse, and validate component XML
  • Editor Interaction — Open, save, close components; get selection
  • Preview & Screenshots — Preview with device support; capture editor or canvas screenshots
  • Controller Operations — List and switch controller pages
  • Publishing — Publish individual or all packages
  • Plugin Management — Hot-reload command handler; reload all plugins

System Requirements

  • Python 3.10+
  • FairyGUI Editor (Windows)
  • MCP client (Claude Code / Cursor / any MCP-compatible tool)
  • Windows OS (window screenshot features require Win32 API)

Quick Start

1. Install Python MCP Server

bash
cd fairyGUI-MCP
pip install -e .

2. Install FairyGUI Editor Plugin

Copy plugin/MCPBridge/ into your FairyGUI project's plugins/ directory:

your-fairygui-project/
└── plugins/
    └── MCPBridge/
        ├── package.json
        ├── main.lua
        ├── src/
        └── bridge/

Open FairyGUI editor and look for [MCPBridge] Plugin started in the console.

3. Configure MCP Client

json
{
  "mcpServers": {
    "fairygui-tools": {
      "command": "python",
      "args": ["-m", "mcp_fairygui.server"],
      "cwd": "/path/to/fairyGUI-MCP",
      "env": {
        "UI_PROJECT_PATH": "/path/to/your/fairygui-project"
      }
    }
  }
}

4. Verify

Call fg_editor_status — you should see "Editor: Running, Plugin communication: OK".

Available Tools (22)

ToolDescription
fg_list_packagesList all UI packages
fg_get_package_infoGet detailed package info
fg_list_resourcesList resources by type
fg_search_componentSearch components across packages
fg_read_componentRead component XML
fg_parse_componentParse to structured description
fg_validate_componentValidate against best practices
fg_move_resourceMove or rename resource
fg_delete_resourceDelete resource (with reference check)
fg_editor_statusCheck editor status
fg_editor_activateActivate editor window
fg_editor_reloadRefresh resources
fg_editor_open_componentOpen component
fg_editor_previewPreview component
fg_editor_start_testStart F5 preview (with device)
fg_editor_stop_testStop F5 preview
fg_editor_capture_previewCapture preview screenshot
fg_editor_screenshotCapture editor/canvas screenshot
fg_editor_get_selectionGet selected elements
fg_editor_list_controllersList controllers with pages
fg_editor_switch_controllerSwitch controller page
fg_editor_saveSave component
fg_editor_closeClose component
fg_editor_publish_packagePublish a package
fg_editor_publish_allPublish all packages
fg_editor_reload_pluginHot-reload command handler
fg_editor_reload_all_pluginsReload all plugins

Contributing

  1. Fork this repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push the branch: git push origin feature/amazing-feature
  5. Submit a Pull Request

License

MIT License

Installation

TypingMind
{
  "mcpServers": {
    "fairygui-mcp": {
      "command": "python",
      "args": [
        "-m",
        "mcp_fairygui.server"
      ],
      "env": {
        "UI_PROJECT_PATH": "<UI_PROJECT_PATH>"
      }
    }
  }
}

Use MCP for FairyGUI MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once MCP for FairyGUI is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add MCP for FairyGUI as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the MCP for FairyGUI MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "fairygui-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the MCP for FairyGUI MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the MCP for FairyGUI MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use MCP for FairyGUI to help me with this task?
MCP for FairyGUI
Sure. I read it.
Here is what I found using MCP for FairyGUI.

Frequently asked questions

What is the MCP for FairyGUI MCP server used for?

MCP for FairyGUI is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use MCP for FairyGUI MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use MCP for FairyGUI with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use MCP for FairyGUI MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With MCP for FairyGUI connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect MCP for FairyGUI MCP to TypingMind?

MCP for FairyGUI runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does MCP for FairyGUI MCP provide in TypingMind?

MCP for FairyGUI exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use MCP for FairyGUI MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If MCP for FairyGUI requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇