Skip to content

Commit a02ab72

Browse files
committed
Add McpServerTool attributes
1 parent 25e0e36 commit a02ab72

File tree

8 files changed

+52
-18
lines changed

8 files changed

+52
-18
lines changed

MssqlMcp/MssqlMcp/Tools/CreateTable.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace Mssql.McpServer;
99

1010
public partial class Tools
1111
{
12-
[McpServerTool, Description("Creates a new table in the SQL Database. Expects a valid CREATE TABLE SQL statement as input.")]
12+
[McpServerTool(
13+
Title = "Create Table",
14+
ReadOnly = false,
15+
Destructive = false),
16+
Description("Creates a new table in the SQL Database. Expects a valid CREATE TABLE SQL statement as input.")]
1317
public async Task<DbOperationResult> CreateTable(
1418
[Description("CREATE TABLE SQL statement")] string sql)
1519
{

MssqlMcp/MssqlMcp/Tools/DescribeTable.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ namespace Mssql.McpServer;
1010

1111
public partial class Tools
1212
{
13-
[McpServerTool, Description("Returns table schema")]
13+
[McpServerTool(
14+
Title = "Describe Table",
15+
ReadOnly = true,
16+
Idempotent = true,
17+
Destructive = false),
18+
Description("Returns table schema")]
1419
public async Task<DbOperationResult> DescribeTable(
1520
[Description("Name of table")] string name)
1621
{

MssqlMcp/MssqlMcp/Tools/DropTable.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace Mssql.McpServer;
99

1010
public partial class Tools
1111
{
12-
[McpServerTool, Description("Drops a table in the SQL Database. Expects a valid DROP TABLE SQL statement as input.")]
12+
[McpServerTool(
13+
Title = "Drop Table",
14+
ReadOnly = false,
15+
Destructive = true),
16+
Description("Drops a table in the SQL Database. Expects a valid DROP TABLE SQL statement as input.")]
1317
public async Task<DbOperationResult> DropTable(
1418
[Description("DROP TABLE SQL statement")] string sql)
1519
{

MssqlMcp/MssqlMcp/Tools/InsertData.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace Mssql.McpServer;
99

1010
public partial class Tools
1111
{
12-
[McpServerTool, Description("Updates data in a table in the SQL Database. Expects a valid INSERT SQL statement as input. ")]
12+
[McpServerTool(
13+
Title = "Insert Data",
14+
ReadOnly = false,
15+
Destructive = false),
16+
Description("Updates data in a table in the SQL Database. Expects a valid INSERT SQL statement as input. ")]
1317
public async Task<DbOperationResult> InsertData(
1418
[Description("INSERT SQL statement")] string sql)
1519
{

MssqlMcp/MssqlMcp/Tools/ListTables.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ public partial class Tools
1212
{
1313
private const string ListTablesQuery = @"SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_SCHEMA, TABLE_NAME";
1414

15-
[McpServerTool, Description("Lists all tables in the SQL Database.")]
15+
[McpServerTool(
16+
Title = "List Tables",
17+
ReadOnly = true,
18+
Idempotent = true,
19+
Destructive = false),
20+
Description("Lists all tables in the SQL Database.")]
1621
public async Task<DbOperationResult> ListTables()
1722
{
1823
var conn = await _connectionFactory.GetOpenConnectionAsync();

MssqlMcp/MssqlMcp/Tools/ReadData.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
namespace Mssql.McpServer;
1010
public partial class Tools
1111
{
12-
[McpServerTool, Description("Executes SQL queries against SQL Database to read data")]
12+
[McpServerTool(
13+
Title = "Read Data",
14+
ReadOnly = true,
15+
Idempotent = true,
16+
Destructive = false),
17+
Description("Executes SQL queries against SQL Database to read data")]
1318
public async Task<DbOperationResult> ReadData(
1419
[Description("SQL query to execute")] string sql)
1520
{

MssqlMcp/MssqlMcp/Tools/UpdateData.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace Mssql.McpServer;
99

1010
public partial class Tools
1111
{
12-
[McpServerTool, Description("Updates data in a table in the SQL Database. Expects a valid UPDATE SQL statement as input.")]
12+
[McpServerTool(
13+
Title = "Update Data",
14+
ReadOnly = false,
15+
Destructive = true),
16+
Description("Updates data in a table in the SQL Database. Expects a valid UPDATE SQL statement as input.")]
1317
public async Task<DbOperationResult> UpdateData(
1418
[Description("UPDATE SQL statement")] string sql)
1519
{

MssqlMcp/README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ This project is a .NET 8 console application implementing a Model Context Protoc
3737

3838
2. VSCode: **Start VSCode, and add MCP Server config to VSCode Settings**
3939

40+
Load the settings file in VSCode (Ctrl+Shift+P > Preferences: Open Settings (JSON)).
41+
42+
Add a new MCP Server with the following settings:
43+
4044
---
4145
```json
42-
"MSSQL MCP": {
43-
"type": "stdio",
44-
"command": "C:\\src\\MssqlMcp\\MssqlMcp\\bin\\Debug\\net8.0\\MssqlMcp.exe",
45-
"env": {
46+
"MSSQL MCP": {
47+
"type": "stdio",
48+
"command": "C:\\src\\MssqlMcp\\MssqlMcp\\bin\\Debug\\net8.0\\MssqlMcp.exe",
49+
"env": {
4650
"CONNECTION_STRING": "Server=.;Database=test;Trusted_Connection=True;TrustServerCertificate=True"
4751
}
4852
}
@@ -56,7 +60,6 @@ e.g. your MCP settings should look like this if "MSSQL MCP" is your own MCP Serv
5660
---
5761
```json
5862
"mcp": {
59-
6063
"servers": {
6164
"MSSQL MCP": {
6265
"type": "stdio",
@@ -69,11 +72,10 @@ e.g. your MCP settings should look like this if "MSSQL MCP" is your own MCP Serv
6972
```
7073
---
7174

72-
And example of using a connection string for Azure SQL Database:
75+
An example of using a connection string for Azure SQL Database:
7376
---
7477
```json
7578
"mcp": {
76-
7779
"servers": {
7880
"MSSQL MCP": {
7981
"type": "stdio",
@@ -88,13 +90,13 @@ And example of using a connection string for Azure SQL Database:
8890

8991
**Run the MCP Server**
9092

91-
Save the Settings file, and then you should see the "Start" button appear in the Settings json. Click "start" to start the MCP Server.
93+
Save the Settings file, and then you should see the "Start" button appear in the settings.json. Click "Start" to start the MCP Server. (You can then click on "Running" to view the Output window).
9294

9395
Start Chat (Ctrl+Shift+I), make sure Agent Mode is selected.
9496

9597
Click the tools icon, and ensure the "MSSQL MCP" tools are selected.
9698

97-
Then type in the chat window "List tables in DB" and hit enter.
99+
Then type in the chat window "List tables in the database" and hit enter. (If you have other tools loaded, you may need to specify "MSSQL MCP" in the initial prompt, e.g. "Using MSSQL MCP, list tables").
98100

99101
3. Claude Desktop: **Add MCP Server config to Claude Desktop**
100102

@@ -116,12 +118,13 @@ Add a new MCP Server with the following settings:
116118
}
117119
}
118120
```
121+
---
119122

120-
Save the file, start a new Chat, you'll see the "Tools" icon, it should list 8 MSSQL MCP tools.
123+
Save the file, start a new Chat, you'll see the "Tools" icon, it should list 7 MSSQL MCP tools.
121124

122125
# Troubleshooting
123126

124-
1. If you get a connection reset error using "Active Directory Default", try "Active Directory Interactive"
127+
1. If you get a "Task canceled" error using "Active Directory Default", try "Active Directory Interactive".
125128

126129

127130

0 commit comments

Comments
 (0)