Skip to main content
Glama

run_tests

Execute Unity's Test Runner tests with specified filters and modes (EditMode, PlayMode, or All), enabling efficient testing within the Unity Editor MCP Server environment.

Instructions

Runs Unity's Test Runner tests

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
testFilterNoOptional test filter (e.g. specific test name or namespace)
testModeNoThe test mode to run (EditMode, PlayMode, or All)

Implementation Reference

  • Core execution logic for the 'run_tests' tool: parses parameters, sends request to McpUnity to run Unity Test Runner tests, handles response, extracts statistics and results, returns formatted text content with summary and JSON details.
    async function toolHandler(mcpUnity: McpUnity, params: any = {}): Promise<CallToolResult> { const { testMode = 'EditMode', testFilter = '', returnOnlyFailures = true, returnWithLogs = false } = params; // Create and wait for the test run const response = await mcpUnity.sendRequest({ method: toolName, params: { testMode, testFilter, returnOnlyFailures, returnWithLogs } }); // Process the test results if (!response.success) { throw new McpUnityError( ErrorType.TOOL_EXECUTION, response.message || `Failed to run tests: Mode=${testMode}, Filter=${testFilter || 'none'}` ); } // Extract test results const testResults = response.results || []; const testCount = response.testCount || 0; const passCount = response.passCount || 0; const failCount = response.failCount || 0; const skipCount = response.skipCount || 0; return { content: [ { type: 'text', text: response.message }, { type: 'text', text: JSON.stringify({ testCount, passCount, failCount, skipCount, results: testResults }, null, 2) } ] }; }
  • Zod schema defining the input parameters for the 'run_tests' tool.
    const paramsSchema = z.object({ testMode: z.string().optional().default('EditMode').describe('The test mode to run (EditMode or PlayMode) - defaults to EditMode (optional)'), testFilter: z.string().optional().default('').describe('The specific test filter to run (e.g. specific test name or class name, must include namespace) (optional)'), returnOnlyFailures: z.boolean().optional().default(true).describe('Whether to show only failed tests in the results (optional)'), returnWithLogs: z.boolean().optional().default(false).describe('Whether to return the test logs in the results (optional)') });
  • Registration function for the 'run_tests' tool, which calls server.tool with name, description, schema, and a logging wrapper around the toolHandler.
    export function registerRunTestsTool(server: McpServer, mcpUnity: McpUnity, logger: Logger) { logger.info(`Registering tool: ${toolName}`); // Register this tool with the MCP server server.tool( toolName, toolDescription, paramsSchema.shape, async (params: any = {}) => { try { logger.info(`Executing tool: ${toolName}`, params); const result = await toolHandler(mcpUnity, params); logger.info(`Tool execution successful: ${toolName}`); return result; } catch (error) { logger.error(`Tool execution failed: ${toolName}`, error); throw error; } } ); }
  • Application-level call to register the 'run_tests' tool during server initialization.
    registerRunTestsTool(server, mcpUnity, toolLogger);

Other Tools

Related Tools

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/CoderGamester/mcp-unity'

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