sql-mcp-server 0.1.0__tar.gz

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.
@@ -0,0 +1,215 @@
1
+ #local files
2
+ .venv
3
+ .env
4
+ test.sql
5
+ package-lock.json
6
+ node_modules/
7
+ main.py
8
+ code_explanation.md.resolved
9
+ # Byte-compiled / optimized / DLL files
10
+ __pycache__/
11
+ *.py[codz]
12
+ *$py.class
13
+
14
+ # C extensions
15
+ *.so
16
+
17
+ # Distribution / packaging
18
+ .Python
19
+ build/
20
+ develop-eggs/
21
+ dist/
22
+ downloads/
23
+ eggs/
24
+ .eggs/
25
+ lib/
26
+ lib64/
27
+ parts/
28
+ sdist/
29
+ var/
30
+ wheels/
31
+ share/python-wheels/
32
+ *.egg-info/
33
+ .installed.cfg
34
+ *.egg
35
+ MANIFEST
36
+
37
+ # PyInstaller
38
+ # Usually these files are written by a python script from a template
39
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
40
+ *.manifest
41
+ *.spec
42
+
43
+ # Installer logs
44
+ pip-log.txt
45
+ pip-delete-this-directory.txt
46
+
47
+ # Unit test / coverage reports
48
+ htmlcov/
49
+ .tox/
50
+ .nox/
51
+ .coverage
52
+ .coverage.*
53
+ .cache
54
+ nosetests.xml
55
+ coverage.xml
56
+ *.cover
57
+ *.py.cover
58
+ .hypothesis/
59
+ .pytest_cache/
60
+ cover/
61
+
62
+ # Translations
63
+ *.mo
64
+ *.pot
65
+
66
+ # Django stuff:
67
+ *.log
68
+ local_settings.py
69
+ db.sqlite3
70
+ db.sqlite3-journal
71
+
72
+ # Flask stuff:
73
+ instance/
74
+ .webassets-cache
75
+
76
+ # Scrapy stuff:
77
+ .scrapy
78
+
79
+ # Sphinx documentation
80
+ docs/_build/
81
+
82
+ # PyBuilder
83
+ .pybuilder/
84
+ target/
85
+
86
+ # Jupyter Notebook
87
+ .ipynb_checkpoints
88
+
89
+ # IPython
90
+ profile_default/
91
+ ipython_config.py
92
+
93
+ # pyenv
94
+ # For a library or package, you might want to ignore these files since the code is
95
+ # intended to run in multiple environments; otherwise, check them in:
96
+ # .python-version
97
+
98
+ # pipenv
99
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
100
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
101
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
102
+ # install all needed dependencies.
103
+ #Pipfile.lock
104
+
105
+ # UV
106
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
107
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
108
+ # commonly ignored for libraries.
109
+ #uv.lock
110
+
111
+ # poetry
112
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
113
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
114
+ # commonly ignored for libraries.
115
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
116
+ #poetry.lock
117
+ #poetry.toml
118
+
119
+ # pdm
120
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
121
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
122
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
123
+ #pdm.lock
124
+ #pdm.toml
125
+ .pdm-python
126
+ .pdm-build/
127
+
128
+ # pixi
129
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
130
+ #pixi.lock
131
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
132
+ # in the .venv directory. It is recommended not to include this directory in version control.
133
+ .pixi
134
+
135
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
136
+ __pypackages__/
137
+
138
+ # Celery stuff
139
+ celerybeat-schedule
140
+ celerybeat.pid
141
+
142
+ # SageMath parsed files
143
+ *.sage.py
144
+
145
+ # Environments
146
+ .env
147
+ .envrc
148
+ .venv
149
+ env/
150
+ venv/
151
+ ENV/
152
+ env.bak/
153
+ venv.bak/
154
+
155
+ # Spyder project settings
156
+ .spyderproject
157
+ .spyproject
158
+
159
+ # Rope project settings
160
+ .ropeproject
161
+
162
+ # mkdocs documentation
163
+ /site
164
+
165
+ # mypy
166
+ .mypy_cache/
167
+ .dmypy.json
168
+ dmypy.json
169
+
170
+ # Pyre type checker
171
+ .pyre/
172
+
173
+ # pytype static type analyzer
174
+ .pytype/
175
+
176
+ # Cython debug symbols
177
+ cython_debug/
178
+
179
+ # PyCharm
180
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
181
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
182
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
183
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
184
+ #.idea/
185
+
186
+ # Abstra
187
+ # Abstra is an AI-powered process automation framework.
188
+ # Ignore directories containing user credentials, local state, and settings.
189
+ # Learn more at https://abstra.io/docs
190
+ .abstra/
191
+
192
+ # Visual Studio Code
193
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
194
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
195
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
196
+ # you could uncomment the following to ignore the entire vscode folder
197
+ # .vscode/
198
+
199
+ # Ruff stuff:
200
+ .ruff_cache/
201
+
202
+ # PyPI configuration file
203
+ .pypirc
204
+
205
+ # Cursor
206
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
207
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
208
+ # refer to https://docs.cursor.com/context/ignore-files
209
+ .cursorignore
210
+ .cursorindexingignore
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Snehangshu Bhuin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: sql-mcp-server
3
+ Version: 0.1.0
4
+ Summary: MCP server that connects Claude to a Microsoft SQL Server database
5
+ Author: Snehangshu
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Keywords: ai,claude,database,mcp,sql-server
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Database
15
+ Requires-Python: >=3.12
16
+ Requires-Dist: mcp[cli]>=1.26.0
17
+ Requires-Dist: pyodbc>=5.3.0
18
+ Requires-Dist: python-dotenv>=1.2.2
19
+ Description-Content-Type: text/markdown
20
+
21
+ # SQL Assistant MCP Server
22
+
23
+ An MCP server that connects Claude to a Microsoft SQL Server database over stdio. Ask Claude to query your database, check table structures, or see how a query runs — without leaving the chat window.
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install sql-mcp-server
31
+ ```
32
+
33
+ You also need the **ODBC Driver for SQL Server** installed:
34
+ https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server
35
+
36
+ ---
37
+
38
+ ## Tools
39
+
40
+ **list_tables** — Lists every user-created table in the database, grouped by schema.
41
+
42
+ **describe_table** — Shows columns, data types, nullability, and defaults for a table.
43
+
44
+ **run_query** — Runs a SELECT query and returns results. Write operations (INSERT, UPDATE, DELETE, DROP, etc.) are blocked.
45
+
46
+ **explain_query** — Returns SQL Server's estimated execution plan via `SET SHOWPLAN_TEXT`. Useful before running a slow or unfamiliar query.
47
+
48
+ **get_table_sample** — Returns the first N rows (up to 20) from a table. Default is 5 — pass `rows=10` for more.
49
+
50
+ ---
51
+
52
+ ## Project structure
53
+ ```
54
+ sql-mcp-server/
55
+ ├── server.py # MCP server and tool definitions
56
+ ├── db.py # SQL Server connection helper (loads .env)
57
+ ├── pyproject.toml # Project metadata and dependencies
58
+ ├── uv.lock # Locked dependency versions (uv)
59
+ ├── .env # Connection config (not committed)
60
+ └── README.md
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Setup
66
+
67
+ ### 1. Configure the database connection
68
+
69
+ Create a `.env` file in the project root:
70
+
71
+ **Windows Authentication (Trusted Connection):**
72
+ ```env
73
+ DB_DRIVER=ODBC Driver 17 for SQL Server
74
+ DB_SERVER=YOUR_SERVER_NAME\\SQLEXPRESS
75
+ DB_NAME=your_database_name
76
+ ```
77
+
78
+ **SQL Server Authentication (username + password):**
79
+ ```env
80
+ DB_DRIVER=ODBC Driver 17 for SQL Server
81
+ DB_SERVER=YOUR_SERVER_NAME\\SQLEXPRESS
82
+ DB_NAME=your_database_name
83
+ DB_USER=your_username
84
+ DB_PASSWORD=your_password
85
+ ```
86
+
87
+ If you're using the Claude Desktop config below, put your credentials in the `env` block — no `.env` file needed.
88
+
89
+ ---
90
+
91
+ ### 2. Register with Claude Desktop
92
+
93
+ Add this to `claude_desktop_config.json`:
94
+
95
+ **Windows Authentication:**
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "sql-assistant": {
100
+ "command": "uv",
101
+ "args": [
102
+ "--directory",
103
+ "C:/path/to/sql-mcp-server",
104
+ "run",
105
+ "server.py"
106
+ ],
107
+ "env": {
108
+ "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
109
+ "DB_NAME": "your_database_name",
110
+ "DB_DRIVER": "ODBC Driver 17 for SQL Server"
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ **SQL Server Authentication:**
118
+ ```json
119
+ {
120
+ "mcpServers": {
121
+ "sql-assistant": {
122
+ "command": "uv",
123
+ "args": [
124
+ "--directory",
125
+ "C:/path/to/sql-mcp-server",
126
+ "run",
127
+ "server.py"
128
+ ],
129
+ "env": {
130
+ "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
131
+ "DB_NAME": "your_database_name",
132
+ "DB_DRIVER": "ODBC Driver 17 for SQL Server",
133
+ "DB_USER": "your_username",
134
+ "DB_PASSWORD": "your_password"
135
+ }
136
+ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ Replace the placeholder values with your actual details. Restart Claude Desktop after saving.
142
+
143
+ ---
144
+
145
+ ## Usage
146
+
147
+ With the server running, try asking Claude:
148
+
149
+ - "What tables are in the database?"
150
+ - "Describe the Orders table."
151
+ - "Show me 10 rows from Customers."
152
+ - "Run: SELECT TOP 5 * FROM Sales.Orders WHERE Status = 'Pending'"
153
+ - "Explain this query: SELECT * FROM Products WHERE Price > 100"
154
+
155
+ ---
156
+
157
+ ## Safety
158
+
159
+ Only SELECT queries run. These keywords are blocked before they reach the database:
160
+
161
+ `INSERT` `UPDATE` `DELETE` `DROP` `TRUNCATE` `ALTER` `CREATE` `EXEC`
162
+
163
+ Table and schema names are validated against injection patterns. Results cap at 200 rows.
164
+
165
+ > ⚠️ **Don't commit your `.env` file** — it contains your connection credentials.
166
+
167
+ ---
168
+
169
+ ## Requirements
170
+
171
+ - Python 3.12+
172
+ - SQL Server with ODBC Driver 17 or 18
173
+ - Claude Desktop with MCP support
174
+
175
+ ---
176
+
177
+ ## License
178
+
179
+ MIT
@@ -0,0 +1,159 @@
1
+ # SQL Assistant MCP Server
2
+
3
+ An MCP server that connects Claude to a Microsoft SQL Server database over stdio. Ask Claude to query your database, check table structures, or see how a query runs — without leaving the chat window.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install sql-mcp-server
11
+ ```
12
+
13
+ You also need the **ODBC Driver for SQL Server** installed:
14
+ https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server
15
+
16
+ ---
17
+
18
+ ## Tools
19
+
20
+ **list_tables** — Lists every user-created table in the database, grouped by schema.
21
+
22
+ **describe_table** — Shows columns, data types, nullability, and defaults for a table.
23
+
24
+ **run_query** — Runs a SELECT query and returns results. Write operations (INSERT, UPDATE, DELETE, DROP, etc.) are blocked.
25
+
26
+ **explain_query** — Returns SQL Server's estimated execution plan via `SET SHOWPLAN_TEXT`. Useful before running a slow or unfamiliar query.
27
+
28
+ **get_table_sample** — Returns the first N rows (up to 20) from a table. Default is 5 — pass `rows=10` for more.
29
+
30
+ ---
31
+
32
+ ## Project structure
33
+ ```
34
+ sql-mcp-server/
35
+ ├── server.py # MCP server and tool definitions
36
+ ├── db.py # SQL Server connection helper (loads .env)
37
+ ├── pyproject.toml # Project metadata and dependencies
38
+ ├── uv.lock # Locked dependency versions (uv)
39
+ ├── .env # Connection config (not committed)
40
+ └── README.md
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Setup
46
+
47
+ ### 1. Configure the database connection
48
+
49
+ Create a `.env` file in the project root:
50
+
51
+ **Windows Authentication (Trusted Connection):**
52
+ ```env
53
+ DB_DRIVER=ODBC Driver 17 for SQL Server
54
+ DB_SERVER=YOUR_SERVER_NAME\\SQLEXPRESS
55
+ DB_NAME=your_database_name
56
+ ```
57
+
58
+ **SQL Server Authentication (username + password):**
59
+ ```env
60
+ DB_DRIVER=ODBC Driver 17 for SQL Server
61
+ DB_SERVER=YOUR_SERVER_NAME\\SQLEXPRESS
62
+ DB_NAME=your_database_name
63
+ DB_USER=your_username
64
+ DB_PASSWORD=your_password
65
+ ```
66
+
67
+ If you're using the Claude Desktop config below, put your credentials in the `env` block — no `.env` file needed.
68
+
69
+ ---
70
+
71
+ ### 2. Register with Claude Desktop
72
+
73
+ Add this to `claude_desktop_config.json`:
74
+
75
+ **Windows Authentication:**
76
+ ```json
77
+ {
78
+ "mcpServers": {
79
+ "sql-assistant": {
80
+ "command": "uv",
81
+ "args": [
82
+ "--directory",
83
+ "C:/path/to/sql-mcp-server",
84
+ "run",
85
+ "server.py"
86
+ ],
87
+ "env": {
88
+ "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
89
+ "DB_NAME": "your_database_name",
90
+ "DB_DRIVER": "ODBC Driver 17 for SQL Server"
91
+ }
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ **SQL Server Authentication:**
98
+ ```json
99
+ {
100
+ "mcpServers": {
101
+ "sql-assistant": {
102
+ "command": "uv",
103
+ "args": [
104
+ "--directory",
105
+ "C:/path/to/sql-mcp-server",
106
+ "run",
107
+ "server.py"
108
+ ],
109
+ "env": {
110
+ "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
111
+ "DB_NAME": "your_database_name",
112
+ "DB_DRIVER": "ODBC Driver 17 for SQL Server",
113
+ "DB_USER": "your_username",
114
+ "DB_PASSWORD": "your_password"
115
+ }
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ Replace the placeholder values with your actual details. Restart Claude Desktop after saving.
122
+
123
+ ---
124
+
125
+ ## Usage
126
+
127
+ With the server running, try asking Claude:
128
+
129
+ - "What tables are in the database?"
130
+ - "Describe the Orders table."
131
+ - "Show me 10 rows from Customers."
132
+ - "Run: SELECT TOP 5 * FROM Sales.Orders WHERE Status = 'Pending'"
133
+ - "Explain this query: SELECT * FROM Products WHERE Price > 100"
134
+
135
+ ---
136
+
137
+ ## Safety
138
+
139
+ Only SELECT queries run. These keywords are blocked before they reach the database:
140
+
141
+ `INSERT` `UPDATE` `DELETE` `DROP` `TRUNCATE` `ALTER` `CREATE` `EXEC`
142
+
143
+ Table and schema names are validated against injection patterns. Results cap at 200 rows.
144
+
145
+ > ⚠️ **Don't commit your `.env` file** — it contains your connection credentials.
146
+
147
+ ---
148
+
149
+ ## Requirements
150
+
151
+ - Python 3.12+
152
+ - SQL Server with ODBC Driver 17 or 18
153
+ - Claude Desktop with MCP support
154
+
155
+ ---
156
+
157
+ ## License
158
+
159
+ MIT
@@ -0,0 +1,27 @@
1
+ import pyodbc
2
+ import os
3
+ from dotenv import load_dotenv
4
+ from pathlib import Path
5
+
6
+ # Force load .env from the project folder
7
+ load_dotenv(dotenv_path=Path(__file__).parent / ".env")
8
+
9
+ # db.py — support both auth modes
10
+ def get_connection():
11
+ driver = os.getenv("DB_DRIVER", "ODBC Driver 17 for SQL Server")
12
+ server = os.getenv("DB_SERVER")
13
+ database = os.getenv("DB_NAME")
14
+ username = os.getenv("DB_USER") # new
15
+ password = os.getenv("DB_PASSWORD") # new
16
+
17
+ if username and password:
18
+ conn_str = (
19
+ f"DRIVER={{{driver}}};SERVER={server};DATABASE={database};"
20
+ f"UID={username};PWD={password};TrustServerCertificate=yes;"
21
+ )
22
+ else:
23
+ conn_str = (
24
+ f"DRIVER={{{driver}}};SERVER={server};DATABASE={database};"
25
+ "Trusted_Connection=yes;TrustServerCertificate=yes;"
26
+ )
27
+ return pyodbc.connect(conn_str)
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "sql-mcp-server"
3
+ version = "0.1.0"
4
+ description = "MCP server that connects Claude to a Microsoft SQL Server database"
5
+ readme = "README.md"
6
+ license = { text = "MIT" }
7
+ requires-python = ">=3.12"
8
+ authors = [
9
+ { name = "Snehangshu" },
10
+ ]
11
+ keywords = ["mcp", "sql-server", "claude", "database", "ai"]
12
+ classifiers = [
13
+ "Development Status :: 3 - Alpha",
14
+ "Intended Audience :: Developers",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Topic :: Database",
19
+ ]
20
+ dependencies = [
21
+ "mcp[cli]>=1.26.0",
22
+ "pyodbc>=5.3.0",
23
+ "python-dotenv>=1.2.2",
24
+ ]
25
+
26
+ [project.scripts]
27
+ sql-mcp-server = "server:main"
28
+
29
+ [build-system]
30
+ requires = ["hatchling"]
31
+ build-backend = "hatchling.build"
32
+
33
+ [tool.hatch.build.targets.wheel]
34
+ packages = ["."]
35
+ only-include = ["server.py", "db.py"]