ue-mcp 1.4.12 → 1.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (465) hide show
  1. package/README.md +4 -5
  2. package/dist/bridge/bridge-timeouts.js +16 -0
  3. package/dist/bridge/bridge-timeouts.js.map +1 -1
  4. package/dist/bridge/bridge.d.ts +58 -3
  5. package/dist/bridge/bridge.js +149 -8
  6. package/dist/bridge/bridge.js.map +1 -1
  7. package/dist/cli/cli-commands.js +7 -1
  8. package/dist/cli/cli-commands.js.map +1 -1
  9. package/dist/cli/doctor.d.ts +9 -0
  10. package/dist/cli/doctor.js +63 -0
  11. package/dist/cli/doctor.js.map +1 -1
  12. package/dist/cli/editor-flag.js +5 -1
  13. package/dist/cli/editor-flag.js.map +1 -1
  14. package/dist/cli/extension-cli.d.ts +3 -0
  15. package/dist/cli/extension-cli.js +83 -16
  16. package/dist/cli/extension-cli.js.map +1 -1
  17. package/dist/cli/flow-cli.js +3 -1
  18. package/dist/cli/flow-cli.js.map +1 -1
  19. package/dist/cli/init-core.d.ts +74 -1
  20. package/dist/cli/init-core.js +231 -38
  21. package/dist/cli/init-core.js.map +1 -1
  22. package/dist/cli/init.js +86 -22
  23. package/dist/cli/init.js.map +1 -1
  24. package/dist/cli/login-cli.d.ts +27 -1
  25. package/dist/cli/login-cli.js +130 -17
  26. package/dist/cli/login-cli.js.map +1 -1
  27. package/dist/cli/plugin-cli.js +1 -1
  28. package/dist/cli/plugin-cli.js.map +1 -1
  29. package/dist/cli/tools-cli.d.ts +14 -0
  30. package/dist/cli/tools-cli.js +270 -0
  31. package/dist/cli/tools-cli.js.map +1 -0
  32. package/dist/cli/ui/ansi.d.ts +2 -0
  33. package/dist/cli/ui/ansi.js +8 -0
  34. package/dist/cli/ui/ansi.js.map +1 -1
  35. package/dist/codeintel/config-hierarchy.d.ts +73 -0
  36. package/dist/codeintel/config-hierarchy.js +165 -0
  37. package/dist/codeintel/config-hierarchy.js.map +1 -0
  38. package/dist/config/project.d.ts +12 -4
  39. package/dist/config/project.js.map +1 -1
  40. package/dist/core/archive.d.ts +8 -0
  41. package/dist/core/archive.js +40 -0
  42. package/dist/core/archive.js.map +1 -0
  43. package/dist/core/env.d.ts +4 -0
  44. package/dist/core/env.js +4 -0
  45. package/dist/core/env.js.map +1 -1
  46. package/dist/core/errors.d.ts +9 -1
  47. package/dist/core/errors.js +8 -0
  48. package/dist/core/errors.js.map +1 -1
  49. package/dist/core/png.d.ts +31 -0
  50. package/dist/core/png.js +308 -0
  51. package/dist/core/png.js.map +1 -0
  52. package/dist/core/types.d.ts +31 -0
  53. package/dist/daemon/daemon.js +16 -2
  54. package/dist/daemon/daemon.js.map +1 -1
  55. package/dist/daemon/extension-install.d.ts +14 -0
  56. package/dist/daemon/extension-install.js +25 -29
  57. package/dist/daemon/extension-install.js.map +1 -1
  58. package/dist/daemon/install-names.d.ts +10 -0
  59. package/dist/daemon/install-names.js +39 -0
  60. package/dist/daemon/install-names.js.map +1 -0
  61. package/dist/daemon/tools-routes.d.ts +23 -0
  62. package/dist/daemon/tools-routes.js +46 -0
  63. package/dist/daemon/tools-routes.js.map +1 -0
  64. package/dist/diagram/action.d.ts +25 -0
  65. package/dist/diagram/action.js +141 -0
  66. package/dist/diagram/action.js.map +1 -0
  67. package/dist/diagram/adapters.d.ts +48 -0
  68. package/dist/diagram/adapters.js +569 -0
  69. package/dist/diagram/adapters.js.map +1 -0
  70. package/dist/diagram/mermaid.d.ts +22 -0
  71. package/dist/diagram/mermaid.js +164 -0
  72. package/dist/diagram/mermaid.js.map +1 -0
  73. package/dist/diagram/model.d.ts +59 -0
  74. package/dist/diagram/model.js +17 -0
  75. package/dist/diagram/model.js.map +1 -0
  76. package/dist/diagram/png.d.ts +17 -0
  77. package/dist/diagram/png.js +48 -0
  78. package/dist/diagram/png.js.map +1 -0
  79. package/dist/diagram/select.d.ts +26 -0
  80. package/dist/diagram/select.js +146 -0
  81. package/dist/diagram/select.js.map +1 -0
  82. package/dist/diagram/svg.d.ts +10 -0
  83. package/dist/diagram/svg.js +254 -0
  84. package/dist/diagram/svg.js.map +1 -0
  85. package/dist/diagram/theme.d.ts +33 -0
  86. package/dist/diagram/theme.js +37 -0
  87. package/dist/diagram/theme.js.map +1 -0
  88. package/dist/dispatch/call-pipeline.d.ts +8 -0
  89. package/dist/dispatch/call-pipeline.js +19 -2
  90. package/dist/dispatch/call-pipeline.js.map +1 -1
  91. package/dist/dispatch/inline-image.d.ts +70 -0
  92. package/dist/dispatch/inline-image.js +198 -0
  93. package/dist/dispatch/inline-image.js.map +1 -0
  94. package/dist/dispatch/lease-paths.d.ts +16 -0
  95. package/dist/dispatch/lease-paths.js +42 -0
  96. package/dist/dispatch/lease-paths.js.map +1 -0
  97. package/dist/dispatch/leases.d.ts +71 -0
  98. package/dist/dispatch/leases.js +191 -0
  99. package/dist/dispatch/leases.js.map +1 -0
  100. package/dist/dispatch/offline.js +17 -0
  101. package/dist/dispatch/offline.js.map +1 -1
  102. package/dist/dispatch/server-dispatch.d.ts +32 -1
  103. package/dist/dispatch/server-dispatch.js +70 -2
  104. package/dist/dispatch/server-dispatch.js.map +1 -1
  105. package/dist/editor/bridge-binaries.d.ts +2 -0
  106. package/dist/editor/bridge-binaries.js +12 -22
  107. package/dist/editor/bridge-binaries.js.map +1 -1
  108. package/dist/editor/dialog-guard.d.ts +10 -0
  109. package/dist/editor/dialog-guard.js +26 -4
  110. package/dist/editor/dialog-guard.js.map +1 -1
  111. package/dist/editor/editor-plugin.d.ts +16 -0
  112. package/dist/editor/editor-plugin.js +98 -0
  113. package/dist/editor/editor-plugin.js.map +1 -0
  114. package/dist/editor/engine-root.d.ts +2 -0
  115. package/dist/editor/engine-root.js +2 -2
  116. package/dist/editor/engine-root.js.map +1 -1
  117. package/dist/editor/install-marker.d.ts +2 -0
  118. package/dist/editor/install-marker.js +13 -6
  119. package/dist/editor/install-marker.js.map +1 -1
  120. package/dist/extensions/registry-auth.d.ts +60 -1
  121. package/dist/extensions/registry-auth.js +202 -5
  122. package/dist/extensions/registry-auth.js.map +1 -1
  123. package/dist/extensions/skill-catalog.d.ts +20 -0
  124. package/dist/extensions/skill-catalog.js +56 -0
  125. package/dist/extensions/skill-catalog.js.map +1 -0
  126. package/dist/flow/flow-tool.js +10 -2
  127. package/dist/flow/flow-tool.js.map +1 -1
  128. package/dist/flow/guarded-bridge.d.ts +6 -4
  129. package/dist/flow/guarded-bridge.js +11 -5
  130. package/dist/flow/guarded-bridge.js.map +1 -1
  131. package/dist/flow/loader.js +19 -0
  132. package/dist/flow/loader.js.map +1 -1
  133. package/dist/flow/run-action.js +37 -5
  134. package/dist/flow/run-action.js.map +1 -1
  135. package/dist/flow/write-methods.js +4 -0
  136. package/dist/flow/write-methods.js.map +1 -1
  137. package/dist/integrations/agent-guides.d.ts +29 -0
  138. package/dist/integrations/agent-guides.js +125 -0
  139. package/dist/integrations/agent-guides.js.map +1 -0
  140. package/dist/integrations/claude-code/mcp-client-config.d.ts +16 -4
  141. package/dist/integrations/claude-code/mcp-client-config.js +57 -10
  142. package/dist/integrations/claude-code/mcp-client-config.js.map +1 -1
  143. package/dist/integrations/claude-code/unreal-mcp-entries.d.ts +33 -0
  144. package/dist/integrations/claude-code/unreal-mcp-entries.js +159 -0
  145. package/dist/integrations/claude-code/unreal-mcp-entries.js.map +1 -0
  146. package/dist/integrations/epic/project-status.d.ts +25 -0
  147. package/dist/integrations/epic/project-status.js +35 -0
  148. package/dist/integrations/epic/project-status.js.map +1 -0
  149. package/dist/integrations/epic/toolset-settings.d.ts +28 -0
  150. package/dist/integrations/epic/toolset-settings.js +136 -0
  151. package/dist/integrations/epic/toolset-settings.js.map +1 -0
  152. package/dist/integrations/epic/unreal-assistant.d.ts +64 -0
  153. package/dist/integrations/epic/unreal-assistant.js +209 -0
  154. package/dist/integrations/epic/unreal-assistant.js.map +1 -0
  155. package/dist/integrations/epic/unreal-canvas.d.ts +48 -0
  156. package/dist/integrations/epic/unreal-canvas.js +126 -0
  157. package/dist/integrations/epic/unreal-canvas.js.map +1 -0
  158. package/dist/integrations/epic/unreal-mcp-server.d.ts +74 -0
  159. package/dist/integrations/epic/unreal-mcp-server.js +231 -0
  160. package/dist/integrations/epic/unreal-mcp-server.js.map +1 -0
  161. package/dist/server/context-projection.js +5 -3
  162. package/dist/server/context-projection.js.map +1 -1
  163. package/dist/server/editor-resources.d.ts +39 -0
  164. package/dist/server/editor-resources.js +94 -0
  165. package/dist/server/editor-resources.js.map +1 -0
  166. package/dist/server/mcp-server.d.ts +7 -0
  167. package/dist/server/mcp-server.js +49 -13
  168. package/dist/server/mcp-server.js.map +1 -1
  169. package/dist/server/runtime.js +21 -1
  170. package/dist/server/runtime.js.map +1 -1
  171. package/dist/server/skill-prompts.d.ts +16 -0
  172. package/dist/server/skill-prompts.js +22 -0
  173. package/dist/server/skill-prompts.js.map +1 -0
  174. package/dist/sessions/session-load.d.ts +16 -0
  175. package/dist/sessions/session-load.js +64 -20
  176. package/dist/sessions/session-load.js.map +1 -1
  177. package/dist/sessions/session.d.ts +9 -0
  178. package/dist/sessions/session.js +8 -0
  179. package/dist/sessions/session.js.map +1 -1
  180. package/dist/surface/action-signature.js +9 -0
  181. package/dist/surface/action-signature.js.map +1 -1
  182. package/dist/surface/category-state.d.ts +119 -0
  183. package/dist/surface/category-state.js +232 -0
  184. package/dist/surface/category-state.js.map +1 -0
  185. package/dist/surface/context/call-envelope.d.ts +7 -0
  186. package/dist/surface/context/call-envelope.js +11 -0
  187. package/dist/surface/context/call-envelope.js.map +1 -1
  188. package/dist/surface/context/instructions.d.ts +2 -0
  189. package/dist/surface/context/instructions.js +20 -10
  190. package/dist/surface/context/instructions.js.map +1 -1
  191. package/dist/surface/context/micro-context.d.ts +7 -0
  192. package/dist/surface/context/micro-context.js +70 -14
  193. package/dist/surface/context/micro-context.js.map +1 -1
  194. package/dist/surface/context/tool-search.js +6 -2
  195. package/dist/surface/context/tool-search.js.map +1 -1
  196. package/dist/surface/epic-engines.d.ts +24 -0
  197. package/dist/surface/epic-engines.js +32 -0
  198. package/dist/surface/epic-engines.js.map +1 -0
  199. package/dist/surface/epic-input.d.ts +27 -2
  200. package/dist/surface/epic-input.js +39 -2
  201. package/dist/surface/epic-input.js.map +1 -1
  202. package/dist/surface/epic-surface.d.ts +15 -17
  203. package/dist/surface/epic-surface.js +13 -57
  204. package/dist/surface/epic-surface.js.map +1 -1
  205. package/dist/surface/registered-surface.d.ts +21 -4
  206. package/dist/surface/registered-surface.js +67 -23
  207. package/dist/surface/registered-surface.js.map +1 -1
  208. package/dist/surface/schemas.d.ts +8 -0
  209. package/dist/surface/schemas.js +14 -3
  210. package/dist/surface/schemas.js.map +1 -1
  211. package/dist/tool-counts.json +38 -31
  212. package/dist/tools/ai-assistant-wait.d.ts +17 -0
  213. package/dist/tools/ai-assistant-wait.js +45 -0
  214. package/dist/tools/ai-assistant-wait.js.map +1 -0
  215. package/dist/tools/animation.js +14 -8
  216. package/dist/tools/animation.js.map +1 -1
  217. package/dist/tools/asset.js +18 -5
  218. package/dist/tools/asset.js.map +1 -1
  219. package/dist/tools/audio.js +3 -0
  220. package/dist/tools/audio.js.map +1 -1
  221. package/dist/tools/blueprint.js +7 -0
  222. package/dist/tools/blueprint.js.map +1 -1
  223. package/dist/tools/canvas-results.d.ts +32 -0
  224. package/dist/tools/canvas-results.js +137 -0
  225. package/dist/tools/canvas-results.js.map +1 -0
  226. package/dist/tools/canvas.d.ts +19 -0
  227. package/dist/tools/canvas.js +254 -0
  228. package/dist/tools/canvas.js.map +1 -0
  229. package/dist/tools/chooser.js +42 -6
  230. package/dist/tools/chooser.js.map +1 -1
  231. package/dist/tools/demo.js +2 -2
  232. package/dist/tools/demo.js.map +1 -1
  233. package/dist/tools/editor/batch.js +1 -1
  234. package/dist/tools/editor/batch.js.map +1 -1
  235. package/dist/tools/editor-csv-profile.d.ts +62 -0
  236. package/dist/tools/editor-csv-profile.js +266 -0
  237. package/dist/tools/editor-csv-profile.js.map +1 -0
  238. package/dist/tools/editor.js +41 -12
  239. package/dist/tools/editor.js.map +1 -1
  240. package/dist/tools/epic/animation.generated.d.ts +1 -1
  241. package/dist/tools/epic/animation.generated.js +5051 -695
  242. package/dist/tools/epic/animation.generated.js.map +1 -1
  243. package/dist/tools/epic/asset.generated.d.ts +1 -1
  244. package/dist/tools/epic/asset.generated.js +848 -156
  245. package/dist/tools/epic/asset.generated.js.map +1 -1
  246. package/dist/tools/epic/audio.generated.d.ts +6 -0
  247. package/dist/tools/epic/audio.generated.js +323 -0
  248. package/dist/tools/epic/audio.generated.js.map +1 -0
  249. package/dist/tools/epic/blueprint.generated.d.ts +1 -1
  250. package/dist/tools/epic/blueprint.generated.js +467 -118
  251. package/dist/tools/epic/blueprint.generated.js.map +1 -1
  252. package/dist/tools/epic/catalog-engines.d.ts +2 -0
  253. package/dist/tools/epic/catalog-engines.js +4 -0
  254. package/dist/tools/epic/catalog-engines.js.map +1 -0
  255. package/dist/tools/epic/conversation.generated.js +11 -11
  256. package/dist/tools/epic/conversation.generated.js.map +1 -1
  257. package/dist/tools/epic/dataflow.generated.d.ts +1 -1
  258. package/dist/tools/epic/dataflow.generated.js +349 -29
  259. package/dist/tools/epic/dataflow.generated.js.map +1 -1
  260. package/dist/tools/epic/editor.generated.d.ts +1 -1
  261. package/dist/tools/epic/editor.generated.js +575 -41
  262. package/dist/tools/epic/editor.generated.js.map +1 -1
  263. package/dist/tools/epic/effects.d.ts +9 -3
  264. package/dist/tools/epic/effects.js +3384 -33
  265. package/dist/tools/epic/effects.js.map +1 -1
  266. package/dist/tools/epic/epic.generated.d.ts +1 -1
  267. package/dist/tools/epic/epic.generated.js +68 -10
  268. package/dist/tools/epic/epic.generated.js.map +1 -1
  269. package/dist/tools/epic/gameplay.generated.d.ts +1 -1
  270. package/dist/tools/epic/gameplay.generated.js +502 -45
  271. package/dist/tools/epic/gameplay.generated.js.map +1 -1
  272. package/dist/tools/epic/gas.generated.d.ts +1 -1
  273. package/dist/tools/epic/gas.generated.js +29 -21
  274. package/dist/tools/epic/gas.generated.js.map +1 -1
  275. package/dist/tools/epic/index.d.ts +4 -0
  276. package/dist/tools/epic/index.js +4 -0
  277. package/dist/tools/epic/index.js.map +1 -1
  278. package/dist/tools/epic/level.generated.d.ts +1 -1
  279. package/dist/tools/epic/level.generated.js +524 -95
  280. package/dist/tools/epic/level.generated.js.map +1 -1
  281. package/dist/tools/epic/material.generated.d.ts +1 -1
  282. package/dist/tools/epic/material.generated.js +152 -76
  283. package/dist/tools/epic/material.generated.js.map +1 -1
  284. package/dist/tools/epic/niagara.generated.d.ts +1 -1
  285. package/dist/tools/epic/niagara.generated.js +124 -115
  286. package/dist/tools/epic/niagara.generated.js.map +1 -1
  287. package/dist/tools/epic/pcg.generated.d.ts +1 -1
  288. package/dist/tools/epic/pcg.generated.js +322 -47
  289. package/dist/tools/epic/pcg.generated.js.map +1 -1
  290. package/dist/tools/epic/plugins.generated.d.ts +1 -1
  291. package/dist/tools/epic/plugins.generated.js +143 -36
  292. package/dist/tools/epic/plugins.generated.js.map +1 -1
  293. package/dist/tools/epic/project.generated.d.ts +1 -1
  294. package/dist/tools/epic/project.generated.js +144 -31
  295. package/dist/tools/epic/project.generated.js.map +1 -1
  296. package/dist/tools/epic/reflection.generated.d.ts +1 -1
  297. package/dist/tools/epic/reflection.generated.js +33 -16
  298. package/dist/tools/epic/reflection.generated.js.map +1 -1
  299. package/dist/tools/epic/source_control.generated.d.ts +6 -0
  300. package/dist/tools/epic/source_control.generated.js +260 -0
  301. package/dist/tools/epic/source_control.generated.js.map +1 -0
  302. package/dist/tools/epic/statetree.generated.d.ts +1 -1
  303. package/dist/tools/epic/statetree.generated.js +292 -20
  304. package/dist/tools/epic/statetree.generated.js.map +1 -1
  305. package/dist/tools/epic/toolset-routes.d.ts +6 -0
  306. package/dist/tools/epic/toolset-routes.js +74 -0
  307. package/dist/tools/epic/toolset-routes.js.map +1 -0
  308. package/dist/tools/epic/widget.generated.d.ts +1 -1
  309. package/dist/tools/epic/widget.generated.js +797 -85
  310. package/dist/tools/epic/widget.generated.js.map +1 -1
  311. package/dist/tools/epic.js +22 -4
  312. package/dist/tools/epic.js.map +1 -1
  313. package/dist/tools/gameplay.js +10 -0
  314. package/dist/tools/gameplay.js.map +1 -1
  315. package/dist/tools/graph-diagrams.d.ts +15 -0
  316. package/dist/tools/graph-diagrams.js +153 -0
  317. package/dist/tools/graph-diagrams.js.map +1 -0
  318. package/dist/tools/landscape.js +12 -1
  319. package/dist/tools/landscape.js.map +1 -1
  320. package/dist/tools/level.js +35 -1
  321. package/dist/tools/level.js.map +1 -1
  322. package/dist/tools/material.js +7 -1
  323. package/dist/tools/material.js.map +1 -1
  324. package/dist/tools/networking.js +1 -0
  325. package/dist/tools/networking.js.map +1 -1
  326. package/dist/tools/pcg.js +8 -1
  327. package/dist/tools/pcg.js.map +1 -1
  328. package/dist/tools/project/categories.d.ts +74 -0
  329. package/dist/tools/project/categories.js +405 -0
  330. package/dist/tools/project/categories.js.map +1 -0
  331. package/dist/tools/project/config.js +93 -0
  332. package/dist/tools/project/config.js.map +1 -1
  333. package/dist/tools/project/leases.d.ts +8 -0
  334. package/dist/tools/project/leases.js +107 -0
  335. package/dist/tools/project/leases.js.map +1 -0
  336. package/dist/tools/project/localization.d.ts +7 -0
  337. package/dist/tools/project/localization.js +21 -0
  338. package/dist/tools/project/localization.js.map +1 -0
  339. package/dist/tools/project/sessions.js +29 -1
  340. package/dist/tools/project/sessions.js.map +1 -1
  341. package/dist/tools/project.js +25 -4
  342. package/dist/tools/project.js.map +1 -1
  343. package/dist/tools/source_control.js +3 -0
  344. package/dist/tools/source_control.js.map +1 -1
  345. package/dist/tools/specs/animation.generated.js +3 -3
  346. package/dist/tools/specs/animation.generated.js.map +1 -1
  347. package/dist/tools/specs/asset.generated.js +223 -12
  348. package/dist/tools/specs/asset.generated.js.map +1 -1
  349. package/dist/tools/specs/chooser.generated.js +1039 -63
  350. package/dist/tools/specs/chooser.generated.js.map +1 -1
  351. package/dist/tools/specs/demo.generated.js +11 -3
  352. package/dist/tools/specs/demo.generated.js.map +1 -1
  353. package/dist/tools/specs/editor.generated.js +444 -15
  354. package/dist/tools/specs/editor.generated.js.map +1 -1
  355. package/dist/tools/specs/epic.generated.js +215 -3
  356. package/dist/tools/specs/epic.generated.js.map +1 -1
  357. package/dist/tools/specs/gameplay.generated.js +175 -4
  358. package/dist/tools/specs/gameplay.generated.js.map +1 -1
  359. package/dist/tools/specs/landscape.generated.js +483 -7
  360. package/dist/tools/specs/landscape.generated.js.map +1 -1
  361. package/dist/tools/specs/level.generated.js +1218 -68
  362. package/dist/tools/specs/level.generated.js.map +1 -1
  363. package/dist/tools/specs/networking.generated.js +83 -0
  364. package/dist/tools/specs/networking.generated.js.map +1 -1
  365. package/dist/tools/specs/pcg.generated.js +125 -5
  366. package/dist/tools/specs/pcg.generated.js.map +1 -1
  367. package/dist/tools/specs/project.generated.js +134 -0
  368. package/dist/tools/specs/project.generated.js.map +1 -1
  369. package/dist/tools/specs/statetree.generated.js +245 -9
  370. package/dist/tools/specs/statetree.generated.js.map +1 -1
  371. package/dist/tools/specs/widget.generated.js +362 -3
  372. package/dist/tools/specs/widget.generated.js.map +1 -1
  373. package/dist/tools/statetree.js +12 -1
  374. package/dist/tools/statetree.js.map +1 -1
  375. package/dist/tools/widget.js +12 -0
  376. package/dist/tools/widget.js.map +1 -1
  377. package/dist/tools.js +2 -0
  378. package/dist/tools.js.map +1 -1
  379. package/dist/ue-mcp.default.yml +14785 -983
  380. package/package.json +4 -2
  381. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/BridgePortConfig.cpp +56 -4
  382. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/BridgeRequestContext.h +54 -0
  383. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/BridgeServer.cpp +203 -18
  384. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/BridgeServer.h +42 -0
  385. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/HandlerCatalog.cpp +6 -0
  386. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/HandlerDeferred.cpp +225 -0
  387. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/HandlerLevelSwitch.h +123 -0
  388. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/HandlerScriptErrors.h +44 -0
  389. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Animation/AnimationHandlers.cpp +7 -7
  390. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers.cpp +15 -0
  391. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers.h +9 -0
  392. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers_Import.cpp +147 -0
  393. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers_Redirectors.cpp +11 -0
  394. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers_SemanticSearch.cpp +435 -0
  395. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Chooser/ChooserHandlers.cpp +363 -331
  396. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Chooser/ChooserHandlers.h +30 -0
  397. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Chooser/ChooserHandlers_Authoring.cpp +2178 -0
  398. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Chooser/HandlerChooserShared.h +1005 -0
  399. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Demo/DemoHandlers.cpp +104 -11
  400. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Demo/DemoHandlers.h +19 -1
  401. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Dialog/DialogHandlers.cpp +54 -2
  402. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Dialog/DialogHandlers.h +9 -0
  403. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Editor/EditorHandlers.cpp +31 -0
  404. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Editor/EditorHandlers.h +15 -0
  405. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Editor/EditorHandlers_CsvProfile.cpp +272 -0
  406. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Editor/EditorHandlers_MapCheck.cpp +197 -0
  407. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Editor/EditorHandlers_Profiling.cpp +11 -16
  408. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Editor/EditorHandlers_PythonPaths.cpp +237 -0
  409. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Editor/EditorHandlers_TraceAnalysis.cpp +790 -0
  410. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/EpicHandlers.cpp +201 -56
  411. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/EpicHandlers.h +30 -0
  412. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/EpicHandlers_AIAssistant.cpp +510 -0
  413. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/EpicHandlers_MCP.cpp +394 -0
  414. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/EpicHandlers_Toolsets.cpp +542 -0
  415. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/MCPAIAssistantListener.h +19 -0
  416. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Gas/GasHandlers_Runtime.cpp +10 -7
  417. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Landscape/LandscapeHandlers.cpp +9 -23
  418. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Landscape/LandscapeHandlers.h +4 -0
  419. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Landscape/LandscapeHandlers_Sculpt.cpp +7 -0
  420. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Landscape/LandscapeHandlers_Splines.cpp +1253 -0
  421. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Landscape/LandscapeHandlers_Splines.h +39 -0
  422. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelGeneratorRecords.h +84 -0
  423. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers.cpp +57 -12
  424. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers.h +33 -0
  425. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_Blockout.cpp +987 -0
  426. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_Blockout.h +23 -0
  427. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_PerfAudit.cpp +925 -0
  428. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_ReplaceActors.cpp +387 -0
  429. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_SplineGen.cpp +813 -0
  430. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_SplineGen.h +22 -0
  431. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_WorldPartitionSubsystem.cpp +1238 -0
  432. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Localization/LocalizationHandlers.cpp +982 -0
  433. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Localization/LocalizationHandlers.h +32 -0
  434. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/MachineLearning/MachineLearningHandlers.cpp +44 -0
  435. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/MachineLearning/MachineLearningHandlers.h +29 -0
  436. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/MachineLearning/MachineLearningHandlers_LearningAgents.cpp +491 -0
  437. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/MachineLearning/MachineLearningHandlers_NNE.cpp +532 -0
  438. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Networking/NetworkingHandlers.cpp +14 -0
  439. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Networking/NetworkingHandlers.h +2 -0
  440. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Networking/NetworkingHandlers_Audit.cpp +496 -0
  441. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PCG/PCGEdgeValidation.h +150 -0
  442. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PCG/PCGHandlers.cpp +26 -1
  443. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PCG/PCGHandlers.h +5 -0
  444. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PCG/PCGHandlers_CustomHLSL.cpp +290 -0
  445. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PCG/PCGHandlers_LevelToAsset.cpp +34 -3
  446. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Sequencer/MovieRenderQueueHandlers.cpp +1215 -0
  447. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Sequencer/MovieRenderQueueHandlers.h +27 -0
  448. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/StateTree/StateTreeHandlers.cpp +72 -0
  449. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/StateTree/StateTreeHandlers.h +11 -0
  450. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/StateTree/StateTreeHandlers_NodesAndBindings.cpp +1172 -0
  451. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Widget/WidgetHandlers.cpp +4 -0
  452. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Widget/WidgetHandlers_MVVM.cpp +396 -0
  453. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Widget/WidgetHandlers_MVVM.h +32 -0
  454. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/DialogBlockingWindowTests.cpp +74 -0
  455. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/HandlerSpecContractTests.cpp +4 -0
  456. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Public/HandlerDeferred.h +76 -0
  457. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Public/HandlerEngineVersion.h +4 -0
  458. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Public/HandlerMVVMBackend.h +92 -0
  459. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Public/HandlerStaticInvoke.h +96 -0
  460. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/UE_MCP_Bridge.Build.cs +75 -0
  461. package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeMVVM/Private/UE_MCP_BridgeMVVMModule.cpp +1277 -0
  462. package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeMVVM/UE_MCP_BridgeMVVM.Build.cs +58 -0
  463. package/plugin/ue_mcp_bridge/UE_MCP_Bridge.uplugin +7 -2
  464. package/skills/ue-mcp-animation/SKILL.md +4 -4
  465. package/skills/ue-mcp-epic-routing/SKILL.md +4 -0
