@eamonboyle/mssql-mcp 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,361 +1,329 @@
1
- # MSSQL MCP Server
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
- [![npm version](https://img.shields.io/npm/v/@eamonboyle/mssql-mcp.svg)](https://www.npmjs.com/package/@eamonboyle/mssql-mcp)
5
- [![Node.js 20+](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen)](https://nodejs.org/)
6
- [![X: @eamonyo](https://img.shields.io/badge/X-%40eamonyo-000000?style=flat-square&logo=x&logoColor=white)](https://x.com/eamonyo)
7
-
8
- [![Add to Cursor](https://img.shields.io/badge/Add_to-Cursor-000000?style=for-the-badge&logo=cursor&logoColor=white)](https://cursor.com/en/install-mcp?name=MSSQL&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBlYW1vbmJveWxlL21zc3FsLW1jcCJdLCJlbnYiOnsiU0VSVkVSX05BTUUiOiJsb2NhbGhvc3QiLCJEQVRBQkFTRV9OQU1FIjoiWW91ckRhdGFiYXNlIiwiREFUQUJBU0VTIjoiIiwiREJfVVNFUiI6IiIsIkRCX1BBU1NXT1JEIjoiIiwiUkVBRE9OTFkiOiJmYWxzZSIsIkNPTk5FQ1RJT05fVElNRU9VVCI6IjMwIiwiUVVFUllfVElNRU9VVF9NUyI6IjMwMDAwIiwiTUFYX1JPV1MiOiIxMDAwMCIsIlRSVVNUX1NFUlZFUl9DRVJUSUZJQ0FURSI6ImZhbHNlIiwiTUNQX1RSQU5TUE9SVCI6InN0ZGlvIiwiTUNQX0hUVFBfSE9TVCI6IjEyNy4wLjAuMSIsIk1DUF9IVFRQX1BPUlQiOiIzMzMzIiwiTUNQX0JBU0VfVVJMIjoiIiwiRU5BQkxFX0RETCI6ImZhbHNlIiwiTUFYX1dSSVRFX1JPV1MiOiIxMDAiLCJSRVFVSVJFX1dSSVRFX1BSRVZJRVciOiJ0cnVlIn19)
9
- [![Install in VS Code](https://img.shields.io/badge/Install_in-VS_Code-007ACC?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://intradeus.github.io/http-protocol-redirector?r=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522mssql%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522-y%2522%252C%2522%2540eamonboyle%252Fmssql-mcp%2522%255D%252C%2522env%2522%253A%257B%2522SERVER_NAME%2522%253A%2522localhost%2522%252C%2522DATABASE_NAME%2522%253A%2522YourDatabase%2522%252C%2522DATABASES%2522%253A%2522%2522%252C%2522DB_USER%2522%253A%2522%2522%252C%2522DB_PASSWORD%2522%253A%2522%2522%252C%2522READONLY%2522%253A%2522false%2522%252C%2522CONNECTION_TIMEOUT%2522%253A%252230%2522%252C%2522QUERY_TIMEOUT_MS%2522%253A%252230000%2522%252C%2522MAX_ROWS%2522%253A%252210000%2522%252C%2522TRUST_SERVER_CERTIFICATE%2522%253A%2522false%2522%252C%2522MCP_TRANSPORT%2522%253A%2522stdio%2522%252C%2522MCP_HTTP_HOST%2522%253A%2522127.0.0.1%2522%252C%2522MCP_HTTP_PORT%2522%253A%25223333%2522%252C%2522MCP_BASE_URL%2522%253A%2522%2522%252C%2522ENABLE_DDL%2522%253A%2522false%2522%252C%2522MAX_WRITE_ROWS%2522%253A%2522100%2522%252C%2522REQUIRE_WRITE_PREVIEW%2522%253A%2522true%2522%257D%257D)
10
-
11
- > ⚠️ **EXPERIMENTAL USE ONLY** — This MCP Server is provided for educational and experimental purposes. It is NOT intended for production use. Use appropriate security measures and test thoroughly before any deployment.
12
-
13
- ## What is this? 🤔
14
-
15
- An [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that lets AI assistants like Claude, Cursor, and other LLM-powered tools query and manage your Microsoft SQL Server database using natural language.
16
-
17
- ### Quick Example
18
-
19
- ```
20
- You: "Show me all customers from New York"
21
- AI: *queries your MSSQL database and returns the results in plain English*
22
- ```
23
-
24
- ## Features 📊
25
-
26
- - **Natural language to SQL** — Ask questions in plain English
27
- - **Row-level CRUD support** — Read, insert, update, and delete rows with dedicated tools
28
- - **Schema discovery** — Inspect tables, views, procedures, functions, and triggers; summarize counts with `summarize_schema`
29
- - **Dependency impact analysis** — `describe_dependencies` before drops or refactors
30
- - **Safer write workflows** — `preview_update` and `preview_delete` plus confirmation gating for destructive tools
31
- - **Rich text tool results** — Concise summaries with JSON inlined in the primary text block when helpful, plus resource links for large artifacts
32
- - **Query analysis** — Generate estimated execution plans with `explain_query`
33
- - **MCP resources and prompts** — Expose schema snapshots, query artifacts, and prompt templates to capable clients
34
- - **Remote transport support** — Run locally over `stdio` or remotely over Streamable HTTP
35
- - **Multi-database support** — Connect to multiple databases on the same server
36
- - **Read-only mode** — Restrict to inspection, search, read, and explain tools for safer environments
37
- - **Secure by default** — WHERE clauses required for updates/deletes; SQL injection safeguards for reads; DDL tools off unless `ENABLE_DDL=true`
38
-
39
- ## Supported AI Clients
40
-
41
- - [Claude Desktop](https://claude.ai/)
42
- - [Cursor](https://cursor.com/) (VS Code with AI)
43
- - [VS Code Agent](https://marketplace.visualstudio.com/items?itemName=Anthropic.anthropic-vscode) extension
44
- - Any MCP-compatible client
45
-
46
- ## Quick Start 🚀
47
-
48
- ### One-Click Install (Cursor / VS Code)
49
-
50
- Click **Add to Cursor** or **Install in VS Code** above to add the MCP server—no cloning required; it runs via `npx`.
51
-
52
- **Cursor** opens a dedicated install page that lists env vars you can edit before saving (similar to a short form). The **Add to Cursor** preset includes every variable from the table below (connection, timeouts, **`ENABLE_DDL`** defaulting to **`false`**, write caps, **`MCP_TRANSPORT`** / HTTP settings, **`MCP_BASE_URL`**, etc.); set **`ENABLE_DDL`** to **`true`** there if you want schema tools.
53
-
54
- **VS Code** only applies the JSON embedded in the `vscode:mcp/install` link: you get static placeholder values, not an interactive database wizard. To be prompted for host, database, and credentials when the server starts, add [`inputs`](https://code.visualstudio.com/docs/copilot/reference/mcp-configuration#_input-variables-for-sensitive-data) to `.vscode/mcp.json` as in the **Prompted inputs** example under **VS Code (`mcp.json`)** below.
55
-
56
- ### Prerequisites
57
-
58
- - **Node.js 20** or higher
59
- - SQL Server (local, Azure SQL, or remote)
60
- - An MCP-compatible AI client (Claude Desktop, Cursor, etc.)
61
-
62
- ### Installation
63
-
64
- **From npm** (recommended):
65
-
66
- ```bash
67
- npx -y @eamonboyle/mssql-mcp
68
- ```
69
-
70
- Or install globally: `npm install -g @eamonboyle/mssql-mcp`
71
-
72
- **From source** (for development):
73
-
74
- ```bash
75
- git clone https://github.com/eamonboyle/mssql-mcp.git
76
- cd mssql-mcp
77
- npm install
78
- npm run build
79
- ```
80
-
81
- To exercise MCP tools against a real database locally, start the seeded Docker SQL Server (`npm run db:up`). See [`docs/dev-database.md`](docs/dev-database.md).
82
-
83
- ## Configuration
84
-
85
- ### Environment Variables
86
-
87
- | Variable | Required | Description |
88
- | -------------------------- | -------- | ------------------------------------------------------------------------------------ |
89
- | `SERVER_NAME` | Yes | SQL Server host (e.g., `localhost`, `my-server.database.windows.net`) |
90
- | `DATABASE_NAME` | Yes\*\* | Default database name. Optional when `DATABASES` is set. |
91
- | `DB_USER` | Yes\* | SQL Server username (for SQL authentication) |
92
- | `DB_PASSWORD` | Yes\* | SQL Server password (for SQL authentication) |
93
- | `READONLY` | No | `"true"` for read-only mode, `"false"` for full access (default: `"false"`) |
94
- | `DATABASES` | No | Comma-separated allowlist for multi-database access (e.g., `ProdDB,StagingDB`) |
95
- | `CONNECTION_TIMEOUT` | No | Timeout in seconds (default: `30`) |
96
- | `QUERY_TIMEOUT_MS` | No | Query timeout in milliseconds (default: `30000`) |
97
- | `MAX_ROWS` | No | Maximum rows returned by read tools (default: `10000`) |
98
- | `TRUST_SERVER_CERTIFICATE` | No | `"true"` for self-signed certs (e.g., local dev) (default: `"false"`) |
99
- | `MCP_TRANSPORT` | No | `stdio` (default) or `http` |
100
- | `MCP_HTTP_HOST` | No | Bind host for Streamable HTTP mode (default: `127.0.0.1`) |
101
- | `MCP_HTTP_PORT` | No | Bind port for Streamable HTTP mode (default: `3333`) |
102
- | `MCP_BASE_URL` | No | Optional externally visible base URL for remote deployments |
103
- | `ENABLE_DDL` | No | `"true"` enables `create_table`, `create_index`, and `drop_table` (default: `false`) |
104
- | `MAX_WRITE_ROWS` | No | Maximum rows a single write tool may affect before it is blocked (default: `100`) |
105
- | `REQUIRE_WRITE_PREVIEW` | No | `"true"` (default): call `preview_update` / `preview_delete`, then pass the returned `previewToken` with `confirmed=true` on `update_data` / `delete_data`. Set `"false"` to skip the token (confirmation still applies). |
106
-
107
- \* Required for SQL authentication. For Windows/Integrated authentication, consult the [mssql](https://www.npmjs.com/package/mssql) package documentation.
108
-
109
- \*\* Required for single-database setups. When `DATABASES` is provided, `DATABASE_NAME` becomes optional and is used as the default database if set.
110
-
111
- ### Cursor (`mcp.json`)
112
-
113
- Use [global or project MCP config](https://cursor.com/docs/context/mcp): e.g. `~/.cursor/mcp.json` or `.cursor/mcp.json` in your repo.
114
-
115
- ```json
116
- {
117
- "mcpServers": {
118
- "mssql": {
119
- "command": "npx",
120
- "args": ["-y", "@eamonboyle/mssql-mcp"],
121
- "env": {
122
- "SERVER_NAME": "localhost",
123
- "DATABASE_NAME": "AppDB",
124
- "DATABASES": "AppDB,ReportingDB",
125
- "DB_USER": "your_username",
126
- "DB_PASSWORD": "your_password",
127
- "READONLY": "false"
128
- }
129
- }
130
- }
131
- }
132
- ```
133
-
134
- Restart Cursor after changes.
135
-
136
- ### Cursor HTTP MCP
137
-
138
- To expose the server remotely over Streamable HTTP:
139
-
140
- ```json
141
- {
142
- "mcpServers": {
143
- "mssql-http": {
144
- "url": "http://127.0.0.1:3333"
145
- }
146
- }
147
- }
148
- ```
149
-
150
- Run the server with:
151
-
152
- ```bash
153
- MCP_TRANSPORT=http MCP_HTTP_HOST=127.0.0.1 MCP_HTTP_PORT=3333 npx -y @eamonboyle/mssql-mcp
154
- ```
155
-
156
- ### VS Code (`mcp.json`)
157
-
158
- VS Code uses `.vscode/mcp.json` (or **MCP: Open User Configuration**) with a top-level [`servers`](https://code.visualstudio.com/docs/copilot/reference/mcp-configuration) object—**not** `mcpServers`.
159
-
160
- **Static env** (same idea as the one-click link; edit values in the file):
161
-
162
- ```json
163
- {
164
- "servers": {
165
- "mssql": {
166
- "type": "stdio",
167
- "command": "npx",
168
- "args": ["-y", "@eamonboyle/mssql-mcp"],
169
- "env": {
170
- "SERVER_NAME": "localhost",
171
- "DATABASE_NAME": "AppDB",
172
- "DATABASES": "AppDB,ReportingDB",
173
- "DB_USER": "your_username",
174
- "DB_PASSWORD": "your_password",
175
- "READONLY": "false",
176
- "CONNECTION_TIMEOUT": "30",
177
- "QUERY_TIMEOUT_MS": "30000",
178
- "MAX_ROWS": "10000",
179
- "TRUST_SERVER_CERTIFICATE": "false"
180
- }
181
- }
182
- }
183
- }
184
- ```
185
-
186
- **Prompted inputs** (closest to Cursor’s hosted form: VS Code asks on first start, then stores values). Use `${input:…}` in `env` and define matching entries under `inputs`:
187
-
188
- ```json
189
- {
190
- "inputs": [
191
- {
192
- "type": "promptString",
193
- "id": "mssql-server",
194
- "description": "SQL Server host (e.g. localhost or my-server.database.windows.net)"
195
- },
196
- {
197
- "type": "promptString",
198
- "id": "mssql-database",
199
- "description": "Default database name"
200
- },
201
- {
202
- "type": "promptString",
203
- "id": "mssql-databases",
204
- "description": "Optional: comma-separated DB allowlist (e.g. AppDB,ReportingDB). Leave empty for a single database."
205
- },
206
- {
207
- "type": "promptString",
208
- "id": "mssql-user",
209
- "description": "SQL Server login (SQL authentication)"
210
- },
211
- {
212
- "type": "promptString",
213
- "id": "mssql-password",
214
- "description": "SQL Server password",
215
- "password": true
216
- }
217
- ],
218
- "servers": {
219
- "mssql": {
220
- "type": "stdio",
221
- "command": "npx",
222
- "args": ["-y", "@eamonboyle/mssql-mcp"],
223
- "env": {
224
- "SERVER_NAME": "${input:mssql-server}",
225
- "DATABASE_NAME": "${input:mssql-database}",
226
- "DATABASES": "${input:mssql-databases}",
227
- "DB_USER": "${input:mssql-user}",
228
- "DB_PASSWORD": "${input:mssql-password}",
229
- "READONLY": "false",
230
- "CONNECTION_TIMEOUT": "30",
231
- "QUERY_TIMEOUT_MS": "30000",
232
- "MAX_ROWS": "10000",
233
- "TRUST_SERVER_CERTIFICATE": "false"
234
- }
235
- }
236
- }
237
- }
238
- ```
239
-
240
- ### Claude Desktop Setup
241
-
242
- 1. Open **File → Settings → Developer → Edit Config**
243
- 2. Add the MCP server configuration:
244
-
245
- ```json
246
- {
247
- "mcpServers": {
248
- "mssql": {
249
- "command": "npx",
250
- "args": ["-y", "@eamonboyle/mssql-mcp"],
251
- "env": {
252
- "SERVER_NAME": "localhost",
253
- "DATABASE_NAME": "AppDB",
254
- "DATABASES": "AppDB,ReportingDB",
255
- "DB_USER": "your_username",
256
- "DB_PASSWORD": "your_password",
257
- "READONLY": "false"
258
- }
259
- }
260
- }
261
- }
262
- ```
263
-
264
- 3. Restart Claude Desktop.
265
-
266
- ### Multi-Database Support
267
-
268
- To allow queries across multiple databases:
269
-
270
- ```json
271
- "env": {
272
- "SERVER_NAME": "your-server.database.windows.net",
273
- "DATABASE_NAME": "ProdDB",
274
- "DATABASES": "ProdDB,StagingDB,AnalyticsDB",
275
- "DB_USER": "your_username",
276
- "DB_PASSWORD": "your_password",
277
- "READONLY": "false"
278
- }
279
- ```
280
-
281
- `DATABASES` defines which databases the MCP can access. All tools accept an optional `databaseName` parameter. When omitted, the server uses `DATABASE_NAME` if it is included in `DATABASES`; otherwise it falls back to the first entry in `DATABASES`.
282
-
283
- ## Sample Configurations
284
-
285
- See `src/samples/` for example configs:
286
-
287
- - `claude_desktop_config.json` — Claude Desktop
288
- - `vscode_agent_config.json` — VS Code Agent
289
-
290
- ## Usage Examples
291
-
292
- Once configured, you can ask things like:
293
-
294
- - "Show me all users from New York"
295
- - "List the configured databases this MCP can access"
296
- - "Preview the rows that would be updated before changing status to archived"
297
- - "Explain this query and open the execution plan viewer"
298
- - "Show the foreign keys and relationships around dbo.Orders"
299
- - "Search the customers table for email addresses containing acme.com"
300
- - "Create a new table called products with columns for id, name, and price"
301
- - "Update all pending orders to completed status"
302
- - "Delete inactive sessions older than 30 days"
303
- - "List all tables in the database"
304
- - "Describe the schema of the customers table"
305
- - "List all views and procedures in the reporting database"
306
- - "Which tables are using the most storage?"
307
- - "Explain why this SELECT query is slow"
308
-
309
- ## Available Tools
310
-
311
- | Tool | Read-only | Description |
312
- | ------------------------ | --------- | --------------------------------------------------------------------------- |
313
- | `list_databases` | ✓ | List configured/allowed databases |
314
- | `list_table` | ✓ | List tables in a database |
315
- | `describe_table` | ✓ | Get table schema (optional `schemaName`) |
316
- | `list_objects` | ✓ | List tables, views, procedures, functions, and triggers |
317
- | `describe_object` | ✓ | Describe an object definition and metadata |
318
- | `summarize_schema` | ✓ | High-level object counts by type and per schema |
319
- | `list_largest_tables` | ✓ | Rank user tables by reserved and used storage, with row counts |
320
- | `list_foreign_keys` | ✓ | List foreign key relationships |
321
- | `describe_relationships` | ✓ | Foreign keys involving a specific table |
322
- | `describe_dependencies` | ✓ | Objects that depend on a given object |
323
- | `analyze_table` | ✓ | Row counts, storage, and indexes for a table |
324
- | `read_data` | ✓ | Execute validated SELECT queries |
325
- | `search_data` | ✓ | Search one or more columns with parameterized `LIKE` |
326
- | `explain_query` | ✓ | Get an estimated execution plan for a SELECT query |
327
- | `preview_update` | ✓ | Preview rows that would be updated; returns `previewToken` when required |
328
- | `preview_delete` | ✓ | Preview rows that would be deleted; returns `previewToken` when required |
329
- | `insert_data` | | Insert rows (optional `schemaName`) |
330
- | `update_data` | | Update rows (requires filters; optional `schemaName`) |
331
- | `delete_data` | | Delete rows (requires filters; optional `schemaName`) |
332
- | `create_table` | | Create tables (requires `ENABLE_DDL=true`) |
333
- | `create_index` | | Create indexes (requires `ENABLE_DDL=true`) |
334
- | `drop_table` | | Drop tables (requires `ENABLE_DDL=true`; optional `schemaName`) |
335
-
336
- ## Resources And Prompts
337
-
338
- Clients that support MCP resources and prompts can use additional discovery surfaces:
339
-
340
- - **Resources** — Server config, prompt catalog, per-database table lists, per-database object lists, and dynamic table/object resources
341
- - **Prompts** — `explore_schema`, `draft_safe_select`, and `review_write_operation`
342
-
343
- ## Changelog
344
-
345
- Release notes: [CHANGELOG.md](https://github.com/eamonboyle/mssql-mcp/blob/main/CHANGELOG.md).
346
-
347
- ## Security Notes
348
-
349
- - **Credentials** — Never commit `DB_USER`/`DB_PASSWORD` or config files with secrets. Use environment variables or a secrets manager.
350
- - **Read-only mode** — Set `READONLY: "true"` when you only need queries.
351
- - **WHERE clauses** — Update and delete operations require explicit WHERE clauses to reduce accidental full-table changes.
352
- - **SQL injection** — The server validates and restricts dangerous SQL patterns.
353
- - **DDL tools** — Disabled by default (`ENABLE_DDL` unset or `false`). Set `ENABLE_DDL=true` only if the assistant should create/drop tables or indexes.
354
-
355
- ## Contributing
356
-
357
- Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. By participating, you agree to uphold our [Code of Conduct](CODE_OF_CONDUCT.md).
358
-
359
- ## License
360
-
361
- MIT License — see [LICENSE](LICENSE) for details.
1
+ # MSSQL MCP Server
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm version](https://img.shields.io/npm/v/@eamonboyle/mssql-mcp.svg)](https://www.npmjs.com/package/@eamonboyle/mssql-mcp)
5
+ [![Node.js 20+](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen)](https://nodejs.org/)
6
+ [![X: @eamonyo](https://img.shields.io/badge/X-%40eamonyo-000000?style=flat-square&logo=x&logoColor=white)](https://x.com/eamonyo)
7
+
8
+ [![Add to Cursor](https://img.shields.io/badge/Add_to-Cursor-000000?style=for-the-badge&logo=cursor&logoColor=white)](https://cursor.com/en/install-mcp?name=mssql-local&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBlYW1vbmJveWxlL21zc3FsLW1jcCJdLCJlbnYiOnsiU0VSVkVSX05BTUUiOiJsb2NhbGhvc3QiLCJEQVRBQkFTRV9OQU1FIjoiQXBwREIiLCJEQVRBQkFTRVMiOiJBcHBEQixSZXBvcnRpbmdEQiIsIkRCX1VTRVIiOiJ5b3VyX3VzZXJuYW1lIiwiREJfUEFTU1dPUkQiOiJ5b3VyX3Bhc3N3b3JkIiwiVFJVU1RfU0VSVkVSX0NFUlRJRklDQVRFIjoidHJ1ZSIsIlJFQURPTkxZIjoiZmFsc2UiLCJFTkFCTEVfRERMIjoiZmFsc2UifX0=)
9
+ [![Install in VS Code](https://img.shields.io/badge/Install_in-VS_Code-007ACC?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://intradeus.github.io/http-protocol-redirector?r=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522mssql-local%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522-y%2522%252C%2522%2540eamonboyle%252Fmssql-mcp%2522%255D%252C%2522env%2522%253A%257B%2522SERVER_NAME%2522%253A%2522localhost%2522%252C%2522DATABASE_NAME%2522%253A%2522AppDB%2522%252C%2522DATABASES%2522%253A%2522AppDB%252CReportingDB%2522%252C%2522DB_USER%2522%253A%2522your_username%2522%252C%2522DB_PASSWORD%2522%253A%2522your_password%2522%252C%2522TRUST_SERVER_CERTIFICATE%2522%253A%2522true%2522%252C%2522READONLY%2522%253A%2522false%2522%252C%2522ENABLE_DDL%2522%253A%2522false%2522%257D%257D)
10
+
11
+ > Experimental use only. This server is intended for education and evaluation, not production. Use a dedicated least-privilege SQL login and test all operations.
12
+
13
+ ## Overview
14
+
15
+ `@eamonboyle/mssql-mcp` exposes Microsoft SQL Server tools, resources, and prompts through the [Model Context Protocol](https://modelcontextprotocol.io/). The MCP client and its language model interpret natural-language requests and choose tools. This package validates requests, executes SQL Server operations, and returns structured results.
16
+
17
+ Key capabilities:
18
+
19
+ - Schema, object, relationship, dependency, and storage discovery
20
+ - Validated reads, parameterized searches, and estimated execution plans
21
+ - Insert, update, and delete tools with confirmation and row limits
22
+ - Preview tokens for update and delete operations
23
+ - DDL tools with an explicit configuration gate
24
+ - Multiple allowed databases on one SQL Server
25
+ - Local stdio and stateless Streamable HTTP transports
26
+
27
+ Supported clients include Cursor, VS Code, Claude Desktop, and other MCP-compatible hosts.
28
+
29
+ ## Quick start
30
+
31
+ ### Prerequisites
32
+
33
+ - Node.js 20 or newer
34
+ - Microsoft SQL Server
35
+ - An MCP-compatible client
36
+
37
+ The recommended installation runs the published package directly:
38
+
39
+ ```bash
40
+ npx -y @eamonboyle/mssql-mcp
41
+ ```
42
+
43
+ A global installation also exposes the `mssql-mcp` command:
44
+
45
+ ```bash
46
+ npm install -g @eamonboyle/mssql-mcp
47
+ mssql-mcp
48
+ ```
49
+
50
+ The one-click links use the minimal configuration shown below. Replace the sample connection values before use.
51
+
52
+ The badge payloads are generated from `src/samples/claude_desktop_config.json`. After changing the sample, run `npm run docs:update-install-links`; use `npm run docs:check-install-links` to verify they are current.
53
+
54
+ ## Minimal MCP configuration
55
+
56
+ The standard presets show connection placeholders and keep DDL disabled:
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "mssql-local": {
62
+ "command": "npx",
63
+ "args": ["-y", "@eamonboyle/mssql-mcp"],
64
+ "env": {
65
+ "SERVER_NAME": "localhost",
66
+ "DATABASE_NAME": "AppDB",
67
+ "DATABASES": "AppDB,ReportingDB",
68
+ "DB_USER": "your_username",
69
+ "DB_PASSWORD": "your_password",
70
+ "TRUST_SERVER_CERTIFICATE": "true",
71
+ "READONLY": "false",
72
+ "ENABLE_DDL": "false"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ Cursor uses `mcpServers` in `~/.cursor/mcp.json` or `.cursor/mcp.json`. Claude Desktop uses the same shape in its configuration file.
80
+
81
+ Set `ENABLE_DDL=true` only when the assistant specifically needs to create or remove schema objects.
82
+
83
+ VS Code uses `.vscode/mcp.json` or its user MCP configuration with a top-level `servers` object:
84
+
85
+ ```json
86
+ {
87
+ "servers": {
88
+ "mssql-local": {
89
+ "type": "stdio",
90
+ "command": "npx",
91
+ "args": ["-y", "@eamonboyle/mssql-mcp"],
92
+ "env": {
93
+ "SERVER_NAME": "localhost",
94
+ "DATABASE_NAME": "AppDB",
95
+ "DATABASES": "AppDB,ReportingDB",
96
+ "DB_USER": "your_username",
97
+ "DB_PASSWORD": "your_password",
98
+ "TRUST_SERVER_CERTIFICATE": "true",
99
+ "READONLY": "false",
100
+ "ENABLE_DDL": "false"
101
+ }
102
+ }
103
+ }
104
+ }
105
+ ```
106
+
107
+ See [`src/samples/`](src/samples/) for copyable Claude Desktop and VS Code files. Do not commit configuration files containing real credentials.
108
+
109
+ ## Required configuration
110
+
111
+ The server validates these variables before starting. Missing or blank values produce an actionable startup error.
112
+
113
+ | Variable | Accepted format | Purpose |
114
+ | -------------------------- | ---------------------- | --------------------------------------------------------------------- |
115
+ | `DB_USER` | Nonblank string | SQL authentication username |
116
+ | `DB_PASSWORD` | Nonblank string | SQL authentication password |
117
+
118
+ At least one database variable is required: set `DATABASE_NAME`, `DATABASES`, or both. With only `DATABASE_NAME`, that database is both the default and the allowlist. With only `DATABASES`, the first entry is the default. When both are set, `DATABASE_NAME` is used if it appears in `DATABASES`; otherwise the first allowed database is the runtime default.
119
+
120
+ ### Hostname and port
121
+
122
+ > Do not include the port in `SERVER_NAME`. Values such as `localhost,1434` are not supported by the Node.js `mssql` driver configuration used by this package. Set `SERVER_NAME` to the hostname and use `SERVER_PORT` separately.
123
+
124
+ ```json
125
+ {
126
+ "SERVER_NAME": "localhost",
127
+ "SERVER_PORT": "1434"
128
+ }
129
+ ```
130
+
131
+ For a Docker port mapping such as:
132
+
133
+ ```yaml
134
+ ports:
135
+ - "1434:1433"
136
+ ```
137
+
138
+ use the published host port:
139
+
140
+ ```text
141
+ SERVER_NAME=localhost
142
+ SERVER_PORT=1434
143
+ ```
144
+
145
+ The container still listens on `1433`, but the MCP process connects through host port `1434`.
146
+
147
+ ## Advanced configuration
148
+
149
+ Optional variables do not need empty placeholders. In-code defaults apply when they are absent.
150
+
151
+ | Variable | Accepted format | Default | Purpose |
152
+ | ----------------------- | ----------------------------- | --------------------- | -------------------------------------------------------------- |
153
+ | `SERVER_NAME` | Hostname | `localhost` | SQL Server hostname only |
154
+ | `SERVER_PORT` | Integer from `1` to `65535` | Driver default `1433` | SQL Server TCP port; omitted from the driver config when unset |
155
+ | `ENCRYPT` | `"true"` or `"false"` | `"false"` | Enable TLS encryption in the `mssql` driver |
156
+ | `TRUST_SERVER_CERTIFICATE` | `"true"` or `"false"` | `"true"` | Trust the SQL Server certificate without validating its chain |
157
+ | `READONLY` | `"true"` or `"false"` | `"false"` | Remove write and DDL tools when enabled |
158
+ | `ENABLE_DDL` | `"true"` or `"false"` | `"false"` | Allow registered DDL tools to execute |
159
+ | `CONNECTION_TIMEOUT` | Positive integer seconds | `30` | SQL Server connection timeout |
160
+ | `QUERY_TIMEOUT_MS` | Positive integer milliseconds | `30000` | SQL request timeout |
161
+ | `MAX_ROWS` | Positive integer | `10000` | Maximum rows returned by read tools |
162
+ | `MAX_WRITE_ROWS` | Positive integer | `100` | Maximum rows one write operation may affect |
163
+ | `REQUIRE_WRITE_PREVIEW` | `"true"` or `"false"` | `"true"` | Require a matching preview token for updates and deletes |
164
+ | `MCP_TRANSPORT` | `stdio` or `http` | `stdio` | MCP transport mode |
165
+ | `MCP_HTTP_HOST` | Host or IP string | `127.0.0.1` | Bind address for HTTP mode |
166
+ | `MCP_HTTP_PORT` | Integer from `1` to `65535` | `3333` | Bind port for HTTP mode |
167
+ | `MCP_BASE_URL` | Absolute HTTP or HTTPS URL | Unset | Public HTTP base advertised by the server; `/mcp` is appended |
168
+
169
+ Blank optional values use their documented defaults. Explicit nonblank invalid integers, booleans, ports, URLs, or transport names fail validation rather than falling back silently.
170
+
171
+ `ENCRYPT=false` preserves the existing unencrypted connection behavior. Set `ENCRYPT=true` for TLS. With encryption enabled, keep `TRUST_SERVER_CERTIFICATE=false` for certificates that chain to a trusted authority. Use `TRUST_SERVER_CERTIFICATE=true` only when explicitly accepting a self-signed or otherwise untrusted certificate, such as local development.
172
+
173
+ ## Multi-database behavior
174
+
175
+ `DATABASES` is an allowlist. Every tool accepts an optional `databaseName`. When a tool omits it, the server uses `DATABASE_NAME` if that name is allowed, otherwise it uses the first entry in `DATABASES`. A requested database outside the allowlist is rejected.
176
+
177
+ ## Safe writes and DDL
178
+
179
+ `READONLY=true` removes insert, update, delete, and DDL tools. Read-only preview tools remain available because they do not modify data.
180
+
181
+ When writes are enabled:
182
+
183
+ 1. `insert_data`, `update_data`, `delete_data`, and DDL tools require `confirmed: true` unless the client completes MCP elicitation.
184
+ 2. `update_data` and `delete_data` require nonempty structured `filters`, not raw SQL WHERE text.
185
+ 3. With the default `REQUIRE_WRITE_PREVIEW=true`, call `preview_update` or `preview_delete` first and pass its `previewToken` to the matching write.
186
+ 4. Preview tokens expire after 10 minutes, are single-use, and are bound to the same tool, table, filters, and update payload.
187
+ 5. `MAX_WRITE_ROWS` rejects oversized operations, and update/delete execution applies a row cap.
188
+
189
+ Supported filter operators are `=`, `!=`, `>`, `>=`, `<`, `<=`, `LIKE`, `IN`, `IS NULL`, and `IS NOT NULL`.
190
+
191
+ DDL tools are registered when `READONLY=false`, but calls fail with `DDL_DISABLED` unless `ENABLE_DDL=true`.
192
+
193
+ For `insert_data`, pass the table in `tableName` and the schema separately in `schemaName`. Do not use a dotted `schema.table` value for `tableName`.
194
+
195
+ ## Streamable HTTP
196
+
197
+ The default transport is stdio. To run the stateless HTTP transport from a directory containing a configured `.env`:
198
+
199
+ ```bash
200
+ MCP_TRANSPORT=http npx -y @eamonboyle/mssql-mcp
201
+ ```
202
+
203
+ The default endpoint is:
204
+
205
+ ```text
206
+ http://127.0.0.1:3333/mcp
207
+ ```
208
+
209
+ An HTTP client must accept `application/json, text/event-stream`. Each HTTP request creates a fresh MCP server instance. Preview tokens use a process-wide store so they remain valid across requests to the same process.
210
+
211
+ For a reverse proxy or externally published path, set `MCP_BASE_URL` to the public base without the final `/mcp` segment:
212
+
213
+ ```text
214
+ MCP_BASE_URL=https://example.com/services/mssql
215
+ ```
216
+
217
+ The server continues binding to `MCP_HTTP_HOST:MCP_HTTP_PORT`, logs `https://example.com/services/mssql/mcp` as its public endpoint, and exposes that URL through `mssql://config/server`. `MCP_E2E_BASE_URL` is a separate test-harness variable used only by `scripts/e2e-mcp-tools.mjs`.
218
+
219
+ Cursor HTTP configuration:
220
+
221
+ ```json
222
+ {
223
+ "mcpServers": {
224
+ "mssql-http": {
225
+ "url": "http://127.0.0.1:3333/mcp"
226
+ }
227
+ }
228
+ }
229
+ ```
230
+
231
+ ## Tools
232
+
233
+ | Tool | Mode | Purpose |
234
+ | ------------------------ | ----- | ---------------------------------------------------------------- |
235
+ | `list_databases` | Read | List configured databases |
236
+ | `list_table` | Read | List tables, optionally filtered by schema names in `parameters` |
237
+ | `describe_table` | Read | Describe a table schema |
238
+ | `list_objects` | Read | List tables, views, procedures, functions, and triggers |
239
+ | `describe_object` | Read | Return object metadata and definitions |
240
+ | `summarize_schema` | Read | Summarize object counts by type and schema |
241
+ | `list_largest_tables` | Read | Rank tables by storage and row count |
242
+ | `list_foreign_keys` | Read | List foreign keys |
243
+ | `describe_relationships` | Read | Describe foreign keys involving one table |
244
+ | `describe_dependencies` | Read | List objects that depend on an object |
245
+ | `analyze_table` | Read | Return row counts, storage, and index details |
246
+ | `read_data` | Read | Execute a validated SELECT query |
247
+ | `search_data` | Read | Search columns with parameterized LIKE predicates |
248
+ | `explain_query` | Read | Generate an estimated SELECT execution plan |
249
+ | `preview_update` | Read | Preview an update and issue a token when required |
250
+ | `preview_delete` | Read | Preview a delete and issue a token when required |
251
+ | `insert_data` | Write | Insert rows |
252
+ | `update_data` | Write | Update rows selected by structured filters |
253
+ | `delete_data` | Write | Delete rows selected by structured filters |
254
+ | `create_table` | DDL | Create a table |
255
+ | `create_index` | DDL | Create an index |
256
+ | `drop_table` | DDL | Drop a table |
257
+
258
+ ## Resources and prompts
259
+
260
+ Clients with MCP resource support can discover:
261
+
262
+ - `mssql://config/server`
263
+ - `mssql://config/prompts`
264
+ - `mssql://database/{databaseName}/tables`
265
+ - `mssql://database/{databaseName}/objects`
266
+ - `mssql://database/{databaseName}/schema-summary`
267
+ - `mssql://database/{databaseName}/foreign-keys`
268
+ - `mssql://table/{databaseName}/{schemaName}/{tableName}`
269
+ - `mssql://object/{databaseName}/{schemaName}/{objectName}`
270
+ - `mssql://database/{databaseName}/object/{schemaName}/{objectName}/dependencies`
271
+ - `mssql://query-plan/{planId}`
272
+ - `mssql://query-result/{resultId}`
273
+
274
+ Table and object listings are cached for 30 seconds. Query plan and large query result resources are temporary process-local artifacts.
275
+
276
+ Available prompts:
277
+
278
+ - `explore_schema`
279
+ - `draft_safe_select`
280
+ - `review_write_operation`
281
+
282
+ ## Development
283
+
284
+ For local source development only:
285
+
286
+ ```bash
287
+ git clone https://github.com/eamonboyle/mssql-mcp.git
288
+ cd mssql-mcp
289
+ npm install
290
+ npm run build
291
+ node /path/to/mssql-mcp/dist/index.js
292
+ ```
293
+
294
+ The repository includes a seeded SQL Server 2022 Docker environment:
295
+
296
+ ```bash
297
+ cp .env.example .env
298
+ npm run db:up
299
+ npm run test:e2e
300
+ ```
301
+
302
+ See [`docs/dev-database.md`](docs/dev-database.md) for database and E2E details and [`CONTRIBUTING.md`](CONTRIBUTING.md) for build, lint, and test commands.
303
+
304
+ ## Troubleshooting
305
+
306
+ - `SERVER_PORT must be a valid TCP port`: use a whole number from `1` to `65535`.
307
+ - `getaddrinfo ENOTFOUND localhost,1434`: move `1434` from `SERVER_NAME` to `SERVER_PORT`.
308
+ - `DDL_DISABLED`: set `ENABLE_DDL` to `"true"` only when DDL access is intended.
309
+ - `PREVIEW_TOKEN_INVALID`: create a new matching preview and use its token once within 10 minutes.
310
+ - stdio JSON parse errors: ensure scripts and dependencies write logs to stderr, not stdout.
311
+ - database rejected: add it to `DATABASES` and use the exact allowed name in `databaseName`.
312
+
313
+ ## Security
314
+
315
+ - Use a dedicated SQL login with the minimum permissions required.
316
+ - Set `READONLY=true` whenever writes are unnecessary.
317
+ - Keep `ENABLE_DDL=false` unless schema changes are explicitly needed.
318
+ - Keep credentials out of source control and use your client's secret-input support or a secrets manager.
319
+ - Bind HTTP mode to a trusted interface and add network authentication or isolation outside this package.
320
+ - Set `ENCRYPT=true` for TLS deployments and keep `TRUST_SERVER_CERTIFICATE=false` when the server certificate is publicly or privately trusted.
321
+ - Report vulnerabilities through the [security policy](.github/SECURITY.md).
322
+
323
+ ## Project links
324
+
325
+ - [Changelog](CHANGELOG.md)
326
+ - [Contributing](CONTRIBUTING.md)
327
+ - [Code of Conduct](CODE_OF_CONDUCT.md)
328
+ - [Security Policy](.github/SECURITY.md)
329
+ - [License](LICENSE)