@cemalturkcann/mariadb-mcp-server 1.0.2 → 1.1.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 (3) hide show
  1. package/README.md +66 -31
  2. package/package.json +1 -1
  3. package/src/config.js +42 -6
package/README.md CHANGED
@@ -13,18 +13,27 @@ MCP (Model Context Protocol) server for MariaDB/MySQL databases. Provides AI ass
13
13
  ## Installation
14
14
 
15
15
  ```bash
16
- npm install -g mariadb-mcp-server
16
+ npm install -g @cemalturkcann/mariadb-mcp-server
17
17
  ```
18
18
 
19
19
  Or use directly with npx:
20
20
 
21
21
  ```bash
22
- npx mariadb-mcp-server
22
+ npx @cemalturkcann/mariadb-mcp-server
23
23
  ```
24
24
 
25
25
  ## Configuration
26
26
 
27
- Create a `config.json` next to the package (or set `DB_MCP_CONFIG_PATH` env var):
27
+ The server looks for `config.json` in this order:
28
+
29
+ 1. `DB_MCP_CONFIG_PATH` environment variable
30
+ 2. Next to the package (`../config.json` relative to `src/`)
31
+ 3. Current working directory
32
+ 4. `~/.config/mariadb-mcp/config.json`
33
+
34
+ If no config is found, a default one is created automatically at `~/.config/mariadb-mcp/config.json` with a local read-only connection.
35
+
36
+ Example config:
28
37
 
29
38
  ```json
30
39
  {
@@ -57,52 +66,78 @@ Create a `config.json` next to the package (or set `DB_MCP_CONFIG_PATH` env var)
57
66
 
58
67
  ### Connection options
59
68
 
60
- | Field | Type | Default | Description |
61
- |-------|------|---------|-------------|
62
- | `host` | string | `localhost` | Database host |
63
- | `port` | number | `3306` | Database port |
64
- | `user` | string | `root` | Database user |
65
- | `password` | string | `""` | Database password |
66
- | `database` | string | `""` | Default database |
67
- | `description` | string | `""` | Human-readable label |
68
- | `read` | boolean | `true` | Allow read queries |
69
- | `write` | boolean | `false` | Allow write queries |
70
- | `ssl` | boolean/object | `false` | SSL configuration |
71
- | `statement_timeout_ms` | number | *none* | Connection timeout (0 or omit = unlimited) |
72
- | `default_row_limit` | number | *none* | Default LIMIT for SELECT (0 or omit = unlimited) |
73
- | `max_row_limit` | number | *none* | Max allowed LIMIT (0 or omit = unlimited) |
69
+ | Field | Type | Default | Description |
70
+ | ---------------------- | -------------- | ----------- | ------------------------------------------------ |
71
+ | `host` | string | `localhost` | Database host |
72
+ | `port` | number | `3306` | Database port |
73
+ | `user` | string | `root` | Database user |
74
+ | `password` | string | `""` | Database password |
75
+ | `database` | string | `""` | Default database |
76
+ | `description` | string | `""` | Human-readable label |
77
+ | `read` | boolean | `true` | Allow read queries |
78
+ | `write` | boolean | `false` | Allow write queries |
79
+ | `ssl` | boolean/object | `false` | SSL configuration |
80
+ | `statement_timeout_ms` | number | _none_ | Connection timeout (0 or omit = unlimited) |
81
+ | `default_row_limit` | number | _none_ | Default LIMIT for SELECT (0 or omit = unlimited) |
82
+ | `max_row_limit` | number | _none_ | Max allowed LIMIT (0 or omit = unlimited) |
74
83
 
75
84
  ## MCP Tools
76
85
 
77
- | Tool | Description | Requires |
78
- |------|-------------|----------|
79
- | `list_connections` | List all configured connections | — |
80
- | `list_databases` | Show databases on a connection | `read` |
81
- | `list_tables` | Show tables (optionally in a specific database) | `read` |
82
- | `describe_table` | Show column definitions | `read` |
83
- | `execute_select` | Run SELECT/SHOW/DESCRIBE/EXPLAIN queries | `read` |
84
- | `execute_write` | Run INSERT/UPDATE/DELETE/DDL queries | `write` |
85
- | `execute_transaction` | Run multiple write queries atomically | `write` |
86
- | `suggest_query` | Suggest a query for manual review | — |
86
+ | Tool | Description | Requires |
87
+ | --------------------- | ----------------------------------------------- | -------- |
88
+ | `list_connections` | List all configured connections | — |
89
+ | `list_databases` | Show databases on a connection | `read` |
90
+ | `list_tables` | Show tables (optionally in a specific database) | `read` |
91
+ | `describe_table` | Show column definitions | `read` |
92
+ | `execute_select` | Run SELECT / SHOW / DESCRIBE / EXPLAIN queries | `read` |
93
+ | `execute_write` | Run INSERT / UPDATE / DELETE / DDL queries | `write` |
94
+ | `execute_transaction` | Run multiple write queries atomically | `write` |
95
+ | `suggest_query` | Suggest a query for manual review | — |
87
96
 
88
- ## Claude Desktop / MCP Client Setup
97
+ ## MCP Client Setup
89
98
 
90
- Add to your MCP client config:
99
+ ### Claude Code
100
+
101
+ Add to `~/.claude.json`:
91
102
 
92
103
  ```json
