UNPKG

unity-editor-mcp

Version:

MCP server for Unity Editor integration - enables AI assistants to control Unity Editor

44 lines (39 loc) 1.17 kB
import { BaseToolHandler } from '../base/BaseToolHandler.js'; /** * Handler for getting Unity editor state */ export class GetEditorStateToolHandler extends BaseToolHandler { constructor(unityConnection) { super( 'get_editor_state', 'Get current Unity editor state including play mode status', { type: 'object', properties: {}, required: [] } ); this.unityConnection = unityConnection; } /** * Executes the get editor state command * @param {object} params - Empty object for this command * @returns {Promise<object>} Editor state information */ async execute(params) { // Ensure connected if (!this.unityConnection.isConnected()) { throw new Error('Unity connection not available'); } // Send get state command to Unity const result = await this.unityConnection.sendCommand('get_editor_state', params); // Check for Unity-side errors if (result.status === 'error') { const error = new Error(result.error); error.code = 'UNITY_ERROR'; throw error; } // Return the state information return result; } }