mcp-dbutils 0.2.3__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.
- mcp_dbutils/__init__.py +62 -0
- mcp_dbutils/base.py +182 -0
- mcp_dbutils/config.py +59 -0
- mcp_dbutils/log.py +33 -0
- mcp_dbutils/postgres/__init__.py +6 -0
- mcp_dbutils/postgres/config.py +66 -0
- mcp_dbutils/postgres/handler.py +150 -0
- mcp_dbutils/postgres/server.py +205 -0
- mcp_dbutils/sqlite/__init__.py +6 -0
- mcp_dbutils/sqlite/config.py +74 -0
- mcp_dbutils/sqlite/handler.py +117 -0
- mcp_dbutils/sqlite/server.py +202 -0
- mcp_dbutils-0.2.3.dist-info/METADATA +218 -0
- mcp_dbutils-0.2.3.dist-info/RECORD +17 -0
- mcp_dbutils-0.2.3.dist-info/WHEEL +4 -0
- mcp_dbutils-0.2.3.dist-info/entry_points.txt +2 -0
- mcp_dbutils-0.2.3.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,218 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: mcp-dbutils
|
3
|
+
Version: 0.2.3
|
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
|
+
Description-Content-Type: text/markdown
|
14
|
+
|
15
|
+
# MCP Database Utilities
|
16
|
+
|
17
|
+

|
18
|
+

|
19
|
+

|
20
|
+

