这是一个基于模型上下文协议(MCP)的服务器,提供强大的源代码分析功能,专门针对 Unreal Engine 代码库。此工具使像 Claude 和 Cline 这样的AI助手能够深入理解并分析 Unreal Engine 源代码。
<a href="https://glama.ai/mcp/servers/z36022whws"><img width="380" height="200" src="https://gips1.baidu.com/it/u=1585994291,3245614023&fm=3081&app=3081&f=PNG?w=760&h=400" alt="Unreal Engine 代码分析器 MCP 服务器" /></a>
git clone https://github.com/ayeletstudioindia/unreal-analyzer-mcp
cd unreal-analyzer-mcp
npm install
npm run build
在您的 Claude 桌面配置文件中添加以下内容(Windows 系统路径为 %APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"unreal-analyzer": {
"command": "node",
"args": ["path/to/unreal-analyzer/build/index.js"],
"env": {}
}
}
}
在您的 Cline MCP 设置文件中添加以下内容(Windows 系统路径为 %APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json):
{
"mcpServers": {
"unreal-analyzer": {
"command": "node",
"args": ["path/to/unreal-analyzer/build/index.js"],
"env": {}
}
}
}
分析器使用以下构建:
关键依赖项:
在使用任何分析工具之前,必须先设置 Unreal Engine 源代码路径或自定义代码库路径:
{
"name": "set_unreal_path",
"arguments": {
"path": "/path/to/UnrealEngine/Source"
}
}
{
"name": "set_custom_codebase",
"arguments": {
"path": "/path/to/your/codebase"
}
}
自定义代码库功能允许您分析任何 C++ 项目。例如:
分析自定义游戏引擎示例:
// 使用自定义代码库初始化
{
"name": "set_custom_codebase",
"arguments": {
"path": "/path/to/game-engine"
}
}
// 分析引擎的渲染器类
{
"name": "analyze_class",
"arguments": {
"className": "Renderer"
}
}
// 查找所有与着色器相关的代码
{
"name": "search_code",
"arguments": {
"query": "shader|glsl|hlsl",
"filePattern": "*.{h,cpp,hpp}"
}
}
// 获取渲染系统类层次结构
{
"name": "find_class_hierarchy",
"arguments": {
"className": "RenderSystem",
"includeImplementedInterfaces": true
}
}
分析 Qt 应用程序示例:
// 使用 Qt 项目初始化
{
"name": "set_custom_codebase",
"arguments": {
"path": "/path/to/qt-app"
}
}
// 查找小部件类定义
{
"name": "search_code",
"arguments": {
"query": "class.*:.*public.*QWidget",
"filePattern": "*.h"
}
}
// 分析主窗口类
{
"name": "analyze_class",
"arguments": {
"className": "MainWindow"
}
}
// 查找信号/槽连接
{
"name": "find_references",
"arguments": {
"identifier": "connect",
"type": "function"
}
}
// 获取关于 AActor 类的详细信息
{
"name": "analyze_class",
"arguments": {
"className": "AActor"
}
}
示例输出:
{
"name": "AActor",
"properties": [
{
"name": "RootComponent",
"type": "USceneComponent*",
"access": "protected"
}
// ... 其他属性
],
"methods": [
{
"name": "BeginPlay",
"returnType": "void",
"access": "protected",
"virtual": true
}
// ... 其他方法
]
}
// 获取 ACharacter 的继承层次结构
{
"name": "find_class_hierarchy",
"arguments": {
"className": "ACharacter",
"includeImplementedInterfaces": true
}
}
示例输出:
{
"class": "ACharacter",
"inheritsFrom": "APawn",
"interfaces": ["IMovementModeInterface"],
"hierarchy": [
"ACharacter",
"APawn",
"AActor",
"UObject"
]
}
// 查找所有对 BeginPlay 函数的引用
{
"name": "find_references",
"arguments": {
"identifier": "BeginPlay",
"type": "function"
}
}
示例输出:
{
"references": [
{
"file": "Actor.cpp",
"line": 245,
"context": "void AActor::BeginPlay() { ... }"
},
{
"file": "Character.cpp",
"line": 178,
"context": "Super::BeginPlay();"
}
]
}
// 搜索与物理相关的代码
{
"name": "search_code",
"arguments": {
"query": "PhysicsHandle",
"filePattern": "*.h",
"includeComments": true
}
}
示例输出:
{
"matches": [
{
"file": "PhysicsEngine/PhysicsHandleComponent.h",
"line": 15,
"context": "class UPhysicsHandleComponent : public UActorComponent",
"snippet": "// Component used for grabbing and moving physics objects"
}
]
}
分析器提供了两个强大的工具来理解和遵循 Unreal Engine 最佳实践:
// 在文件中检测模式
{
"name": "detect_patterns",
"arguments": {
"filePath": "Source/MyGame/MyActor.h"
}
}
示例输出:
{
"patterns": [
{
"pattern": "UPROPERTY 宏",
"description": "用于 Unreal 反射系统的属性声明",
"location": "Source/MyGame/MyActor.h:15",
"context": "UPROPERTY(EditAnywhere, BlueprintReadWrite)\nfloat Health;",
"improvements": "考虑添加一个 Category 标签以更好地组织\n考虑添加 Meta 标签进行验证",
"documentation": "https://docs.unrealengine.com/5.0/en-US/unreal-engine-uproperty-specifier-reference/",
"bestPractices": "使用适当的标签 (EditAnywhere, BlueprintReadWrite)\n考虑复制需求 (Replicated, ReplicatedUsing)\n使用类别分组相关属性",
"examples": "UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = \"Combat\")\nfloat Health;\nUPROPERTY(Replicated, Meta = (ClampMin = \"0.0\"))\nfloat Speed;"
}
]
}
// 获取特定 Unreal 概念的最佳实践
{
"name": "get_best_practices",
"arguments": {
"concept": "UPROPERTY" // 或 UFUNCTION, Components, Events, Replication, Blueprints
}
}
示例输出:
{
"description": "用于 Unreal 反射系统的属性声明",
"bestPractices": [
"使用适当的标签 (EditAnywhere, BlueprintReadWrite)",
"考虑复制需求 (Replicated, ReplicatedUsing)",
"使用类别分组相关属性",
"使用 Meta 标签进行验证和 UI 自定义"
],
"examples": [
"UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = \"Combat\")\nfloat Health;",
"UPROPERTY(Replicated, Meta = (ClampMin = \"0.0\"))\nfloat Speed;"
],
"documentation": "https://docs.unrealengine.com/5.0/en-US/unreal-engine-uproperty-specifier-reference/"
}
最佳实践指南涵盖了关键的 Unreal Engine 概念:
// 查询 API 文档
{
"name": "query_api",
"arguments": {
"query": "Actor",
"category": "Object",
"module": "Core",
"includeExamples": true,
"maxResults": 10
}
}
示例输出:
{
"results": [
{
"class": "AActor",
"description": "游戏中所有角色的基础类",
"module": "Core",
"category": "Object",
"syntax": "class AActor : public UObject",
"examples": [
"// 创建一个新的角色\nAActor* MyActor = GetWorld()->SpawnActor<AActor>();"
],
"remarks": [
"角色是游戏的基本构建块",
"可以在关卡中放置或动态生成"
],
"documentation": "https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Core/AActor",
"relevance": 100
}
]
}
API 文档查询工具提供:
// 分析物理子系统
{
"name": "analyze_subsystem",
"arguments": {
"subsystem": "Physics"
}
}
示例输出:
{
"name": "Physics",
"coreClasses": [
"UPhysicsEngine",
"FPhysScene",
"UBodySetup"
],
"keyFeatures": [
"PhysX 集成",
"碰撞检测",
"物理材质"
],
"commonUseCases": [
"角色移动",
"车辆模拟",
"可破坏环境"
]
}
分析器现在包括全面的 API 文档功能:
自动文档生成
智能搜索
文档分类
模块组织
与现有工具的集成
search_code 中的文件模式参数缩小结果范围当出现以下情况时,分析器会抛出清晰的错误消息:
该项目包括所有主要组件的全面测试覆盖:
分析器测试:针对 UnrealCodeAnalyzer 类的核心功能测试
游戏类型测试:验证游戏类型知识库
MCP 服务器测试:测试 MCP 服务器实现
运行所有测试:
npm test
在开发期间运行监视模式下的测试(非常有用):
npm run test:watch
在贡献新功能时,请确保:
src/__tests__ 目录下欢迎贡献!请随时提交改进的拉取请求:
在提交 PR 之前:
npm test)