Skip to content

fix: remove mcp protocol version and fix "The CancellationTokenSource has been disposed" in ShellInterpreter - #150

Merged
Mike Krüger (mkrueger) merged 8 commits into
Azure:mainfrom
wondertalik:fix/remove-mcp-protocol-version
Jul 6, 2026
Merged

Mike Krüger (mkrueger) merged 8 commits into
Azure:mainfrom
wondertalik:fix/remove-mcp-protocol-version

Conversation

@wondertalik

Copy link
Copy Markdown

Hi there,

The pr has 2 changes:

  1. claude code couldn't connect to mcp server. I checked copilot cli didn't have this problem. I tried to install the latest preview and tried to use cosmosdbshell embeded in current vnext-EN20260602 GA image.
sh-5.2$ cosmosdbshell
Cosmos Shell version: 1.1.4-preview
MCP server is off.
Report issues at https://github.com/Azure/CosmosDBShell
Cosmos DB shell ready.
Not connected. Run 'connect <endpoint>' to authenticate, or 'help connect' for more options.
CS >                                                                                             

Add .mcp to the current project.

{
  "mcpServers": {
    "cosmosdb": {
      "type": "http",
      "url": "http://127.0.0.1:6128/"
    }
  }
}

The error from claude Claude Code v2.1.198:

Cosmosdb MCP Server

   Status:           ✘ failed
   Issue:            Server's protocol version is not supported: 2025-07-05
   Auth:             ✘ not authenticated
   URL:              http://127.0.0.1:6128/
   Config location:  /Users/admin/Works/Caropticom/NewOne/caropticom_backend_copy/.mcp.json

To reproduce, run cosmos via docker and use cosmosdbshell --mcp --connect "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" --connect-mode gateway and 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.

  1. Not related to any agent. Basically agent couldn't use any tool. The error from console
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 504

After those 2 fixing i can use cosmosdbshell wih new cosmosdb emulator.

@wondertalik

Copy link
Copy Markdown
Author

Vitalii Koretskyi (@wondertalik) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

Agreed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 shared CancellationTokenSource has 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>
Copilot AI review requested due to automatic review settings July 2, 2026 15:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings July 3, 2026 04:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

@mkrueger

Mike Krüger (mkrueger) commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

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 :/.

@mkrueger

Copy link
Copy Markdown
Collaborator

Build failure: StyleCop SA1505

The build-test-package and Emulator Integration Tests checks are failing due to a StyleCop analyzer violation (warnings are treated as errors in this repo), not a compile error.

Issue — SA1505: An opening brace should not be followed by a blank line, at ShellInterpreter.cs:320. The new CancelPrompt() body inserts a blank line immediately after the method's opening brace:

public void CancelPrompt()
{
                              // <-- SA1505: blank line right after '{'
    var tokenSource = currentTokenSource;
    try
    {

Fix — remove that single blank line between { and var tokenSource = currentTokenSource;. (The blank line before this.editorCancelTokenSource.Cancel(); is fine — SA1505 only flags a blank line following an opening brace.) After that one-line whitespace change, CI should pass.

1 similar comment
@mkrueger

Copy link
Copy Markdown
Collaborator

Build failure: StyleCop SA1505

The build-test-package and Emulator Integration Tests checks are failing due to a StyleCop analyzer violation (warnings are treated as errors in this repo), not a compile error.

Issue — SA1505: An opening brace should not be followed by a blank line, at ShellInterpreter.cs:320. The new CancelPrompt() body inserts a blank line immediately after the method's opening brace:

public void CancelPrompt()
{
                              // <-- SA1505: blank line right after '{'
    var tokenSource = currentTokenSource;
    try
    {

Fix — remove that single blank line between { and var tokenSource = currentTokenSource;. (The blank line before this.editorCancelTokenSource.Cancel(); is fine — SA1505 only flags a blank line following an opening brace.) After that one-line whitespace change, CI should pass.

@wondertalik

Copy link
Copy Markdown
Author
@wondertalik

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI review requested due to automatic review settings July 4, 2026 10:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

@mkrueger
Mike Krüger (mkrueger) merged commit c039b93 into Azure:main Jul 6, 2026
4 checks passed
Mike Krüger (mkrueger) added a commit that referenced this pull request Jul 20, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants