@futuretea/mysql-mcp-server 0.0.2

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +253 -0
  3. package/bin/index.js +37 -0
  4. package/package.json +17 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 futuretea
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,253 @@
1
+ # MySQL Read-Only MCP Server
2
+
3
+ [中文文档](README.zh.md)
4
+
5
+ An MCP (Model Context Protocol) server and CLI for one MySQL 8.0.46 target.
6
+ It provides metadata discovery and a strict read-only query tool. It does not
7
+ support writes, administration, backups, replication, or dynamic targets.
8
+
9
+ ## Quick start
10
+
11
+ ```bash
12
+ # Requires Go 1.25+ (see .tool-versions)
13
+ make build
14
+ ./bin/mysql-mcp-server version
15
+
16
+ # Set this only in the runtime environment. Do not commit it.
17
+ export MYSQL_DSN='<runtime-dsn>'
18
+
19
+ # Start MCP server (stdio, default)
20
+ ./bin/mysql-mcp-server mcp
21
+
22
+ # List / call tools from the CLI (no MCP client required)
23
+ ./bin/mysql-mcp-server tools list
24
+ ./bin/mysql-mcp-server tools call mysql_list_tables --params '{"database":"inventory"}'
25
+ ./bin/mysql-mcp-server tools call mysql_query --params '{"sql":"SELECT 1"}'
26
+ ```
27
+
28
+ ## Features
29
+
30
+ - Six MySQL discovery and query tools are available through both MCP and CLI.
31
+ - JSON parameter validation occurs at the shared tool-handler boundary.
32
+ - A Vitess AST query boundary and `database/sql` read-only transaction protect accepted queries.
33
+ - Stdio, Streamable HTTP, and SSE transports are supported.
34
+
35
+ ## MySQL tools
36
+
37
+ | Tool | Parameters | Result |
38
+ |---|---|---|
39
+ | `mysql_get_server_info` | none | Version, version comment, and current database. |
40
+ | `mysql_list_databases` | none | Databases visible to the runtime account. |
41
+ | `mysql_list_tables` | `database` | Base tables and views in a database. |
42
+ | `mysql_describe_table` | `database`, `table` | Column metadata. |
43
+ | `mysql_list_indexes` | `database`, `table` | Indexes and key parts. |
44
+ | `mysql_query` | `sql` | Columns and safely encoded rows from one query. |
45
+
46
+ Successful calls use a JSON envelope with `schema_version: 1`. Unknown,
47
+ missing, empty, and non-string parameters are rejected before any database call.
48
+
49
+ `mysql_query` accepts one parsed read query only. It rejects multiple or
50
+ non-query statements, `INTO`, locking reads, user-variable assignments, and
51
+ blocked session/file functions. Accepted queries run in a read-only transaction
52
+ that is always rolled back.
53
+
54
+ This is not proof that stored functions, UDFs, views, or plugins have no side
55
+ effects. Use a least-privilege account; do not grant `EXECUTE`, `FILE`,
56
+ `LOCK TABLES`, or administrative privileges.
57
+
58
+ ## CLI commands
59
+
60
+ | Command | Purpose |
61
+ |---------|---------|
62
+ | `mysql-mcp-server mcp` | Start the MCP server (stdio or HTTP) |
63
+ | `mysql-mcp-server tools list` | List enabled tools |
64
+ | `mysql-mcp-server tools describe <name>` | Show tool schema |
65
+ | `mysql-mcp-server tools call <name>` | Invoke a tool with JSON params |
66
+ | `mysql-mcp-server version` | Print build metadata |
67
+ | `mysql-mcp-server completion <shell>` | Generate shell completion |
68
+
69
+ ### Tools examples
70
+
71
+ ```bash
72
+ ./bin/mysql-mcp-server tools list
73
+ ./bin/mysql-mcp-server tools list --json
74
+ ./bin/mysql-mcp-server tools describe mysql_query
75
+ ./bin/mysql-mcp-server tools describe mysql_query --json
76
+ ./bin/mysql-mcp-server tools call mysql_list_tables --params '{"database":"inventory"}'
77
+ echo '{"sql":"SELECT 1"}' | ./bin/mysql-mcp-server tools call mysql_query --params-file -
78
+ ```
79
+
80
+ ## MCP transports
81
+
82
+ ### Stdio (default)
83
+
84
+ ```bash
85
+ ./bin/mysql-mcp-server mcp
86
+ ```
87
+
88
+ Cursor / Claude Desktop style config:
89
+
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "mysql-mcp-server": {
94
+ "command": "/absolute/path/to/bin/mysql-mcp-server",
95
+ "args": ["mcp"]
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ ### Streamable HTTP
102
+
103
+ ```bash
104
+ ./bin/mysql-mcp-server mcp --port 8080
105
+ curl -s http://127.0.0.1:8080/healthz
106
+ ```
107
+
108
+ Client config example:
109
+
110
+ ```json
111
+ {
112
+ "mcpServers": {
113
+ "mysql-mcp-server": {
114
+ "url": "http://127.0.0.1:8080/mcp"
115
+ }
116
+ }
117
+ }
118
+ ```
119
+
120
+ ### SSE
121
+
122
+ Same process as HTTP mode. Endpoints:
123
+
124
+ | Path | Purpose |
125
+ |------|---------|
126
+ | `/healthz` | Health check (`GET`/`HEAD`) |
127
+ | `/mcp` | Streamable HTTP |
128
+ | `/sse` | SSE connection |
129
+ | `/message` | SSE message endpoint |
130
+
131
+ ```bash
132
+ ./bin/mysql-mcp-server mcp --port 8080 --sse-base-url http://127.0.0.1:8080
133
+ ```
134
+
135
+ ### Docker
136
+
137
+ ```bash
138
+ # Build
139
+ make docker
140
+
141
+ # Stdio (default ENTRYPOINT is `mysql-mcp-server mcp`)
142
+ docker run -i --rm -e MYSQL_DSN ghcr.io/futuretea/mysql-mcp-server:dev
143
+
144
+ # HTTP
145
+ docker run --rm -e MYSQL_DSN -p 8080:8080 ghcr.io/futuretea/mysql-mcp-server:dev --port 8080 --listen 0.0.0.0
146
+ ```
147
+
148
+ HTTP / SSE have **no auth and no TLS**. Default `--listen 127.0.0.1`. Use only on trusted networks; put a reverse proxy in front if you expose the port.
149
+
150
+ ## Configuration
151
+
152
+ Priority: **flags > environment variables > config file > defaults**.
153
+
154
+ ### Environment variables
155
+
156
+ | Variable | Description | Default |
157
+ |----------|-------------|---------|
158
+ | `MCP_LOG_LEVEL` | Log level | `info` |
159
+ | `MCP_PORT` | HTTP port (`0` = stdio) | `0` |
160
+ | `MCP_LISTEN` | HTTP listen host | `127.0.0.1` |
161
+ | `MCP_SSE_BASE_URL` | Public SSE base URL | `""` |
162
+ | `MYSQL_DSN` | Required single MySQL runtime DSN; never logged or returned | none |
163
+
164
+ ### Config file
165
+
166
+ See `config.example.yaml`:
167
+
168
+ ```yaml
169
+ port: 0
170
+ listen: 127.0.0.1
171
+ sse_base_url: ""
172
+ log_level: info
173
+ enabled_tools: []
174
+ disabled_tools: []
175
+ enabled_domains: []
176
+ disabled_domains: []
177
+ ```
178
+
179
+ ```bash
180
+ ./bin/mysql-mcp-server mcp --config config.example.yaml --port 8080
181
+ ```
182
+
183
+ ## Project layout
184
+
185
+ ```
186
+ cmd/mcp-server/ # binary entrypoint
187
+ internal/cmd/ # cobra CLI (mcp / tools / version / completion)
188
+ internal/mysql/ # connection, discovery, query boundary, result encoding
189
+ pkg/core/ # config / logging / version
190
+ pkg/server/mcp/ # MCP registration and transports
191
+ pkg/server/http/ # HTTP / SSE / healthz
192
+ pkg/toolset/ # Toolset interface and filters
193
+ pkg/toolset/mysql/ # six MySQL tool definitions and shared parameter decoder
194
+ ```
195
+
196
+ ## Operational limits
197
+
198
+ This slice deliberately does not impose query timeouts, row limits, response
199
+ size limits, or concurrency budgets. Keep the server on trusted networks; HTTP
200
+ and SSE have no built-in authentication or TLS termination.
201
+
202
+ ## Development
203
+
204
+ ```bash
205
+ make tidy
206
+ make format
207
+ make lint
208
+ make test
209
+ make coverage
210
+ make ci
211
+ make build
212
+ make docker
213
+ ```
214
+
215
+ ### Local MySQL E2E
216
+
217
+ The real MySQL E2E suite is opt-in and never runs in GitHub Actions or through
218
+ `make ci`. It starts and removes its own disposable `mysql:8.0.46` container,
219
+ then exercises the compiled CLI and MCP stdio transport:
220
+
221
+ ```bash
222
+ MYSQL_MCP_INTEGRATION=1 go test ./internal/mysql -run '^TestMySQL8046Integration$' -count=1
223
+ ```
224
+
225
+ ## Use released artifacts
226
+
227
+ Release tags use `vX.Y.Z`. Use `X.Y.Z` for npm and `vX.Y.Z` for Docker.
228
+
229
+ ```bash
230
+ npx -y @futuretea/mysql-mcp-server@<version>
231
+ docker run --rm -i ghcr.io/futuretea/mysql-mcp-server:v<version>
232
+ ```
233
+
234
+ Both launch the MCP server's `mcp` command. Arguments after the package or image are forwarded to that command.
235
+
236
+ Configure an MCP client that supports stdio with npm:
237
+
238
+ ```json
239
+ {
240
+ "mcpServers": {
241
+ "mysql-mcp-server": {
242
+ "command": "npx",
243
+ "args": ["-y", "@futuretea/mysql-mcp-server@<version>"]
244
+ }
245
+ }
246
+ }
247
+ ```
248
+
249
+ Supported release platforms are recorded in `.github/ci/release-platforms.json`.
250
+
251
+ ## License
252
+
253
+ [MIT](LICENSE)
package/bin/index.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require('child_process');
4
+
5
+ const architecture = {x64: 'amd64', arm64: 'arm64'}[process.arch];
6
+ const platform = process.platform === 'win32' ? 'windows' : process.platform;
7
+ const suffix = process.platform === 'win32' ? '.exe' : '';
8
+
9
+ if (!architecture) {
10
+ throw new Error(`Unsupported architecture: ${process.arch}`);
11
+ }
12
+
13
+ const packageName = `@futuretea/mysql-mcp-server-${platform}-${architecture}`;
14
+ const binaryName = 'mysql-mcp-server';
15
+
16
+ const resolveBinaryPath = () => {
17
+ try {
18
+ return require.resolve(`${packageName}/bin/${binaryName}${suffix}`);
19
+ } catch {
20
+ throw new Error(`Could not resolve a binary for ${process.platform}/${process.arch}`);
21
+ }
22
+ };
23
+
24
+ const child = childProcess.spawn(resolveBinaryPath(), ['mcp', ...process.argv.slice(2)], {
25
+ stdio: 'inherit',
26
+ });
27
+
28
+ for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) {
29
+ process.on(signal, () => {
30
+ if (!child.killed) child.kill(signal);
31
+ });
32
+ }
33
+
34
+ child.on('close', (code, signal) => {
35
+ if (signal) process.exit(128 + (signal === 'SIGTERM' ? 15 : signal === 'SIGINT' ? 2 : 1));
36
+ process.exit(code || 0);
37
+ });
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@futuretea/mysql-mcp-server",
3
+ "version": "0.0.2",
4
+ "description": "MCP server binary launcher",
5
+ "main": "./bin/index.js",
6
+ "bin": {
7
+ "mysql-mcp-server": "bin/index.js"
8
+ },
9
+ "optionalDependencies": {
10
+ "@futuretea/mysql-mcp-server-darwin-amd64": "0.0.2",
11
+ "@futuretea/mysql-mcp-server-darwin-arm64": "0.0.2",
12
+ "@futuretea/mysql-mcp-server-linux-amd64": "0.0.2",
13
+ "@futuretea/mysql-mcp-server-linux-arm64": "0.0.2",
14
+ "@futuretea/mysql-mcp-server-windows-amd64": "0.0.2"
15
+ },
16
+ "license": "MIT"
17
+ }