mcp-dbutils 0.5.0__py3-none-any.whl → 0.7.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.
- mcp_dbutils/base.py +45 -14
- {mcp_dbutils-0.5.0.dist-info → mcp_dbutils-0.7.0.dist-info}/METADATA +37 -6
- {mcp_dbutils-0.5.0.dist-info → mcp_dbutils-0.7.0.dist-info}/RECORD +6 -6
- {mcp_dbutils-0.5.0.dist-info → mcp_dbutils-0.7.0.dist-info}/WHEEL +0 -0
- {mcp_dbutils-0.5.0.dist-info → mcp_dbutils-0.7.0.dist-info}/entry_points.txt +0 -0
- {mcp_dbutils-0.5.0.dist-info → mcp_dbutils-0.7.0.dist-info}/licenses/LICENSE +0 -0
mcp_dbutils/base.py
CHANGED
@@ -220,29 +220,60 @@ class DatabaseServer:
|
|
220
220
|
},
|
221
221
|
"required": ["database", "sql"]
|
222
222
|
}
|
223
|
+
),
|
224
|
+
types.Tool(
|
225
|
+
name="list_tables",
|
226
|
+
description="List all available tables in the specified database",
|
227
|
+
inputSchema={
|
228
|
+
"type": "object",
|
229
|
+
"properties": {
|
230
|
+
"database": {
|
231
|
+
"type": "string",
|
232
|
+
"description": "Database configuration name"
|
233
|
+
}
|
234
|
+
},
|
235
|
+
"required": ["database"]
|
236
|
+
}
|
223
237
|
)
|
224
238
|
]
|
225
239
|
|
226
240
|
@self.server.call_tool()
|
227
241
|
async def handle_call_tool(name: str, arguments: dict) -> list[types.TextContent]:
|
228
|
-
if name != "query":
|
229
|
-
raise ConfigurationError(f"Unknown tool: {name}")
|
230
|
-
|
231
242
|
if "database" not in arguments:
|
232
243
|
raise ConfigurationError("Database configuration name must be specified")
|
233
244
|
|
234
|
-
sql = arguments.get("sql", "").strip()
|
235
|
-
if not sql:
|
236
|
-
raise ConfigurationError("SQL query cannot be empty")
|
237
|
-
|
238
|
-
# Only allow SELECT statements
|
239
|
-
if not sql.lower().startswith("select"):
|
240
|
-
raise ConfigurationError("Only SELECT queries are supported for security reasons")
|
241
|
-
|
242
245
|
database = arguments["database"]
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
+
|
247
|
+
if name == "list_tables":
|
248
|
+
async with self.get_handler(database) as handler:
|
249
|
+
tables = await handler.get_tables()
|
250
|
+
if not tables:
|
251
|
+
# 空表列表的情况也返回数据库类型
|
252
|
+
return [types.TextContent(type="text", text=f"[{handler.db_type}] No tables found")]
|
253
|
+
|
254
|
+
formatted_tables = "\n".join([
|
255
|
+
f"Table: {table.name}\n" +
|
256
|
+
f"URI: {table.uri}\n" +
|
257
|
+
(f"Description: {table.description}\n" if table.description else "") +
|
258
|
+
"---"
|
259
|
+
for table in tables
|
260
|
+
])
|
261
|
+
# 添加数据库类型前缀
|
262
|
+
return [types.TextContent(type="text", text=f"[{handler.db_type}]\n{formatted_tables}")]
|
263
|
+
elif name == "query":
|
264
|
+
sql = arguments.get("sql", "").strip()
|
265
|
+
if not sql:
|
266
|
+
raise ConfigurationError("SQL query cannot be empty")
|
267
|
+
|
268
|
+
# Only allow SELECT statements
|
269
|
+
if not sql.lower().startswith("select"):
|
270
|
+
raise ConfigurationError("Only SELECT queries are supported for security reasons")
|
271
|
+
|
272
|
+
async with self.get_handler(database) as handler:
|
273
|
+
result = await handler.execute_query(sql)
|
274
|
+
return [types.TextContent(type="text", text=result)]
|
275
|
+
else:
|
276
|
+
raise ConfigurationError(f"Unknown tool: {name}")
|
246
277
|
|
247
278
|
async def run(self):
|
248
279
|
"""Run server"""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: mcp-dbutils
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.0
|
4
4
|
Summary: MCP Database Utilities Service
|
5
5
|
Author: Dong Hao
|
6
6
|
License-Expression: MIT
|
@@ -39,6 +39,7 @@ MCP Database Utilities is a unified database access service that supports multip
|
|
39
39
|
- Support for multiple database configurations
|
40
40
|
- Secure read-only query execution
|
41
41
|
- Table structure and schema information retrieval
|
42
|
+
- Database tables listing via MCP tools
|
42
43
|
- Intelligent connection management and resource cleanup
|
43
44
|
- Debug mode support
|
44
45
|
|
@@ -165,16 +166,31 @@ databases:
|
|
165
166
|
user: postgres # Credentials must be provided separately
|
166
167
|
password: secret # Not included in JDBC URL for security
|
167
168
|
|
168
|
-
# SQLite
|
169
|
+
# SQLite standard configuration
|
169
170
|
my_sqlite:
|
170
171
|
type: sqlite
|
171
|
-
path: /app/sqlite.db #
|
172
|
+
path: /app/sqlite.db # Database file path
|
172
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
|
173
180
|
```
|
174
181
|
|
175
|
-
The configuration supports
|
182
|
+
The configuration supports JDBC URL format for both PostgreSQL and SQLite:
|
183
|
+
|
184
|
+
PostgreSQL:
|
176
185
|
1. Standard configuration with individual parameters
|
177
|
-
2. JDBC URL configuration with separate credentials
|
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
|
178
194
|
|
179
195
|
### Debug Mode
|
180
196
|
Set environment variable `MCP_DEBUG=1` to enable debug mode for detailed logging output.
|
@@ -277,9 +293,24 @@ except Exception as e:
|
|
277
293
|
### DatabaseServer
|
278
294
|
Core server class providing:
|
279
295
|
- Resource list retrieval
|
280
|
-
- Tool call handling
|
296
|
+
- Tool call handling (list_tables, query)
|
281
297
|
- Database handler management
|
282
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
|
+
|
283
314
|
### DatabaseHandler
|
284
315
|
Abstract base class defining interfaces:
|
285
316
|
- get_tables(): Get table resource list
|
@@ -1,5 +1,5 @@
|
|
1
1
|
mcp_dbutils/__init__.py,sha256=xcfE1spAaONAoxBYB1ZyDX8tw7nxV1PMqo_RwxLDp0A,1892
|
2
|
-
mcp_dbutils/base.py,sha256=
|
2
|
+
mcp_dbutils/base.py,sha256=aawU0mY78Ga8YhSYvzOaBi1V8qSYTWyAuZzmXTc37Rg,11232
|
3
3
|
mcp_dbutils/config.py,sha256=EwnPNuQVCBKd5WOXQfROyDTM-YpM_Odp0GhCPRg8YwE,1863
|
4
4
|
mcp_dbutils/log.py,sha256=fibVIwsb1HVU5zriGrDZTMEirKjgIuxuN_B_YTdAJ7I,996
|
5
5
|
mcp_dbutils/stats.py,sha256=2hiKi_M8V4xhVHlH5FS-Df5GuMEpuzif12C8ik06Khs,2538
|
@@ -11,8 +11,8 @@ mcp_dbutils/sqlite/__init__.py,sha256=QV4th2ywzUmCCa3GHCcBf8blJ_E8OYy0dJ2fSf1TfS
|
|
11
11
|
mcp_dbutils/sqlite/config.py,sha256=RTHT2Xx--g-osD73CpT8DrCk0VHpHfPil3D6YUzXD-g,4519
|
12
12
|
mcp_dbutils/sqlite/handler.py,sha256=bf_k93rCcJn09zc7tsqrlbiTGUg3FspimfWKxK_JQTs,4970
|
13
13
|
mcp_dbutils/sqlite/server.py,sha256=7Bbq9l7Ca_4dzkAbbdRcXxvHoO_NFLzZHwlhKB0HIJc,7724
|
14
|
-
mcp_dbutils-0.
|
15
|
-
mcp_dbutils-0.
|
16
|
-
mcp_dbutils-0.
|
17
|
-
mcp_dbutils-0.
|
18
|
-
mcp_dbutils-0.
|
14
|
+
mcp_dbutils-0.7.0.dist-info/METADATA,sha256=smgCaufFbIkvOFhDGqrajHYC9WxeQcDCWRerr_bxHp8,10840
|
15
|
+
mcp_dbutils-0.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
mcp_dbutils-0.7.0.dist-info/entry_points.txt,sha256=XTjt0QmYRgKOJQT6skR9bp1EMUfIrgpHeZJPZ3CJffs,49
|
17
|
+
mcp_dbutils-0.7.0.dist-info/licenses/LICENSE,sha256=1A_CwpWVlbjrKdVEYO77vYfnXlW7oxcilZ8FpA_BzCI,1065
|
18
|
+
mcp_dbutils-0.7.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|