|
| 1 | +import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; |
| 2 | +import { z } from "zod"; |
| 3 | + |
| 4 | +/** |
| 5 | + * Registers the gameobject handling prompt with the MCP server. |
| 6 | + * This prompt defines the proper workflow for handling GameObjects within the Unity Editor. |
| 7 | + * |
| 8 | + * @param server The McpServer instance to register the prompt with. |
| 9 | + */ |
| 10 | +export function registerGameObjectHandlingPrompt(server: McpServer) { |
| 11 | + server.prompt( |
| 12 | + 'gameobject_handling_strategy', |
| 13 | + 'Defines the proper workflow for handling gameobjects in Unity', |
| 14 | + { |
| 15 | + gameObjectId: z.string().describe("The ID of the GameObject to handle. It can be the name of the GameObject or the path to the GameObject."), |
| 16 | + }, |
| 17 | + async ({ gameObjectId }) => ({ |
| 18 | + messages: [ |
| 19 | + { |
| 20 | + role: 'user', |
| 21 | + content: { |
| 22 | + type: 'text', |
| 23 | + text: `You are an expert AI assistant integrated with Unity via MCP. You have access to the following resources and tools: |
| 24 | ++- Resource "get_hierarchy" (unity://hierarchy) to list all GameObjects. |
| 25 | ++- Resource "get_gameobject" (unity://gameobject/{id}) to fetch detailed GameObject info, with the id being the name of the GameObject or the path to the GameObject. |
| 26 | ++- Tool "select_gameobject" to select a GameObject by ID or path. |
| 27 | ++- Tool "update_component" to update or add a component on a GameObject. |
| 28 | ++ |
| 29 | ++Workflow: |
| 30 | ++1. Use "get_hierarchy" to confirm the GameObject ID or path for "${gameObjectId}". |
| 31 | ++2. Invoke "select_gameobject" to focus on the target GameObject in Unity. |
| 32 | ++3. Optionally, use "unity://gameobject/${gameObjectId}" to retrieve detailed properties. |
| 33 | ++4. Apply changes with "update_component" as per user requirements. |
| 34 | ++5. Confirm success and report any errors. |
| 35 | ++ |
| 36 | ++Always validate inputs and request clarification if the identifier is ambiguous.` |
| 37 | + } |
| 38 | + }, |
| 39 | + { |
| 40 | + role: 'user', |
| 41 | + content: { |
| 42 | + type: 'text', |
| 43 | + text: `Handle GameObject "${gameObjectId}" through the above workflow.` |
| 44 | + } |
| 45 | + } |
| 46 | + ] |
| 47 | + }) |
| 48 | + ); |
| 49 | +} |
0 commit comments