1- import { McpServer } from " @modelcontextprotocol/sdk/server/mcp.js" ;
2- import { McpUnity } from " ../unity/mcpUnity.js" ;
3- import { McpUnityError , ErrorType } from " ../utils/errors.js" ;
4- import * as z from " zod" ;
5- import { Logger } from " ../utils/logger.js" ;
1+ import { McpServer } from ' @modelcontextprotocol/sdk/server/mcp.js' ;
2+ import { McpUnity } from ' ../unity/mcpUnity.js' ;
3+ import { McpUnityError , ErrorType } from ' ../utils/errors.js' ;
4+ import * as z from ' zod' ;
5+ import { Logger } from ' ../utils/logger.js' ;
66
77// Constants for the tool
8- const toolName = "create_prefab" ;
9- const toolDescription =
10- "Creates a prefab with optional MonoBehaviour script and serialized field values" ;
8+ const toolName = 'create_prefab' ;
9+ const toolDescription = 'Creates a prefab with optional MonoBehaviour script and serialized field values' ;
1110
1211// Parameter schema for the tool
1312const paramsSchema = z . object ( {
14- componentName : z
15- . string ( )
16- . optional ( )
17- . describe (
18- "The name of the MonoBehaviour Component to add to the prefab (optional)"
19- ) ,
20- prefabName : z . string ( ) . describe ( "The name of the prefab to create" ) ,
21- fieldValues : z
22- . record ( z . any ( ) )
23- . optional ( )
24- . describe (
25- "Optional JSON object of serialized field values to apply to the prefab"
26- ) ,
13+ componentName : z . string ( ) . optional ( ) . describe ( 'The name of the MonoBehaviour Component to add to the prefab (optional)' ) ,
14+ prefabName : z . string ( ) . describe ( 'The name of the prefab to create' ) ,
15+ fieldValues : z . record ( z . any ( ) ) . optional ( ) . describe ( 'Optional JSON object of serialized field values to apply to the prefab' )
2716} ) ;
2817
2918/**
3019 * Creates and registers the CreatePrefab tool with the MCP server
31- *
20+ *
3221 * @param server The MCP server to register the tool with
3322 * @param mcpUnity The McpUnity instance to communicate with Unity
3423 * @param logger The logger instance for diagnostic information
3524 */
36- export function registerCreatePrefabTool (
37- server : McpServer ,
38- mcpUnity : McpUnity ,
39- logger : Logger
40- ) {
25+ export function registerCreatePrefabTool ( server : McpServer , mcpUnity : McpUnity , logger : Logger ) {
4126 logger . info ( `Registering tool: ${ toolName } ` ) ;
42-
27+
4328 server . tool (
4429 toolName ,
4530 toolDescription ,
@@ -60,7 +45,7 @@ export function registerCreatePrefabTool(
6045
6146/**
6247 * Handler function for the CreatePrefab tool
63- *
48+ *
6449 * @param mcpUnity The McpUnity instance to communicate with Unity
6550 * @param params The validated parameters for the tool
6651 * @returns A promise that resolves to the tool execution result
@@ -73,29 +58,27 @@ async function toolHandler(mcpUnity: McpUnity, params: any) {
7358 "'prefabName' must be provided"
7459 ) ;
7560 }
76-
61+
7762 const response = await mcpUnity . sendRequest ( {
7863 method : toolName ,
79- params,
64+ params
8065 } ) ;
81-
66+
8267 if ( ! response . success ) {
8368 throw new McpUnityError (
8469 ErrorType . TOOL_EXECUTION ,
8570 response . message || `Failed to create prefab`
8671 ) ;
8772 }
88-
73+
8974 return {
90- content : [
91- {
92- type : response . type ,
93- text : response . message || `Successfully created prefab` ,
94- } ,
95- ] ,
75+ content : [ {
76+ type : response . type ,
77+ text : response . message || `Successfully created prefab`
78+ } ] ,
9679 // Include the prefab path in the result for programmatic access
9780 data : {
98- prefabPath : response . prefabPath ,
99- } ,
81+ prefabPath : response . prefabPath
82+ }
10083 } ;
10184}
0 commit comments