mysql-readonly-mcp

mysql-readonly-mcp

Provides secure, read-only access to a single MySQL database for schema inspection and querying.

Category
访问服务器

README

MySQL Read-Only MCP Server

MySQL Read-Only MCP Server is a Model Context Protocol (MCP) server that provides secure, read-only access to a single MySQL database. It is designed for MCP-compatible clients that need to inspect schema details, preview table data, and run analytical queries without allowing data or schema changes.

Overview

  • Read-only query execution for MySQL
  • Single database configuration per server instance
  • Built-in query validation and row limits
  • Schema inspection and relationship discovery tools
  • Compatible with MCP clients such as Claude Desktop and editor integrations

Installation

Run with npx

npx -y mysql-readonly-mcp

Prefer npx or a globally installed binary in MCP client configuration. Do not point MCP clients to a cloned repository checkout such as .../mysql-readonly-mcp/dist/index.js, because some clients and agents may treat that checkout as part of the active workspace.

Global installation

npm install -g mysql-readonly-mcp
mysql-readonly-mcp

Configuration

The server reads its connection settings from environment variables.

Variable Description Default
MYSQL_HOST MySQL host localhost
MYSQL_PORT MySQL port 3306
MYSQL_USER MySQL user root
MYSQL_PASSWORD MySQL password empty
MYSQL_DATABASE Database name mysql
MYSQL_QUERY_TIMEOUT_MS Query execution timeout in milliseconds (minimum 1000) 30000

Each server instance connects to one database. To work with multiple databases, configure multiple MCP server entries and point each one to a different MYSQL_DATABASE value.

Client setup

Claude Desktop

Configuration file locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "mysql-production": {
      "command": "npx",
      "args": ["-y", "mysql-readonly-mcp"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "readonly_user",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "production_db"
      }
    }
  }
}

Generic MCP configuration

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "mysql-readonly-mcp"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "password",
        "MYSQL_DATABASE": "app_db"
      }
    }
  }
}

This is the recommended setup for editor and assistant clients because it keeps the MCP server isolated from the repository source tree.

Multiple database connections

Use separate MCP server entries when you need access to more than one database.

{
  "mcpServers": {
    "mysql-production": {
      "command": "npx",
      "args": ["-y", "mysql-readonly-mcp"],
      "env": {
        "MYSQL_HOST": "prod-db.example.com",
        "MYSQL_USER": "readonly_user",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "production"
      }
    },
    "mysql-staging": {
      "command": "npx",
      "args": ["-y", "mysql-readonly-mcp"],
      "env": {
        "MYSQL_HOST": "staging-db.example.com",
        "MYSQL_USER": "readonly_user",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "staging"
      }
    }
  }
}

Available tools

Tool Purpose Parameters
list_tables List tables and views with metadata None
describe_table Describe table columns, keys, and indexes table
preview_data Preview rows from a table table, columns, limit, where
run_query Execute validated read-only SQL query, limit
show_relations Show incoming and outgoing foreign key relations table
db_stats Summarize database size and largest tables None
db_info Show which database this server instance is connected to None

Tool details

list_tables

Returns table name, table type, row count estimate, and storage engine for the configured database.

describe_table

Returns:

  • Column definitions
  • Primary key columns
  • Foreign key relationships
  • Index information

preview_data

Parameters:

  • table (required)
  • columns (optional)
  • limit (optional, default 10, max 100)
  • where (optional basic filter expression, without the WHERE keyword)

For complex filtering, joins, unions, or advanced SQL expressions, use run_query instead of preview_data.

run_query

Accepted statements:

  • SELECT
  • SHOW
  • DESCRIBE
  • EXPLAIN

Rejected statements include data modification, schema modification, and permission-changing queries such as INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, GRANT, REVOKE, and LOCK.

show_relations

Returns:

  • Tables that reference the target table
  • Tables referenced by the target table
  • Relationship type when it can be inferred

db_stats

Returns:

  • Total table count
  • Estimated total row count
  • Total database size
  • Largest tables by row count
  • Largest tables by size

db_info

Returns the connection details for this server instance: database name, host, port, user, and active query timeout. Useful when multiple MCP server instances are configured and you need to confirm which one you are addressing. The password is never included in the output.

Prompts

The server exposes a connection_info prompt for MCP clients that support prompts. When retrieved, it provides a summary of the database this server connects to and a reminder that the server is scoped to that single database. This helps LLM clients avoid routing queries to the wrong server instance.

Security model

The server is intended for inspection and analysis, not for write operations.

  • Query validation blocks non-read-only statements
  • Preview queries are capped at 100 rows
  • Custom queries are capped at 5000 rows
  • Query execution timeout defaults to 30 seconds and is configurable via MYSQL_QUERY_TIMEOUT_MS
  • Sensitive credentials are sanitized in error messages

Troubleshooting

Connection refused

  • Confirm that MySQL is running
  • Confirm that MYSQL_HOST and MYSQL_PORT are correct
  • Confirm that network access to the MySQL server is allowed

Access denied

  • Confirm that MYSQL_USER and MYSQL_PASSWORD are correct
  • Confirm that the user has read access to the configured database
  • Confirm that the MySQL user is allowed to connect from the current host

Query rejected

  • Confirm that the query is read-only
  • Use only SELECT, SHOW, DESCRIBE, or EXPLAIN

License

MIT. See LICENSE for details.

Links

  • npm: https://www.npmjs.com/package/mysql-readonly-mcp
  • Repository: https://github.com/beydemirfurkan/mysql-readonly-mcp
  • Issues: https://github.com/beydemirfurkan/mysql-readonly-mcp/issues

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选