Skip to content

[Bug] Custom tools fail to inject unity_instance automatically (HTTP connection) #482

@alan49973028

Description

@alan49973028

Environment
Unity MCP Version: 8.3.0
Connection Type: HTTP

Description
I am experiencing an issue where custom tools fail to trigger correctly, whereas the built-in official commands work perfectly fine.

When attempting to use a custom tool, the system persistently throws an error indicating that unity_instances cannot be found. The LLM fails to list the unity_instances or automatically call set_active_instance to select the context.

Root Cause Analysis
It seems that the _inject_unity_instance logic does not automatically resolve the target instance for custom tools, even when there is only one active connection.

Proposed Solution / Workaround
I managed to fix this issue by modifying the server source code, specifically within the _inject_unity_instance section.

The Logic Change: I added a check for the number of active Unity instances:

If there is exactly one Unity instance connected: The system should automatically select and inject this instance.

If there are zero or multiple instances: Keep the original behavior (throw an error or require manual selection).

After implementing this logic, my custom tools are triggering correctly. I suggest merging a similar logic into the official release to improve the developer experience for single-instance setups.

Note: This issue description was translated and summarized by AI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions