Skip to main content
Glama
BaseTest.cs3.38 kB
/* ┌──────────────────────────────────────────────────────────────────┐ │ Author: Ivan Murzak (https://github.com/IvanMurzak) │ │ Repository: GitHub (https://github.com/IvanMurzak/Unity-MCP) │ │ Copyright (c) 2025 Ivan Murzak │ │ Licensed under the Apache License, Version 2.0. │ │ See the LICENSE file in the project root for more information. │ └──────────────────────────────────────────────────────────────────┘ */ #nullable enable using System.Collections; using System.Collections.Generic; using System.Text.Json; using com.IvanMurzak.McpPlugin.Common.Model; using com.IvanMurzak.ReflectorNet; using NUnit.Framework; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.TestTools; namespace com.IvanMurzak.Unity.MCP.Editor.Tests { public class BaseTest { [UnitySetUp] public virtual IEnumerator SetUp() { Debug.Log($"[{GetType().GetTypeShortName()}] SetUp"); UnityMcpPlugin.InitSingletonIfNeeded(); yield return null; } [UnityTearDown] public virtual IEnumerator TearDown() { Debug.Log($"[{GetType().GetTypeShortName()}] TearDown"); DestroyAllGameObjectsInActiveScene(); yield return null; } protected static void DestroyAllGameObjectsInActiveScene() { var scene = SceneManager.GetActiveScene(); foreach (var go in scene.GetRootGameObjects()) Object.DestroyImmediate(go); } protected virtual ResponseData<ResponseCallTool> RunTool(string toolName, string json) { var reflector = McpPlugin.McpPlugin.Instance!.McpManager.Reflector; Debug.Log($"{toolName} Started with JSON:\n{json}"); var parameters = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json); var request = new RequestCallTool(toolName, parameters!); var task = McpPlugin.McpPlugin.Instance.McpManager.ToolManager!.RunCallTool(request); var result = task.Result; Debug.Log($"{toolName} Completed"); var jsonResult = result.ToJson(reflector); Debug.Log($"{toolName} Result:\n{jsonResult}"); Assert.IsFalse(result.Status == ResponseStatus.Error, $"Tool call failed with error status: {result.Message}"); Assert.IsNotNull(result.Message, $"Tool call returned null message"); Assert.IsFalse(result.Message!.Contains("[Error]"), $"Tool call failed with error: {result.Message}"); Assert.IsNotNull(result.Value, $"Tool call returned null value"); Assert.IsFalse(result.Value!.Status == ResponseStatus.Error, $"Tool call failed"); Assert.IsFalse(jsonResult.Contains("[Error]"), $"Tool call failed with error in JSON: {jsonResult}"); Assert.IsFalse(jsonResult.Contains("[Warning]"), $"Tool call contains warnings in JSON: {jsonResult}"); return result; } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/IvanMurzak/Unity-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server