mcp-dbutils 0.2.3__tar.gz → 0.2.8__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.
Files changed (34) hide show
  1. mcp_dbutils-0.2.8/.coveragerc +17 -0
  2. mcp_dbutils-0.2.8/.github/workflows/test.yml +77 -0
  3. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/.gitignore +3 -0
  4. mcp_dbutils-0.2.8/CHANGELOG.md +158 -0
  5. mcp_dbutils-0.2.8/Dockerfile +17 -0
  6. mcp_dbutils-0.2.3/README.md → mcp_dbutils-0.2.8/PKG-INFO +125 -13
  7. mcp_dbutils-0.2.3/PKG-INFO → mcp_dbutils-0.2.8/README.md +103 -27
  8. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/README_CN.md +89 -12
  9. mcp_dbutils-0.2.8/pyproject.toml +38 -0
  10. mcp_dbutils-0.2.8/smithery.yaml +21 -0
  11. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/base.py +68 -15
  12. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/postgres/handler.py +12 -12
  13. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/sqlite/handler.py +19 -8
  14. mcp_dbutils-0.2.8/src/mcp_dbutils/stats.py +85 -0
  15. mcp_dbutils-0.2.8/tests/conftest.py +123 -0
  16. mcp_dbutils-0.2.8/tests/integration/test_monitoring.py +78 -0
  17. mcp_dbutils-0.2.8/tests/integration/test_postgres.py +83 -0
  18. mcp_dbutils-0.2.8/tests/integration/test_prompts.py +41 -0
  19. mcp_dbutils-0.2.8/tests/integration/test_sqlite.py +84 -0
  20. mcp_dbutils-0.2.8/tests/unit/test_stats.py +93 -0
  21. mcp_dbutils-0.2.3/CHANGELOG.md +0 -69
  22. mcp_dbutils-0.2.3/pyproject.toml +0 -23
  23. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/.github/workflows/publish.yml +0 -0
  24. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/LICENSE +0 -0
  25. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/config.yaml.example +0 -0
  26. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/__init__.py +0 -0
  27. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/config.py +0 -0
  28. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/log.py +0 -0
  29. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/postgres/__init__.py +0 -0
  30. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/postgres/config.py +0 -0
  31. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/postgres/server.py +0 -0
  32. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/sqlite/__init__.py +0 -0
  33. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/sqlite/config.py +0 -0
  34. {mcp_dbutils-0.2.3 → mcp_dbutils-0.2.8}/src/mcp_dbutils/sqlite/server.py +0 -0
@@ -0,0 +1,17 @@
1
+ [run]
2
+ source = src/mcp_dbutils
3
+ omit =
4
+ tests/*
5
+ **/__init__.py
6
+
7
+ [report]
8
+ exclude_lines =
9
+ pragma: no cover
10
+ def __repr__
11
+ raise NotImplementedError
12
+ if __name__ == .__main__.:
13
+ pass
14
+ raise ImportError
15
+
16
+ [html]
17
+ directory = coverage_html
@@ -0,0 +1,77 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ services:
14
+ postgres:
15
+ image: postgres:15-alpine
16
+ env:
17
+ POSTGRES_PASSWORD: postgres
18
+ ports:
19
+ - 5432:5432
20
+ options: >-
21
+ --health-cmd pg_isready
22
+ --health-interval 10s
23
+ --health-timeout 5s
24
+ --health-retries 5
25
+
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+
29
+ - name: Install uv
30
+ uses: astral-sh/setup-uv@v4
31
+
32
+ - name: Set up Python
33
+ run: uv python install
34
+
35
+ - name: Create and activate venv
36
+ run: |
37
+ uv venv
38
+ . .venv/bin/activate
39
+
40
+ - name: Install dependencies
41
+ run: uv pip install -e ".[test]"
42
+
43
+ - name: Run tests with coverage
44
+ id: tests
45
+ run: |
46
+ uv run pytest \
47
+ -v \
48
+ --cov=src/mcp_dbutils \
49
+ --cov-report=html \
50
+ --cov-report=term-missing \
51
+ --cov-report=json:coverage.json \
52
+ tests/
53
+
54
+ - name: Calculate coverage percentage
55
+ id: calc_coverage
56
+ run: |
57
+ COVERAGE=$(jq -r '.totals.percent_covered' coverage.json)
58
+ echo "Coverage: $COVERAGE"
59
+ echo "percentage=${COVERAGE%.*}" >> $GITHUB_OUTPUT
60
+ if (( $(echo "$COVERAGE >= 90" | bc -l) )); then
61
+ echo "color=green" >> $GITHUB_OUTPUT
62
+ elif (( $(echo "$COVERAGE >= 80" | bc -l) )); then
63
+ echo "color=yellow" >> $GITHUB_OUTPUT
64
+ else
65
+ echo "color=red" >> $GITHUB_OUTPUT
66
+ fi
67
+
68
+ - name: Create Coverage Badge
69
+ uses: schneegans/dynamic-badges-action@v1.7.0
70
+ with:
71
+ auth: ${{ secrets.GIST_SECRET }}
72
+ gistID: bdd0a63ec2a816539ff8c136ceb41e48
73
+ filename: coverage.json
74
+ label: "coverage"
75
+ message: "${{ steps.calc_coverage.outputs.percentage }}%"
76
+ color: "${{ steps.calc_coverage.outputs.color }}"
77
+ namedLogo: python
@@ -6,6 +6,8 @@ __pycache__/
6
6
  *.so
