TiDB MCP Server
A Model Context Protocol (MCP) server for TiDB that allows executing SELECT queries through MCP tools.
Features
- Execute SELECT queries on TiDB
- Secure connection via environment variables
- Lightweight and easy to use
Prerequisites
Installation
Via npx
Global installation
npm install -g tidb-mcp-server
tidb-mcp-server
Configuration
Set these environment variables before running:
export TIDB_HOST="your_tidb_host"
export TIDB_PORT="your_tidb_port"
export TIDB_USER="your_username"
export TIDB_PASS="your_password"
export TIDB_DB="your_database"
# Optional operation permissions (default: false)
export ALLOW_INSERT_OPERATION="false" # Set to "true" to allow INSERT operations
export ALLOW_UPDATE_OPERATION="false" # Set to "true" to allow UPDATE operations
export ALLOW_DELETE_OPERATION="false" # Set to "true" to allow DELETE operations
WARNING: Enabling these operations may expose your database to modification risks.
Only enable what you need and ensure proper access controls are in place.
Usage
- Start the server:
- Add to MCP configuration (cline_mcp_settings.json):
{
"mcpServers": {
"tidb-server": {
"command": "npx",
"args": ["-y", "tidb-mcp-server"], # Also adding the -y flag for consistency
"env": {
"TIDB_HOST": "your_tidb_host",
"TIDB_PORT": "your_tidb_port",
"TIDB_USER": "your_username",
"TIDB_PASS": "your_password",
"TIDB_DB": "your_database"
}
}
}
}
- Use the MCP tool:
const result = await use_mcp_tool({
server_name: 'tidb-server',
tool_name: 'tidb_query',
arguments: {
sql: 'SELECT * FROM your_table LIMIT 10'
}
});
Development
- Clone the repo:
git clone https://github.com/l1806858547/tidb-server.git
cd tidb-server
- Install dependencies:
- Build:
- Run:
License
MIT