Notify MCP clients about shell location changes - #223
Open
Mike Krüger (mkrueger) wants to merge 2 commits into
Open
Mike Krüger (mkrueger) wants to merge 2 commits into
Mike Krüger (mkrueger) wants to merge 2 commits into
Conversation
Expose the shared shell navigation state as the MCP resource cosmos://shell/current-location and support resources/subscribe for it. Subscribed clients receive notifications/resources/updated whenever the location or connection changes, including interactive cd, connect, and disconnect, and can re-read the resource for the new value. - Raise ShellInterpreter.LocationChanged only when the location or the underlying CosmosClient actually changes. - Coalesce pending notifications through a single-slot channel. - Reject subscriptions to other URIs with an InvalidParams protocol error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mike Krüger (mkrueger)
requested review from
a team
and
a balanced review from Copilot
September 29, 2026 08:37
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall line coverage in commit 2a7424b in the Show a line coverage summary of the most impacted files.
Updated |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The reconnect and ARM-reattachment change-detection branch lacks regression coverage.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds a subscribable MCP resource that reports shared shell location changes.
Changes:
- Exposes
cosmos://shell/current-location. - Tracks subscriptions and publishes coalesced update notifications.
- Adds documentation and MCP integration tests.
| File | Description |
|---|---|
README.md |
Links to location subscription documentation. |
docs/mcp.md |
Documents resource and subscription behavior. |
ToolOperations.cs |
Handles subscribe and unsubscribe requests. |
ServerInstructions.md |
Informs clients about the resource. |
ResourceOperations.cs |
Implements the location resource. |
McpServer.cs |
Registers subscriptions and advertises capability. |
LocationResourceSubscriptions.cs |
Tracks clients and sends notifications. |
ShellInterpreter.cs |
Emits location and connection change events. |
ToolOperationsCallToolTests.cs |
Updates test construction and cleanup. |
ShellLocationChangedTests.cs |
Tests basic location-change detection. |
ResourceOperationsTests.cs |
Tests resource JSON content. |
McpLocationSubscriptionTests.cs |
Tests end-to-end subscriptions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Dispose the port-probe TcpListener in the subscription test. - Limit the per-subscriber catch to the running state via an exception filter so a failed notification only drops that subscriber. - Cover client-identity change detection: a new client at the same location notifies; a changed ARM context with the same client does not. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
MCP clients had no way to learn that the shared shell location changed between tool calls (for example when the user runs
cdinteractively). The location was only visible in thecurrentLocationfield of the next tool response.This PR exposes the navigation state as a subscribable MCP resource:
cosmos://shell/current-locationreturning{ "currentLocation": ... }(nullwhen disconnected,/,/db, or/db/container).resources.subscribeand handlesresources/subscribe/resources/unsubscribefor that URI.notifications/resources/updatedwhenever the location or connection changes, including interactivecd,connect, anddisconnect. Clients re-read the resource for the new value.Implementation notes
ShellInterpreter.LocationChangedfires from theStatesetter only when the location string or the underlyingCosmosClientchanges.cd's double assignment and ARM-context reattachment do not produce duplicate events. The handler only writes to a channel, so it never blocks under the execution lock.LocationResourceSubscriptions(hosted service) tracks subscribed sessions via weak references and drops sessions whose notification fails.DropWrite), since the notification carries only the URI. Scripts with manycdcalls do not flood clients.InvalidParamsMcpProtocolExceptionwith a readable message, not a generic internal error.resources/subscribe). The 2026-07-28subscriptions/listenflow is out of scope until the SDK supports it.Docs
docs/mcp.md: new "Shell Location Updates" section.README.mdandServerInstructions.md: short pointers.Testing
McpLocationSubscriptionTests): a real MCP HTTP client subscribes, receives the notification after a state change, and reads the updated value. It also checks that an invalid subscription URI yieldsInvalidParams.ResourceOperationsTests) and change detection (ShellLocationChangedTests).