|
1 | | -# MSSQL Database MCP Server |
2 | | - |
3 | | -<div align="center"> |
4 | | - <img src="./src/img/logo.png" alt="MSSQL Database MCP server logo" width="400"/> |
5 | | -</div> |
6 | | - |
7 | | -## What is this? 🤔 |
8 | | - |
9 | | -This is a server that lets your LLMs (like Claude) talk directly to your MSSQL Database data! Think of it as a friendly translator that sits between your AI assistant and your database, making sure they can chat securely and efficiently. |
10 | | - |
11 | | -### Quick Example |
12 | | -```text |
13 | | -You: "Show me all customers from New York" |
14 | | -Claude: *queries your MSSQL Database database and gives you the answer in plain English* |
15 | | -``` |
16 | | - |
17 | | -## How Does It Work? 🛠️ |
18 | | - |
19 | | -This server leverages the Model Context Protocol (MCP), a versatile framework that acts as a universal translator between AI models and databases. It supports multiple AI assistants including Claude Desktop and VS Code Agent. |
20 | | - |
21 | | -### What Can It Do? 📊 |
22 | | - |
23 | | -- Run MSSQL Database queries by just asking questions in plain English |
24 | | -- Create, read, update, and delete data |
25 | | -- Manage database schema (tables, indexes) |
26 | | -- Secure connection handling |
27 | | -- Real-time data interaction |
28 | | - |
29 | | -## Quick Start 🚀 |
30 | | - |
31 | | -### Prerequisites |
32 | | -- Node.js 14 or higher |
33 | | -- Claude Desktop or VS Code with Agent extension |
34 | | - |
35 | | -### Set up project |
36 | | - |
37 | | -1. **Install Dependencies** |
38 | | - Run the following command in the root folder to install all necessary dependencies: |
39 | | - ```bash |
40 | | - npm install |
41 | | - ``` |
42 | | - |
43 | | -2. **Build the Project** |
44 | | - Compile the project by running: |
45 | | - ```bash |
46 | | - npm run build |
47 | | - ``` |
48 | | - |
49 | | -## Configuration Setup |
50 | | - |
51 | | -### Option 1: VS Code Agent Setup |
52 | | - |
53 | | -1. **Install VS Code Agent Extension** |
54 | | - - Open VS Code |
55 | | - - Go to Extensions (Ctrl+Shift+X) |
56 | | - - Search for "Agent" and install the official Agent extension |
57 | | - |
58 | | -2. **Create MCP Configuration File** |
59 | | - - Create a `.vscode/mcp.json` file in your workspace |
60 | | - - Add the following configuration: |
61 | | - |
62 | | - ```json |
63 | | - { |
64 | | - "servers": { |
65 | | - "mssql-nodejs": { |
66 | | - "type": "stdio", |
67 | | - "command": "node", |
68 | | - "args": ["q:\\Repos\\SQL-AI-samples\\MssqlMcp\\Node\\dist\\index.js"], |
69 | | - "env": { |
70 | | - "SERVER_NAME": "your-server-name.database.windows.net", |
71 | | - "DATABASE_NAME": "your-database-name", |
72 | | - "READONLY": "false" |
73 | | - } |
74 | | - } |
75 | | - } |
76 | | - } |
77 | | - ``` |
78 | | - |
79 | | -3. **Alternative: User Settings Configuration** |
80 | | - - Open VS Code Settings (Ctrl+,) |
81 | | - - Search for "mcp" |
82 | | - - Click "Edit in settings.json" |
83 | | - - Add the following configuration: |
84 | | - |
85 | | - ```json |
86 | | - { |
87 | | - "mcp": { |
88 | | - "servers": { |
89 | | - "mssql": { |
90 | | - "command": "node", |
91 | | - "args": ["C:/path/to/your/Node/dist/index.js"], |
92 | | - "env": { |
93 | | - "SERVER_NAME": "your-server-name.database.windows.net", |
94 | | - "DATABASE_NAME": "your-database-name", |
95 | | - "READONLY": "false" |
96 | | - } |
97 | | - } |
98 | | - } |
99 | | - } |
100 | | - } |
101 | | - ``` |
102 | | - |
103 | | -4. **Restart VS Code** |
104 | | - - Close and reopen VS Code for the changes to take effect |
105 | | - |
106 | | -5. **Verify MCP Server** |
107 | | - - Open Command Palette (Ctrl+Shift+P) |
108 | | - - Run "MCP: List Servers" to verify your server is configured |
109 | | - - You should see "mssql" in the list of available servers |
110 | | - |
111 | | -### Option 2: Claude Desktop Setup |
112 | | - |
113 | | -1. **Open Claude Desktop Settings** |
114 | | - - Navigate to File → Settings → Developer → Edit Config |
115 | | - - Open the `claude_desktop_config` file |
116 | | - |
117 | | -2. **Add MCP Server Configuration** |
118 | | - Replace the content with the configuration below, updating the path and credentials: |
119 | | - |
120 | | - ```json |
121 | | - { |
122 | | - "mcpServers": { |
123 | | - "mssql": { |
124 | | - "command": "node", |
125 | | - "args": ["C:/path/to/your/Node/dist/index.js"], |
126 | | - "env": { |
127 | | - "SERVER_NAME": "your-server-name.database.windows.net", |
128 | | - "DATABASE_NAME": "your-database-name", |
129 | | - "READONLY": "false" |
130 | | - } |
131 | | - } |
132 | | - } |
133 | | - } |
134 | | - ``` |
135 | | - |
136 | | -3. **Restart Claude Desktop** |
137 | | - - Close and reopen Claude Desktop for the changes to take effect |
138 | | - |
139 | | -### Configuration Parameters |
140 | | - |
141 | | -- **SERVER_NAME**: Your MSSQL Database server name (e.g., `my-server.database.windows.net`) |
142 | | -- **DATABASE_NAME**: Your database name |
143 | | -- **READONLY**: Set to `"true"` to restrict to read-only operations, `"false"` for full access |
144 | | -- **Path**: Update the path in `args` to point to your actual project location |
145 | | - |
146 | | -## Sample Configurations |
147 | | - |
148 | | -You can find sample configuration files in the `src/samples/` folder: |
149 | | -- `claude_desktop_config.json` - For Claude Desktop |
150 | | -- `vscode_agent_config.json` - For VS Code Agent |
151 | | - |
152 | | -## Usage Examples |
153 | | - |
154 | | -Once configured, you can interact with your database using natural language: |
155 | | - |
156 | | -- "Show me all users from New York" |
157 | | -- "Create a new table called products with columns for id, name, and price" |
158 | | -- "Update all pending orders to completed status" |
159 | | -- "List all tables in the database" |
160 | | - |
161 | | -## Security Notes |
162 | | - |
163 | | -- The server requires a WHERE clause for read operations to prevent accidental full table scans |
164 | | -- Update operations require explicit WHERE clauses for security |
165 | | -- Set `READONLY: "true"` in production environments if you only need read access |
166 | | - |
167 | | -You should now have successfully configured the MCP server for MSSQL Database with your preferred AI assistant. This setup allows you to seamlessly interact with MSSQL Database through natural language queries! |
| 1 | +# MSSQL Database MCP Server |
| 2 | + |
| 3 | +<div align="center"> |
| 4 | + <img src="./src/img/logo.png" alt="MSSQL Database MCP server logo" width="400"/> |
| 5 | +</div> |
| 6 | + |
| 7 | +## What is this? 🤔 |
| 8 | + |
| 9 | +This is a server that lets your LLMs (like Claude) talk directly to your MSSQL Database data! Think of it as a friendly translator that sits between your AI assistant and your database, making sure they can chat securely and efficiently. |
| 10 | + |
| 11 | +### Quick Example |
| 12 | +```text |
| 13 | +You: "Show me all customers from New York" |
| 14 | +Claude: *queries your MSSQL Database database and gives you the answer in plain English* |
| 15 | +``` |
| 16 | + |
| 17 | +## How Does It Work? 🛠️ |
| 18 | + |
| 19 | +This server leverages the Model Context Protocol (MCP), a versatile framework that acts as a universal translator between AI models and databases. It supports multiple AI assistants including Claude Desktop and VS Code Agent. |
| 20 | + |
| 21 | +### What Can It Do? 📊 |
| 22 | + |
| 23 | +- Run MSSQL Database queries by just asking questions in plain English |
| 24 | +- Create, read, update, and delete data |
| 25 | +- Manage database schema (tables, indexes) |
| 26 | +- Secure connection handling |
| 27 | +- Real-time data interaction |
| 28 | + |
| 29 | +## Quick Start 🚀 |
| 30 | + |
| 31 | +### Prerequisites |
| 32 | +- Node.js 14 or higher |
| 33 | +- Claude Desktop or VS Code with Agent extension |
| 34 | + |
| 35 | +### Set up project |
| 36 | + |
| 37 | +1. **Install Dependencies** |
| 38 | + Run the following command in the root folder to install all necessary dependencies: |
| 39 | + ```bash |
| 40 | + npm install |
| 41 | + ``` |
| 42 | + |
| 43 | +2. **Build the Project** |
| 44 | + Compile the project by running: |
| 45 | + ```bash |
| 46 | + npm run build |
| 47 | + ``` |
| 48 | + |
| 49 | +## Configuration Setup |
| 50 | + |
| 51 | +### Option 1: VS Code Agent Setup |
| 52 | + |
| 53 | +1. **Install VS Code Agent Extension** |
| 54 | + - Open VS Code |
| 55 | + - Go to Extensions (Ctrl+Shift+X) |
| 56 | + - Search for "Agent" and install the official Agent extension |
| 57 | + |
| 58 | +2. **Create MCP Configuration File** |
| 59 | + - Create a `.vscode/mcp.json` file in your workspace |
| 60 | + - Add the following configuration: |
| 61 | + |
| 62 | + ```json |
| 63 | + { |
| 64 | + "servers": { |
| 65 | + "mssql-nodejs": { |
| 66 | + "type": "stdio", |
| 67 | + "command": "node", |
| 68 | + "args": ["q:\\Repos\\SQL-AI-samples\\MssqlMcp\\Node\\dist\\index.js"], |
| 69 | + "env": { |
| 70 | + "SERVER_NAME": "your-server-name.database.windows.net", |
| 71 | + "DATABASE_NAME": "your-database-name", |
| 72 | + "READONLY": "false" |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + ``` |
| 78 | + |
| 79 | +3. **Alternative: User Settings Configuration** |
| 80 | + - Open VS Code Settings (Ctrl+,) |
| 81 | + - Search for "mcp" |
| 82 | + - Click "Edit in settings.json" |
| 83 | + - Add the following configuration: |
| 84 | + |
| 85 | + ```json |
| 86 | + { |
| 87 | + "mcp": { |
| 88 | + "servers": { |
| 89 | + "mssql": { |
| 90 | + "command": "node", |
| 91 | + "args": ["C:/path/to/your/Node/dist/index.js"], |
| 92 | + "env": { |
| 93 | + "SERVER_NAME": "your-server-name.database.windows.net", |
| 94 | + "DATABASE_NAME": "your-database-name", |
| 95 | + "READONLY": "false" |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + ``` |
| 102 | + |
| 103 | +4. **Restart VS Code** |
| 104 | + - Close and reopen VS Code for the changes to take effect |
| 105 | + |
| 106 | +5. **Verify MCP Server** |
| 107 | + - Open Command Palette (Ctrl+Shift+P) |
| 108 | + - Run "MCP: List Servers" to verify your server is configured |
| 109 | + - You should see "mssql" in the list of available servers |
| 110 | + |
| 111 | +### Option 2: Claude Desktop Setup |
| 112 | + |
| 113 | +1. **Open Claude Desktop Settings** |
| 114 | + - Navigate to File → Settings → Developer → Edit Config |
| 115 | + - Open the `claude_desktop_config` file |
| 116 | + |
| 117 | +2. **Add MCP Server Configuration** |
| 118 | + Replace the content with the configuration below, updating the path and credentials: |
| 119 | + |
| 120 | + ```json |
| 121 | + { |
| 122 | + "mcpServers": { |
| 123 | + "mssql": { |
| 124 | + "command": "node", |
| 125 | + "args": ["C:/path/to/your/Node/dist/index.js"], |
| 126 | + "env": { |
| 127 | + "SERVER_NAME": "your-server-name.database.windows.net", |
| 128 | + "DATABASE_NAME": "your-database-name", |
| 129 | + "READONLY": "false" |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + ``` |
| 135 | + |
| 136 | +3. **Restart Claude Desktop** |
| 137 | + - Close and reopen Claude Desktop for the changes to take effect |
| 138 | + |
| 139 | +### Configuration Parameters |
| 140 | + |
| 141 | +- **SERVER_NAME**: Your MSSQL Database server name (e.g., `my-server.database.windows.net`) |
| 142 | +- **DATABASE_NAME**: Your database name |
| 143 | +- **READONLY**: Set to `"true"` to restrict to read-only operations, `"false"` for full access |
| 144 | +- **Path**: Update the path in `args` to point to your actual project location. |
| 145 | +- **CONNECTION_TIMEOUT**: (Optional) Connection timeout in seconds. Defaults to `30` if not set. |
| 146 | +- **TRUST_SERVER_CERTIFICATE**: (Optional) Set to `"true"` to trust self-signed server certificates (useful for development or when connecting to servers with self-signed certs). Defaults to `"false"`. |
| 147 | + |
| 148 | +## Sample Configurations |
| 149 | + |
| 150 | +You can find sample configuration files in the `src/samples/` folder: |
| 151 | +- `claude_desktop_config.json` - For Claude Desktop |
| 152 | +- `vscode_agent_config.json` - For VS Code Agent |
| 153 | + |
| 154 | +## Usage Examples |
| 155 | + |
| 156 | +Once configured, you can interact with your database using natural language: |
| 157 | + |
| 158 | +- "Show me all users from New York" |
| 159 | +- "Create a new table called products with columns for id, name, and price" |
| 160 | +- "Update all pending orders to completed status" |
| 161 | +- "List all tables in the database" |
| 162 | + |
| 163 | +## Security Notes |
| 164 | + |
| 165 | +- The server requires a WHERE clause for read operations to prevent accidental full table scans |
| 166 | +- Update operations require explicit WHERE clauses for security |
| 167 | +- Set `READONLY: "true"` in production environments if you only need read access |
| 168 | + |
| 169 | +You should now have successfully configured the MCP server for MSSQL Database with your preferred AI assistant. This setup allows you to seamlessly interact with MSSQL Database through natural language queries! |
0 commit comments