|
| 1 | +import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; |
| 2 | +import * as z from "zod"; |
| 3 | + |
| 4 | +/** |
| 5 | + * Registers the prefab creation prompt with the MCP server. |
| 6 | + * This prompt defines the proper workflow for creating prefabs in Unity, optionally with MonoBehaviour scripts. |
| 7 | + * |
| 8 | + * @param server The McpServer instance to register the prompt with. |
| 9 | + */ |
| 10 | +export function registerPrefabCreationPrompt(server: McpServer) { |
| 11 | + server.prompt( |
| 12 | + 'prefab_creation_strategy', |
| 13 | + 'Defines the proper workflow for creating prefabs in Unity, optionally with MonoBehaviour scripts', |
| 14 | + { |
| 15 | + scriptName: z.string().optional().describe("The name of the MonoBehaviour script to create a prefab from (without .cs extension). Optional."), |
| 16 | + prefabName: z.string().describe("The name for the new prefab (without .prefab extension)."), |
| 17 | + fieldValues: z.string().optional().describe("Optional key-value pairs to set serialized field values on the component, as a JSON string."), |
| 18 | + }, |
| 19 | + async ({ scriptName, prefabName, fieldValues }) => ({ |
| 20 | + messages: [ |
| 21 | + { |
| 22 | + role: 'user', |
| 23 | + content: { |
| 24 | + type: 'text', |
| 25 | + text: `You are an expert AI assistant integrated with Unity via MCP. |
| 26 | +
|
| 27 | +When creating prefabs in Unity, you have access to the following tools: |
| 28 | +- Tool "create_prefab" to create a prefab with optional MonoBehaviour script and serialized field values. |
| 29 | +
|
| 30 | +Workflow: |
| 31 | +1. Determine an appropriate name for the new prefab. |
| 32 | +2. Optionally, identify the MonoBehaviour script name that should be used for the prefab. |
| 33 | +3. Optionally, identify any serialized field values that should be set on the component. |
| 34 | +4. Use the "create_prefab" tool with the prefab name, optional script name, and optional field values. |
| 35 | +5. Confirm success and report the path of the created prefab. |
| 36 | +
|
| 37 | +Guidance: |
| 38 | +- The script must already be compiled in the Unity project if provided. |
| 39 | +- The prefab will be saved in the Assets/Prefabs/ directory. |
| 40 | +- If a prefab with the same name already exists, a unique name will be generated. |
| 41 | +- Field values should match the serialized fields in the MonoBehaviour script if provided. |
| 42 | +- Field values should be provided as a JSON string. |
| 43 | +- Always validate inputs and request clarification if needed.` |
| 44 | + } |
| 45 | + }, |
| 46 | + { |
| 47 | + role: 'user', |
| 48 | + content: { |
| 49 | + type: 'text', |
| 50 | + text: `Create a prefab named "${prefabName}"${scriptName ? ` from the script "${scriptName}"` : ''}${fieldValues ? ` with field values: ${fieldValues}` : ''}.` |
| 51 | + } |
| 52 | + } |
| 53 | + ] |
| 54 | + }) |
| 55 | + ); |
| 56 | +} |
0 commit comments