Skip to content

Commit 762b38c

Browse files
committed
fixed issue spamming hierarchy information request from MCP host for the get_gameObject ResourceTemplate
1 parent 764e625 commit 762b38c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Server/build/resources/getGameObjectResource.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
22
import { McpUnityError, ErrorType } from '../utils/errors.js';
3-
import { resourceUri as hierarchyResourceUri } from './getHierarchyResource.js';
3+
import { resourceName as hierarchyResourceName } from './getHierarchyResource.js';
44
// Constants for the resource
55
const resourceName = 'get_gameobject';
66
const resourceUri = 'unity://gameobject/{id}';
@@ -16,7 +16,9 @@ const resourceMimeType = 'application/json';
1616
export function createGetGameObjectResource(server, mcpUnity, logger) {
1717
// Create a resource template with the MCP SDK
1818
const resourceTemplate = new ResourceTemplate(resourceUri, {
19-
list: async () => listGameObjects(mcpUnity, logger, resourceMimeType)
19+
// This list method is commented because is calling getHierarchyResource every second to the MCP client in the current format.
20+
// TODO: Find a new way to implement this so that it doesn't request the list of game objects so often
21+
list: undefined //async () => listGameObjects(mcpUnity, logger, resourceMimeType)
2022
});
2123
logger.info(`Registering resource: ${resourceName}`);
2224
// Register this resource with the MCP server
@@ -73,7 +75,7 @@ async function resourceHandler(mcpUnity, uri, variables, logger) {
7375
*/
7476
async function listGameObjects(mcpUnity, logger, resourceMimeType) {
7577
const hierarchyResponse = await mcpUnity.sendRequest({
76-
method: hierarchyResourceUri,
78+
method: hierarchyResourceName,
7779
params: {}
7880
});
7981
if (!hierarchyResponse.success) {

Server/src/resources/getGameObjectResource.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
44
import { McpUnity } from '../unity/mcpUnity.js';
55
import { Variables } from '@modelcontextprotocol/sdk/shared/uriTemplate.js';
66
import { McpUnityError, ErrorType } from '../utils/errors.js';
7-
import { resourceUri as hierarchyResourceUri } from './getHierarchyResource.js';
7+
import { resourceName as hierarchyResourceName } from './getHierarchyResource.js';
88

99
// Constants for the resource
1010
const resourceName = 'get_gameobject';
@@ -24,7 +24,9 @@ export function createGetGameObjectResource(server: McpServer, mcpUnity: McpUnit
2424
const resourceTemplate = new ResourceTemplate(
2525
resourceUri,
2626
{
27-
list: async () => listGameObjects(mcpUnity, logger, resourceMimeType)
27+
// This list method is commented because is calling getHierarchyResource every second to the MCP client in the current format.
28+
// TODO: Find a new way to implement this so that it doesn't request the list of game objects so often
29+
list: undefined//async () => listGameObjects(mcpUnity, logger, resourceMimeType)
2830
}
2931
);
3032
logger.info(`Registering resource: ${resourceName}`);
@@ -94,7 +96,7 @@ async function resourceHandler(mcpUnity: McpUnity, uri: URL, variables: Variable
9496
*/
9597
async function listGameObjects(mcpUnity: McpUnity, logger: Logger, resourceMimeType: string) {
9698
const hierarchyResponse = await mcpUnity.sendRequest({
97-
method: hierarchyResourceUri,
99+
method: hierarchyResourceName,
98100
params: {}
99101
});
100102

0 commit comments

Comments
 (0)