A secure, efficient, and intelligent MySQL server for the Model Context Protocol
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
We haven't yet run this listing's install command through our automated sandbox check. This isn't a red flag β we're steadily working through the catalog.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
A robust and secure MySQL database server implemented under Anthropic's Model Context Protocol (MCP). Designed specifically to solve the shortcomings of current generic MCP servers through Graceful Degradation, Active Performance Protection, and Aggressive Token Optimization.
LIMIT clauses automatically at the AST level.GRANT or CALL).SET SESSION TRANSACTION READ ONLY directly into the connection pool sockets. This guarantees that even if a theoretical bypass exists in the AST parser, the MySQL engine itself will physically reject any data modification.metadata.json) to database schema exploration, and exposes Semantic Templates via the official MCP Prompts API (templates.json) so the LLM uses pre-approved analytical queries instead of hallucinating them.β
), saving up to 50% of Output Tokens compared to verbose JSON. When results hit the applied LIMIT, a -- rows: N (truncated at LIMIT X) footer is appended so the LLM does not assume a complete dataset.completions/complete capability for resource templates (mysql://tables/{name}) and the query_templates prompt.SELECT and SHOW VIEW privileges.You can use this MCP server with any compatible client. Below are the configurations for the most popular ones.
Edit your claude_desktop_config.json (usually located at %APPDATA%\Claude\claude_desktop_config.json on Windows or ~/Library/Application Support/Claude/claude_desktop_config.json on macOS) and add the following:
Using NPX (Recommended)
You can easily integrate this server globally into Claude Code:
To use within Cursor IDE:
command.tokenlite-mysql.(Note: Cursor handles environment variables directly in the IDE UI, make sure to add your DB credentials there).
execute_safe_query applies two separate limits. Do not confuse them:
| Variable | What it controls | Default | Example |
|---|---|---|---|
MCP_EXPLAIN_MAX_SCAN_ROWS | Security gate: blocks queries whose EXPLAIN plan shows a full table scan (type: ALL) with more estimated rows than this threshold. The query is rejected before execution. | 1000 | 5000 allows scanning tables up to ~5000 rows without an index |
MCP_QUERY_ROW_LIMIT | Result cap: max rows returned to the LLM. Injected as LIMIT at the AST level. When reached, CSV includes -- rows: N (truncated at LIMIT X). | 500 | 1000 returns up to 1000 rows per SELECT |
Deprecated alias: MCP_SAFE_QUERY_MAX_ROWS still works as a fallback for MCP_EXPLAIN_MAX_SCAN_ROWS only. It does not control the result LIMIT.
Worked example with MCP_EXPLAIN_MAX_SCAN_ROWS=5000 and MCP_QUERY_ROW_LIMIT=500 on a customers table (~1502 rows):
SELECT * FROM customers β passes EXPLAIN (1502 < 5000), executes with LIMIT 500, returns 500 rows + truncation footer.| Variable | Description | Default | Required |
|---|---|---|---|
DB_HOST | MySQL Host address | localhost | No |
DB_PORT | MySQL Port | 3306 | No |
DB_USER | MySQL Username | root | No |
DB_PASSWORD | MySQL Password | '' | No |
DB_NAME | MySQL Database name | test | Yes |
MCP_EXPLAIN_MAX_SCAN_ROWS | EXPLAIN guardrail: max estimated rows for unindexed full table scans before blocking. | 1000 | No |
MCP_QUERY_ROW_LIMIT | Max rows returned per SELECT (AST-injected LIMIT + truncation footer). | 500 | No |
MCP_SAFE_QUERY_ENABLE_BLOCKING | Enable or disable the EXPLAIN guardrail. | true | No |
MCP_METADATA_PATH | Absolute path to your custom metadata.json dictionary. | (Disabled) | No |
MCP_TEMPLATES_PATH | Absolute path to your custom templates.json queries. | (Disabled) | No |
TOOL_PREFIX | Prefix for tool names (useful when running multiple instances). | Derived from DB_NAME (e.g., mydb_). Random fallback only if DB_NAME is unset. | No |
MCP_RATE_LIMIT_RPM | Max tool invocations per minute (sliding window). Set to 0 to disable. | 60 | No |
MYSQL_QUERY_TIMEOUT | Max execution time for a query (in ms). Aborts heavy queries to protect against DoS. | 15000 | No |
MYSQL_CONNECTION_LIMIT | Max concurrent pool connections. | 10 | No |
MYSQL_CONNECT_TIMEOUT | Max time to wait for a socket to establish (in ms). | 10000 | No |
MYSQL_RETRY_ATTEMPTS | Max retries on transient connection errors (ECONNREFUSED, PROTOCOL_CONNECTION_LOST, etc.). | 3 | No |
MYSQL_RETRY_DELAY_MS | Base delay (ms) for exponential backoff between retries (1s, 2s, 4s...). | 1000 | No |
MYSQL_QUEUE_LIMIT | Max queued requests when all pool connections are busy. Prevents unbounded growth if MySQL is down. | 50 | No |
MCP_DDL_CACHE_TTL | Time-to-live (in seconds) for cached DDL statements. Reduces latency on repeated search_schema calls. Invalidated by refresh_schema. | 60 | No |
MCP_LOG_LEVEL | Minimum severity for MCP log notifications: debug, info, notice, warning, error, critical, alert, emergency. | info | No |
ALLOW_INSERT_OPERATION | Enable INSERT and REPLACE queries. | false | No |
ALLOW_UPDATE_OPERATION | Enable UPDATE queries. | false | No |
ALLOW_DELETE_OPERATION | Enable DELETE and TRUNCATE queries. | false | No |
ALLOW_DDL_OPERATION | Enable Data Definition Language (CREATE, ALTER, DROP, RENAME). | false | No |
DB_SSL | Enable TLS for the MySQL connection (recommended for managed/cloud databases). | false | No |
DB_SSL_REJECT_UNAUTHORIZED | Reject self-signed or untrusted TLS certificates when DB_SSL=true. | true | No |
TokenLite can teach the LLM about your company's business rules. To enable this, map the absolute paths of two JSON files via .env or your MCP client config:
metadata.json (Semantic Dictionary)Translate integer statuses or internal jargon so the LLM understands the data.
Define FK mappings the heuristic engine can't auto-detect (e.g., created_by β users). Add a _relationships key to your metadata.json:
These are treated as authoritative (not heuristic) and take priority over automatic detection.
The heuristic engine also assigns a confidence score (0β100) to each inferred FK based on name matching (+40), data type validation (+30), primary key verification (+20), and index presence (+10). Only FKs scoring β₯70 are accepted.
templates.json (Pre-approved SQL)Stop the LLM from hallucinating complex metrics by providing vetted templates.
Factual signals from GitHub, npm, and our automated checks β not a rating.
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/tokenlite-mysql-mcp)<a href="https://allmcps.com/mcp/tokenlite-mysql-mcp"><img src="https://allmcps.com/api/badge/tokenlite-mysql-mcp?style=directory" alt="Tokenlite Mysql MCP on AllMCPs" /></a>