mcp-dbutils 0.2.3__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,33 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ name: Build and Publish to PyPI
10
+ runs-on: ubuntu-latest
11
+ environment: pypi
12
+ permissions:
13
+ id-token: write # Required for trusted publishing
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v4
20
+ with:
21
+ enable-cache: false
22
+
23
+ - name: Set up Python
24
+ run: uv python install
25
+
26
+ - name: Install build dependencies
27
+ run: uv sync --all-extras
28
+
29
+ - name: Build package
30
+ run: uv build
31
+
32
+ - name: Publish to PyPI
33
+ run: uv publish
@@ -0,0 +1,43 @@
1
+ # Python
2
+ docs/
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+ *.so
7
+ .Python
8
+ build/
9
+ develop-eggs/
10
+ dist/
11
+ downloads/
12
+ eggs/
13
+ .eggs/
14
+ lib/
15
+ lib64/
16
+ parts/
17
+ sdist/
18
+ var/
19
+ wheels/
20
+ share/python-wheels/
21
+ *.egg-info/
22
+ .installed.cfg
23
+ *.egg
24
+ MANIFEST
25
+ uv.lock
26
+
27
+ # Virtual Environment
28
+ .env
29
+ .venv
30
+ env/
31
+ venv/
32
+ ENV/
33
+ .python-version
34
+
35
+ # IDE
36
+ .idea/
37
+ .vscode/
38
+ *.swp
39
+ *.swo
40
+
41
+ # OS
42
+ .DS_Store
43
+ Thumbs.db
@@ -0,0 +1,69 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.2.3] - 2025-02-09
6
+
7
+ ### Added
8
+ - Added comprehensive installation guides for uvx, pip, and Docker
9
+ - Added GitHub Actions workflow for automated PyPI releases
10
+ - Added both English and Chinese documentation
11
+ - Added project badges and repository information
12
+
13
+ ### Changed
14
+ - Internationalized all code messages and docstrings
15
+ - Updated Python version requirement to 3.10+
16
+ - Improved documentation structure and examples
17
+ - Unified project naming to mcp-dbutils across all references
18
+
19
+ ## [0.2.2] - 2025-02-09
20
+
21
+ ### Added
22
+ - Added explicit database type declaration in configs
23
+ - Improved database type awareness in query results
24
+ - Standardized field naming across different database types
25
+
26
+ ### Changed
27
+ - Unified response format for normal results and error messages
28
+ - Enhanced error reporting with database-specific details
29
+
30
+ ## [0.2.1] - 2025-02-09
31
+
32
+ ### Added
33
+ - SQLite database support with basic CRUD operations
34
+ - Password protection for SQLite databases
35
+ - Table schema inspection for SQLite
36
+ - URI connection string support for SQLite
37
+
38
+ ### Fixed
39
+ - Automatic database type detection from config
40
+ - Connection handling improvements
41
+
42
+ ## [0.2.0] - 2025-02-09
43
+
44
+ ### Changed
45
+ - Renamed project from mcp-postgres to mcp-dbutils
46
+ - Restructured project for multi-database support
47
+ - Added base classes for database handling
48
+ - Improved configuration management
49
+ - Enhanced error handling and logging
50
+
51
+ ## [0.1.1] - 2025-02-08
52
+
53
+ ### Added
54
+ - Enhanced PostgreSQL error logging with error codes
55
+ - Improved error details with pgcode and pgerror
56
+ - Better error differentiation between PostgreSQL-specific and general errors
57
+
58
+ ### Changed
59
+ - Maintained backwards compatibility while improving error flow
60
+
61
+ ## [0.1.0] - 2025-02-08
62
+
63
+ ### Added
64
+ - Initial PostgreSQL implementation
65
+ - YAML configuration for multiple databases
66
+ - Connection pool management
67
+ - Table structure querying
68
+ - Read-only SQL query execution
69
+ - Basic error handling and logging
@@ -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.
@@ -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
+ ![GitHub Repo stars](https://img.shields.io/github/stars/donghao1393/mcp-dbutils)
18
+ ![PyPI version](https://img.shields.io/pypi/v/mcp-dbutils)
19
+ ![Python versions](https://img.shields.io/pypi/pyversions/mcp-dbutils)
20
+ ![License](https://img.shields.io/github/license/donghao1393/mcp-dbutils)
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,204 @@
1
+ # MCP Database Utilities
2
+
3
+ ![GitHub Repo stars](https://img.shields.io/github/stars/donghao1393/mcp-dbutils)
4
+ ![PyPI version](https://img.shields.io/pypi/v/mcp-dbutils)
5
+ ![Python versions](https://img.shields.io/pypi/pyversions/mcp-dbutils)
6
+ ![License](https://img.shields.io/github/license/donghao1393/mcp-dbutils)
7
+
8
+ [中文文档](README_CN.md)
9
+
10
+ ## Overview
11
+ 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.
12
+
13
+ ## Features
14
+ - Unified database access interface
15
+ - Support for multiple database configurations
16
+ - Secure read-only query execution
17
+ - Table structure and schema information retrieval
18
+ - Intelligent connection management and resource cleanup
19
+ - Debug mode support
20
+
21
+ ## Installation and Configuration
22
+
23
+ ### Installation Methods
24
+
25
+ #### Using uvx (Recommended)
26
+ No installation required, run directly using `uvx`:
27
+ ```bash
28
+ uvx mcp-dbutils --config /path/to/config.yaml
29
+ ```
30
+
31
+ Add to Claude configuration:
32
+ ```json
33
+ "mcpServers": {
34
+ "database": {
35
+ "command": "uvx",
36
+ "args": ["mcp-dbutils", "--config", "/path/to/config.yaml"]
37
+ }
38
+ }
39
+ ```
40
+
41
+ #### Using pip
42
+ ```bash
43
+ pip install mcp-dbutils
44
+ ```
45
+
46
+ Add to Claude configuration:
47
+ ```json
48
+ "mcpServers": {
49
+ "database": {
50
+ "command": "python",
51
+ "args": ["-m", "mcp_dbutils", "--config", "/path/to/config.yaml"]
52
+ }
53
+ }
54
+ ```
55
+
56
+ #### Using Docker
57
+ ```bash
58
+ docker run -i --rm \
59
+ -v /path/to/config.yaml:/app/config.yaml \
60
+ mcp/dbutils --config /app/config.yaml
61
+ ```
62
+
63
+ Add to Claude configuration:
64
+ ```json
65
+ "mcpServers": {
66
+ "database": {
67
+ "command": "docker",
68
+ "args": ["run", "-i", "--rm", "-v", "/path/to/config.yaml:/app/config.yaml",
69
+ "mcp/dbutils", "--config", "/app/config.yaml"]
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### Requirements
75
+ - Python 3.10+
76
+ - PostgreSQL (optional)
77
+ - SQLite3 (optional)
78
+
79
+ ### Configuration File
80
+ The project requires a YAML configuration file, specified via the `--config` parameter. Configuration example:
81
+
82
+ ```yaml
83
+ databases:
84
+ # PostgreSQL example
85
+ my_postgres:
86
+ type: postgres
87
+ dbname: test_db
88
+ user: postgres
89
+ password: secret
90
+ host: localhost
91
+ port: 5432
92
+
93
+ # SQLite example
94
+ my_sqlite:
95
+ type: sqlite
96
+ path: /path/to/database.db
97
+ password: optional_password # optional
98
+ ```
99
+
100
+ ### Debug Mode
101
+ Set environment variable `MCP_DEBUG=1` to enable debug mode for detailed logging output.
102
+
103
+ ## Architecture Design
104
+
105
+ ### Core Concept: Abstraction Layer
106
+ 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.
107
+
108
+ #### 1. Simplified User Interaction
109
+ - Users only need to know the database configuration name (e.g., "my_postgres")
110
+ - No need to deal with connection parameters and implementation details
111
+ - MCP server automatically handles database connections and queries
112
+
113
+ #### 2. Unified Interface Design
114
+ - DatabaseHandler abstract class defines unified operation interfaces
115
+ - All specific database implementations (PostgreSQL/SQLite) follow the same interface
116
+ - Users interact with different databases in the same way
117
+
118
+ #### 3. Configuration and Implementation Separation
119
+ - Complex database configuration parameters are encapsulated in configuration files
120
+ - Runtime access through simple database names
121
+ - Easy management and modification of database configurations without affecting business code
122
+
123
+ ### System Components
124
+ 1. DatabaseServer
125
+ - Core component of the MCP server
126
+ - Handles resource and tool requests
127
+ - Manages database connection lifecycle
128
+
129
+ 2. DatabaseHandler
130
+ - Abstract base class defining unified interface
131
+ - Includes get_tables(), get_schema(), execute_query(), etc.
132
+ - Implemented by PostgreSQL and SQLite handlers
133
+
134
+ 3. Configuration System
135
+ - YAML-based configuration file
136
+ - Support for multiple database configurations
137
+ - Type-safe configuration validation
138
+
139
+ 4. Error Handling and Logging
140
+ - Unified error handling mechanism
141
+ - Detailed logging output
142
+ - Sensitive information masking
143
+
144
+ ## Usage Examples
145
+
146
+ ### Basic Query
147
+ ```python
148
+ # Access through database name
149
+ async with server.get_handler("my_postgres") as handler:
150
+ # Execute SQL query
151
+ result = await handler.execute_query("SELECT * FROM users")
152
+ ```
153
+
154
+ ### View Table Structure
155
+ ```python
156
+ # Get all tables
157
+ tables = await handler.get_tables()
158
+
159
+ # Get specific table schema
160
+ schema = await handler.get_schema("users")
161
+ ```
162
+
163
+ ### Error Handling
164
+ ```python
165
+ try:
166
+ async with server.get_handler("my_db") as handler:
167
+ result = await handler.execute_query("SELECT * FROM users")
168
+ except ValueError as e:
169
+ print(f"Configuration error: {e}")
170
+ except Exception as e:
171
+ print(f"Query error: {e}")
172
+ ```
173
+
174
+ ## Security Notes
175
+ - Supports SELECT queries only to protect database security
176
+ - Automatically masks sensitive information (like passwords) in logs
177
+ - Executes queries in read-only transactions
178
+
179
+ ## API Documentation
180
+
181
+ ### DatabaseServer
182
+ Core server class providing:
183
+ - Resource list retrieval
184
+ - Tool call handling
185
+ - Database handler management
186
+
187
+ ### DatabaseHandler
188
+ Abstract base class defining interfaces:
189
+ - get_tables(): Get table resource list
190
+ - get_schema(): Get table structure
191
+ - execute_query(): Execute SQL query
192
+ - cleanup(): Resource cleanup
193
+
194
+ ### PostgreSQL Implementation
195
+ Provides PostgreSQL-specific features:
196
+ - Remote connection support
197
+ - Table description information
198
+ - Constraint queries
199
+
200
+ ### SQLite Implementation
201
+ Provides SQLite-specific features:
202
+ - File path handling
203
+ - URI scheme support
204
+ - Password protection support (optional)