@@ -0,0 +1,790 @@
1
+ // editor(analyze_trace): read a recorded .utrace back and summarise it.
2
+ //
3
+ // editor(start_trace) and editor(stop_trace) write a trace and report where it
4
+ // landed. This file is the other half: it opens the file with the engine's own
5
+ // analysis stack (TraceServices, the module Unreal Insights is built on) and
6
+ // answers the questions a profiling pass starts with, without leaving the
7
+ // editor:
8
+ //
9
+ // * frames: count, average, p50/p95/p99, min and max frame time;
10
+ // * hitches: every frame over a threshold, in time order;
11
+ // * worst frames, each with the CPU timers that spent its time;
12
+ // * top timers over the window, by inclusive or exclusive time;
13
+ // * GPU busy time per frame, when the trace carries GPU timing;
14
+ // * bookmarks with their times and the frame they fell in.
15
+ //
16
+ // How a session is opened and read mirrors Insights: ITraceServicesModule hands
17
+ // out the analysis service, StartAnalysis runs the analyzers on worker threads,
18
+ // and every provider read happens inside FAnalysisSessionReadScope once
19
+ // IsAnalysisComplete reports true. A long trace takes a while to analyse, so a
20
+ // bridge request defers its answer (HandlerDeferred.h): the handler starts the
21
+ // session on the game thread, returns the deferred marker, and a pool task
22
+ // waits for the analysis, reports progress, builds the summary and completes
23
+ // the call. A cancel stops the session.
24
+ //
25
+ // Engine versions. TraceServices exists on every supported engine, but its
26
+ // timing-profiler surface moved a lot before 5.7 (aggregation parameters, timer
27
+ // readers, GPU queues). The headers read for this file are 5.7, 5.8 and 5.9, so
28
+ // the analysis is compiled from 5.7 up and older engines get a clear error
29
+ // rather than a guess at an API nobody here has read. Within that range the
30
+ // calls used here (CreateAggregation, ReadTimeline, EnumerateGpuQueues and the
31
+ // frame, thread and bookmark providers) have the same signatures.
32
+ //
33
+ // Every helper is prefixed MCPTraceAnalysis: the module is a unity build, and
34
+ // two .cpp files that share a blob share their anonymous namespaces.
35
+
36
+ #include "EditorHandlers.h"
37
+
38
+ #include "HandlerDeferred.h"
39
+ #include "HandlerUtils.h"
40
+
41
+ #include "Async/Async.h"
42
+ #include "HAL/FileManager.h"
43
+ #include "HAL/PlatformProcess.h"
44
+ #include "HAL/PlatformTime.h"
45
+ #include "Misc/DateTime.h"
46
+ #include "Misc/Paths.h"
47
+ #include "Modules/ModuleManager.h"
48
+ #include "ProfilingDebugging/MiscTrace.h"
49
+ #include "ProfilingDebugging/TraceAuxiliary.h"
50
+
51
+ #include "Dom/JsonObject.h"
52
+ #include "Dom/JsonValue.h"
53
+
54
+ #if UE_MCP_HAS_5_7_API
55
+ #include "TraceServices/AnalysisService.h"
56
+ #include "TraceServices/Containers/Tables.h"
57
+ #include "TraceServices/Containers/Timelines.h"
58
+ #include "TraceServices/ITraceServicesModule.h"
59
+ #include "TraceServices/Model/AnalysisSession.h"
60
+ #include "TraceServices/Model/Bookmarks.h"
61
+ #include "TraceServices/Model/Frames.h"
62
+ #include "TraceServices/Model/Threads.h"
63
+ #include "TraceServices/Model/TimingProfiler.h"
64
+ #endif
65
+
66
+ namespace
67
+ {
68
+ /** What the caller asked for, copied off the params on the game thread so
69
+ * the pool task never touches the request object. */
70
+ struct FMCPTraceAnalysisRequest
71
+ {
72
+ FString File;
73
+ double WindowStart = 0.0;
74
+ /** Negative: to the end of the trace. */
75
+ double WindowEnd = -1.0;
76
+ double HitchThresholdMs = 50.0;
77
+ int32 WorstFrames = 10;
78
+ int32 TopTimers = 20;
79
+ int32 TimersPerFrame = 5;
80
+ int32 MaxHitches = 50;
81
+ int32 MaxBookmarks = 100;
82
+ bool bAllThreads = false;
83
+ bool bSortExclusive = false;
84
+ bool bRenderingFrames = false;
85
+ bool bDumpToFile = false;
86
+ FString OutputPath;
87
+ };
88
+
89
+ /** The newest .utrace under Saved/Profiling, which is where start_trace
90
+ * writes by default. Empty when there is none. */
91
+ FString MCPTraceAnalysisNewestTrace()
92
+ {
93
+ const FString Dir = FPaths::ConvertRelativePathToFull(
94
+ FPaths::Combine(FPaths::ProjectSavedDir(), TEXT("Profiling")));
95
+ TArray<FString> Found;
96
+ IFileManager::Get().FindFilesRecursive(Found, *Dir, TEXT("*.utrace"), /*Files=*/true, /*Directories=*/false);
97
+ FString Newest;
98
+ FDateTime NewestStamp = FDateTime::MinValue();
99
+ for (const FString& Path : Found)
100
+ {
101
+ const FDateTime Stamp = IFileManager::Get().GetTimeStamp(*Path);
102
+ if (Newest.IsEmpty() || Stamp > NewestStamp)
103
+ {
104
+ Newest = Path;
105
+ NewestStamp = Stamp;
106
+ }
107
+ }
108
+ return Newest;
109
+ }
110
+
111
+ /** A relative path is tried under Saved/Profiling first, where traces
112
+ * land, then under the project directory. */
113
+ FString MCPTraceAnalysisResolveFile(const FString& Requested)
114
+ {
115
+ if (!FPaths::IsRelative(Requested))
116
+ {
117
+ return FPaths::ConvertRelativePathToFull(Requested);
118
+ }
119
+ const FString UnderProfiling = FPaths::ConvertRelativePathToFull(
120
+ FPaths::Combine(FPaths::ProjectSavedDir(), TEXT("Profiling"), Requested));
121
+ if (FPaths::FileExists(UnderProfiling))
122
+ {
123
+ return UnderProfiling;
124
+ }
125
+ return FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectDir(), Requested));
126
+ }
127
+
128
+ #if UE_MCP_HAS_5_7_API
129
+ double MCPTraceAnalysisPercentile(const TArray<double>& Sorted, double P)
130
+ {
131
+ if (Sorted.Num() == 0) return 0.0;
132
+ // Nearest rank: the smallest value with at least P of the samples at
133
+ // or below it. No interpolation, so every reported value is a frame
134
+ // that really happened.
135
+ const int32 Rank = FMath::Clamp(FMath::CeilToInt(P * Sorted.Num()) - 1, 0, Sorted.Num() - 1);
136
+ return Sorted[Rank];
137
+ }
138
+
139
+ TSharedPtr<FJsonObject> MCPTraceAnalysisDistribution(TArray<double> Values)
140
+ {
141
+ TSharedPtr<FJsonObject> Out = MakeShared<FJsonObject>();
142
+ Values.Sort();
143
+ double Total = 0.0;
144
+ for (double V : Values) Total += V;
145
+ Out->SetNumberField(TEXT("count"), Values.Num());
146
+ Out->SetNumberField(TEXT("avgMs"), Values.Num() > 0 ? Total / Values.Num() : 0.0);
147
+ Out->SetNumberField(TEXT("p50Ms"), MCPTraceAnalysisPercentile(Values, 0.50));
148
+ Out->SetNumberField(TEXT("p95Ms"), MCPTraceAnalysisPercentile(Values, 0.95));
149
+ Out->SetNumberField(TEXT("p99Ms"), MCPTraceAnalysisPercentile(Values, 0.99));
150
+ Out->SetNumberField(TEXT("minMs"), Values.Num() > 0 ? Values[0] : 0.0);
151
+ Out->SetNumberField(TEXT("maxMs"), Values.Num() > 0 ? Values.Last() : 0.0);
152
+ return Out;
153
+ }
154
+
155
+ struct FMCPTraceAnalysisFrame
156
+ {
157
+ uint64 Index = 0;
158
+ double Start = 0.0;
159
+ double End = 0.0;
160
+ double Ms = 0.0;
161
+ };
162
+
163
+ struct FMCPTraceAnalysisTimerRow
164
+ {
165
+ FString Name;
166
+ const TCHAR* Type = TEXT("cpu");
167
+ uint64 Count = 0;
168
+ double InclusiveMs = 0.0;
169
+ double ExclusiveMs = 0.0;
170
+ double MaxInclusiveMs = 0.0;
171
+ double AvgInclusiveMs = 0.0;
172
+ };
173
+
174
+ const TCHAR* MCPTraceAnalysisTimerTypeName(const TraceServices::FTimingProfilerTimer* Timer)
175
+ {
176
+ if (!Timer) return TEXT("unknown");
177
+ switch (Timer->Type)
178
+ {
179
+ case TraceServices::ETimingProfilerTimerType::CpuScope: return TEXT("cpu");
180
+ case TraceServices::ETimingProfilerTimerType::CpuSampling: return TEXT("cpuSampling");
181
+ case TraceServices::ETimingProfilerTimerType::GpuScope: return TEXT("gpu");
182
+ case TraceServices::ETimingProfilerTimerType::VerseSampling: return TEXT("verse");
183
+ default: return TEXT("unknown");
184
+ }
185
+ }
186
+
187
+ /** One aggregation over [Start, End], CPU timelines only. ThreadId unset
188
+ * means every CPU thread; set, only that one. Rows come back unsorted:
189
+ * the caller sorts by the column it reports, because the engine's own
190
+ * sort only knows inclusive time and the per-frame view wants exclusive. */
191
+ TArray<FMCPTraceAnalysisTimerRow> MCPTraceAnalysisAggregate(
192
+ const TraceServices::ITimingProfilerProvider& Timing, double Start, double End, TOptional<uint32> ThreadId)
193
+ {
194
+ TArray<FMCPTraceAnalysisTimerRow> Rows;
195
+
196
+ TraceServices::FCreateAggregationParams Params;
197
+ Params.IntervalStart = Start;
198
+ Params.IntervalEnd = End;
199
+ if (ThreadId.IsSet())
200
+ {
201
+ const uint32 Wanted = ThreadId.GetValue();
202
+ Params.CpuThreadFilter = [Wanted](uint32 Id) { return Id == Wanted; };
203
+ }
204
+ else
205
+ {
206
+ Params.CpuThreadFilter = [](uint32) { return true; };
207
+ }
208
+
209
+ TUniquePtr<TraceServices::ITable<TraceServices::FTimingProfilerAggregatedStats>> Table(Timing.CreateAggregation(Params));
210
+ if (!Table.IsValid()) return Rows;
211
+
212
+ TUniquePtr<TraceServices::ITableReader<TraceServices::FTimingProfilerAggregatedStats>> Reader(Table->CreateReader());
213
+ if (!Reader.IsValid()) return Rows;
214
+
215
+ for (; Reader->IsValid(); Reader->NextRow())
216
+ {
217
+ const TraceServices::FTimingProfilerAggregatedStats* Stats = Reader->GetCurrentRow();
218
+ if (!Stats || Stats->InstanceCount == 0) continue;
219
+ FMCPTraceAnalysisTimerRow Row;
220
+ Row.Name = (Stats->Timer && Stats->Timer->Name) ? FString(Stats->Timer->Name) : FString(TEXT("<unnamed>"));
221
+ Row.Type = MCPTraceAnalysisTimerTypeName(Stats->Timer);
222
+ Row.Count = Stats->InstanceCount;
223
+ Row.InclusiveMs = Stats->TotalInclusiveTime * 1000.0;
224
+ Row.ExclusiveMs = Stats->TotalExclusiveTime * 1000.0;
225
+ Row.MaxInclusiveMs = Stats->MaxInclusiveTime > 0.0 ? Stats->MaxInclusiveTime * 1000.0 : 0.0;
226
+ Row.AvgInclusiveMs = Stats->AverageInclusiveTime * 1000.0;
227
+ Rows.Add(MoveTemp(Row));
228
+ }
229
+ return Rows;
230
+ }
231
+
232
+ void MCPTraceAnalysisSortRows(TArray<FMCPTraceAnalysisTimerRow>& Rows, bool bExclusive)
233
+ {
234
+ Rows.Sort([bExclusive](const FMCPTraceAnalysisTimerRow& A, const FMCPTraceAnalysisTimerRow& B)
235
+ {
236
+ const double KeyA = bExclusive ? A.ExclusiveMs : A.InclusiveMs;
237
+ const double KeyB = bExclusive ? B.ExclusiveMs : B.InclusiveMs;
238
+ if (KeyA != KeyB) return KeyA > KeyB;
239
+ return A.Name < B.Name;
240
+ });
241
+ }
242
+
243
+ TArray<TSharedPtr<FJsonValue>> MCPTraceAnalysisTimerRowsToJson(
244
+ const TArray<FMCPTraceAnalysisTimerRow>& Rows, int32 Limit, int32 FrameCount)
245
+ {
246
+ TArray<TSharedPtr<FJsonValue>> Out;
247
+ for (int32 i = 0; i < Rows.Num() && i < Limit; ++i)
248
+ {
249
+ const FMCPTraceAnalysisTimerRow& Row = Rows[i];
250
+ TSharedPtr<FJsonObject> Obj = MakeShared<FJsonObject>();
251
+ Obj->SetStringField(TEXT("name"), Row.Name);
252
+ Obj->SetStringField(TEXT("type"), Row.Type);
253
+ Obj->SetNumberField(TEXT("count"), static_cast<double>(Row.Count));
254
+ Obj->SetNumberField(TEXT("inclusiveMs"), Row.InclusiveMs);
255
+ Obj->SetNumberField(TEXT("exclusiveMs"), Row.ExclusiveMs);
256
+ Obj->SetNumberField(TEXT("maxInclusiveMs"), Row.MaxInclusiveMs);
257
+ Obj->SetNumberField(TEXT("avgInclusiveMs"), Row.AvgInclusiveMs);
258
+ if (FrameCount > 0)
259
+ {
260
+ Obj->SetNumberField(TEXT("inclusiveMsPerFrame"), Row.InclusiveMs / FrameCount);
261
+ Obj->SetNumberField(TEXT("exclusiveMsPerFrame"), Row.ExclusiveMs / FrameCount);
262
+ }
263
+ Out.Add(MakeShared<FJsonValueObject>(Obj));
264
+ }
265
+ return Out;
266
+ }
267
+
268
+ /** GPU busy time per frame: for every GPU timeline the trace carries, the
269
+ * depth-0 scopes are summed into the frames they overlap, and a frame's
270
+ * figure is the busiest single timeline (queues run in parallel, so
271
+ * adding them would count overlapping work twice). It approximates GPU
272
+ * frame time from the scopes the RHI emitted; work outside any scope is
273
+ * not counted, which the result says. */
274
+ bool MCPTraceAnalysisGpuPerFrame(
275
+ const TraceServices::ITimingProfilerProvider& Timing,
276
+ const TArray<FMCPTraceAnalysisFrame>& Frames,
277
+ TArray<double>& OutPerFrameMs,
278
+ int32& OutTimelineCount)
279
+ {
280
+ OutPerFrameMs.Init(0.0, Frames.Num());
281
+ OutTimelineCount = 0;
282
+ if (Frames.Num() == 0) return false;
283
+
284
+ TArray<uint32> TimelineIndices;
285
+ uint32 Index = 0;
286
+ if (Timing.GetGpuTimelineIndex(Index)) TimelineIndices.AddUnique(Index);
287
+ if (Timing.GetGpu2TimelineIndex(Index)) TimelineIndices.AddUnique(Index);
288
+ Timing.EnumerateGpuQueues([&TimelineIndices](const TraceServices::FGpuQueueInfo& Queue)
289
+ {
290
+ if (Queue.TimelineIndex != ~0u) TimelineIndices.AddUnique(Queue.TimelineIndex);
291
+ });
292
+
293
+ const double WindowStart = Frames[0].Start;
294
+ const double WindowEnd = Frames.Last().End;
295
+ bool bAnyEvent = false;
296
+
297
+ for (const uint32 TimelineIndex : TimelineIndices)
298
+ {
299
+ TArray<double> Busy;
300
+ Busy.Init(0.0, Frames.Num());
301
+ bool bTimelineHasEvents = false;
302
+
303
+ Timing.ReadTimeline(TimelineIndex, [&](const TraceServices::ITimingProfilerProvider::Timeline& Timeline)
304
+ {
305
+ Timeline.EnumerateEvents(WindowStart, WindowEnd,
306
+ [&](double EventStart, double EventEnd, uint32 Depth, const TraceServices::FTimingProfilerEvent&) -> TraceServices::EEventEnumerate
307
+ {
308
+ if (Depth != 0 || EventEnd <= EventStart) return TraceServices::EEventEnumerate::Continue;
309
+ bTimelineHasEvents = true;
310
+ // First frame that ends after this event starts.
311
+ int32 Lo = 0;
312
+ int32 Hi = Frames.Num();
313
+ while (Lo < Hi)
314
+ {
315
+ const int32 Mid = (Lo + Hi) / 2;
316
+ if (Frames[Mid].End <= EventStart) Lo = Mid + 1; else Hi = Mid;
317
+ }
318
+ for (int32 F = Lo; F < Frames.Num() && Frames[F].Start < EventEnd; ++F)
319
+ {
320
+ const double Overlap = FMath::Min(EventEnd, Frames[F].End) - FMath::Max(EventStart, Frames[F].Start);
321
+ if (Overlap > 0.0) Busy[F] += Overlap * 1000.0;
322
+ }
323
+ return TraceServices::EEventEnumerate::Continue;
324
+ });
325
+ });
326
+
327
+ if (!bTimelineHasEvents) continue;
328
+ bAnyEvent = true;
329
+ ++OutTimelineCount;
330
+ for (int32 F = 0; F < Frames.Num(); ++F)
331
+ {
332
+ OutPerFrameMs[F] = FMath::Max(OutPerFrameMs[F], Busy[F]);
333
+ }
334
+ }
335
+ return bAnyEvent;
336
+ }
337
+
338
+ /** The whole summary. Called inside FAnalysisSessionReadScope on a
339
+ * completed session. Returns an error string on a request the trace
340
+ * cannot answer, or empty with OutResult filled. */
341
+ FString MCPTraceAnalysisSummarise(
342
+ const TraceServices::IAnalysisSession& Session,
343
+ const FMCPTraceAnalysisRequest& Request,
344
+ TSharedPtr<FJsonObject>& OutResult)
345
+ {
346
+ TArray<FString> Warnings;
347
+ const double Duration = Session.GetDurationSeconds();
348
+ const double WindowStart = FMath::Max(0.0, Request.WindowStart);
349
+ const double WindowEnd = Request.WindowEnd < 0.0 ? Duration : FMath::Min(Request.WindowEnd, Duration);
350
+ if (WindowEnd <= WindowStart)
351
+ {
352
+ return FString::Printf(
353
+ TEXT("The time window [%.3f, %.3f] s holds nothing: the trace lasts %.3f s. Pass startSeconds below endSeconds, inside the trace."),
354
+ WindowStart, WindowEnd, Duration);
355
+ }
356
+
357
+ const ETraceFrameType FrameType = Request.bRenderingFrames ? TraceFrameType_Rendering : TraceFrameType_Game;
358
+ const TraceServices::IFrameProvider& FrameProvider = TraceServices::ReadFrameProvider(Session);
359
+ const uint64 FramesInTrace = FrameProvider.GetFrameCount(FrameType);
360
+
361
+ // Whole frames inside the window only. A frame cut by the window edge
362
+ // would report a duration it did not have, and the last frame of a
363
+ // trace often never ended.
364
+ TArray<FMCPTraceAnalysisFrame> Frames;
365
+ FrameProvider.EnumerateFrames(FrameType, WindowStart, WindowEnd, [&](const TraceServices::FFrame& Frame)
366
+ {
367
+ if (Frame.StartTime < WindowStart || Frame.EndTime > WindowEnd) return;
368
+ if (!(Frame.EndTime > Frame.StartTime) || Frame.EndTime >= Duration + 1.0) return;
369
+ FMCPTraceAnalysisFrame Row;
370
+ Row.Index = Frame.Index;
371
+ Row.Start = Frame.StartTime;
372
+ Row.End = Frame.EndTime;
373
+ Row.Ms = (Frame.EndTime - Frame.StartTime) * 1000.0;
374
+ Frames.Add(Row);
375
+ });
376
+ Frames.Sort([](const FMCPTraceAnalysisFrame& A, const FMCPTraceAnalysisFrame& B) { return A.Start < B.Start; });
377
+
378
+ TSharedPtr<FJsonObject> Result = MCPSuccess();
379
+ Result->SetNumberField(TEXT("sessionDurationSeconds"), Duration);
380
+ TSharedPtr<FJsonObject> Window = MakeShared<FJsonObject>();
381
+ Window->SetNumberField(TEXT("startSeconds"), WindowStart);
382
+ Window->SetNumberField(TEXT("endSeconds"), WindowEnd);
383
+ Window->SetBoolField(TEXT("wholeTrace"), Request.WindowStart <= 0.0 && Request.WindowEnd < 0.0);
384
+ Result->SetObjectField(TEXT("window"), Window);
385
+
386
+ // ── Frames ──────────────────────────────────────────────────────────
387
+ TArray<double> FrameMs;
388
+ FrameMs.Reserve(Frames.Num());
389
+ double TotalMs = 0.0;
390
+ for (const FMCPTraceAnalysisFrame& Frame : Frames)
391
+ {
392
+ FrameMs.Add(Frame.Ms);
393
+ TotalMs += Frame.Ms;
394
+ }
395
+ TSharedPtr<FJsonObject> FramesObj = MCPTraceAnalysisDistribution(FrameMs);
396
+ FramesObj->SetStringField(TEXT("frameType"), Request.bRenderingFrames ? TEXT("rendering") : TEXT("game"));
397
+ FramesObj->SetNumberField(TEXT("framesInTrace"), static_cast<double>(FramesInTrace));
398
+ FramesObj->SetNumberField(TEXT("avgFps"), TotalMs > 0.0 ? Frames.Num() * 1000.0 / TotalMs : 0.0);
399
+ Result->SetObjectField(TEXT("frames"), FramesObj);
400
+ if (FramesInTrace == 0)
401
+ {
402
+ Warnings.Add(TEXT("The trace has no frame events. Record with the 'frame' channel on (the 'default' preset includes it)."));
403
+ }
404
+
405
+ // ── Hitches ─────────────────────────────────────────────────────────
406
+ {
407
+ TArray<TSharedPtr<FJsonValue>> List;
408
+ int32 Count = 0;
409
+ double HitchTotalMs = 0.0;
410
+ for (const FMCPTraceAnalysisFrame& Frame : Frames)
411
+ {
412
+ if (Frame.Ms < Request.HitchThresholdMs) continue;
413
+ ++Count;
414
+ HitchTotalMs += Frame.Ms;
415
+ if (List.Num() >= Request.MaxHitches) continue;
416
+ TSharedPtr<FJsonObject> Row = MakeShared<FJsonObject>();
417
+ Row->SetNumberField(TEXT("frameIndex"), static_cast<double>(Frame.Index));
418
+ Row->SetNumberField(TEXT("startSeconds"), Frame.Start);
419
+ Row->SetNumberField(TEXT("durationMs"), Frame.Ms);
420
+ List.Add(MakeShared<FJsonValueObject>(Row));
421
+ }
422
+ TSharedPtr<FJsonObject> Hitches = MakeShared<FJsonObject>();
423
+ Hitches->SetNumberField(TEXT("thresholdMs"), Request.HitchThresholdMs);
424
+ Hitches->SetNumberField(TEXT("count"), Count);
425
+ Hitches->SetNumberField(TEXT("totalMs"), HitchTotalMs);
426
+ Hitches->SetArrayField(TEXT("list"), List);
427
+ Hitches->SetBoolField(TEXT("truncated"), List.Num() < Count);
428
+ Result->SetObjectField(TEXT("hitches"), Hitches);
429
+ }
430
+
431
+ // ── Threads ─────────────────────────────────────────────────────────
432
+ TOptional<uint32> GameThreadId;
433
+ {
434
+ const TraceServices::IThreadProvider& Threads = TraceServices::ReadThreadProvider(Session);
435
+ Threads.EnumerateThreads([&GameThreadId](const TraceServices::FThreadInfo& Info)
436
+ {
437
+ if (!GameThreadId.IsSet() && Info.Name && FCString::Stricmp(Info.Name, TEXT("GameThread")) == 0)
438
+ {
439
+ GameThreadId = Info.Id;
440
+ }
441
+ });
442
+ }
443
+ TOptional<uint32> TimerThread = Request.bAllThreads ? TOptional<uint32>() : GameThreadId;
444
+ FString ThreadScope = Request.bAllThreads ? TEXT("all") : TEXT("game");
445
+ if (!Request.bAllThreads && !GameThreadId.IsSet())
446
+ {
447
+ ThreadScope = TEXT("all");
448
+ Warnings.Add(TEXT("No thread named GameThread is in the trace, so timers are aggregated over every CPU thread."));
449
+ }
450
+
451
+ // ── Timers: worst frames and the window ─────────────────────────────
452
+ const TraceServices::ITimingProfilerProvider* Timing = TraceServices::ReadTimingProfilerProvider(Session);
453
+ TArray<TSharedPtr<FJsonValue>> WorstJson;
454
+ {
455
+ TArray<FMCPTraceAnalysisFrame> Worst = Frames;
456
+ Worst.Sort([](const FMCPTraceAnalysisFrame& A, const FMCPTraceAnalysisFrame& B) { return A.Ms > B.Ms; });
457
+ for (int32 i = 0; i < Worst.Num() && i < Request.WorstFrames; ++i)
458
+ {
459
+ const FMCPTraceAnalysisFrame& Frame = Worst[i];
460
+ TSharedPtr<FJsonObject> Row = MakeShared<FJsonObject>();
461
+ Row->SetNumberField(TEXT("frameIndex"), static_cast<double>(Frame.Index));
462
+ Row->SetNumberField(TEXT("startSeconds"), Frame.Start);
463
+ Row->SetNumberField(TEXT("durationMs"), Frame.Ms);
464
+ if (Timing && Request.TimersPerFrame > 0)
465
+ {
466
+ TArray<FMCPTraceAnalysisTimerRow> Rows = MCPTraceAnalysisAggregate(*Timing, Frame.Start, Frame.End, TimerThread);
467
+ // Exclusive time names where the frame went; inclusive time
468
+ // would list the call-stack spine (the engine tick and its
469
+ // parents) first in every frame.
470
+ MCPTraceAnalysisSortRows(Rows, /*bExclusive=*/true);
471
+ Row->SetArrayField(TEXT("topTimers"), MCPTraceAnalysisTimerRowsToJson(Rows, Request.TimersPerFrame, 0));
472
+ }
473
+ WorstJson.Add(MakeShared<FJsonValueObject>(Row));
474
+ }
475
+ }
476
+ Result->SetArrayField(TEXT("worstFrames"), WorstJson);
477
+
478
+ TSharedPtr<FJsonObject> TopTimers = MakeShared<FJsonObject>();
479
+ TopTimers->SetStringField(TEXT("threads"), ThreadScope);
480
+ TopTimers->SetStringField(TEXT("sortedBy"), Request.bSortExclusive ? TEXT("exclusive") : TEXT("inclusive"));
481
+ if (Timing)
482
+ {
483
+ TArray<FMCPTraceAnalysisTimerRow> Rows = MCPTraceAnalysisAggregate(*Timing, WindowStart, WindowEnd, TimerThread);
484
+ MCPTraceAnalysisSortRows(Rows, Request.bSortExclusive);
485
+ TopTimers->SetNumberField(TEXT("distinctTimers"), Rows.Num());
486
+ TopTimers->SetArrayField(TEXT("rows"), MCPTraceAnalysisTimerRowsToJson(Rows, Request.TopTimers, Frames.Num()));
487
+ TopTimers->SetBoolField(TEXT("truncated"), Rows.Num() > Request.TopTimers);
488
+ if (Rows.Num() == 0)
489
+ {
490
+ Warnings.Add(TEXT("No CPU timer events in the window. Record with the 'cpu' channel on (the 'default' preset includes it)."));
491
+ }
492
+ }
493
+ else
494
+ {
495
+ TopTimers->SetNumberField(TEXT("distinctTimers"), 0);
496
+ TopTimers->SetArrayField(TEXT("rows"), TArray<TSharedPtr<FJsonValue>>());
497
+ TopTimers->SetBoolField(TEXT("truncated"), false);
498
+ Warnings.Add(TEXT("The trace has no timing-profiler data. Record with the 'cpu' channel on (the 'default' preset includes it)."));
499
+ }
500
+ Result->SetObjectField(TEXT("topTimers"), TopTimers);
501
+
502
+ // ── GPU ─────────────────────────────────────────────────────────────
503
+ {
504
+ TSharedPtr<FJsonObject> Gpu = MakeShared<FJsonObject>();
505
+ TArray<double> PerFrame;
506
+ int32 TimelineCount = 0;
507
+ const bool bPresent = Timing && MCPTraceAnalysisGpuPerFrame(*Timing, Frames, PerFrame, TimelineCount);
508
+ Gpu->SetBoolField(TEXT("present"), bPresent);
509
+ if (bPresent)
510
+ {
511
+ TArray<double> Measured;
512
+ for (double Ms : PerFrame) if (Ms > 0.0) Measured.Add(Ms);
513
+ TSharedPtr<FJsonObject> Dist = MCPTraceAnalysisDistribution(Measured);
514
+ Gpu->SetObjectField(TEXT("busyMsPerFrame"), Dist);
515
+ Gpu->SetNumberField(TEXT("framesWithGpuWork"), Measured.Num());
516
+ Gpu->SetNumberField(TEXT("timelines"), TimelineCount);
517
+ Gpu->SetStringField(TEXT("method"),
518
+ TEXT("Per game frame, the time covered by top-level GPU scopes on the busiest GPU timeline. It approximates GPU frame time; GPU work outside any scope is not counted."));
519
+ }
520
+ else
521
+ {
522
+ Gpu->SetStringField(TEXT("reason"),
523
+ TEXT("The trace carries no GPU timing events. Record with the 'gpu' channel on, from an editor with a real RHI (a -nullrhi editor emits none)."));
524
+ }
525
+ Result->SetObjectField(TEXT("gpu"), Gpu);
526
+ }
527
+
528
+ // ── Bookmarks ───────────────────────────────────────────────────────
529
+ {
530
+ const TraceServices::IBookmarkProvider& Bookmarks = TraceServices::ReadBookmarkProvider(Session);
531
+ TArray<TSharedPtr<FJsonValue>> List;
532
+ int32 Count = 0;
533
+ Bookmarks.EnumerateBookmarks(WindowStart, WindowEnd, [&](const TraceServices::FBookmark& Bookmark)
534
+ {
535
+ ++Count;
536
+ if (List.Num() >= Request.MaxBookmarks) return;
537
+ TSharedPtr<FJsonObject> Row = MakeShared<FJsonObject>();
538
+ Row->SetNumberField(TEXT("timeSeconds"), Bookmark.Time);
539
+ Row->SetStringField(TEXT("text"), Bookmark.Text ? FString(Bookmark.Text) : FString());
540
+ Row->SetNumberField(TEXT("frameIndex"),
541
+ static_cast<double>(FrameProvider.GetFrameNumberForTimestamp(FrameType, Bookmark.Time)));
542
+ List.Add(MakeShared<FJsonValueObject>(Row));
543
+ });
544
+ TSharedPtr<FJsonObject> BookmarksObj = MakeShared<FJsonObject>();
545
+ BookmarksObj->SetNumberField(TEXT("count"), Count);
546
+ BookmarksObj->SetNumberField(TEXT("countInTrace"), static_cast<double>(Bookmarks.GetBookmarkCount()));
547
+ BookmarksObj->SetArrayField(TEXT("list"), List);
548
+ BookmarksObj->SetBoolField(TEXT("truncated"), List.Num() < Count);
549
+ Result->SetObjectField(TEXT("bookmarks"), BookmarksObj);
550
+ }
551
+
552
+ Result->SetArrayField(TEXT("warnings"), MCPStringListToJson(Warnings));
553
+ OutResult = Result;
554
+ return FString();
555
+ }
556
+
557
+ /** Write the full result to disk and turn the response into a pointer to
558
+ * it, keeping the headline numbers inline. Game thread. */
559
+ TSharedPtr<FJsonValue> MCPTraceAnalysisFinish(TSharedPtr<FJsonObject> Result, const FMCPTraceAnalysisRequest& Request)
560
+ {
561
+ if (!Request.bDumpToFile)
562
+ {
563
+ return MCPResult(Result);
564
+ }
565
+ const FString DefaultPath = FPaths::Combine(FPaths::ProjectSavedDir(), TEXT("UE_MCP"), TEXT("TraceAnalysis"),
566
+ FPaths::GetBaseFilename(Request.File) + TEXT(".analysis.json"));
567
+ const FString Target = MCPResolveDumpPath(Request.OutputPath.IsEmpty() ? DefaultPath : Request.OutputPath);
568
+
569
+ FString JsonText;
570
+ const TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&JsonText);
571
+ if (!FJsonSerializer::Serialize(Result.ToSharedRef(), Writer))
572
+ {
573
+ return MCPError(TEXT("Failed to serialise the trace analysis to JSON."));
574
+ }
575
+ FString Error;
576
+ if (!MCPWriteDumpFile(Target, JsonText, TEXT("trace analysis"), Error))
577
+ {
578
+ return MCPError(Error);
579
+ }
580
+
581
+ TSharedPtr<FJsonObject> Short = MCPSuccess();
582
+ Short->SetBoolField(TEXT("dumpedToFile"), true);
583
+ Short->SetStringField(TEXT("outputPath"), FPaths::ConvertRelativePathToFull(Target));
584
+ for (const TCHAR* Key : { TEXT("traceFile"), TEXT("traceFileBytes"), TEXT("analysisSeconds"),
585
+ TEXT("sessionDurationSeconds"), TEXT("window"), TEXT("frames"), TEXT("gpu"), TEXT("warnings") })
586
+ {
587
+ if (const TSharedPtr<FJsonValue> Value = Result->TryGetField(Key)) Short->SetField(Key, Value);
588
+ }
589
+ const TSharedPtr<FJsonObject>* Hitches = nullptr;
590
+ if (Result->TryGetObjectField(TEXT("hitches"), Hitches) && Hitches)
591
+ {
592
+ Short->SetNumberField(TEXT("hitchCount"), (*Hitches)->GetNumberField(TEXT("count")));
593
+ }
594
+ const TSharedPtr<FJsonObject>* Bookmarks = nullptr;
595
+ if (Result->TryGetObjectField(TEXT("bookmarks"), Bookmarks) && Bookmarks)
596
+ {
597
+ Short->SetNumberField(TEXT("bookmarkCount"), (*Bookmarks)->GetNumberField(TEXT("count")));
598
+ }
599
+ return MCPResult(Short);
600
+ }
601
+
602
+ void MCPTraceAnalysisStamp(TSharedPtr<FJsonObject> Result, const FMCPTraceAnalysisRequest& Request, double WallStart)
603
+ {
604
+ Result->SetStringField(TEXT("traceFile"), Request.File);
605
+ Result->SetNumberField(TEXT("traceFileBytes"), static_cast<double>(IFileManager::Get().FileSize(*Request.File)));
606
+ Result->SetNumberField(TEXT("analysisSeconds"), FPlatformTime::Seconds() - WallStart);
607
+ }
608
+
609
+ /** State the pool task and the cancel hook share. */
610
+ struct FMCPTraceAnalysisJob
611
+ {
612
+ TSharedPtr<const TraceServices::IAnalysisSession> Session;
613
+ };
614
+ #endif // UE_MCP_HAS_5_7_API
615
+ }
616
+
617
+ // ---------------------------------------------------------------------------
618
+ // analyze_insights_trace -- summarise a recorded .utrace.
619
+ // ---------------------------------------------------------------------------
620
+ TSharedPtr<FJsonValue> FEditorHandlers::AnalyzeInsightsTrace(const TSharedPtr<FJsonObject>& Params)
621
+ {
622
+ MCP_CHECK_GAME_THREAD();
623
+
624
+ FMCPTraceAnalysisRequest Request;
625
+ FString Requested = OptionalString(Params, TEXT("file"));
626
+ Requested.TrimStartAndEndInline();
627
+ Request.WindowStart = OptionalNumber(Params, TEXT("startSeconds"), 0.0);
628
+ Request.WindowEnd = OptionalNumber(Params, TEXT("endSeconds"), -1.0);
629
+ Request.HitchThresholdMs = FMath::Max(0.1, OptionalNumber(Params, TEXT("hitchThresholdMs"), 50.0));
630
+ Request.WorstFrames = FMath::Clamp(OptionalInt(Params, TEXT("worstFrames"), 10), 0, 50);
631
+ Request.TopTimers = FMath::Clamp(OptionalInt(Params, TEXT("topTimers"), 20), 0, 200);
632
+ Request.TimersPerFrame = FMath::Clamp(OptionalInt(Params, TEXT("timersPerFrame"), 5), 0, 20);
633
+ Request.MaxHitches = FMath::Clamp(OptionalInt(Params, TEXT("maxHitches"), 50), 0, 500);
634
+ Request.MaxBookmarks = FMath::Clamp(OptionalInt(Params, TEXT("maxBookmarks"), 100), 0, 1000);
635
+ const FString Threads = OptionalString(Params, TEXT("threads"), TEXT("game")).ToLower();
636
+ const FString TimerSort = OptionalString(Params, TEXT("timerSort"), TEXT("inclusive")).ToLower();
637
+ const FString FrameType = OptionalString(Params, TEXT("frameType"), TEXT("game")).ToLower();
638
+ Request.bDumpToFile = OptionalBool(Params, TEXT("dumpToFile"), false);
639
+ Request.OutputPath = OptionalString(Params, TEXT("outputPath"));
640
+
641
+ if (Threads != TEXT("game") && Threads != TEXT("all"))
642
+ {
643
+ return MCPError(FString::Printf(TEXT("Unknown threads '%s'. Use game (the game thread only, the default) or all (every CPU thread)."), *Threads));
644
+ }
645
+ if (TimerSort != TEXT("inclusive") && TimerSort != TEXT("exclusive"))
646
+ {
647
+ return MCPError(FString::Printf(TEXT("Unknown timerSort '%s'. Use inclusive (the default) or exclusive."), *TimerSort));
648
+ }
649
+ if (FrameType != TEXT("game") && FrameType != TEXT("rendering"))
650
+ {
651
+ return MCPError(FString::Printf(TEXT("Unknown frameType '%s'. Use game (the default) or rendering."), *FrameType));
652
+ }
653
+ if (!Request.OutputPath.IsEmpty() && !Request.bDumpToFile)
654
+ {
655
+ return MCPError(TEXT("outputPath needs dumpToFile=true."));
656
+ }
657
+ if (Request.WindowEnd >= 0.0 && Request.WindowEnd <= Request.WindowStart)
658
+ {
659
+ return MCPError(TEXT("endSeconds must be greater than startSeconds."));
660
+ }
661
+ Request.bAllThreads = Threads == TEXT("all");
662
+ Request.bSortExclusive = TimerSort == TEXT("exclusive");
663
+ Request.bRenderingFrames = FrameType == TEXT("rendering");
664
+
665
+ Request.File = Requested.IsEmpty() ? MCPTraceAnalysisNewestTrace() : MCPTraceAnalysisResolveFile(Requested);
666
+ if (Request.File.IsEmpty())
667
+ {
668
+ return MCPError(TEXT("No file was given and no .utrace is under <Project>/Saved/Profiling. Record one with editor(start_trace) and editor(stop_trace), or pass file."));
669
+ }
670
+ if (!FPaths::FileExists(Request.File))
671
+ {
672
+ return MCPError(FString::Printf(TEXT("Trace file not found: %s"), *Request.File));
673
+ }
674
+ if (!Request.File.EndsWith(TEXT(".utrace"), ESearchCase::IgnoreCase))
675
+ {
676
+ return MCPError(FString::Printf(TEXT("'%s' is not a .utrace file."), *Request.File));
677
+ }
678
+ // The file a running trace writes to is still growing and has no end; an
679
+ // analysis of it would describe a moment and present it as the whole run.
680
+ if (FTraceAuxiliary::IsConnected())
681
+ {
682
+ const FString Destination = FPaths::ConvertRelativePathToFull(FTraceAuxiliary::GetTraceDestinationString());
683
+ if (FPaths::IsSamePath(Destination, Request.File))
684
+ {
685
+ return MCPError(TEXT("That trace is still being written. Stop it with editor(stop_trace) first; the file is only complete after the stop."));
686
+ }
687
+ }
688
+
689
+ #if UE_MCP_HAS_5_7_API
690
+ ITraceServicesModule* Module = FModuleManager::LoadModulePtr<ITraceServicesModule>(TEXT("TraceServices"));
691
+ if (!Module)
692
+ {
693
+ return MCPError(TEXT("The TraceServices module could not be loaded, so the trace cannot be analysed in this editor."));
694
+ }
695
+ const TSharedPtr<TraceServices::IAnalysisService> Service = Module->GetAnalysisService();
696
+ if (!Service.IsValid())
697
+ {
698
+ return MCPError(TEXT("TraceServices returned no analysis service."));
699
+ }
700
+
701
+ const double WallStart = FPlatformTime::Seconds();
702
+ const FMCPDeferredCallPtr Deferred = MCPDeferRequest();
703
+ if (!Deferred)
704
+ {
705
+ // Called in-process rather than for a bridge request: nothing can wait
706
+ // for a later answer, so analyse here and block.
707
+ const TSharedPtr<const TraceServices::IAnalysisSession> Session = Service->Analyze(*Request.File);
708
+ if (!Session.IsValid())
709
+ {
710
+ return MCPError(FString::Printf(TEXT("TraceServices could not open '%s' for analysis."), *Request.File));
711
+ }
712
+ TSharedPtr<FJsonObject> Result;
713
+ FString Error;
714
+ {
715
+ TraceServices::FAnalysisSessionReadScope ReadScope(*Session);
716
+ Error = MCPTraceAnalysisSummarise(*Session, Request, Result);
717
+ }
718
+ if (!Error.IsEmpty()) return MCPError(Error);
719
+ MCPTraceAnalysisStamp(Result, Request, WallStart);
720
+ return MCPTraceAnalysisFinish(Result, Request);
721
+ }
722
+
723
+ const TSharedPtr<FMCPTraceAnalysisJob, ESPMode::ThreadSafe> Job = MakeShared<FMCPTraceAnalysisJob, ESPMode::ThreadSafe>();
724
+ Job->Session = Service->StartAnalysis(*Request.File);
725
+ if (!Job->Session.IsValid())
726
+ {
727
+ return MCPError(FString::Printf(TEXT("TraceServices could not open '%s' for analysis."), *Request.File));
728
+ }
729
+
730
+ Deferred->SetCancelNote(TEXT("The analysis session was stopped. Nothing was written, so there is nothing to undo."));
731
+ Deferred->OnCancel([Job](const FString&)
732
+ {
733
+ if (Job->Session.IsValid()) Job->Session->Stop(/*bAndWait=*/false);
734
+ });
735
+
736
+ FMCPDeferredCallPtr DeferredCopy = Deferred;
737
+ Async(EAsyncExecution::ThreadPool, [DeferredCopy, Job, Request, WallStart]()
738
+ {
739
+ const TraceServices::IAnalysisSession& Session = *Job->Session;
740
+ double LastReport = 0.0;
741
+ while (!Session.IsAnalysisComplete())
742
+ {
743
+ if (DeferredCopy->IsCancelled())
744
+ {
745
+ Session.Stop(/*bAndWait=*/true);
746
+ return;
747
+ }
748
+ FPlatformProcess::Sleep(0.05f);
749
+ const double Now = FPlatformTime::Seconds();
750
+ if (Now - LastReport >= 1.0)
751
+ {
752
+ LastReport = Now;
753
+ double Analysed = 0.0;
754
+ {
755
+ TraceServices::FAnalysisSessionReadScope ReadScope(Session);
756
+ Analysed = Session.GetDurationSeconds();
757
+ }
758
+ DeferredCopy->ReportProgress(Analysed, 0.0,
759
+ FString::Printf(TEXT("Analysed %.1f s of trace"), Analysed));
760
+ }
761
+ }
762
+ if (DeferredCopy->IsCancelled()) return;
763
+
764
+ TSharedPtr<FJsonObject> Result;
765
+ FString Error;
766
+ {
767
+ TraceServices::FAnalysisSessionReadScope ReadScope(Session);
768
+ Error = MCPTraceAnalysisSummarise(Session, Request, Result);
769
+ }
770
+
771
+ // The dump write and the final stamp go back to the game thread, where
772
+ // every other file write in the bridge happens.
773
+ AsyncTask(ENamedThreads::GameThread, [DeferredCopy, Result, Error, Request, WallStart]()
774
+ {
775
+ if (DeferredCopy->IsCancelled()) return;
776
+ if (!Error.IsEmpty())
777
+ {
778
+ DeferredCopy->Complete(MCPError(Error));
779
+ return;
780
+ }
781
+ MCPTraceAnalysisStamp(Result, Request, WallStart);
782
+ DeferredCopy->Complete(MCPTraceAnalysisFinish(Result, Request));
783
+ });
784
+ });
785
+ return MCPDeferredMarker();
786
+ #else
787
+ return MCPError(TEXT("editor(analyze_trace) needs UE 5.7 or newer: the TraceServices timing API it reads changed shape before 5.7. ")
788
+ TEXT("Open the file in Unreal Insights with the openCommand editor(stop_trace) reported."));
789
+ #endif
790
+ }