虚幻引擎代码分析器 MCP 服务器
模型上下文协议 (MCP) 服务器,为虚幻引擎代码库提供强大的源代码分析功能。该工具使 Claude 和 Cline 等 AI 助手能够深入理解和分析虚幻引擎源代码。
特征
类分析:获取有关 C++ 类的详细信息,包括方法、属性和继承
层次结构映射:可视化并理解类继承层次结构
代码搜索:通过上下文感知结果搜索代码
引用查找:找到对类、函数或变量的所有引用
子系统分析:分析主要的虚幻引擎子系统,如渲染、物理等。
游戏类型知识:内置游戏类型、功能和实现模式的知识库
模式检测与学习:识别常见的虚幻引擎模式并提供学习资源
自定义代码库支持:分析您自己的虚幻引擎项目代码库
Related MCP server: RAPID MCP Server
快速入门
安装
克隆此存储库:
git clone https://github.com/ayeletstudioindia/unreal-analyzer-mcp
cd unreal-analyzer-mcp
安装依赖项:
构建项目:
配置
对于克劳德桌面应用程序
将以下内容添加到您的 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": {}
}
}
}
技术细节
该分析仪采用以下方式构建:
TypeScript 用于类型安全代码
用于稳健 C++ 解析的 Tree-sitter
用于 AI 助手集成的模型上下文协议 SDK
用于文件模式匹配的 Glob
关键依赖项:
用法
在使用任何分析工具之前,您必须首先设置虚幻引擎源路径或自定义代码库路径:
设置分析
对于虚幻引擎源代码
{
"name": "set_unreal_path",
"arguments": {
"path": "/path/to/UnrealEngine/Source"
}
}
对于自定义 C++ 代码库
{
"name": "set_custom_codebase",
"arguments": {
"path": "/path/to/your/codebase"
}
}
自定义代码库功能允许您分析任何 C++ 项目。例如:
分析自定义游戏引擎的示例:
// Initialize with custom codebase
{
"name": "set_custom_codebase",
"arguments": {
"path": "/path/to/game-engine"
}
}
// Analyze engine's renderer class
{
"name": "analyze_class",
"arguments": {
"className": "Renderer"
}
}
// Find all shader-related code
{
"name": "search_code",
"arguments": {
"query": "shader|glsl|hlsl",
"filePattern": "*.{h,cpp,hpp}"
}
}
// Get render system class hierarchy
{
"name": "find_class_hierarchy",
"arguments": {
"className": "RenderSystem",
"includeImplementedInterfaces": true
}
}
分析 Qt 应用程序的示例:
// Initialize with Qt project
{
"name": "set_custom_codebase",
"arguments": {
"path": "/path/to/qt-app"
}
}
// Find widget class definitions
{
"name": "search_code",
"arguments": {
"query": "class.*:.*public.*QWidget",
"filePattern": "*.h"
}
}
// Analyze main window class
{
"name": "analyze_class",
"arguments": {
"className": "MainWindow"
}
}
// Find signal/slot connections
{
"name": "find_references",
"arguments": {
"identifier": "connect",
"type": "function"
}
}
可用工具
1. 阶级分析
// Get detailed information about the AActor class
{
"name": "analyze_class",
"arguments": {
"className": "AActor"
}
}
示例输出:
{
"name": "AActor",
"properties": [
{
"name": "RootComponent",
"type": "USceneComponent*",
"access": "protected"
}
// ... other properties
],
"methods": [
{
"name": "BeginPlay",
"returnType": "void",
"access": "protected",
"virtual": true
}
// ... other methods
]
}
2.类层次分析
// Get the inheritance hierarchy for ACharacter
{
"name": "find_class_hierarchy",
"arguments": {
"className": "ACharacter",
"includeImplementedInterfaces": true
}
}
示例输出:
{
"class": "ACharacter",
"inheritsFrom": "APawn",
"interfaces": ["IMovementModeInterface"],
"hierarchy": [
"ACharacter",
"APawn",
"AActor",
"UObject"
]
}
3. 参考查找
// Find all references to the BeginPlay function
{
"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();"
}
]
}
4. 代码搜索
// Search for physics-related code
{
"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"
}
]
}
5. 模式检测和最佳实践
该分析器提供了两个强大的工具来帮助您理解和遵循虚幻引擎的最佳实践:
模式检测
// Detect patterns in a file
{
"name": "detect_patterns",
"arguments": {
"filePath": "Source/MyGame/MyActor.h"
}
}
示例输出:
{
"patterns": [
{
"pattern": "UPROPERTY Macro",
"description": "Property declaration for Unreal reflection system",
"location": "Source/MyGame/MyActor.h:15",
"context": "UPROPERTY(EditAnywhere, BlueprintReadWrite)\nfloat Health;",
"improvements": "Consider adding a Category specifier for better organization\nConsider adding Meta tags for validation",
"documentation": "https://docs.unrealengine.com/5.0/en-US/unreal-engine-uproperty-specifier-reference/",
"bestPractices": "Use appropriate specifiers (EditAnywhere, BlueprintReadWrite)\nConsider replication needs (Replicated, ReplicatedUsing)\nGroup related properties with categories",
"examples": "UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = \"Combat\")\nfloat Health;\nUPROPERTY(Replicated, Meta = (ClampMin = \"0.0\"))\nfloat Speed;"
}
]
}
最佳实践指南
// Get best practices for specific Unreal concepts
{
"name": "get_best_practices",
"arguments": {
"concept": "UPROPERTY" // or UFUNCTION, Components, Events, Replication, Blueprints
}
}
示例输出:
{
"description": "Property declaration for Unreal reflection system",
"bestPractices": [
"Use appropriate specifiers (EditAnywhere, BlueprintReadWrite)",
"Consider replication needs (Replicated, ReplicatedUsing)",
"Group related properties with categories",
"Use Meta tags for validation and UI customization"
],
"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/"
}
最佳实践指南涵盖了虚幻引擎的关键概念:
UPROPERTY:房产反映与曝光
UFUNCTION:函数反射和蓝图集成
组件:组件创建和管理
事件:事件处理和委托
复制:网络复制设置
蓝图:蓝图/C++交互模式
6. API文档查询
// Search the API documentation
{
"name": "query_api",
"arguments": {
"query": "Actor",
"category": "Object",
"module": "Core",
"includeExamples": true,
"maxResults": 10
}
}
示例输出:
{
"results": [
{
"class": "AActor",
"description": "Base class for all actors in the game",
"module": "Core",
"category": "Object",
"syntax": "class AActor : public UObject",
"examples": [
"// Create a new actor\nAActor* MyActor = GetWorld()->SpawnActor<AActor>();"
],
"remarks": [
"Actors are the base building blocks of the game",
"Can be placed in levels or spawned dynamically"
],
"documentation": "https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Core/AActor",
"relevance": 100
}
]
}
API文档查询工具提供:
跨类文档的全文搜索
按类别和模块过滤
代码示例和使用模式
基于相关性的结果排序
官方文档链接
7.子系统分析
// Analyze the Physics subsystem
{
"name": "analyze_subsystem",
"arguments": {
"subsystem": "Physics"
}
}
示例输出:
{
"name": "Physics",
"coreClasses": [
"UPhysicsEngine",
"FPhysScene",
"UBodySetup"
],
"keyFeatures": [
"PhysX integration",
"Collision detection",
"Physical materials"
],
"commonUseCases": [
"Character movement",
"Vehicle simulation",
"Destructible environments"
]
}
API 文档
该分析器现在包括全面的 API 文档功能:
自动文档生成
从源代码注释中提取文档
分析阶级结构和关系
按类型和模块对类进行分类
生成语法示例和使用模式
智能搜索
所有文档的全文搜索
基于相关性的结果排名
类别和模块过滤
代码示例包含
文档类别
对象:基础对象类(UObject 衍生品)
演员:演员类别(AActor 衍生品)
结构:数据结构和类型
组件:组件类
杂项:其他类和实用程序
模块组织
核心:核心引擎功能
RenderCore:渲染系统
PhysicsCore:物理引擎
以及其他发动机模块
与现有工具集成
包含类别分析的链接以获取详细信息
连接到模式检测以获得最佳实践
参考虚幻引擎官方文档
提供学习资源和示例
最佳实践
在使用分析工具之前,请务必设置虚幻引擎路径或自定义代码库路径
分析时使用特定的类名(例如,“MyClass”而不仅仅是“Class”)
利用search_code中的文件模式参数来缩小结果范围
在分析类层次结构时包含已实现的接口,以便全面理解
在深入研究特定类别之前,使用子系统分析工具获取高级概述(仅限虚幻引擎)
错误处理
在以下情况下,分析器将抛出明确的错误消息:
性能考虑
大型代码库可能需要更长时间进行分析
复杂的类层次结构可能需要更多的处理时间
广泛的搜索模式可能会产生许多匹配结果
考虑使用更具体的查询来获得更快的结果
测试
该项目包括对所有主要组件的全面测试:
测试覆盖率
运行测试
运行所有测试:
在监视模式下运行测试(在开发期间很有用):
编写测试
在贡献新功能时,请确保:
所有新功能都有相应的测试覆盖率
测试组织在src/__tests__目录中
适当地模拟外部依赖
遵循现有的测试模式以保持一致性
贡献
欢迎贡献代码!欢迎提交 PR 来改进以下功能:
源代码解析能力
新的分析功能
性能优化
文档改进
测试覆盖率
提交 PR 之前:
确保所有测试通过( npm test )
添加新功能测试
根据需要更新文档