Skip to content

Commit d44822e

Browse files
committed
feat(prompt): implement robust GameObject handling workflow prompt for LLMs
1 parent 1bd4998 commit d44822e

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

Server/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { registerGetPackagesResource } from './resources/getPackagesResource.js'
1717
import { registerGetAssetsResource } from './resources/getAssetsResource.js';
1818
import { registerGetTestsResource } from './resources/getTestsResource.js';
1919
import { registerGetGameObjectResource } from './resources/getGameObjectResource.js';
20-
import { registerGameObjectHandlingStrategyPrompt } from './prompts/gameobjectHandlingStrategyPrompt.js';
20+
import { registerGameObjectHandlingPrompt } from './prompts/gameobjectHandlingStrategyPrompt.js';
2121

2222
// Initialize loggers
2323
const serverLogger = new Logger('Server', LogLevel.INFO);
@@ -62,7 +62,7 @@ registerGetPackagesResource(server, mcpUnity, resourceLogger);
6262
registerGetAssetsResource(server, mcpUnity, resourceLogger);
6363

6464
// Register all prompts into the MCP server
65-
registerGameObjectHandlingStrategyPrompt(server);
65+
registerGameObjectHandlingPrompt(server);
6666

6767
// Server startup function
6868
async function startServer() {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

Server/src/prompts/gameobjectHandlingStrategyPrompt.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)