|
| 1 | +using CrdtEcsBridge.RestrictedActions; |
| 2 | +using Cysharp.Threading.Tasks; |
| 3 | +using DCL.ECSComponents; |
| 4 | +using DCL.McpServer.Core; |
| 5 | +using Newtonsoft.Json.Linq; |
| 6 | +using System.Threading; |
| 7 | + |
| 8 | +namespace DCL.McpServer.Tools |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// Plays or stops an avatar emote through <see cref="IGlobalWorldActions" />, the same intent path |
| 12 | + /// a scene uses, so agents can verify emote-driven behaviour without touching the avatar directly. |
| 13 | + /// </summary> |
| 14 | + public class TriggerEmoteTool : IMcpTool |
| 15 | + { |
| 16 | + private readonly IGlobalWorldActions globalWorldActions; |
| 17 | + |
| 18 | + public string Name => "trigger_emote"; |
| 19 | + |
| 20 | + public string Description => |
| 21 | + "Play an avatar emote by URN (e.g. a base emote like 'wave', 'dance', 'clap'), or stop the current one with stop: true."; |
| 22 | + |
| 23 | + public JObject InputSchema => |
| 24 | + McpInputSchema.Object() |
| 25 | + .String("urn", "Emote URN or base emote id (wave, dance, clap...).") |
| 26 | + .Boolean("loop", "Loop the emote until stopped. Default false.") |
| 27 | + .Boolean("stop", "Stop the currently playing emote instead of triggering one.") |
| 28 | + .Build(); |
| 29 | + |
| 30 | + public McpToolAnnotations Annotations => McpToolAnnotations.Mutating(destructive: false, idempotent: false); |
| 31 | + |
| 32 | + public TriggerEmoteTool(IGlobalWorldActions globalWorldActions) |
| 33 | + { |
| 34 | + this.globalWorldActions = globalWorldActions; |
| 35 | + } |
| 36 | + |
| 37 | + public async UniTask<McpToolResult> ExecuteAsync(JObject arguments, CancellationToken ct) |
| 38 | + { |
| 39 | + bool stop = arguments.GetBool("stop", false); |
| 40 | + string urn = arguments.GetString("urn", string.Empty); |
| 41 | + |
| 42 | + if (!stop && string.IsNullOrEmpty(urn)) |
| 43 | + return McpToolResult.Error("urn is required (or pass stop: true)."); |
| 44 | + |
| 45 | + await UniTask.SwitchToMainThread(ct); |
| 46 | + |
| 47 | + if (stop) |
| 48 | + { |
| 49 | + globalWorldActions.StopEmote(); |
| 50 | + return McpToolResult.Text("Emote stopped."); |
| 51 | + } |
| 52 | + |
| 53 | + bool loop = arguments.GetBool("loop", false); |
| 54 | + globalWorldActions.TriggerEmote(urn, loop, AvatarEmoteMask.AemFullBody); |
| 55 | + |
| 56 | + return McpToolResult.Text($"Emote '{urn}' triggered{(loop ? " (looping)" : string.Empty)}."); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments