-
Notifications
You must be signed in to change notification settings - Fork 752
feat(stdio): add MCP tool toggle support with tools/list_changed notifications #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
whatevertogo
wants to merge
20
commits into
CoplayDev:beta
Choose a base branch
from
whatevertogo:feat/stdio-tool-toggle-from-dev
base: beta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b7929ed
feat(stdio): add MCP tool toggle support for stdio transport
whatevertogo b88905f
feat(stdio): add tools/list_changed notifications for tool toggle
whatevertogo 640aef8
feat(stdio): add configuration options for stdio status freshness and…
whatevertogo b87baaf
Add per-call unity_instance routing via middleware argument interception
dsarno 2e2ca8a
merge: PR #772 per-call unity_instance routing with stdio tool toggle
whatevertogo 4e8b556
Merge branch 'CoplayDev:beta' into feat/stdio-tool-toggle-from-dev
whatevertogo 252a540
Merge branch 'feat/stdio-tool-toggle-from-dev' of github.com:whatever…
whatevertogo 7036b45
feat: add stdio tool filtering tests and address code review feedback
whatevertogo 5b475a1
test(middleware): add status file schema compatibility tests
whatevertogo 01920d2
feat(editor): add HTTP tool reregistration on tool toggle
whatevertogo 8fe196a
Refactor instance resolution and simplify status refresh handling
whatevertogo aaa3260
Merge pull request #12 from whatevertogo/codex/simplify-duplicated-br…
whatevertogo 5d9b4fd
Merge branch 'feat/stdio-tool-toggle-from-dev' of github.com:whatever…
whatevertogo 5feeb33
fix: harden stdio tool refresh and instance selection middleware
whatevertogo 683a6f5
test: update set_active_instance integration mocks for middleware res…
whatevertogo 345a36a
merge: resolve PR #763 conflicts with upstream/beta
whatevertogo fa5d4f5
Merge branch 'CoplayDev:beta' into feat/stdio-tool-toggle-from-dev
whatevertogo b52dcad
fix: streamline tool disabling logic and enhance tool visibility checks
whatevertogo e22594e
Merge branch 'feat/stdio-tool-toggle-from-dev' of github.com:whatever…
whatevertogo efff0df
Merge branch 'CoplayDev:beta' into feat/stdio-tool-toggle-from-dev
whatevertogo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -147,6 +147,8 @@ These options apply to the `mcp-for-unity` command (whether run via `uvx`, Docke | |||||||||||||||||||||||||||
| - `UNITY_MCP_HTTP_REMOTE_HOSTED` - Enable remote-hosted mode (`true`, `1`, or `yes`) | ||||||||||||||||||||||||||||
| - `UNITY_MCP_DEFAULT_INSTANCE` - Default Unity instance to target (project name, hash, or `Name@hash`) | ||||||||||||||||||||||||||||
| - `UNITY_MCP_SKIP_STARTUP_CONNECT=1` - Skip initial Unity connection attempt on startup | ||||||||||||||||||||||||||||
| - `UNITY_MCP_STDIO_STATUS_TTL_SECONDS` - Freshness window for stdio status files used by tools/list filtering (default: `15`) | ||||||||||||||||||||||||||||
| - `UNITY_MCP_STDIO_TOOLS_WATCH_INTERVAL_SECONDS` - Poll interval for stdio tool-list change watcher in seconds (default: `1.0`, minimum: `0.2`) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| API key authentication (remote-hosted mode): | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -164,6 +166,45 @@ Telemetry: | |||||||||||||||||||||||||||
| - `UNITY_MCP_TELEMETRY_ENDPOINT` - Override telemetry endpoint URL | ||||||||||||||||||||||||||||
| - `UNITY_MCP_TELEMETRY_TIMEOUT` - Override telemetry request timeout (seconds) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ### MCP tool toggles in stdio | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| The `manage_editor` tool exposes MCP tool enable/disable controls: | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - `set_mcp_tool_enabled` (`tool_name`, `enabled`) | ||||||||||||||||||||||||||||
| - `get_mcp_tool_enabled` (`tool_name`) | ||||||||||||||||||||||||||||
| - `list_mcp_tools` | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Example: | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ```json | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| "action": "set_mcp_tool_enabled", | ||||||||||||||||||||||||||||
| "tool_name": "manage_scene", | ||||||||||||||||||||||||||||
| "enabled": false | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| When running in `stdio`, `tools/list` is filtered by Unity's enabled tool state. | ||||||||||||||||||||||||||||
| If all Unity-managed tools are disabled, `tools/list` will only show server-only tools. | ||||||||||||||||||||||||||||
| The Unity status file (`~/.unity-mcp/unity-mcp-status-<hash>.json`) now includes: | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| - `project_hash` | ||||||||||||||||||||||||||||
| - `enabled_tools` | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Tool toggle changes trigger an immediate status-file refresh, so `tools/list` | ||||||||||||||||||||||||||||
| updates do not depend on waiting for the next heartbeat. | ||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| When a client session initializes in `stdio`, the server sends | ||||||||||||||||||||||||||||
| `notifications/tools/list_changed` to trigger an immediate tool-list refresh. | ||||||||||||||||||||||||||||
| During runtime, a stdio watcher monitors status-file changes and emits the same | ||||||||||||||||||||||||||||
| notification when enabled-tool state changes. | ||||||||||||||||||||||||||||
| To avoid stale instance data, stdio filtering only uses recent status files | ||||||||||||||||||||||||||||
| (default freshness window: 15s, configurable via `UNITY_MCP_STDIO_STATUS_TTL_SECONDS`). | ||||||||||||||||||||||||||||
| Watcher interval defaults to 1.0s (minimum 0.2s), configurable via | ||||||||||||||||||||||||||||
| `UNITY_MCP_STDIO_TOOLS_WATCH_INTERVAL_SECONDS`. | ||||||||||||||||||||||||||||
| Compatibility note: if a client ignores `notifications/tools/list_changed`, | ||||||||||||||||||||||||||||
| tool calls still enforce enabled/disabled state, but visible list updates may | ||||||||||||||||||||||||||||
| still require reconnecting that client. | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| #### Tool toggle environment variables | |
| These environment variables control how often the server checks for tool/status updates | |
| and how long status information is considered valid: | |
| - `UNITY_MCP_STDIO_TOOLS_WATCH_INTERVAL_SECONDS` | |
| Interval in seconds between checks for tool/status file changes. | |
| Default: `1.0` (minimum: `0.2`). | |
| - `UNITY_MCP_STDIO_STATUS_TTL_SECONDS` | |
| Time-to-live in seconds for status information before it is considered stale. | |
| Default: `15.0`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enabled_tools array is built by filtering GetEnabledTools() which only returns enabled tools. This means when all Unity-managed tools are disabled, enabled_tools will be an empty array. However, an empty array is semantically different from a missing field - it explicitly states "no tools are enabled" rather than "state unknown".
The Python middleware correctly handles this case by checking for an empty set and filtering out all Unity-managed tools while keeping server-only tools visible. However, this semantic difference could be documented more clearly - an empty array means "all Unity tools disabled" while a missing field means "backward compatibility: no filtering".