kingbase-mcp-server 1.0.0

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.
package/TOOLS.md ADDED
@@ -0,0 +1,366 @@
1
+ # KingBase MCP Server - Tool Reference
2
+
3
+ This is the auto-generated reference for all available tools in the KingBase MCP Server.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Read-Only Tools](#read-only-tools) (8 tools)
8
+ - [Write Tools](#write-tools) (3 tools)
9
+
10
+ ## Overview
11
+
12
+ **Total Tools**: 11
13
+
14
+ The KingBase MCP Server exposes database tools in two categories:
15
+ - **Read-Only Tools**: Safe to use in any context, no data modification
16
+ - **Write Tools**: Modify database state, require proper access permissions
17
+
18
+ ---
19
+
20
+ ## Read-Only Tools
21
+
22
+ Read-only tools are safe for querying and inspecting the database without making changes.
23
+
24
+ ### 🔒 kb_query
25
+
26
+ **Title**: Execute Query
27
+
28
+ **Description**:
29
+ Execute a read-only SQL query (SELECT/WITH/SHOW) against the KingBase database.
30
+
31
+ Returns query results as a formatted table. Use parameterized queries ($1, $2, ...) for safe value substitution.
32
+
33
+ Only read-only statements are allowed. For INSERT/UPDATE/DELETE use kb_execute; for DDL use kb_execute_ddl.
34
+
35
+ 🔑 Auto-schema feature: Unqualified table names (without schema prefix) are automatically qualified with the configured schema (DB_SCHEMA env var). You can optionally override this with the 'schema' parameter.
36
+
37
+ Args:
38
+ - sql (string): The SELECT query to execute
39
+ - params (array, optional): Parameter values for $1, $2, ... placeholders
40
+ - schema (string, optional): Override the default schema for auto-qualifying table names
41
+
42
+ Returns:
43
+ Formatted table of query results with row count.
44
+
45
+ Examples:
46
+ - sql: "SELECT * FROM biz_cm_attachment LIMIT 5" (auto-qualified with configured schema)
47
+ - sql: "SELECT * FROM users WHERE status = $1", params: ["active"]
48
+ - sql: "SELECT * FROM public.sys_user" (explicit schema, not auto-qualified)
49
+
50
+ **Annotations**:
51
+ - Read-Only: ✓
52
+ - Destructive: ✗
53
+ - Idempotent: ✓
54
+ - Open World: ✗
55
+
56
+ ### 🔒 kb_list_schemas
57
+
58
+ **Title**: List Schemas
59
+
60
+ **Description**:
61
+ List all schemas in the KingBase database.
62
+
63
+ Returns schema names excluding internal PostgreSQL/KingBase system schemas.
64
+
65
+ Args: None
66
+
67
+ Returns:
68
+ List of schema names with their owners.
69
+
70
+ **Annotations**:
71
+ - Read-Only: ✓
72
+ - Destructive: ✗
73
+ - Idempotent: ✓
74
+ - Open World: ✗
75
+
76
+ ### 🔒 kb_list_tables
77
+
78
+ **Title**: List Tables
79
+
80
+ **Description**:
81
+ List all tables and/or views in a schema.
82
+
83
+ Args:
84
+ - schema (string, optional): Schema name, defaults to DB_SCHEMA env or 'public'
85
+ - type ('table' | 'view' | 'all'): Filter by type (default: 'all')
86
+
87
+ Returns:
88
+ List of tables/views with their type, owner, and estimated row count.
89
+
90
+ **Annotations**:
91
+ - Read-Only: ✓
92
+ - Destructive: ✗
93
+ - Idempotent: ✓
94
+ - Open World: ✗
95
+
96
+ ### 🔒 kb_describe_table
97
+
98
+ **Title**: Describe Table
99
+
100
+ **Description**:
101
+ Get detailed structure of a table or view, including columns, types, constraints, and comments.
102
+
103
+ Args:
104
+ - table (string): Table or view name
105
+ - schema (string, optional): Schema name, defaults to DB_SCHEMA env or 'public'
106
+
107
+ Returns:
108
+ Table structure with column names, data types, nullable, defaults, and comments.
109
+
110
+ **Annotations**:
111
+ - Read-Only: ✓
112
+ - Destructive: ✗
113
+ - Idempotent: ✓
114
+ - Open World: ✗
115
+
116
+ ### 🔒 kb_list_indexes
117
+
118
+ **Title**: List Indexes
119
+
120
+ **Description**:
121
+ List all indexes on a table including columns, uniqueness, and index type.
122
+
123
+ Args:
124
+ - table (string): Table name
125
+ - schema (string, optional): Schema name, defaults to DB_SCHEMA env or 'public'
126
+
127
+ Returns:
128
+ List of indexes with name, columns, uniqueness, and method (btree/hash/gin/gist).
129
+
130
+ **Annotations**:
131
+ - Read-Only: ✓
132
+ - Destructive: ✗
133
+ - Idempotent: ✓
134
+ - Open World: ✗
135
+
136
+ ### 🔒 kb_list_constraints
137
+
138
+ **Title**: List Constraints
139
+
140
+ **Description**:
141
+ List all constraints (PK, FK, UNIQUE, CHECK) on a table.
142
+
143
+ Args:
144
+ - table (string): Table name
145
+ - schema (string, optional): Schema name, defaults to DB_SCHEMA env or 'public'
146
+
147
+ Returns:
148
+ List of constraints with name, type, columns, and referenced table (for FK).
149
+
150
+ **Annotations**:
151
+ - Read-Only: ✓
152
+ - Destructive: ✗
153
+ - Idempotent: ✓
154
+ - Open World: ✗
155
+
156
+ ### 🔒 kb_table_data
157
+
158
+ **Title**: Preview Table Data
159
+
160
+ **Description**:
161
+ Preview data from a table with optional filtering and pagination.
162
+
163
+ A convenient shortcut for common SELECT operations without writing full SQL.
164
+
165
+ Args:
166
+ - table (string): Table name
167
+ - schema (string, optional): Schema name, defaults to DB_SCHEMA env or 'public'
168
+ - limit (number, default 100, max 1000): Number of rows
169
+ - offset (number, default 0): Rows to skip
170
+ - where (string, optional): WHERE condition (without WHERE keyword)
171
+ - order_by (string, optional): ORDER BY clause (without ORDER BY keyword)
172
+
173
+ Returns:
174
+ Formatted table of row data with total count.
175
+
176
+ Examples:
177
+ - table: "users", limit: 10, where: "status = 'active'", order_by: "created_at DESC"
178
+ - table: "orders", limit: 50, offset: 100
179
+
180
+ **Annotations**:
181
+ - Read-Only: ✓
182
+ - Destructive: ✗
183
+ - Idempotent: ✓
184
+ - Open World: ✗
185
+
186
+ ### 🔒 kb_table_stats
187
+
188
+ **Title**: Table Statistics
189
+
190
+ **Description**:
191
+ Get storage and usage statistics for a table, including row count, size, and dead tuples.
192
+
193
+ Args:
194
+ - table (string): Table name
195
+ - schema (string, optional): Schema name, defaults to DB_SCHEMA env or 'public'
196
+
197
+ Returns:
198
+ Table size, row count, index size, dead tuples, and last vacuum/analyze times.
199
+
200
+ **Annotations**:
201
+ - Read-Only: ✓
202
+ - Destructive: ✗
203
+ - Idempotent: ✓
204
+ - Open World: ✗
205
+
206
+ ---
207
+
208
+ ## Write Tools
209
+
210
+ Write tools modify database state and require appropriate access permissions via the `ACCESS_MODE` environment variable.
211
+
212
+ ### ✏️ kb_execute
213
+
214
+ **Title**: Execute DML
215
+
216
+ **Description**:
217
+ Execute a DML statement (INSERT, UPDATE, DELETE) against the KingBase database.
218
+
219
+ Returns the number of affected rows. Use parameterized queries ($1, $2, ...) for safe value substitution.
220
+
221
+ 🔑 Auto-schema feature: Unqualified table names (without schema prefix) are automatically qualified with the configured schema (DB_SCHEMA env var). You can optionally override this with the 'schema' parameter.
222
+
223
+ Args:
224
+ - sql (string): The DML statement to execute
225
+ - params (array, optional): Parameter values for $1, $2, ... placeholders
226
+ - schema (string, optional): Override the default schema for auto-qualifying table names
227
+
228
+ Returns:
229
+ Number of rows affected by the operation.
230
+
231
+ Examples:
232
+ - sql: "UPDATE users SET status = $1 WHERE id = $2", params: ["inactive", 123]
233
+ - sql: "INSERT INTO users (name, email) VALUES ($1, $2)", params: ["John", "john@example.com"]
234
+ - sql: "DELETE FROM logs WHERE created_at < $1", params: ["2024-01-01"]
235
+
236
+ **Annotations**:
237
+ - Read-Only: ✗
238
+ - Destructive: ✓
239
+ - Idempotent: ✗
240
+ - Open World: ✗
241
+
242
+ ### ✏️ kb_execute_ddl
243
+
244
+ **Title**: Execute DDL
245
+
246
+ **Description**:
247
+ Execute a DDL statement (CREATE, ALTER, DROP, TRUNCATE, etc.) against the KingBase database.
248
+
249
+ WARNING: DDL operations modify database structure and can be destructive. DROP and TRUNCATE operations are irreversible.
250
+
251
+ 🔑 Auto-schema feature: Unqualified table names (without schema prefix) are automatically qualified with the configured schema (DB_SCHEMA env var). You can optionally override this with the 'schema' parameter.
252
+
253
+ Args:
254
+ - sql (string): The DDL statement to execute
255
+ - schema (string, optional): Override the default schema for auto-qualifying table names
256
+
257
+ Returns:
258
+ Confirmation message. For dangerous operations (DROP/TRUNCATE/CASCADE), a warning is included.
259
+
260
+ Examples:
261
+ - sql: "CREATE TABLE test (id SERIAL PRIMARY KEY, name VARCHAR(100))"
262
+ - sql: "ALTER TABLE users ADD COLUMN phone VARCHAR(20)"
263
+ - sql: "CREATE INDEX idx_users_email ON users(email)"
264
+
265
+ **Annotations**:
266
+ - Read-Only: ✗
267
+ - Destructive: ✓
268
+ - Idempotent: ✗
269
+ - Open World: ✗
270
+
271
+ ### ✏️ kb_explain
272
+
273
+ **Title**: Explain Query
274
+
275
+ **Description**:
276
+ Get the execution plan for a SQL query using EXPLAIN.
277
+
278
+ Use this to analyze query performance, identify full table scans, and optimize queries.
279
+
280
+ Args:
281
+ - sql (string): The SQL query to explain
282
+ - analyze (boolean, default false): If true, actually executes the query (EXPLAIN ANALYZE) for real timing data
283
+ - format ('text' | 'json' | 'yaml'): Output format (default: 'text')
284
+
285
+ Returns:
286
+ Query execution plan showing scan types, costs, and join strategies.
287
+
288
+ Examples:
289
+ - sql: "SELECT * FROM users WHERE email = 'test@example.com'"
290
+ - sql: "SELECT u.*, o.* FROM users u JOIN orders o ON u.id = o.user_id", analyze: true
291
+
292
+ **Annotations**:
293
+ - Read-Only: ✗
294
+ - Destructive: ✗
295
+ - Idempotent: ✓
296
+ - Open World: ✗
297
+
298
+ ---
299
+
300
+ ## Environment Variables
301
+
302
+ Configure these environment variables to control access and behavior:
303
+
304
+ ### Database Connection
305
+ - `DB_HOST` (default: `localhost`) - Database host
306
+ - `DB_PORT` (default: `54321`) - Database port
307
+ - `DB_USER` (default: `system`) - Database user
308
+ - `DB_PASSWORD` - Database password (required)
309
+ - `DB_NAME` (default: `kingbase`) - Database name
310
+ - `DB_SCHEMA` (default: `public`) - Default schema for table operations
311
+
312
+ ### Access Control
313
+ - `ACCESS_MODE` (default: `readonly`) - Permission level
314
+ - `readonly` - Only read-only tools
315
+ - `readwrite` - readonly + INSERT/UPDATE
316
+ - `full` - readwrite + DELETE
317
+ - `admin` - full + DDL operations
318
+
319
+ ### HTTP Transport (when `TRANSPORT=http`)
320
+ - `TRANSPORT` (default: `stdio`) - Set to `http` for HTTP transport mode
321
+ - `MCP_HOST` (default: `0.0.0.0`) - HTTP server bind address
322
+ - `MCP_PORT` (default: `3000`) - HTTP server port
323
+
324
+ ---
325
+
326
+ ## API Endpoints (HTTP Mode)
327
+
328
+ When running in HTTP mode (`TRANSPORT=http`), these endpoints are available:
329
+
330
+ ### Health Check
331
+ ```
332
+ GET /health
333
+ ```
334
+
335
+ Returns server health status and active session count.
336
+
337
+ ### Tool Discovery
338
+ ```
339
+ GET /tools
340
+ ```
341
+
342
+ List all available tools with summary information.
343
+
344
+ ```
345
+ GET /tools/{toolName}
346
+ ```
347
+
348
+ Get detailed information about a specific tool, including full JSON schema.
349
+
350
+ ### MCP Protocol Endpoint
351
+ ```
352
+ POST /mcp
353
+ PUT /mcp
354
+ DELETE /mcp
355
+ ```
356
+
357
+ MCP protocol endpoints for tool invocation.
358
+
359
+ ---
360
+
361
+ ## Notes
362
+
363
+ - All SQL parameters use PostgreSQL parameterized query syntax (`$1`, `$2`, etc.)
364
+ - Table names without schema prefix are automatically qualified with the configured schema
365
+ - Two-phase confirmation is required for DML (`kb_execute`) and DDL (`kb_execute_ddl`) operations
366
+ - Output is truncated at 50,000 characters
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * KingBase MCP Server
4
+ *
5
+ * Provides tools to interact with KingBase (PostgreSQL-compatible) databases,
6
+ * including query execution, DDL operations, schema inspection, and more.
7
+ */
8
+ import "dotenv/config";