7
7
  .Python
8
8
  build/
9
+ .coverage
10
+ coverage_html/
9
11
  develop-eggs/
10
12
  dist/
11
13
  downloads/
@@ -37,6 +39,7 @@ ENV/
37
39
  .vscode/
38
40
  *.swp
39
41
  *.swo
42
+ memory-bank/
40
43
 
41
44
  # OS
42
45
  .DS_Store
@@ -0,0 +1,158 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.2.11] - 2025-02-15
6
+
7
+ ### Added
8
+ - Added basic prompts support
9
+ - Implemented empty prompts/list handler
10
+ - Added prompts capability configuration
11
+ - Added integration tests for prompts
12
+
13
+ ## [0.2.10] - 2025-02-15
14
+
15
+ ### Added
16
+ - Resource monitoring system
17
+ - Added ResourceStats for resource usage tracking
18
+ - Implemented connection lifecycle monitoring
19
+ - Added error pattern analysis
20
+ - Added memory usage estimation
21
+
22
+ ### Changed
23
+ - Enhanced database handlers
24
+ - Improved error tracking and reporting
25
+ - Added resource cleanup logging
26
+ - Standardized monitoring output format
27
+ - Implemented template method pattern for queries
28
+
29
+ ### Fixed
30
+ - Unified resource monitoring across all database types
31
+ - Added proper cleanup for monitoring resources
32
+
33
+ ## [0.2.9] - 2025-02-15
34
+
35
+ ### Changed
36
+ - Optimized database type handling
37
+ - Removed redundant type detection based on path/dbname
38
+ - Now using explicit 'type' field from configuration
39
+ - Added custom exception classes for better error handling
40
+ - Enhanced logging for handler lifecycle
41
+
42
+ ### Added
43
+ - New exception hierarchy for better error handling
44
+ - DatabaseError as base exception
45
+ - ConfigurationError for configuration issues
46
+ - ConnectionError for connection problems
47
+ - Improved debug logging
48
+ - Added handler creation logs
49
+ - Added cleanup operation logs
50
+ - Enhanced error messages with more context
51
+
52
+ ## [0.2.8] - 2025-02-15
53
+
54
+ ### Changed
55
+ - Improved test configuration and stability
56
+ - Removed custom event_loop fixture in favor of pytest-asyncio's default
57
+ - Configured asyncio_mode to strict for better async test behavior
58
+ - Set asyncio_default_fixture_loop_scope to function level
59
+ - Fixed all pytest-asyncio deprecation warnings
60
+
61
+ ## [0.2.7] - 2025-02-15
62
+
63
+ ### Added
64
+ - Added GitHub Actions workflow for automated testing
65
+ - Added PostgreSQL service in CI environment
66
+ - Added detailed test reporting with coverage in CI
67
+ - Added coverage badge to README using dynamic-badges-action
68
+
69
+ ## [0.2.6] - 2025-02-12
70
+
71
+ ### Added
72
+ - Added test coverage reporting with pytest-cov
73
+ - Added coverage configuration and HTML report generation
74
+ - Added test coverage tracking for all source code
75
+
76
+ ## [0.2.5] - 2025-02-12
77
+
78
+ ### Added
79
+ - Comprehensive automated tests for both PostgreSQL and SQLite handlers
80
+ - Integration tests for database operations
81
+ - Unit tests for configuration
82
+ - Test fixtures and Docker-based test environments
83
+
84
+ ## [0.2.4] - 2025-02-09
85
+
86
+ ### Changed
87
+ - Unified server configuration name to "dbutils"
88
+ - Improved documentation formatting and readability
89
+ - Added architecture diagrams
90
+ - Added contribution guidelines
91
+ - Enhanced installation instructions with environment variables
92
+ - Added acknowledgments section
93
+
94
+ ## [0.2.3] - 2025-02-09
95
+
96
+ ### Added
97
+ - Added comprehensive installation guides for uvx, pip, and Docker
98
+ - Added GitHub Actions workflow for automated PyPI releases
99
+ - Added both English and Chinese documentation
100
+ - Added project badges and repository information
101
+
102
+ ### Changed
103
+ - Internationalized all code messages and docstrings
104
+ - Updated Python version requirement to 3.10+
105
+ - Improved documentation structure and examples
106
+ - Unified project naming to mcp-dbutils across all references
107
+
108
+ ## [0.2.2] - 2025-02-09
109
+
110
+ ### Added
111
+ - Added explicit database type declaration in configs
112
+ - Improved database type awareness in query results
113
+ - Standardized field naming across different database types
114
+
115
+ ### Changed
116
+ - Unified response format for normal results and error messages
117
+ - Enhanced error reporting with database-specific details
118
+
119
+ ## [0.2.1] - 2025-02-09
120
+
121
+ ### Added
122
+ - SQLite database support with basic CRUD operations
123
+ - Password protection for SQLite databases
124
+ - Table schema inspection for SQLite
125
+ - URI connection string support for SQLite
126
+
127
+ ### Fixed
128
+ - Automatic database type detection from config
129
+ - Connection handling improvements
130
+
131
+ ## [0.2.0] - 2025-02-09
132
+
133
+ ### Changed
134
+ - Renamed project from mcp-postgres to mcp-dbutils
135
+ - Restructured project for multi-database support
136
+ - Added base classes for database handling
137
+ - Improved configuration management
138
+ - Enhanced error handling and logging
139
+
140
+ ## [0.1.1] - 2025-02-08
141
+
142
+ ### Added
143
+ - Enhanced PostgreSQL error logging with error codes
144
+ - Improved error details with pgcode and pgerror
145
+ - Better error differentiation between PostgreSQL-specific and general errors
146
+
147
+ ### Changed
148
+ - Maintained backwards compatibility while improving error flow
149
+
150
+ ## [0.1.0] - 2025-02-08
151
+
152
+ ### Added
153
+ - Initial PostgreSQL implementation
154
+ - YAML configuration for multiple databases
155
+ - Connection pool management
156
+ - Table structure querying
157
+ - Read-only SQL query execution
158
+ - Basic error handling and logging
@@ -0,0 +1,17 @@
1
+ # Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile
2
+ # Use a base Python image
3
+ FROM python:3.10-slim AS base
4
+
5
+ # Set the working directory in the container
6
+ WORKDIR /app
7
+
8
+ # Copy the project file
9
+ COPY pyproject.toml README.md src /app/
10
+
11
+ # Install dependencies and the package
12
+ RUN pip install hatchling && \
13
+ hatchling build && \
14
+ pip install dist/*.whl
15
+
16
+ # Set the entry point to run the server
17
+ ENTRYPOINT ["mcp-dbutils", "--config", "/app/config.yaml"]
@@ -1,9 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-dbutils
3
+ Version: 0.2.8
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
+
1
23
  # MCP Database Utilities
2
24
 
3
25
  ![GitHub Repo stars](https://img.shields.io/github/stars/donghao1393/mcp-dbutils)
4
26
  ![PyPI version](https://img.shields.io/pypi/v/mcp-dbutils)
5
- ![Python versions](https://img.shields.io/pypi/pyversions/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)
6
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)
7
31
 
8
32
  [中文文档](README_CN.md)
9
33
 
@@ -21,6 +45,13 @@ MCP Database Utilities is a unified database access service that supports multip
21
45
  ## Installation and Configuration
22
46
 
23
47
  ### Installation Methods
48
+ #### Installing via Smithery
49
+
50
+ To install Database Utilities for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@donghao1393/mcp-dbutils):
51
+
52
+ ```bash
53
+ npx -y @smithery/cli install @donghao1393/mcp-dbutils --client claude
54
+ ```
24
55
 
25
56
  #### Using uvx (Recommended)
26
57
  No installation required, run directly using `uvx`:
@@ -31,9 +62,16 @@ uvx mcp-dbutils --config /path/to/config.yaml
31
62
  Add to Claude configuration:
32
63
  ```json
33
64
  "mcpServers": {
34
- "database": {
65
+ "dbutils": {
35
66
  "command": "uvx",
36
- "args": ["mcp-dbutils", "--config", "/path/to/config.yaml"]
67
+ "args": [
68
+ "mcp-dbutils",
69
+ "--config",
70
+ "/path/to/config.yaml"
71
+ ],
72
+ "env": {
73
+ "MCP_DEBUG": "1" // Optional: Enable debug mode
74
+ }
37
75
  }
38
76
  }
39
77
  ```
@@ -46,9 +84,17 @@ pip install mcp-dbutils
46
84
  Add to Claude configuration:
47
85
  ```json
48
86
  "mcpServers": {
49
- "database": {
87
+ "dbutils": {
50
88
  "command": "python",
51
- "args": ["-m", "mcp_dbutils", "--config", "/path/to/config.yaml"]
89
+ "args": [
90
+ "-m",
91
+ "mcp_dbutils",
92
+ "--config",
93
+ "/path/to/config.yaml"
94
+ ],
95
+ "env": {
96
+ "MCP_DEBUG": "1" // Optional: Enable debug mode
97
+ }
52
98
  }
53
99
  }
54
100
  ```
@@ -57,20 +103,41 @@ Add to Claude configuration:
57
103
  ```bash
58
104
  docker run -i --rm \
59
105
  -v /path/to/config.yaml:/app/config.yaml \
106
+ -v /path/to/sqlite.db:/app/sqlite.db \ # Optional: for SQLite database
107
+ -e MCP_DEBUG=1 \ # Optional: Enable debug mode
60
108
  mcp/dbutils --config /app/config.yaml
61
109
  ```
62
110
 
63
111
  Add to Claude configuration:
64
112
  ```json
65
113
  "mcpServers": {
66
- "database": {
114
+ "dbutils": {
67
115
  "command": "docker",
68
- "args": ["run", "-i", "--rm", "-v", "/path/to/config.yaml:/app/config.yaml",
69
- "mcp/dbutils", "--config", "/app/config.yaml"]
116
+ "args": [
117
+ "run",
118
+ "-i",
119
+ "--rm",
120
+ "-v",
121
+ "/path/to/config.yaml:/app/config.yaml",
122
+ "-v",
123
+ "/path/to/sqlite.db:/app/sqlite.db", // Optional: for SQLite database
124
+ "mcp/dbutils",
125
+ "--config",
126
+ "/app/config.yaml"
127
+ ],
128
+ "env": {
129
+ "MCP_DEBUG": "1" // Optional: Enable debug mode
130
+ }
70
131
  }
71
132
  }
72
133
  ```
73
134
 
135
+ > **Note for Docker database connections:**
136
+ > - For SQLite: Mount your database file using `-v /path/to/sqlite.db:/app/sqlite.db`
137
+ > - For PostgreSQL running on host:
138
+ > - On Mac/Windows: Use `host.docker.internal` as host in config
139
+ > - On Linux: Use `172.17.0.1` (docker0 IP) or run with `--network="host"`
140
+
74
141
  ### Requirements
75
142
  - Python 3.10+
76
143
  - PostgreSQL (optional)
@@ -81,20 +148,21 @@ The project requires a YAML configuration file, specified via the `--config` par
81
148
 
82
149
  ```yaml
83
150
  databases:
84
- # PostgreSQL example
151
+ # PostgreSQL example (when using Docker)
85
152
  my_postgres:
86
153
  type: postgres
87
154
  dbname: test_db
88
155
  user: postgres
89
156
  password: secret
90
- host: localhost
157
+ host: host.docker.internal # For Mac/Windows
158
+ # host: 172.17.0.1 # For Linux (docker0 IP)
91
159
  port: 5432
92
160
 
93
- # SQLite example
161
+ # SQLite example (when using Docker)
94
162
  my_sqlite:
95
163
  type: sqlite
96
- path: /path/to/database.db
97
- password: optional_password # optional
164
+ path: /app/sqlite.db # Mapped path inside container
165
+ password: optional_password # optional
98
166
  ```
99
167
 
100
168
  ### Debug Mode
@@ -103,6 +171,23 @@ Set environment variable `MCP_DEBUG=1` to enable debug mode for detailed logging
103
171
  ## Architecture Design
104
172
 
105
173
  ### Core Concept: Abstraction Layer
174
+
175
+ ```mermaid
176
+ graph TD
177
+ Client[Client] --> DatabaseServer[Database Server]
178
+ subgraph MCP Server
179
+ DatabaseServer
180
+ DatabaseHandler[Database Handler]
181
+ PostgresHandler[PostgreSQL Handler]
182
+ SQLiteHandler[SQLite Handler]
183
+ DatabaseServer --> DatabaseHandler
184
+ DatabaseHandler --> PostgresHandler
185
+ DatabaseHandler --> SQLiteHandler
186
+ end
187
+ PostgresHandler --> PostgreSQL[(PostgreSQL)]
188
+ SQLiteHandler --> SQLite[(SQLite)]
189
+ ```
190
+
106
191
  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
192
 
108
193
  #### 1. Simplified User Interaction
@@ -202,3 +287,30 @@ Provides SQLite-specific features:
202
287
  - File path handling
203
288
  - URI scheme support
204
289
  - Password protection support (optional)
290
+
291
+ ## Contributing
292
+ Contributions are welcome! Here's how you can help:
293
+
294
+ 1. 🐛 Report bugs: Open an issue describing the bug and how to reproduce it
295
+ 2. 💡 Suggest features: Open an issue to propose new features
296
+ 3. 🛠️ Submit PRs: Fork the repo and create a pull request with your changes
297
+
298
+ ### Development Setup
299
+ 1. Clone the repository
300
+ 2. Create a virtual environment using `uv venv`
301
+ 3. Install dependencies with `uv sync --all-extras`
302
+ 4. Run tests with `pytest`
303
+
304
+ For detailed guidelines, see [CONTRIBUTING.md](.github/CONTRIBUTING.md)
305
+
306
+ ## Acknowledgments
307
+ - [MCP Servers](https://github.com/modelcontextprotocol/servers) for inspiration and demonstration
308
+ - AI Editors:
309
+ * [Claude Desktop](https://claude.ai/download)
310
+ * [5ire](https://5ire.app/)
311
+ * [Cline](https://cline.bot)
312
+ - [Model Context Protocol](https://modelcontextprotocol.io/) for comprehensive interfaces
313
+
314
+ ## Star History
315
+
316
+ [![Star History Chart](https://api.star-history.com/svg?repos=donghao1393/mcp-dbutils&type=Date)](https://star-history.com/#donghao1393/mcp-dbutils&Date)