Skip to content

Conversation

sitefinitysteve
Copy link

dotnet changes:

  • Add CRITICAL security restrictions and sanitization to C# per the TS
  • Implement READONLY property on the MCP like we have in NODE

@sitefinitysteve
Copy link
Author

Hey noticed the TS\Node blocked problematic queries going through, but dotnet just let anything happen... this should copy the behaviour.

Copy link

@Copilot Copilot AI left a comment

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 implements comprehensive security enhancements for the MSSQL MCP server, adding READONLY mode checks and extensive SQL query validation to prevent unauthorized database operations and potential security vulnerabilities.

  • Adds READONLY mode environment variable support that blocks destructive operations
  • Implements comprehensive SQL injection protection with keyword filtering and pattern detection
  • Adds a new TestConnection tool for database connectivity validation

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Tools/Tools.cs Adds IsReadOnlyMode property that checks READONLY environment variable
Tools/UpdateData.cs Adds READONLY mode check to prevent UPDATE operations
Tools/InsertData.cs Adds READONLY mode check to prevent INSERT operations
Tools/CreateTable.cs Adds READONLY mode check to prevent CREATE TABLE operations
Tools/DropTable.cs Adds READONLY mode check to prevent DROP TABLE operations
Tools/ReadData.cs Implements comprehensive SQL validation, injection protection, and result sanitization
Tools/TestConnection.cs New tool for testing database connectivity with connection information
MssqlMcp.Tests/UnitTests.cs Adds comprehensive test coverage for READONLY mode and TestConnection functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@AV25242
Copy link
Collaborator

AV25242 commented Aug 21, 2025

@sitefinitysteve thank you for the PR, copilot assisted review and has left few comments PTAL.

@sitefinitysteve
Copy link
Author

@sitefinitysteve thank you for the PR, copilot assisted review and has left few comments PTAL.

Oh cool feature!

I'll get on it once I'm back from vacation

@AV25242
Copy link
Collaborator

AV25242 commented Aug 21, 2025

@sitefinitysteve thank you for the PR, copilot assisted review and has left few comments PTAL.

Oh cool feature!

I'll get on it once I'm back from vacation

@sitefinitysteve the one thing I noticed is that the code currently looks at the readonly flag and returns which is good (second level validation), in addition to this what would be required is showing only the tools that are readonly, i.e describe table, list tables and read.

@sitefinitysteve
Copy link
Author

@sitefinitysteve thank you for the PR, copilot assisted review and has left few comments PTAL.

Oh cool feature!
I'll get on it once I'm back from vacation

@sitefinitysteve the one thing I noticed is that the code currently looks at the readonly flag and returns which is good (second level validation), in addition to this what would be required is showing only the tools that are readonly, i.e describe table, list tables and read.

I believe this is correct, seems to work VSCode reports back properly 9732602

Your MSSQL MCP server is working correctly and has successfully connected to the SQL Server instance. Since READONLY is set to false, you should have access to the full suite of database operations including:

Read Operations: TestConnection, DescribeTable, ListTables, ReadData
Write Operations: ExecuteQuery, CreateTable, InsertData, UpdateData, DeleteData

The connection to your SQL Server 2022 instance at XX with the MSSQLMCP database is functioning properly!
Since you have READONLY mode enabled, you'll only have access to read-only operations like:

Testing connections
Describing table schemas
Listing tables
Reading data from tables
The connection test confirms that your MCP server setup is working properly!

@sitefinitysteve
Copy link
Author

sitefinitysteve commented Sep 4, 2025 via email

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.

2 participants