93
104
  {
94
105
  "mcpServers": {
95
106
  "mariadb": {
96
107
  "command": "npx",
97
- "args": ["-y", "mariadb-mcp-server"],
108
+ "args": ["-y", "@cemalturkcann/mariadb-mcp-server"],
98
109
  "env": {
99
- "DB_MCP_CONFIG_PATH": "/path/to/your/config.json"
110
+ "DB_MCP_CONFIG_PATH": "/path/to/config.json"
100
111
  }
101
112
  }
102
113
  }
103
114
  }
104
115
  ```
105
116
 
117
+ ### OpenCode
118
+
119
+ Add to your project-level `.opencode.json`:
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "mariadb": {
125
+ "type": "local",
126
+ "command": "npx -y @cemalturkcann/mariadb-mcp-server",
127
+ "environment": {
128
+ "DB_MCP_CONFIG_PATH": "/path/to/config.json"
129
+ },
130
+ "enabled": true,
131
+ "timeout": 60000
132
+ }
133
+ }
134
+ }
135
+ ```
136
+
137
+ ### Other MCP Clients
138
+
139
+ Any MCP-compatible client can use this server. The binary name is `mariadb-mcp-server` and it communicates over stdio. Point `DB_MCP_CONFIG_PATH` to your config file.
140
+
106
141
  ## License
107
142
 
108
143
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cemalturkcann/mariadb-mcp-server",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "MCP server for MariaDB/MySQL with per-connection read/write access control",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/config.js CHANGED
@@ -1,5 +1,6 @@
1
- import { existsSync, readFileSync } from "fs";
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
2
  import { dirname, join } from "path";
3
+ import { homedir } from "os";
3
4
  import { fileURLToPath } from "url";
4
5
 
5
6
  const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -34,11 +35,48 @@ function normalizeConnection(connection) {
34
35
  };
35
36
  }
36
37
 
38
+ const DEFAULT_CONFIG = {
39
+ connections: {
40
+ local: {
41
+ host: "localhost",
42
+ port: 3306,
43
+ user: "root",
44
+ password: "",
45
+ database: "",
46
+ description: "Local MariaDB",
47
+ read: true,
48
+ write: false,
49
+ },
50
+ },
51
+ };
52
+
53
+ function getXdgConfigPath() {
54
+ const xdgBase = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
55
+ return join(xdgBase, "mariadb-mcp", "config.json");
56
+ }
57
+
58
+ function createDefaultConfig(configPath) {
59
+ const dir = dirname(configPath);
60
+ mkdirSync(dir, { recursive: true });
61
+ writeFileSync(
62
+ configPath,
63
+ JSON.stringify(DEFAULT_CONFIG, null, 2) + "\n",
64
+ "utf8",
65
+ );
66
+ process.stderr.write(
67
+ `[mariadb-mcp] Created default config at ${configPath}\n`,
68
+ );
69
+ return DEFAULT_CONFIG;
70
+ }
71
+
37
72
  export function loadConfig() {
73
+ const xdgPath = getXdgConfigPath();
74
+
38
75
  const candidates = [
39
76
  process.env.DB_MCP_CONFIG_PATH,
40
77
  join(__dirname, "../config.json"),
41
78
  join(process.cwd(), "config.json"),
79
+ xdgPath,
42
80
  ].filter(Boolean);
43
81
 
44
82
  let rawConfig;
@@ -50,15 +88,13 @@ export function loadConfig() {
50
88
  }
51
89
 
52
90
  if (!rawConfig) {
53
- throw new Error(
54
- "config.json bulunamadi. DB_MCP_CONFIG_PATH ayarlayin veya proje kokune config.json koyun."
55
- );
91
+ rawConfig = createDefaultConfig(xdgPath);
56
92
  }
57
93
 
58
94
  const raw = rawConfig.connections || rawConfig.databases;
59
95
  if (!raw || typeof raw !== "object") {
60
96
  throw new Error(
61
- "config.json icinde 'connections' (veya eski format 'databases') nesnesi olmalidir."
97
+ "config.json icinde 'connections' (veya eski format 'databases') nesnesi olmalidir.",
62
98
  );
63
99
  }
64
100
 
@@ -81,7 +117,7 @@ export function loadConfig() {
81
117
  normalized.default_row_limit > normalized.max_row_limit
82
118
  ) {
83
119
  throw new Error(
84
- `'${name}' icin default_row_limit, max_row_limit degerinden buyuk olamaz.`
120
+ `'${name}' icin default_row_limit, max_row_limit degerinden buyuk olamaz.`,
85
121
  );
86
122
  }
87
123