@conte777/db-view-mcp 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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +341 -0
  3. package/config.example.json +41 -0
  4. package/dist/config/loader.d.ts +6 -0
  5. package/dist/config/loader.js +28 -0
  6. package/dist/config/loader.js.map +1 -0
  7. package/dist/config/types.d.ts +149 -0
  8. package/dist/config/types.js +73 -0
  9. package/dist/config/types.js.map +1 -0
  10. package/dist/connectors/clickhouse.d.ts +20 -0
  11. package/dist/connectors/clickhouse.js +95 -0
  12. package/dist/connectors/clickhouse.js.map +1 -0
  13. package/dist/connectors/interface.d.ts +37 -0
  14. package/dist/connectors/interface.js +2 -0
  15. package/dist/connectors/interface.js.map +1 -0
  16. package/dist/connectors/manager.d.ts +14 -0
  17. package/dist/connectors/manager.js +51 -0
  18. package/dist/connectors/manager.js.map +1 -0
  19. package/dist/connectors/postgresql.d.ts +20 -0
  20. package/dist/connectors/postgresql.js +138 -0
  21. package/dist/connectors/postgresql.js.map +1 -0
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.js +43 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/server.d.ts +9 -0
  26. package/dist/server.js +23 -0
  27. package/dist/server.js.map +1 -0
  28. package/dist/tools/readonly/describe-table.d.ts +19 -0
  29. package/dist/tools/readonly/describe-table.js +22 -0
  30. package/dist/tools/readonly/describe-table.js.map +1 -0
  31. package/dist/tools/readonly/explain.d.ts +17 -0
  32. package/dist/tools/readonly/explain.js +26 -0
  33. package/dist/tools/readonly/explain.js.map +1 -0
  34. package/dist/tools/readonly/list-databases.d.ts +7 -0
  35. package/dist/tools/readonly/list-databases.js +12 -0
  36. package/dist/tools/readonly/list-databases.js.map +1 -0
  37. package/dist/tools/readonly/list-tables.d.ts +17 -0
  38. package/dist/tools/readonly/list-tables.js +21 -0
  39. package/dist/tools/readonly/list-tables.js.map +1 -0
  40. package/dist/tools/readonly/performance.d.ts +43 -0
  41. package/dist/tools/readonly/performance.js +72 -0
  42. package/dist/tools/readonly/performance.js.map +1 -0
  43. package/dist/tools/readonly/query.d.ts +19 -0
  44. package/dist/tools/readonly/query.js +27 -0
  45. package/dist/tools/readonly/query.js.map +1 -0
  46. package/dist/tools/readonly/schema.d.ts +15 -0
  47. package/dist/tools/readonly/schema.js +20 -0
  48. package/dist/tools/readonly/schema.js.map +1 -0
  49. package/dist/tools/registry.d.ts +4 -0
  50. package/dist/tools/registry.js +56 -0
  51. package/dist/tools/registry.js.map +1 -0
  52. package/dist/tools/write/execute.d.ts +19 -0
  53. package/dist/tools/write/execute.js +26 -0
  54. package/dist/tools/write/execute.js.map +1 -0
  55. package/dist/tools/write/transaction.d.ts +28 -0
  56. package/dist/tools/write/transaction.js +76 -0
  57. package/dist/tools/write/transaction.js.map +1 -0
  58. package/dist/transport/http.d.ts +15 -0
  59. package/dist/transport/http.js +96 -0
  60. package/dist/transport/http.js.map +1 -0
  61. package/dist/utils/response.d.ts +31 -0
  62. package/dist/utils/response.js +25 -0
  63. package/dist/utils/response.js.map +1 -0
  64. package/dist/utils/sql-validator.d.ts +5 -0
  65. package/dist/utils/sql-validator.js +36 -0
  66. package/dist/utils/sql-validator.js.map +1 -0
  67. package/package.json +41 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 conte777
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.
package/README.md ADDED
@@ -0,0 +1,341 @@
1
+ # db-view-mcp
2
+
3
+ MCP server that gives AI assistants direct access to PostgreSQL and ClickHouse databases. Supports stdio and HTTP transports, allowing both local IDE integration and remote network access.
4
+
5
+ ## Features
6
+
7
+ - **Multi-database** — connect to any number of PostgreSQL and ClickHouse instances simultaneously
8
+ - **Dual transport** — stdio for IDE integration (Cursor, Claude Code), HTTP for remote/multi-client access
9
+ - **Read & write tools** — SELECT queries with row limits, INSERT/UPDATE/DELETE, DDL, transactions
10
+ - **Schema introspection** — list tables, describe columns, export full DDL
11
+ - **Query analysis** — EXPLAIN ANALYZE support, slow query tracking
12
+ - **SQL safety** — read-only tools validate SQL to block accidental writes
13
+ - **Flexible tool modes** — single tool with `database` parameter, or separate tool per database
14
+ - **Lazy connections** — databases connect on first use by default
15
+ - **Bearer auth** — optional token-based authentication for HTTP transport
16
+ - **Session management** — stateful (per-session MCP server) or stateless HTTP mode
17
+
18
+ ## Quick start
19
+
20
+ ### Install
21
+
22
+ ```bash
23
+ npm install @conte777/db-view-mcp
24
+ ```
25
+
26
+ Or clone and build from source:
27
+
28
+ ```bash
29
+ git clone <repo-url>
30
+ cd db-view-mcp
31
+ npm install
32
+ npm run build
33
+ ```
34
+
35
+ ### Configure
36
+
37
+ Copy the example config and edit it:
38
+
39
+ ```bash
40
+ cp config.example.json config.json
41
+ ```
42
+
43
+ Minimal config (stdio, default):
44
+
45
+ ```json
46
+ {
47
+ "databases": [
48
+ {
49
+ "id": "main_pg",
50
+ "type": "postgresql",
51
+ "host": "localhost",
52
+ "port": 5432,
53
+ "database": "myapp",
54
+ "user": "admin",
55
+ "password": "secret123"
56
+ }
57
+ ]
58
+ }
59
+ ```
60
+
61
+ HTTP transport config:
62
+
63
+ ```json
64
+ {
65
+ "transport": {
66
+ "type": "http",
67
+ "port": 3000,
68
+ "host": "127.0.0.1",
69
+ "stateless": false,
70
+ "auth": {
71
+ "type": "bearer",
72
+ "token": "your-secret-token"
73
+ }
74
+ },
75
+ "databases": [
76
+ {
77
+ "id": "main_pg",
78
+ "type": "postgresql",
79
+ "host": "localhost",
80
+ "port": 5432,
81
+ "database": "myapp",
82
+ "user": "admin",
83
+ "password": "secret123"
84
+ }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ ### Run
90
+
91
+ ```bash
92
+ # Stdio (default)
93
+ npm start -- --config config.json
94
+
95
+ # HTTP via config (set transport.type to "http" in config.json)
96
+ npm start -- --config config.json
97
+
98
+ # HTTP via CLI flag (overrides config)
99
+ npm start -- --config config.json --transport http
100
+
101
+ # Development (no build needed)
102
+ npm run dev -- --config config.json
103
+ ```
104
+
105
+ ### Add to your MCP client
106
+
107
+ **Claude Desktop** (`claude_desktop_config.json`) — stdio:
108
+
109
+ ```json
110
+ {
111
+ "mcpServers": {
112
+ "database": {
113
+ "command": "npx",
114
+ "args": ["-y", "@conte777/db-view-mcp", "--config", "/path/to/config.json"]
115
+ }
116
+ }
117
+ }
118
+ ```
119
+
120
+ **Claude Code** (`.mcp.json`) — stdio:
121
+
122
+ ```json
123
+ {
124
+ "mcpServers": {
125
+ "database": {
126
+ "command": "npx",
127
+ "args": ["-y", "@conte777/db-view-mcp", "--config", "/path/to/config.json"]
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ **Any MCP client** — HTTP:
134
+
135
+ ```bash
136
+ # Start the server
137
+ node dist/index.js --config config.json --transport http
138
+ # Server listens on http://127.0.0.1:3000/mcp
139
+ ```
140
+
141
+ ## Transport modes
142
+
143
+ ### Stdio (default)
144
+
145
+ Communication via stdin/stdout. Best for local IDE integrations where the MCP client spawns the server process.
146
+
147
+ ### HTTP
148
+
149
+ Uses the MCP Streamable HTTP transport (`POST/GET/DELETE /mcp`). Best for:
150
+ - Remote access over the network
151
+ - Multiple clients connecting simultaneously
152
+ - Web application integrations
153
+
154
+ **Stateful mode** (default): each MCP session gets its own `McpServer` instance with a unique session ID. All sessions share database connection pools. Supports transactions across requests within the same session.
155
+
156
+ **Stateless mode** (`"stateless": true`): no session management. Each request is independent. Suitable for simple query scenarios without transactions.
157
+
158
+ #### HTTP endpoints
159
+
160
+ | Method | Path | Description |
161
+ |--------|------|-------------|
162
+ | `POST` | `/mcp` | Send JSON-RPC requests (initialize, tools/call, etc.) |
163
+ | `GET` | `/mcp` | SSE stream for server-to-client notifications |
164
+ | `DELETE` | `/mcp` | Close a session |
165
+ | `GET` | `/health` | Health check — status, active sessions, database list |
166
+
167
+ #### Authentication
168
+
169
+ Optional bearer token authentication:
170
+
171
+ ```json
172
+ {
173
+ "transport": {
174
+ "type": "http",
175
+ "auth": {
176
+ "type": "bearer",
177
+ "token": "your-secret-token"
178
+ }
179
+ }
180
+ }
181
+ ```
182
+
183
+ Requests to `/mcp` must include `Authorization: Bearer your-secret-token`. Requests without a valid token receive `401 Unauthorized`. The `/health` endpoint is not protected.
184
+
185
+ #### Example: initialize a session
186
+
187
+ ```bash
188
+ curl -X POST http://localhost:3000/mcp \
189
+ -H "Content-Type: application/json" \
190
+ -H "Accept: application/json, text/event-stream" \
191
+ -H "Authorization: Bearer your-secret-token" \
192
+ -d '{
193
+ "jsonrpc": "2.0",
194
+ "id": 1,
195
+ "method": "initialize",
196
+ "params": {
197
+ "protocolVersion": "2025-03-26",
198
+ "capabilities": {},
199
+ "clientInfo": { "name": "test", "version": "1.0" }
200
+ }
201
+ }'
202
+ ```
203
+
204
+ The response includes a `Mcp-Session-Id` header. Use it in subsequent requests:
205
+
206
+ ```bash
207
+ curl -X POST http://localhost:3000/mcp \
208
+ -H "Content-Type: application/json" \
209
+ -H "Accept: application/json, text/event-stream" \
210
+ -H "Authorization: Bearer your-secret-token" \
211
+ -H "Mcp-Session-Id: <session-id-from-init>" \
212
+ -d '{
213
+ "jsonrpc": "2.0",
214
+ "id": 2,
215
+ "method": "tools/list",
216
+ "params": {}
217
+ }'
218
+ ```
219
+
220
+ ## Tools
221
+
222
+ ### Read-only
223
+
224
+ | Tool | Description |
225
+ |------|-------------|
226
+ | `query` | Execute a SELECT query with automatic row limit |
227
+ | `list_databases` | List all configured database connections |
228
+ | `list_tables` | List tables and views in a schema |
229
+ | `describe_table` | Get column names, types, nullability, and primary keys |
230
+ | `schema` | Export full DDL for a database |
231
+ | `explain_query` | Run EXPLAIN ANALYZE (PostgreSQL) or EXPLAIN (ClickHouse) |
232
+ | `performance` | Track and retrieve slow queries, set thresholds |
233
+
234
+ ### Write
235
+
236
+ | Tool | Description |
237
+ |------|-------------|
238
+ | `execute` | Run INSERT, UPDATE, DELETE, or DDL statements |
239
+ | `transaction` | Begin, execute within, commit, or rollback transactions (PostgreSQL only) |
240
+
241
+ ## Configuration
242
+
243
+ ### Transport
244
+
245
+ | Field | Type | Default | Description |
246
+ |-------|------|---------|-------------|
247
+ | `transport.type` | `"stdio"` \| `"http"` | `"stdio"` | Transport mode |
248
+ | `transport.port` | number | `3000` | HTTP listen port |
249
+ | `transport.host` | string | `"127.0.0.1"` | HTTP bind address |
250
+ | `transport.stateless` | boolean | `false` | Disable session management |
251
+ | `transport.auth.type` | `"bearer"` | — | Authentication type |
252
+ | `transport.auth.token` | string | — | Bearer token value |
253
+
254
+ The `transport` field is optional. When omitted, stdio is used. The `--transport` CLI flag overrides the config value.
255
+
256
+ ### Defaults
257
+
258
+ | Option | Type | Default | Description |
259
+ |--------|------|---------|-------------|
260
+ | `maxRows` | number | `100` | Maximum rows returned by `query` |
261
+ | `lazyConnection` | boolean | `true` | Connect on first use instead of at startup |
262
+ | `toolsPerDatabase` | boolean | `false` | Register separate tools per database (e.g. `query_main_pg`) |
263
+ | `queryTimeout` | number | `30000` | Query timeout in milliseconds |
264
+
265
+ ### PostgreSQL database
266
+
267
+ | Field | Required | Default | Description |
268
+ |-------|----------|---------|-------------|
269
+ | `id` | yes | — | Unique identifier |
270
+ | `type` | yes | — | Must be `"postgresql"` |
271
+ | `host` | yes | — | Hostname |
272
+ | `port` | no | `5432` | Port |
273
+ | `database` | yes | — | Database name |
274
+ | `user` | yes | — | Username |
275
+ | `password` | no | `""` | Password |
276
+ | `ssl` | no | — | Enable SSL |
277
+ | `description` | no | — | Human-readable label |
278
+ | `lazyConnection` | no | inherits | Override default |
279
+ | `maxRows` | no | inherits | Override default |
280
+ | `queryTimeout` | no | inherits | Override default |
281
+
282
+ ### ClickHouse database
283
+
284
+ | Field | Required | Default | Description |
285
+ |-------|----------|---------|-------------|
286
+ | `id` | yes | — | Unique identifier |
287
+ | `type` | yes | — | Must be `"clickhouse"` |
288
+ | `url` | yes | — | HTTP URL (e.g. `http://localhost:8123`) |
289
+ | `database` | yes | — | Database name |
290
+ | `user` | no | `"default"` | Username |
291
+ | `password` | no | `""` | Password |
292
+ | `description` | no | — | Human-readable label |
293
+ | `lazyConnection` | no | inherits | Override default |
294
+ | `maxRows` | no | inherits | Override default |
295
+ | `queryTimeout` | no | inherits | Override default |
296
+
297
+ ### Per-database tool mode
298
+
299
+ Set `"toolsPerDatabase": true` in defaults to register a separate tool for each database. Instead of a single `query` tool with a `database` parameter, you get `query_main_pg`, `query_analytics`, etc. Useful when connecting many databases to avoid parameter confusion.
300
+
301
+ ## Architecture
302
+
303
+ ```
304
+ src/
305
+ ├── index.ts Entry point: CLI args → config → transport routing
306
+ ├── server.ts Creates McpServer + ConnectorManager, registers tools
307
+ ├── config/
308
+ │ ├── types.ts Zod schemas for config validation (transport, databases)
309
+ │ └── loader.ts Reads config file, parses CLI args (--config, --transport)
310
+ ├── connectors/
311
+ │ ├── interface.ts Connector interface and shared types
312
+ │ ├── manager.ts Connector lifecycle (lazy/eager, create, disconnect)
313
+ │ ├── postgresql.ts PostgreSQL implementation (pg)
314
+ │ └── clickhouse.ts ClickHouse implementation (@clickhouse/client)
315
+ ├── tools/
316
+ │ ├── registry.ts Registers tools in parameter or per-database mode
317
+ │ ├── readonly/ query, list-tables, describe-table, schema, explain, performance
318
+ │ └── write/ execute, transaction
319
+ ├── transport/
320
+ │ └── http.ts HTTP transport: Express app, session management, auth
321
+ └── utils/
322
+ ├── response.ts Standardized MCP response formatting
323
+ └── sql-validator.ts Blocks write keywords in read-only queries
324
+ ```
325
+
326
+ ## ClickHouse limitations
327
+
328
+ - Transactions are not supported (throws an error)
329
+ - Query parameters via `params` are ignored — use ClickHouse's native `{name:Type}` syntax in SQL
330
+
331
+ ## Development
332
+
333
+ ```bash
334
+ npm run dev -- --config config.json # Run with tsx, auto-reload
335
+ npm run build # Compile TypeScript to dist/
336
+ npm start -- --config config.json # Run compiled output
337
+ ```
338
+
339
+ ## License
340
+
341
+ MIT
@@ -0,0 +1,41 @@
1
+ {
2
+ "transport": {
3
+ "type": "http",
4
+ "port": 3000,
5
+ "host": "127.0.0.1",
6
+ "stateless": false,
7
+ "auth": {
8
+ "type": "bearer",
9
+ "token": "your-secret-token"
10
+ }
11
+ },
12
+ "defaults": {
13
+ "maxRows": 100,
14
+ "lazyConnection": true,
15
+ "toolsPerDatabase": false,
16
+ "queryTimeout": 30000
17
+ },
18
+ "databases": [
19
+ {
20
+ "id": "main_pg",
21
+ "type": "postgresql",
22
+ "host": "localhost",
23
+ "port": 5432,
24
+ "database": "myapp",
25
+ "user": "admin",
26
+ "password": "secret123",
27
+ "description": "Main PostgreSQL",
28
+ "lazyConnection": true,
29
+ "maxRows": 200
30
+ },
31
+ {
32
+ "id": "analytics",
33
+ "type": "clickhouse",
34
+ "url": "http://localhost:8123",
35
+ "database": "analytics",
36
+ "user": "default",
37
+ "password": "",
38
+ "description": "ClickHouse analytics"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,6 @@
1
+ import { type AppConfig } from "./types.js";
2
+ export declare function loadConfig(configPath: string): AppConfig;
3
+ export declare function parseCliArgs(args: string[]): {
4
+ configPath: string;
5
+ transport?: "stdio" | "http";
6
+ };
@@ -0,0 +1,28 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { AppConfigSchema } from "./types.js";
4
+ export function loadConfig(configPath) {
5
+ const absolutePath = resolve(configPath);
6
+ const raw = readFileSync(absolutePath, "utf-8");
7
+ const json = JSON.parse(raw);
8
+ return AppConfigSchema.parse(json);
9
+ }
10
+ export function parseCliArgs(args) {
11
+ const configIndex = args.indexOf("--config");
12
+ if (configIndex === -1 || configIndex + 1 >= args.length) {
13
+ throw new Error("Usage: db-view-mcp --config <path-to-config.json> [--transport stdio|http]");
14
+ }
15
+ const result = {
16
+ configPath: args[configIndex + 1],
17
+ };
18
+ const transportIndex = args.indexOf("--transport");
19
+ if (transportIndex !== -1 && transportIndex + 1 < args.length) {
20
+ const value = args[transportIndex + 1];
21
+ if (value !== "stdio" && value !== "http") {
22
+ throw new Error(`Invalid transport: "${value}". Must be "stdio" or "http".`);
23
+ }
24
+ result.transport = value;
25
+ }
26
+ return result;
27
+ }
28
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAkB,MAAM,YAAY,CAAC;AAE7D,MAAM,UAAU,UAAU,CAAC,UAAkB;IAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAc;IACzC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7C,IAAI,WAAW,KAAK,CAAC,CAAC,IAAI,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,MAAM,GAAyD;QACnE,UAAU,EAAE,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;KAClC,CAAC;IAEF,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACnD,IAAI,cAAc,KAAK,CAAC,CAAC,IAAI,cAAc,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,KAAK,+BAA+B,CAAC,CAAC;QAC/E,CAAC;QACD,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,149 @@
1
+ import { z } from "zod";
2
+ declare const PostgresConfigSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ type: z.ZodLiteral<"postgresql">;
5
+ host: z.ZodString;
6
+ port: z.ZodDefault<z.ZodNumber>;
7
+ database: z.ZodString;
8
+ user: z.ZodString;
9
+ password: z.ZodDefault<z.ZodString>;
10
+ ssl: z.ZodOptional<z.ZodBoolean>;
11
+ description: z.ZodOptional<z.ZodString>;
12
+ lazyConnection: z.ZodOptional<z.ZodBoolean>;
13
+ maxRows: z.ZodOptional<z.ZodNumber>;
14
+ queryTimeout: z.ZodOptional<z.ZodNumber>;
15
+ }, z.core.$strip>;
16
+ declare const ClickHouseConfigSchema: z.ZodObject<{
17
+ id: z.ZodString;
18
+ type: z.ZodLiteral<"clickhouse">;
19
+ url: z.ZodString;
20
+ database: z.ZodString;
21
+ user: z.ZodDefault<z.ZodString>;
22
+ password: z.ZodDefault<z.ZodString>;
23
+ description: z.ZodOptional<z.ZodString>;
24
+ lazyConnection: z.ZodOptional<z.ZodBoolean>;
25
+ maxRows: z.ZodOptional<z.ZodNumber>;
26
+ queryTimeout: z.ZodOptional<z.ZodNumber>;
27
+ }, z.core.$strip>;
28
+ declare const DatabaseConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
29
+ id: z.ZodString;
30
+ type: z.ZodLiteral<"postgresql">;
31
+ host: z.ZodString;
32
+ port: z.ZodDefault<z.ZodNumber>;
33
+ database: z.ZodString;
34
+ user: z.ZodString;
35
+ password: z.ZodDefault<z.ZodString>;
36
+ ssl: z.ZodOptional<z.ZodBoolean>;
37
+ description: z.ZodOptional<z.ZodString>;
38
+ lazyConnection: z.ZodOptional<z.ZodBoolean>;
39
+ maxRows: z.ZodOptional<z.ZodNumber>;
40
+ queryTimeout: z.ZodOptional<z.ZodNumber>;
41
+ }, z.core.$strip>, z.ZodObject<{
42
+ id: z.ZodString;
43
+ type: z.ZodLiteral<"clickhouse">;
44
+ url: z.ZodString;
45
+ database: z.ZodString;
46
+ user: z.ZodDefault<z.ZodString>;
47
+ password: z.ZodDefault<z.ZodString>;
48
+ description: z.ZodOptional<z.ZodString>;
49
+ lazyConnection: z.ZodOptional<z.ZodBoolean>;
50
+ maxRows: z.ZodOptional<z.ZodNumber>;
51
+ queryTimeout: z.ZodOptional<z.ZodNumber>;
52
+ }, z.core.$strip>], "type">;
53
+ declare const DefaultsSchema: z.ZodObject<{
54
+ maxRows: z.ZodDefault<z.ZodNumber>;
55
+ lazyConnection: z.ZodDefault<z.ZodBoolean>;
56
+ toolsPerDatabase: z.ZodDefault<z.ZodBoolean>;
57
+ queryTimeout: z.ZodDefault<z.ZodNumber>;
58
+ }, z.core.$strip>;
59
+ declare const HttpTransportConfigSchema: z.ZodObject<{
60
+ type: z.ZodLiteral<"http">;
61
+ port: z.ZodDefault<z.ZodNumber>;
62
+ host: z.ZodDefault<z.ZodString>;
63
+ stateless: z.ZodDefault<z.ZodBoolean>;
64
+ auth: z.ZodOptional<z.ZodObject<{
65
+ type: z.ZodLiteral<"bearer">;
66
+ token: z.ZodString;
67
+ }, z.core.$strip>>;
68
+ }, z.core.$strip>;
69
+ declare const TransportConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
70
+ type: z.ZodLiteral<"stdio">;
71
+ }, z.core.$strip>, z.ZodObject<{
72
+ type: z.ZodLiteral<"http">;
73
+ port: z.ZodDefault<z.ZodNumber>;
74
+ host: z.ZodDefault<z.ZodString>;
75
+ stateless: z.ZodDefault<z.ZodBoolean>;
76
+ auth: z.ZodOptional<z.ZodObject<{
77
+ type: z.ZodLiteral<"bearer">;
78
+ token: z.ZodString;
79
+ }, z.core.$strip>>;
80
+ }, z.core.$strip>], "type">;
81
+ export declare const AppConfigSchema: z.ZodObject<{
82
+ transport: z.ZodDefault<z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
83
+ type: z.ZodLiteral<"stdio">;
84
+ }, z.core.$strip>, z.ZodObject<{
85
+ type: z.ZodLiteral<"http">;
86
+ port: z.ZodDefault<z.ZodNumber>;
87
+ host: z.ZodDefault<z.ZodString>;
88
+ stateless: z.ZodDefault<z.ZodBoolean>;
89
+ auth: z.ZodOptional<z.ZodObject<{
90
+ type: z.ZodLiteral<"bearer">;
91
+ token: z.ZodString;
92
+ }, z.core.$strip>>;
93
+ }, z.core.$strip>], "type">>>;
94
+ defaults: z.ZodPipe<z.ZodOptional<z.ZodObject<{
95
+ maxRows: z.ZodDefault<z.ZodNumber>;
96
+ lazyConnection: z.ZodDefault<z.ZodBoolean>;
97
+ toolsPerDatabase: z.ZodDefault<z.ZodBoolean>;
98
+ queryTimeout: z.ZodDefault<z.ZodNumber>;
99
+ }, z.core.$strip>>, z.ZodTransform<{
100
+ maxRows: number;
101
+ lazyConnection: boolean;
102
+ toolsPerDatabase: boolean;
103
+ queryTimeout: number;
104
+ }, {
105
+ maxRows: number;
106
+ lazyConnection: boolean;
107
+ toolsPerDatabase: boolean;
108
+ queryTimeout: number;
109
+ } | undefined>>;
110
+ databases: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
111
+ id: z.ZodString;
112
+ type: z.ZodLiteral<"postgresql">;
113
+ host: z.ZodString;
114
+ port: z.ZodDefault<z.ZodNumber>;
115
+ database: z.ZodString;
116
+ user: z.ZodString;
117
+ password: z.ZodDefault<z.ZodString>;
118
+ ssl: z.ZodOptional<z.ZodBoolean>;
119
+ description: z.ZodOptional<z.ZodString>;
120
+ lazyConnection: z.ZodOptional<z.ZodBoolean>;
121
+ maxRows: z.ZodOptional<z.ZodNumber>;
122
+ queryTimeout: z.ZodOptional<z.ZodNumber>;
123
+ }, z.core.$strip>, z.ZodObject<{
124
+ id: z.ZodString;
125
+ type: z.ZodLiteral<"clickhouse">;
126
+ url: z.ZodString;
127
+ database: z.ZodString;
128
+ user: z.ZodDefault<z.ZodString>;
129
+ password: z.ZodDefault<z.ZodString>;
130
+ description: z.ZodOptional<z.ZodString>;
131
+ lazyConnection: z.ZodOptional<z.ZodBoolean>;
132
+ maxRows: z.ZodOptional<z.ZodNumber>;
133
+ queryTimeout: z.ZodOptional<z.ZodNumber>;
134
+ }, z.core.$strip>], "type">>;
135
+ }, z.core.$strip>;
136
+ export type PostgresConfig = z.infer<typeof PostgresConfigSchema>;
137
+ export type ClickHouseConfig = z.infer<typeof ClickHouseConfigSchema>;
138
+ export type DatabaseConfig = z.infer<typeof DatabaseConfigSchema>;
139
+ export type Defaults = z.infer<typeof DefaultsSchema>;
140
+ export type AppConfig = z.infer<typeof AppConfigSchema>;
141
+ export type HttpTransportConfig = z.infer<typeof HttpTransportConfigSchema>;
142
+ export type TransportConfig = z.infer<typeof TransportConfigSchema>;
143
+ export type ResolvedDatabaseConfig = DatabaseConfig & {
144
+ lazyConnection: boolean;
145
+ maxRows: number;
146
+ queryTimeout: number;
147
+ };
148
+ export declare function resolveDbConfig(db: DatabaseConfig, defaults: Defaults): ResolvedDatabaseConfig;
149
+ export {};
@@ -0,0 +1,73 @@
1
+ import { z } from "zod";
2
+ const PostgresConfigSchema = z.object({
3
+ id: z.string(),
4
+ type: z.literal("postgresql"),
5
+ host: z.string(),
6
+ port: z.number().default(5432),
7
+ database: z.string(),
8
+ user: z.string(),
9
+ password: z.string().default(""),
10
+ ssl: z.boolean().optional(),
11
+ description: z.string().optional(),
12
+ lazyConnection: z.boolean().optional(),
13
+ maxRows: z.number().optional(),
14
+ queryTimeout: z.number().optional(),
15
+ });
16
+ const ClickHouseConfigSchema = z.object({
17
+ id: z.string(),
18
+ type: z.literal("clickhouse"),
19
+ url: z.string(),
20
+ database: z.string(),
21
+ user: z.string().default("default"),
22
+ password: z.string().default(""),
23
+ description: z.string().optional(),
24
+ lazyConnection: z.boolean().optional(),
25
+ maxRows: z.number().optional(),
26
+ queryTimeout: z.number().optional(),
27
+ });
28
+ const DatabaseConfigSchema = z.discriminatedUnion("type", [
29
+ PostgresConfigSchema,
30
+ ClickHouseConfigSchema,
31
+ ]);
32
+ const DefaultsSchema = z.object({
33
+ maxRows: z.number().default(100),
34
+ lazyConnection: z.boolean().default(true),
35
+ toolsPerDatabase: z.boolean().default(false),
36
+ queryTimeout: z.number().default(30000),
37
+ });
38
+ const HttpTransportConfigSchema = z.object({
39
+ type: z.literal("http"),
40
+ port: z.number().default(3000),
41
+ host: z.string().default("127.0.0.1"),
42
+ stateless: z.boolean().default(false),
43
+ auth: z.object({
44
+ type: z.literal("bearer"),
45
+ token: z.string(),
46
+ }).optional(),
47
+ });
48
+ const StdioTransportConfigSchema = z.object({
49
+ type: z.literal("stdio"),
50
+ });
51
+ const TransportConfigSchema = z.discriminatedUnion("type", [
52
+ StdioTransportConfigSchema,
53
+ HttpTransportConfigSchema,
54
+ ]);
55
+ export const AppConfigSchema = z.object({
56
+ transport: TransportConfigSchema.optional().default({ type: "stdio" }),
57
+ defaults: DefaultsSchema.optional().transform((v) => v ?? {
58
+ maxRows: 100,
59
+ lazyConnection: true,
60
+ toolsPerDatabase: false,
61
+ queryTimeout: 30000,
62
+ }),
63
+ databases: z.array(DatabaseConfigSchema).min(1),
64
+ });
65
+ export function resolveDbConfig(db, defaults) {
66
+ return {
67
+ ...db,
68
+ lazyConnection: db.lazyConnection ?? defaults.lazyConnection,
69
+ maxRows: db.maxRows ?? defaults.maxRows,
70
+ queryTimeout: db.queryTimeout ?? defaults.queryTimeout,
71
+ };
72
+ }
73
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IAChC,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC3B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,cAAc,EAAE,CAAC,CAAC,OAAO,E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