Skip to content

Commit fe27f2b

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

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

Server/build/index.js

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/gameobjectHandlingPrompt.js';
2121
// Initialize loggers
2222
const serverLogger = new Logger('Server', LogLevel.INFO);
2323
const unityLogger = new Logger('Unity', LogLevel.INFO);
@@ -53,7 +53,7 @@ registerGetHierarchyResource(server, mcpUnity, resourceLogger);
5353
registerGetPackagesResource(server, mcpUnity, resourceLogger);
5454
registerGetAssetsResource(server, mcpUnity, resourceLogger);
5555
// Register all prompts into the MCP server
56-
registerGameObjectHandlingStrategyPrompt(server);
56+
registerGameObjectHandlingPrompt(server);
5757
// Server startup function
5858
async function startServer() {
5959
try {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2+
/**
3+
* Registers the gameobject handling prompt with the MCP server.
4+
* This prompt defines the proper workflow for handling GameObjects within the Unity Editor.
5+
*
6+
* @param server The McpServer instance to register the prompt with.
7+
*/
8+
export declare function registerGameObjectHandlingPrompt(server: McpServer): void;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { z } from "zod";
2+
/**
3+
* Registers the gameobject handling prompt with the MCP server.
4+
* This prompt defines the proper workflow for handling GameObjects within the Unity Editor.
5+
*
6+
* @param server The McpServer instance to register the prompt with.
7+
*/
8+
export function registerGameObjectHandlingPrompt(server) {
9+
server.prompt('gameobject_handling_strategy', 'Defines the proper workflow for handling gameobjects in Unity', {
10+
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."),
11+
}, async ({ gameObjectId }) => ({
12+
messages: [
13+
{
14+
role: 'user',
15+
content: {
16+
type: 'text',
17+
text: `You are an expert AI assistant integrated with Unity via MCP. You have access to the following resources and tools:
18+
+- Resource "get_hierarchy" (unity://hierarchy) to list all GameObjects.
19+
+- 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.
20+
+- Tool "select_gameobject" to select a GameObject by ID or path.
21+
+- Tool "update_component" to update or add a component on a GameObject.
22+
+
23+
+Workflow:
24+
+1. Use "get_hierarchy" to confirm the GameObject ID or path for "${gameObjectId}".
25+
+2. Invoke "select_gameobject" to focus on the target GameObject in Unity.
26+
+3. Optionally, use "unity://gameobject/${gameObjectId}" to retrieve detailed properties.
27+
+4. Apply changes with "update_component" as per user requirements.
28+
+5. Confirm success and report any errors.
29+
+
30+
+Always validate inputs and request clarification if the identifier is ambiguous.`
31+
}
32+
},
33+
{
34+
role: 'user',
35+
content: {
36+
type: 'text',
37+
text: `Handle GameObject "${gameObjectId}" through the above workflow.`
38+
}
39+
}
40+
]
41+
}));
42+
}

Server/src/index.ts

Lines changed: 1 addition & 1 deletion
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 { registerGameObjectHandlingPrompt } from './prompts/gameobjectHandlingStrategyPrompt.js';
20+
import { registerGameObjectHandlingPrompt } from './prompts/gameobjectHandlingPrompt.js';
2121

2222
// Initialize loggers
2323
const serverLogger = new Logger('Server', LogLevel.INFO);

0 commit comments

Comments
 (0)