mcp-dbutils 0.8.0__py3-none-any.whl → 0.10.0__py3-none-any.whl

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.
@@ -1,358 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: mcp-dbutils
3
- Version: 0.8.0
4
- Summary: MCP Database Utilities Service
5
- Author: Dong Hao
6
- License-Expression: MIT
7
- License-File: LICENSE
8
- Requires-Python: >=3.10
9
- Requires-Dist: mcp>=1.2.1
10
- Requires-Dist: psycopg2-binary>=2.9.10
11
- Requires-Dist: python-dotenv>=1.0.1
12
- Requires-Dist: pyyaml>=6.0.2
13
- Provides-Extra: test
14
- Requires-Dist: aiosqlite>=0.19.0; extra == 'test'
15
- Requires-Dist: docker>=7.0.0; extra == 'test'
16
- Requires-Dist: pytest-asyncio>=0.23.0; extra == 'test'
17
- Requires-Dist: pytest-cov>=4.1.0; extra == 'test'
18
- Requires-Dist: pytest-docker>=2.0.0; extra == 'test'
19
- Requires-Dist: pytest>=7.0.0; extra == 'test'
20
- Requires-Dist: testcontainers>=3.7.0; extra == 'test'
21
- Description-Content-Type: text/markdown
22
-
23
- # MCP Database Utilities
24
-
25
- ![GitHub Repo stars](https://img.shields.io/github/stars/donghao1393/mcp-dbutils)
26
- ![PyPI version](https://img.shields.io/pypi/v/mcp-dbutils)
27
- [![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/donghao1393/bdd0a63ec2a816539ff8c136ceb41e48/raw/coverage.json)](https://github.com/donghao1393/mcp-dbutils/actions)
28
- ![Python](https://img.shields.io/badge/Python-3.10%2B-blue)
29
- ![License](https://img.shields.io/github/license/donghao1393/mcp-dbutils)
30
- [![smithery badge](https://smithery.ai/badge/@donghao1393/mcp-dbutils)](https://smithery.ai/server/@donghao1393/mcp-dbutils)
31
-
32
- [中文文档](README_CN.md)
33
-
34
- ## Overview
35
- MCP Database Utilities is a unified database access service that supports multiple database types (PostgreSQL and SQLite). Through its abstraction layer design, it provides a simple and unified database operation interface for MCP servers.
36
-
37
- ## Features
38
- - Unified database access interface
39
- - Support for multiple database configurations
40
- - Secure read-only query execution
41
- - Table structure and schema information retrieval
42
- - Database tables listing via MCP tools
43
- - Intelligent connection management and resource cleanup
44
- - Debug mode support
45
-
46
- ## Installation and Configuration
47
-
48
- ### Installation Methods
49
- #### Installing via Smithery
50
-
51
- To install Database Utilities for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@donghao1393/mcp-dbutils):
52
-
53
- ```bash
54
- npx -y @smithery/cli install @donghao1393/mcp-dbutils --client claude
55
- ```
56
-
57
- #### Using uvx (Recommended)
58
- No installation required, run directly using `uvx`:
59
- ```bash
60
- uvx mcp-dbutils --config /path/to/config.yaml
61
- ```
62
-
63
- Add to Claude configuration:
64
- ```json
65
- "mcpServers": {
66
- "mcp-dbutils": {
67
- "command": "uvx",
68
- "args": [
69
- "mcp-dbutils",
70
- "--config",
71
- "/path/to/config.yaml"
72
- ],
73
- "env": {
74
- "MCP_DEBUG": "1" // Optional: Enable debug mode
75
- }
76
- }
77
- }
78
- ```
79
-
80
- #### Using pip
81
- ```bash
82
- pip install mcp-dbutils
83
- ```
84
-
85
- Add to Claude configuration:
86
- ```json
87
- "mcpServers": {
88
- "mcp-dbutils": {
89
- "command": "python",
90
- "args": [
91
- "-m",
92
- "mcp_dbutils",
93
- "--config",
94
- "/path/to/config.yaml"
95
- ],
96
- "env": {
97
- "MCP_DEBUG": "1" // Optional: Enable debug mode
98
- }
99
- }
100
- }
101
- ```
102
-
103
- #### Using Docker
104
- ```bash
105
- docker run -i --rm \
106
- -v /path/to/config.yaml:/app/config.yaml \
107
- -v /path/to/sqlite.db:/app/sqlite.db \ # Optional: for SQLite database
108
- -e MCP_DEBUG=1 \ # Optional: Enable debug mode
109
- mcp/dbutils --config /app/config.yaml
110
- ```
111
-
112
- Add to Claude configuration:
113
- ```json
114
- "mcpServers": {
115
- "mcp-dbutils": {
116
- "command": "docker",
117
- "args": [
118
- "run",
119
- "-i",
120
- "--rm",
121
- "-v",
122
- "/path/to/config.yaml:/app/config.yaml",
123
- "-v",
124
- "/path/to/sqlite.db:/app/sqlite.db", // Optional: for SQLite database
125
- "mcp/dbutils",
126
- "--config",
127
- "/app/config.yaml"
128
- ],
129
- "env": {
130
- "MCP_DEBUG": "1" // Optional: Enable debug mode
131
- }
132
- }
133
- }
134
- ```
135
-
136
- > **Note for Docker database connections:**
137
- > - For SQLite: Mount your database file using `-v /path/to/sqlite.db:/app/sqlite.db`
138
- > - For PostgreSQL running on host:
139
- > - On Mac/Windows: Use `host.docker.internal` as host in config
140
- > - On Linux: Use `172.17.0.1` (docker0 IP) or run with `--network="host"`
141
-
142
- ### Requirements
143
- - Python 3.10+
144
- - PostgreSQL (optional)
145
- - SQLite3 (optional)
146
-
147
- ### Configuration File
148
- The project requires a YAML configuration file, specified via the `--config` parameter. Configuration example:
149
-
150
- ```yaml
151
- databases:
152
- # Standard PostgreSQL configuration example
153
- my_postgres:
154
- type: postgres
155
- dbname: test_db
156
- user: postgres
157
- password: secret
158
- host: host.docker.internal # For Mac/Windows
159
- # host: 172.17.0.1 # For Linux (docker0 IP)
160
- port: 5432
161
-
162
- # PostgreSQL with JDBC URL example
163
- my_postgres_jdbc:
164
- type: postgres
165
- jdbc_url: jdbc:postgresql://host.docker.internal:5432/test_db
166
- user: postgres # Credentials must be provided separately
167
- password: secret # Not included in JDBC URL for security
168
-
169
- # SQLite standard configuration
170
- my_sqlite:
171
- type: sqlite
172
- path: /app/sqlite.db # Database file path
173
- password: optional_password # optional
174
-
175
- # SQLite with JDBC URL configuration
176
- my_sqlite_jdbc:
177
- type: sqlite
178
- jdbc_url: jdbc:sqlite:/app/data.db?mode=ro&cache=shared # Supports query parameters
179
- password: optional_password # Provided separately for security
180
- ```
181
-
182
- The configuration supports JDBC URL format for both PostgreSQL and SQLite:
183
-
184
- PostgreSQL:
185
- 1. Standard configuration with individual parameters
186
- 2. JDBC URL configuration with separate credentials
187
-
188
- SQLite:
189
- 1. Standard configuration with path parameter
190
- 2. JDBC URL configuration with query parameters support:
191
- - mode=ro: Read-only mode
192
- - cache=shared: Shared cache mode
193
- - Other SQLite URI parameters
194
-
195
- ### Debug Mode
196
- Set environment variable `MCP_DEBUG=1` to enable debug mode for detailed logging output.
197
-
198
- ## Architecture Design
199
-
200
- ### Core Concept: Abstraction Layer
201
-
202
- ```mermaid
203
- graph TD
204
- Client[Client] --> DatabaseServer[Database Server]
205
- subgraph MCP Server
206
- DatabaseServer
207
- DatabaseHandler[Database Handler]
208
- PostgresHandler[PostgreSQL Handler]
209
- SQLiteHandler[SQLite Handler]
210
- DatabaseServer --> DatabaseHandler
211
- DatabaseHandler --> PostgresHandler
212
- DatabaseHandler --> SQLiteHandler
213
- end
214
- PostgresHandler --> PostgreSQL[(PostgreSQL)]
215
- SQLiteHandler --> SQLite[(SQLite)]
216
- ```
217
-
218
- The abstraction layer design is the core architectural concept in MCP Database Utilities. Just like a universal remote control that works with different devices, users only need to know the basic operations without understanding the underlying complexities.
219
-
220
- #### 1. Simplified User Interaction
221
- - Users only need to know the database configuration name (e.g., "my_postgres")
222
- - No need to deal with connection parameters and implementation details
223
- - MCP server automatically handles database connections and queries
224
-
225
- #### 2. Unified Interface Design
226
- - DatabaseHandler abstract class defines unified operation interfaces
227
- - All specific database implementations (PostgreSQL/SQLite) follow the same interface
228
- - Users interact with different databases in the same way
229
-
230
- #### 3. Configuration and Implementation Separation
231
- - Complex database configuration parameters are encapsulated in configuration files
232
- - Runtime access through simple database names
233
- - Easy management and modification of database configurations without affecting business code
234
-
235
- ### System Components
236
- 1. DatabaseServer
237
- - Core component of the MCP server
238
- - Handles resource and tool requests
239
- - Manages database connection lifecycle
240
-
241
- 2. DatabaseHandler
242
- - Abstract base class defining unified interface
243
- - Includes get_tables(), get_schema(), execute_query(), etc.
244
- - Implemented by PostgreSQL and SQLite handlers
245
-
246
- 3. Configuration System
247
- - YAML-based configuration file
248
- - Support for multiple database configurations
249
- - Type-safe configuration validation
250
-
251
- 4. Error Handling and Logging
252
- - Unified error handling mechanism
253
- - Detailed logging output
254
- - Sensitive information masking
255
-
256
- ## Usage Examples
257
-
258
- ### Basic Query
259
- ```python
260
- # Access through database name
261
- async with server.get_handler("my_postgres") as handler:
262
- # Execute SQL query
263
- result = await handler.execute_query("SELECT * FROM users")
264
- ```
265
-
266
- ### View Table Structure
267
- ```python
268
- # Get all tables
269
- tables = await handler.get_tables()
270
-
271
- # Get specific table schema
272
- schema = await handler.get_schema("users")
273
- ```
274
-
275
- ### Error Handling
276
- ```python
277
- try:
278
- async with server.get_handler("my_db") as handler:
279
- result = await handler.execute_query("SELECT * FROM users")
280
- except ValueError as e:
281
- print(f"Configuration error: {e}")
282
- except Exception as e:
283
- print(f"Query error: {e}")
284
- ```
285
-
286
- ## Security Notes
287
- - Supports SELECT queries only to protect database security
288
- - Automatically masks sensitive information (like passwords) in logs
289
- - Executes queries in read-only transactions
290
-
291
- ## API Documentation
292
-
293
- ### DatabaseServer
294
- Core server class providing:
295
- - Resource list retrieval
296
- - Tool call handling (list_tables, query)
297
- - Database handler management
298
-
299
- ### MCP Tools
300
-
301
- #### list_tables
302
- Lists all tables in the specified database.
303
- - Parameters:
304
- * database: Database configuration name
305
- - Returns: Text content with a list of table names
306
-
307
- #### query
308
- Executes a SQL query on the specified database.
309
- - Parameters:
310
- * database: Database configuration name
311
- * sql: SQL query to execute (SELECT only)
312
- - Returns: Query results in a formatted text
313
-
314
- ### DatabaseHandler
315
- Abstract base class defining interfaces:
316
- - get_tables(): Get table resource list
317
- - get_schema(): Get table structure
318
- - execute_query(): Execute SQL query
319
- - cleanup(): Resource cleanup
320
-
321
- ### PostgreSQL Implementation
322
- Provides PostgreSQL-specific features:
323
- - Remote connection support
324
- - Table description information
325
- - Constraint queries
326
-
327
- ### SQLite Implementation
328
- Provides SQLite-specific features:
329
- - File path handling
330
- - URI scheme support
331
- - Password protection support (optional)
332
-
333
- ## Contributing
334
- Contributions are welcome! Here's how you can help:
335
-
336
- 1. 🐛 Report bugs: Open an issue describing the bug and how to reproduce it
337
- 2. 💡 Suggest features: Open an issue to propose new features
338
- 3. 🛠️ Submit PRs: Fork the repo and create a pull request with your changes
339
-
340
- ### Development Setup
341
- 1. Clone the repository
342
- 2. Create a virtual environment using `uv venv`
343
- 3. Install dependencies with `uv sync --all-extras`
344
- 4. Run tests with `pytest`
345
-
346
- For detailed guidelines, see [CONTRIBUTING.md](.github/CONTRIBUTING.md)
347
-
348
- ## Acknowledgments
349
- - [MCP Servers](https://github.com/modelcontextprotocol/servers) for inspiration and demonstration
350
- - AI Editors:
351
- * [Claude Desktop](https://claude.ai/download)
352
- * [5ire](https://5ire.app/)
353
- * [Cline](https://cline.bot)
354
- - [Model Context Protocol](https://modelcontextprotocol.io/) for comprehensive interfaces
355
-
356
- ## Star History
357
-
358
- [![Star History Chart](https://api.star-history.com/svg?repos=donghao1393/mcp-dbutils&type=Date)](https://star-history.com/#donghao1393/mcp-dbutils&Date)
@@ -1,18 +0,0 @@
1
- mcp_dbutils/__init__.py,sha256=xcfE1spAaONAoxBYB1ZyDX8tw7nxV1PMqo_RwxLDp0A,1892
2
- mcp_dbutils/base.py,sha256=a6wBdSGsbPQq7fKb_H-relSKbDZov-d75G_Q3S_aYP4,11284
3
- mcp_dbutils/config.py,sha256=EwnPNuQVCBKd5WOXQfROyDTM-YpM_Odp0GhCPRg8YwE,1863
4
- mcp_dbutils/log.py,sha256=fibVIwsb1HVU5zriGrDZTMEirKjgIuxuN_B_YTdAJ7I,996
5
- mcp_dbutils/stats.py,sha256=2hiKi_M8V4xhVHlH5FS-Df5GuMEpuzif12C8ik06Khs,2538
6
- mcp_dbutils/postgres/__init__.py,sha256=Y6v_RsI79pqAfpKM3SrT1T1I9r5yWuKT0GUUNmHD3DE,146
7
- mcp_dbutils/postgres/config.py,sha256=Np0GS5iUaUuWpYI8QfnyjUDy7v-vResQEAexR4W92-o,5447
8
- mcp_dbutils/postgres/handler.py,sha256=JC_Qyw1s6qjVR0tdH7FLAEAs9EPl_-wgFQLryQyMq5c,6089
9
- mcp_dbutils/postgres/server.py,sha256=_S3HF1KooxPB9gX1FedoOOGn93tHlIevCab6vjCt2TU,8715
10
- mcp_dbutils/sqlite/__init__.py,sha256=QV4th2ywzUmCCa3GHCcBf8blJ_E8OYy0dJ2fSf1TfSU,134
11
- mcp_dbutils/sqlite/config.py,sha256=RTHT2Xx--g-osD73CpT8DrCk0VHpHfPil3D6YUzXD-g,4519
12
- mcp_dbutils/sqlite/handler.py,sha256=bf_k93rCcJn09zc7tsqrlbiTGUg3FspimfWKxK_JQTs,4970
13
- mcp_dbutils/sqlite/server.py,sha256=7Bbq9l7Ca_4dzkAbbdRcXxvHoO_NFLzZHwlhKB0HIJc,7724
14
- mcp_dbutils-0.8.0.dist-info/METADATA,sha256=403i2poAoHqP0HCb_w0PL7Dj7e59aewKZaaS_KEiPYA,10840
15
- mcp_dbutils-0.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- mcp_dbutils-0.8.0.dist-info/entry_points.txt,sha256=XTjt0QmYRgKOJQT6skR9bp1EMUfIrgpHeZJPZ3CJffs,49
17
- mcp_dbutils-0.8.0.dist-info/licenses/LICENSE,sha256=1A_CwpWVlbjrKdVEYO77vYfnXlW7oxcilZ8FpA_BzCI,1065
18
- mcp_dbutils-0.8.0.dist-info/RECORD,,