|
21
|
+
|
22
|
+
[中文文档](README_CN.md)
|
23
|
+
|
24
|
+
## Overview
|
25
|
+
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.
|
26
|
+
|
27
|
+
## Features
|
28
|
+
- Unified database access interface
|
29
|
+
- Support for multiple database configurations
|
30
|
+
- Secure read-only query execution
|
31
|
+
- Table structure and schema information retrieval
|
32
|
+
- Intelligent connection management and resource cleanup
|
33
|
+
- Debug mode support
|
34
|
+
|
35
|
+
## Installation and Configuration
|
36
|
+
|
37
|
+
### Installation Methods
|
38
|
+
|
39
|
+
#### Using uvx (Recommended)
|
40
|
+
No installation required, run directly using `uvx`:
|
41
|
+
```bash
|
42
|
+
uvx mcp-dbutils --config /path/to/config.yaml
|
43
|
+
```
|
44
|
+
|
45
|
+
Add to Claude configuration:
|
46
|
+
```json
|
47
|
+
"mcpServers": {
|
48
|
+
"database": {
|
49
|
+
"command": "uvx",
|
50
|
+
"args": ["mcp-dbutils", "--config", "/path/to/config.yaml"]
|
51
|
+
}
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
55
|
+
#### Using pip
|
56
|
+
```bash
|
57
|
+
pip install mcp-dbutils
|
58
|
+
```
|
59
|
+
|
60
|
+
Add to Claude configuration:
|
61
|
+
```json
|
62
|
+
"mcpServers": {
|
63
|
+
"database": {
|
64
|
+
"command": "python",
|
65
|
+
"args": ["-m", "mcp_dbutils", "--config", "/path/to/config.yaml"]
|
66
|
+
}
|
67
|
+
}
|
68
|
+
```
|
69
|
+
|
70
|
+
#### Using Docker
|
71
|
+
```bash
|
72
|
+
docker run -i --rm \
|
73
|
+
-v /path/to/config.yaml:/app/config.yaml \
|
74
|
+
mcp/dbutils --config /app/config.yaml
|
75
|
+
```
|
76
|
+
|
77
|
+
Add to Claude configuration:
|
78
|
+
```json
|
79
|
+
"mcpServers": {
|
80
|
+
"database": {
|
81
|
+
"command": "docker",
|
82
|
+
"args": ["run", "-i", "--rm", "-v", "/path/to/config.yaml:/app/config.yaml",
|
83
|
+
"mcp/dbutils", "--config", "/app/config.yaml"]
|
84
|
+
}
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
### Requirements
|
89
|
+
- Python 3.10+
|
90
|
+
- PostgreSQL (optional)
|
91
|
+
- SQLite3 (optional)
|
92
|
+
|
93
|
+
### Configuration File
|
94
|
+
The project requires a YAML configuration file, specified via the `--config` parameter. Configuration example:
|
95
|
+
|
96
|
+
```yaml
|
97
|
+
databases:
|
98
|
+
# PostgreSQL example
|
99
|
+
my_postgres:
|
100
|
+
type: postgres
|
101
|
+
dbname: test_db
|
102
|
+
user: postgres
|
103
|
+
password: secret
|
104
|
+
host: localhost
|
105
|
+
port: 5432
|
106
|
+
|
107
|
+
# SQLite example
|
108
|
+
my_sqlite:
|
109
|
+
type: sqlite
|
110
|
+
path: /path/to/database.db
|
111
|
+
password: optional_password # optional
|
112
|
+
```
|
113
|
+
|
114
|
+
### Debug Mode
|
115
|
+
Set environment variable `MCP_DEBUG=1` to enable debug mode for detailed logging output.
|
116
|
+
|
117
|
+
## Architecture Design
|
118
|
+
|
119
|
+
### Core Concept: Abstraction Layer
|
120
|
+
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.
|
121
|
+
|
122
|
+
#### 1. Simplified User Interaction
|
123
|
+
- Users only need to know the database configuration name (e.g., "my_postgres")
|
124
|
+
- No need to deal with connection parameters and implementation details
|
125
|
+
- MCP server automatically handles database connections and queries
|
126
|
+
|
127
|
+
#### 2. Unified Interface Design
|
128
|
+
- DatabaseHandler abstract class defines unified operation interfaces
|
129
|
+
- All specific database implementations (PostgreSQL/SQLite) follow the same interface
|
130
|
+
- Users interact with different databases in the same way
|
131
|
+
|
132
|
+
#### 3. Configuration and Implementation Separation
|
133
|
+
- Complex database configuration parameters are encapsulated in configuration files
|
134
|
+
- Runtime access through simple database names
|
135
|
+
- Easy management and modification of database configurations without affecting business code
|
136
|
+
|
137
|
+
### System Components
|
138
|
+
1. DatabaseServer
|
139
|
+
- Core component of the MCP server
|
140
|
+
- Handles resource and tool requests
|
141
|
+
- Manages database connection lifecycle
|
142
|
+
|
143
|
+
2. DatabaseHandler
|
144
|
+
- Abstract base class defining unified interface
|
145
|
+
- Includes get_tables(), get_schema(), execute_query(), etc.
|
146
|
+
- Implemented by PostgreSQL and SQLite handlers
|
147
|
+
|
148
|
+
3. Configuration System
|
149
|
+
- YAML-based configuration file
|
150
|
+
- Support for multiple database configurations
|
151
|
+
- Type-safe configuration validation
|
152
|
+
|
153
|
+
4. Error Handling and Logging
|
154
|
+
- Unified error handling mechanism
|
155
|
+
- Detailed logging output
|
156
|
+
- Sensitive information masking
|
157
|
+
|
158
|
+
## Usage Examples
|
159
|
+
|
160
|
+
### Basic Query
|
161
|
+
```python
|
162
|
+
# Access through database name
|
163
|
+
async with server.get_handler("my_postgres") as handler:
|
164
|
+
# Execute SQL query
|
165
|
+
result = await handler.execute_query("SELECT * FROM users")
|
166
|
+
```
|
167
|
+
|
168
|
+
### View Table Structure
|
169
|
+
```python
|
170
|
+
# Get all tables
|
171
|
+
tables = await handler.get_tables()
|
172
|
+
|
173
|
+
# Get specific table schema
|
174
|
+
schema = await handler.get_schema("users")
|
175
|
+
```
|
176
|
+
|
177
|
+
### Error Handling
|
178
|
+
```python
|
179
|
+
try:
|
180
|
+
async with server.get_handler("my_db") as handler:
|
181
|
+
result = await handler.execute_query("SELECT * FROM users")
|
182
|
+
except ValueError as e:
|
183
|
+
print(f"Configuration error: {e}")
|
184
|
+
except Exception as e:
|
185
|
+
print(f"Query error: {e}")
|
186
|
+
```
|
187
|
+
|
188
|
+
## Security Notes
|
189
|
+
- Supports SELECT queries only to protect database security
|
190
|
+
- Automatically masks sensitive information (like passwords) in logs
|
191
|
+
- Executes queries in read-only transactions
|
192
|
+
|
193
|
+
## API Documentation
|
194
|
+
|
195
|
+
### DatabaseServer
|
196
|
+
Core server class providing:
|
197
|
+
- Resource list retrieval
|
198
|
+
- Tool call handling
|
199
|
+
- Database handler management
|
200
|
+
|
201
|
+
### DatabaseHandler
|
202
|
+
Abstract base class defining interfaces:
|
203
|
+
- get_tables(): Get table resource list
|
204
|
+
- get_schema(): Get table structure
|
205
|
+
- execute_query(): Execute SQL query
|
206
|
+
- cleanup(): Resource cleanup
|
207
|
+
|
208
|
+
### PostgreSQL Implementation
|
209
|
+
Provides PostgreSQL-specific features:
|
210
|
+
- Remote connection support
|
211
|
+
- Table description information
|
212
|
+
- Constraint queries
|
213
|
+
|
214
|
+
### SQLite Implementation
|
215
|
+
Provides SQLite-specific features:
|
216
|
+
- File path handling
|
217
|
+
- URI scheme support
|
218
|
+
- Password protection support (optional)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
mcp_dbutils/__init__.py,sha256=_zVdjN2P_G5qEye7f5vQxiXAd6EwX2gyTL1wpFpqKck,1718
|
2
|
+
mcp_dbutils/base.py,sha256=BQ6lEduhnR0pZnc-YY_OsO-w4XM06dzCJRU1uWnL-5M,6810
|
3
|
+
mcp_dbutils/config.py,sha256=EwnPNuQVCBKd5WOXQfROyDTM-YpM_Odp0GhCPRg8YwE,1863
|
4
|
+
mcp_dbutils/log.py,sha256=RJwWtHyZnJA2YRcyCK-WgnFadNuwtJeYKSxPbE-DCG0,991
|
5
|
+
mcp_dbutils/postgres/__init__.py,sha256=Y6v_RsI79pqAfpKM3SrT1T1I9r5yWuKT0GUUNmHD3DE,146
|
6
|
+
mcp_dbutils/postgres/config.py,sha256=ipjskdlv3u949R9rC2AKPCINRrtEAiKDjeogpFfM6aE,2401
|
7
|
+
mcp_dbutils/postgres/handler.py,sha256=e-E03JST5t_YBgjRs3EmIEbKzym40WhGyScFerP3ueg,5811
|
8
|
+
mcp_dbutils/postgres/server.py,sha256=3AdQyQfgrClkCmWOZ-xFXTeI9t3tpFkrY3qmyOR0b-U,8586
|
9
|
+
mcp_dbutils/sqlite/__init__.py,sha256=QV4th2ywzUmCCa3GHCcBf8blJ_E8OYy0dJ2fSf1TfSU,134
|
10
|
+
mcp_dbutils/sqlite/config.py,sha256=QK1JlY-ZBB5VyhydbiU-aAKNESTWMtyBfawbv2DAVCQ,2452
|
11
|
+
mcp_dbutils/sqlite/handler.py,sha256=v2fFHxepNSUuK65UPo4fwyeBCDG6fit5IuLdBRIKUsY,4220
|
12
|
+
mcp_dbutils/sqlite/server.py,sha256=Q29O2YOW4kqDGc3z1hMXVv4M0KSkuZbqvVDMgZE8Fd8,7593
|
13
|
+
mcp_dbutils-0.2.3.dist-info/METADATA,sha256=TqDZw19V4rPsI5zS89McSFqHBSk73KOWTiaS3tE3dzw,6051
|
14
|
+
mcp_dbutils-0.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
15
|
+
mcp_dbutils-0.2.3.dist-info/entry_points.txt,sha256=XTjt0QmYRgKOJQT6skR9bp1EMUfIrgpHeZJPZ3CJffs,49
|
16
|
+
mcp_dbutils-0.2.3.dist-info/licenses/LICENSE,sha256=1A_CwpWVlbjrKdVEYO77vYfnXlW7oxcilZ8FpA_BzCI,1065
|
17
|
+
mcp_dbutils-0.2.3.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Dong Hao
|
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.
|