Skip to content

Restrict MCP filesystem tools and confirm file transfers - #305

Merged
Mike Krüger (mkrueger) merged 6 commits into
mainfrom
dev/mkrueger/confirm-mcp-filesystem-reads
Nov 24, 2026
Merged

Mike Krüger (mkrueger) merged 6 commits into
mainfrom
dev/mkrueger/confirm-mcp-filesystem-reads

Conversation

@mkrueger

@mkrueger Mike Krüger (mkrueger) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Block cat, dir, and jq server-side for MCP. These commands remain available in the interactive shell, but MCP clients cannot invoke them, even with confirmation support.
  • Require explicit user confirmation before MCP import and export execute, including import dry runs and exports with force. Clients without confirmation support are refused before execution.
  • Explain the transfer risks in confirmation: imports read local data files and can upload their contents to Cosmos DB; exports write local files and can overwrite them.

Confirmation safety

Approval is single-use, expires, and is bound to the exact command, local working directory, and shell state. Prompts show the account, navigation context, file paths, and options. A changed working directory or shell context requires a new confirmation. Interactive shell behavior and Cosmos DB navigation/listing (cd and ls) are unchanged.

These command restrictions are not a filesystem sandbox. Other commands, including bulk file inputs and theme operations, can still access local files. Use only trusted MCP clients.

Validation

  • Application and test projects build successfully with zero warnings.
  • All 180 focused MCP tests pass, including HTTP coverage for clients with current and 2025-11-25 protocol versions, hard-blocked commands, transfer approval/refusal, import dry runs, forced exports, working-directory binding, and replay rejection.
  • Backported the same changes to rel/1.2 in [1.2] Restrict MCP filesystem tools and confirm file transfers #306; its builds and the same 180 tests also pass.

CI emulator stability

The rolling Linux preview image changed after the previous passing run and began returning HTTP 500 instead of the expected HTTP 409 for duplicate creates (PostgresError(SqlState(E24000))). CI now pins the exact image digest from passing run 44800367029. All test assertions remain enabled; no emulator failures are ignored. The same pin is applied in both #305 and #306.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🟡 Changes recommended

The suggested fallback command can enable recursion despite recursive: false because boolean values are formatted separately from their flags; inline boolean formatting and true/false round-trip coverage are needed.

1 open issue
What changed in this PR

This PR extends the shell’s MCP confirmation mechanism to local filesystem reads through dir and cat, while preserving their read-only classification and interactive shell behavior.

Changes:

  • Requires explicit approval for MCP filesystem reads and refuses clients without confirmation support.
  • Binds filesystem approval to the command, working directory, and shell state.
  • Updates help and documentation, with metadata, execution, retry, and HTTP confirmation tests.
File Description
docs/​mcp.md Documents filesystem approval requirements and context binding.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Mcp/​ToolOperations.cs Adds filesystem confirmation prompts and working-directory checks.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Mcp/​McpAnnotationAttribute.cs Broadens the confirmation property’s XML comment beyond destructive commands.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Mcp/​ConfirmationRequestState.cs Generalizes the class summary to command confirmation.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​HelpCommand.cs Explains filesystem confirmation in command help.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​DirCommand.cs Marks directory listing as requiring MCP confirmation.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Commands/​CatCommand.cs Marks file reads as requiring MCP confirmation.
CosmosDBShell.Tests/​ToolOperationsTests.cs Checks filesystem tool annotations and help text.
CosmosDBShell.Tests/​ToolOperationsCallToolTests.cs Covers approval outcomes, directory binding, and replay rejection.
CosmosDBShell.Tests/​McpConfirmationTests.cs Adds HTTP approval and denial coverage for filesystem reads.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 088cc6e dev/mkrueger/confirm... 222edc9 +/-
76% 76% 0%
View coverage of the 4 most impacted files.
File main 088cc6e dev/mkrueger/confirm... 222edc9 +/-
D:\a\CosmosDBSh...olOperations.cs 95% 95% 0%
D:\a\CosmosDBSh...\HelpCommand.cs 86% 86% 0%
D:\a\CosmosDBSh...mportCommand.cs 97% 97% 0%
D:\a\CosmosDBSh...xportCommand.cs 90% 91% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 23, 2026 12:06 UTC

Copilot AI balanced review requested due to automatic review settings November 20, 2026 17: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.

🟢 Approval recommended

No active review issues block the changes requiring explicit approval for MCP filesystem reads.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 20, 2026 19:14

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.

🟢 Approval recommended

There are no active review issues blocking approval of the filesystem-read confirmation changes.

No open issues 🎉

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mike Krüger (mkrueger) added a commit that referenced this pull request Nov 23, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mkrueger Mike Krüger (mkrueger) changed the title Require confirmation for MCP filesystem reads Restrict MCP filesystem tools and confirm file transfers Nov 23, 2026
Copilot AI balanced review requested due to automatic review settings November 23, 2026 09:50

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.

🟢 Approval recommended

No active review issues are reported for the MCP file-access restrictions and transfer-confirmation changes.

No open issues 🎉

Review effort: Balanced

Avoid the rolling preview regression that returns HTTP 500 instead of 409 for duplicate creates. Keep all emulator assertions enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 11:58
Mike Krüger (mkrueger) added a commit that referenced this pull request Nov 23, 2026
Avoid the rolling preview regression that returns HTTP 500 instead of 409 for duplicate creates. Keep all emulator assertions enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🟢 Approval recommended

No active review issues remain for the MCP filesystem access safeguards.

No open issues 🎉

Review effort: Balanced

@mkrueger
Mike Krüger (mkrueger) merged commit 83b3d00 into main Nov 24, 2026
13 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/confirm-mcp-filesystem-reads branch November 24, 2026 09:03
Mike Krüger (mkrueger) added a commit that referenced this pull request Nov 24, 2026
* Require confirmation for MCP filesystem reads

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit bab00db)

* Preserve boolean options in MCP confirmation commands

(cherry picked from commit 05e42db)

* Prevent emulator startup updates from breaking PostgreSQL

(cherry picked from commit 4e022ca)

* Restrict MCP filesystem tools and confirm file transfers (#305)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix MCP confirmation context formatting

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Pin passing emulator image for integration tests (#305)

Avoid the rolling preview regression that returns HTTP 500 instead of 409 for duplicate creates. Keep all emulator assertions enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mike Krüger (mkrueger) added a commit that referenced this pull request Nov 24, 2026
Use the preview image verified by PR #305 and prevent startup package updates from replacing PostgreSQL modules. Keep all test profiles and assertions enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants