
MySQL (read-only, switchable)
io.github.shibbirweb由 GitHub 帳號 shibbirweb 發布v1.1.6更新於 Oct 24, 2026
Read-only MySQL access, with the database and server switchable mid-conversation.
概覽
讓 AI 助理以唯讀方式存取 MySQL,並可在對話中切換資料庫、伺服器與憑證,不必重新啟動用戶端。
- 可以做什麼
- 提供連線類工具(current_connection、list_connections、list_databases、use_database、use_connection、connect)與讀取類工具(list_tables、describe_table、get_table_indexes、get_foreign_keys、get_table_sample、run_query)。目前連線是執行時狀態,因此切換資料庫、設定檔、伺服器或憑證只需一次工具呼叫;切換前會先執行 SELECT 1 驗證,失敗則保留原連線。讀取工具支援僅對該次呼叫生效的 database 參數。唯讀由 SQL 驗證器、停用 multipleStatements 的驅動程式以及唯讀 MySQL 工作階段共同保證。
- 適用情境
- 當助理需要檢視 MySQL 結構並執行唯讀查詢時適用,特別適合在一次對話中於多個資料庫、伺服器或具名設定檔之間切換,而不必修改設定並重新啟動用戶端。適合探索、報表與結構問答,不適合任何需要寫入資料的工作。
- 執行需求
- 以 stdio 方式在本機執行,可用 npx(需要 Node 22 或更新版本)或 Docker 映像。需要可連線的 MySQL 伺服器及連線設定:MYSQL_HOST、MYSQL_PORT、MYSQL_USER、MYSQL_PASSWORD、MYSQL_DATABASE,或使用 MYSQL_PROFILES JSON 物件搭配 MYSQL_DEFAULT_PROFILE。可選逾時 MYSQL_CONNECT_TIMEOUT_MS 與 MYSQL_QUERY_TIMEOUT_MS。並非必須設定:沒有設定時伺服器仍會啟動,工具會提示呼叫 connect。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 MySQL (read-only, switchable),將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
mcp-mysql-read-only
[CI] [M8ven Verified] [npm] [npm downloads] [Docker Hub] [Docker pulls] [Image size] [License: MIT]
An MCP server that gives an AI assistant read-only access to MySQL, and lets it change database, server and credentials mid-conversation without restarting the client.
Most MySQL MCP servers read their connection from environment variables once at startup. Pointing one at a different database means editing a config file and restarting the assistant, which loses your conversation. This server keeps the connection as runtime state, so switching is just another tool call.
Runs from npm with npx, or entirely in Docker with nothing installed on your machine.
The server lives for the whole session, so the active connection is just state inside it. Switching selects a different pool rather than reconnecting, and switching back reuses a warm one.
Quick start
Two ways to run it. npm is the shorter setup; Docker keeps the server inside a container.
npm
Requires Node 22 or newer. There is no container in the way, so 127.0.0.1 means what you expect.
Docker
Use host.docker.internal to reach a MySQL running on the same machine as Docker. Inside the container, localhost means the container itself.
The container is the more isolated of the two: the server runs with only what the image and the environment give it. Over npm it runs directly on your machine with your user's access. Both enforce the same read-only guarantee.
Claude Desktop
Add to claude_desktop_config.json:
Or the same server in Docker:
Claude Code
Same shape, in .mcp.json at your project root:
Either form from the Claude Desktop section works here too.
Restart the client once. After that you never need to restart it to change database.
Credentials in these files sit on disk in plain text. Prefer a MySQL account with only
SELECTgrants, and keep the file out of version control. See Security.
Switching connections
Just ask. These map onto the connection tools:
"switch to the staging database" "what tables are in
analytics?" "connect to MySQL on 10.0.0.5 as reporting_user"
A switch that fails verification is never committed, so the previous connection stays active and the session keeps working:
Named profiles
Define several connections up front with MYSQL_PROFILES, a JSON object:
Passed as a single environment variable:
host defaults to host.docker.internal, port to 3306, password to empty. user and database are required; a profile missing either is skipped with a warning rather than taking the server down.
Reaching somewhere not in the profiles
The connect tool takes a host, user, password and database at runtime and keeps it for the rest of the session under an alias. Nothing is written to disk, and no restart is involved, so you never have to edit MYSQL_PROFILES just to look at one database once.
Tools
Connection
Reading
Every reading tool also accepts an optional database, applied to that call only, leaving the active connection alone. Useful for comparing two databases without switching back and forth.
use_database, use_connection and connect each open the connection and run SELECT 1 before committing the switch, so a bad database name or unreachable host fails immediately. A failed switch leaves the previous connection active.
Configuration
MYSQL_USER plus MYSQL_DATABASE register a profile named default. None of these are required: with no configuration at all the server still starts, and the tools tell you to call connect.
Starting profile: MYSQL_DEFAULT_PROFILE if it names a real profile, else default, else the first one defined.
Security
Two independent layers keep this read-only, so a hole in one is not automatically a write.
A SQL validator. Only SELECT, WITH, SHOW, DESCRIBE, DESC and EXPLAIN may lead a statement. Before any keyword check, string literals, backtick identifiers and --, # and /* */ comments are blanked out, so a keyword or semicolon hidden inside a literal is never mistaken for SQL. Statement stacking is rejected. WITH and EXPLAIN ANALYZE have their bodies scanned for write keywords, because both can carry a write behind a harmless first word. INTO OUTFILE, INTO DUMPFILE, LOAD DATA, SLEEP() and BENCHMARK() are blocked. Table and database names passed as tool arguments must match ^[A-Za-z0-9_$]+$, so they cannot break out of the identifier they are interpolated into.
The MySQL session. Every pooled connection runs SET SESSION TRANSACTION READ ONLY and SET SESSION MAX_EXECUTION_TIME. With autocommit on, each statement is its own read-only transaction, so the server rejects a write with error 1792 even if the validator were somehow bypassed. The driver runs with multipleStatements: false, so a second statement cannot be smuggled in at all.
What this is not
This is a guard, not a permission system. It stops an assistant from writing through this server. It does not stop anyone holding the same credentials from writing through any other client.
Point it at a read-only MySQL user. This is the real protection:
With that, a bug in this server still cannot write anything.
Other limits worth knowing:
SLEEP()andBENCHMARK()are blocked outright as a blunt guard against hanging the session.- A column named exactly
updateordeleteinside aWITHquery is rejected. Backtick it. - Results are truncated to 100 rows in the tool output. The query itself is not limited, so add a
LIMITwhen reading large tables.
Known behaviour
Parallel tool calls. The active connection is a single piece of process state. If a client issues several tool calls in one batch they are handled concurrently, so a use_database batched alongside a run_query is not guaranteed to land first. Sequential calls behave as expected. When a read must be pinned to a particular database, pass the per-call database argument instead of relying on a switch made in the same batch.
Shutdown. The server exits on SIGINT/SIGTERM, not when stdin closes. Open pool sockets keep the event loop alive, and stdin reaching EOF only means no further requests were buffered; treating that as a shutdown signal tears down pools while calls are still in flight. Any script driving the server directly should read until it has the responses it expects, then terminate the process.
Development
Everything runs in Docker, so a clone and Docker are the only requirements:
That starts a throwaway MySQL container, builds the test image, runs the full suite against it and tears everything down. Your own MySQL is never touched.
With Node 22 installed locally:
Integration tests read TEST_MYSQL_HOST, TEST_MYSQL_PORT, TEST_MYSQL_USER, TEST_MYSQL_PASSWORD. They create and drop two scratch databases (mcp_test, mcp_test_alt), so point them at a disposable server. When MySQL is unreachable they skip rather than fail.
Project structure
Dependencies point inward, and no class constructs its own collaborators: everything is injected by ApplicationFactory, which is what lets each part be unit tested without a database or the environment.
Developer documentation, including why each class is built the way it is and which design patterns are used where, lives in the wiki (source in docs/wiki/).
Contributing
Pull requests target master. CI runs the full suite against MySQL 8.0 and 8.4 and builds the image for amd64 and arm64. Please keep changes covered by tests, and update docs/wiki/ when behaviour changes.
There is a second copy of this document, README.dockerhub.md, which is what the release workflow publishes as the Docker Hub description. Docker Hub renders neither mermaid nor relative links, so that copy uses ASCII diagrams and absolute URLs. If you change user-facing behaviour here, change it there too.
Changelog
Release history, including which versions reached npm and which reached only Docker Hub, is in CHANGELOG.md.
Privacy
The server sends nothing anywhere except to the MySQL you point it at: no telemetry, no analytics, nothing written to disk, nothing kept after it exits. What does leave your machine is whatever your assistant reads, since query results become conversation content. PRIVACY.md sets out both halves.
License
MIT © Md. Shibbir Ahmed
來源:README.md,提交 8e703bd
工具
0版本歷史
2- v1.1.6最新Sep 24, 2026
- v1.1.5Sep 22, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分