Repository navigation
fix: remove mcp protocol version and fix "The CancellationTokenSource has been disposed" in ShellInterpreter - #150
Conversation
Agreed |
There was a problem hiding this comment.
Pull request overview
This PR updates the Cosmos DB Shell’s MCP integration to improve compatibility with MCP clients and hardens prompt-cancellation behavior to avoid ObjectDisposedException during MCP tool execution.
Changes:
- Stop explicitly setting an MCP protocol version so the server can use the library defaults (improves client compatibility).
- Prevent
ShellInterpreter.CancelPrompt()from failing when the sharedCancellationTokenSourcehas already been disposed. - Add a regression test covering the disposed shared token-source scenario; add Rider
.idea/to.gitignore.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/McpServer.cs |
Removes explicit MCP protocol version pinning to avoid advertising an unsupported version. |
CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs |
Wraps currentTokenSource.Cancel() to avoid ObjectDisposedException during prompt cancellation. |
CosmosDBShell.Tests/ToolOperationsCallToolTests.cs |
Adds a regression test that simulates an externally-disposed shared token source and validates tool calls still succeed. |
.gitignore |
Ignores JetBrains Rider project metadata directory. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Thanks - I appreciate all input - I didn't expect that I get PRs so soon. Approved. EDIT: Build pipleline has some issues - posted them below. I can't push a fix otherwise I can't approve the PR anymore :/. |
Build failure: StyleCop SA1505The Issue — public void CancelPrompt()
{
// <-- SA1505: blank line right after '{'
var tokenSource = currentTokenSource;
try
{Fix — remove that single blank line between |
1 similar comment
Build failure: StyleCop SA1505The Issue — public void CancelPrompt()
{
// <-- SA1505: blank line right after '{'
var tokenSource = currentTokenSource;
try
{Fix — remove that single blank line between |
|
Mike Krüger (@mkrueger) pushed |
|
@microsoft-github-policy-service agree |
## What Stamps the changelog release heading as `## 1.1.136-preview — 2026-07-20` and fills in the entries for PRs merged since 1.1.115-preview. Supersedes #185 (same content, version heading bumped from `1.1.135` to `1.1.136` to account for the extra git-height commit). ## Added entries - **New features** — `ttl` and `conflict` commands for container time-to-live and conflict-resolution policy ([#151](#151), [#111](#111)). - **Fixes** — MCP protocol-version rejection (e.g. Claude Code) and the `ObjectDisposedException: The CancellationTokenSource has been disposed` error on tool calls ([#150](#150)). - **Build & pipeline** — CodeQL analysis workflow ([#165](#165)), Node 24 GitHub Actions updates ([#152](#152)), and a `union` merge driver for `CHANGELOG.md` ([#172](#172)). ## Scope - `CHANGELOG.md` only. No source or behavior changes. `version.json` is unchanged — the patch is derived from git height by Nerdbank.GitVersioning.
Hi there,
The pr has 2 changes:
vnext-EN20260602GA image.Add
.mcpto the current project.{ "mcpServers": { "cosmosdb": { "type": "http", "url": "http://127.0.0.1:6128/" } } }The error from claude
Claude Code v2.1.198:To reproduce, run cosmos via docker and use
cosmosdbshell --mcp --connect "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" --connect-mode gatewayand run claude, check mcp list.Checking here and here, where LatestProtocolVersion and SupportedProtocolVersions are defined i think it's better to remove the version or use some that does exists. In this PR i just removed.
fail: Azure.Data.Cosmos.Shell.Mcp.ToolOperations[0] An exception occurred running 'ls'. System.ObjectDisposedException: The CancellationTokenSource has been disposed. at System.Threading.CancellationTokenSource.Cancel() at Azure.Data.Cosmos.Shell.Core.ShellInterpreter.CancelPrompt() in /Users/admin/Works/wn/OpenSource/CosmosDBShell/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs:line 321 at Azure.Data.Cosmos.Shell.Mcp.ToolOperations.OnCallToolsAsync(RequestContext`1 parameters, CancellationToken cancellationToken) in /Users/admin/Works/wn/OpenSource/CosmosDBShell/CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/ToolOperations.cs:line 504 connect Connection Information ┌──────────────────┬─────────────────────────┐ │ Account │ cosmosdev │ │ Endpoint │ https://localhost:8081/ │ │ Connection Mode │ Gateway │ │ Read Regions │ South Central US │ │ Write Regions │ South Central US │ │ Current Location │ / │ └──────────────────┴─────────────────────────┘ fail: Azure.Data.Cosmos.Shell.Mcp.ToolOperations[0] An exception occurred running 'connect'. System.ObjectDisposedException: The CancellationTokenSource has been disposed. at System.Threading.CancellationTokenSource.Cancel() at Azure.Data.Cosmos.Shell.Core.ShellInterpreter.CancelPrompt() in /Users/admin/Works/wn/OpenSource/CosmosDBShell/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs:line 321 at Azure.Data.Cosmos.Shell.Mcp.ToolOperations.OnCallToolsAsync(RequestContext`1 parameters, CancellationToken cancellationToken) in /Users/admin/Works/wn/OpenSource/CosmosDBShell/CosmosDBShell/Azure.Data.Cosmos.Shell.Mcp/ToolOperations.cs:line 504After those 2 fixing i can use
cosmosdbshellwih new cosmosdb emulator.