TiDB database integration with schema inspection and query capabilities
This document provides an expert-level guide to deploying and configuring mcp-server-tidb
, a crucial component for integrating TiDB (serverless) databases with Large Language Model (LLM) applications via the Model Context Protocol (MCP). By leveraging MCP, you can empower your LLMs with real-time data access and enhanced contextual awareness, unlocking a new realm of possibilities for AI-driven applications.
The Model Context Protocol (MCP) acts as a standardized interface, enabling seamless communication between LLMs and external data sources like TiDB. This integration is paramount for building intelligent applications that require up-to-date information and complex reasoning capabilities. mcp-server-tidb
serves as the intermediary, translating MCP requests into TiDB queries and relaying the results back to the LLM.
Before diving into the installation process, ensure you have the following prerequisite in place:
Follow these instructions to install and configure mcp-server-tidb
:
Clone the Repository:
git clone https://github.com/c4pt0r/mcp-server-tidb cd mcp-server-tidb
Create and Activate a Virtual Environment using uv:
uv venv source .venv/bin/activate # Or the appropriate activation command for your shell
Install the Package and Dependencies:
uv pip install -e .
This command installs the mcp-server-tidb
package in editable mode, allowing you to modify the source code without reinstalling.
To establish a connection with your TiDB database, you need to configure the necessary credentials. This can be achieved through environment variables or a .env
file.
Create a TiDB Cluster:
Navigate to tidbcloud.com and create a free TiDB database cluster. Note down the host address, port, username, password, and database name.
Configure Environment Variables:
Set the following environment variables with your TiDB cluster details:
TIDB_HOST
: TiDB host address (e.g., gateway01.us-east-1.prod.aws.tidbcloud.com
)TIDB_PORT
: TiDB port (default: 4000
)TIDB_USERNAME
: Database username (e.g., xxxxxxxxxx.<username>
)TIDB_PASSWORD
: Database passwordTIDB_DATABASE
: Database name (default: test
)Alternatively, you can create a .env
file in the project root directory and define these variables within it.
This section demonstrates how to integrate mcp-server-tidb
with Claude Desktop, a popular LLM development environment.
Configure Claude Desktop:
Refer to the official documentation for detailed instructions on configuring Claude Desktop.
Modify claude_desktop_config.json
:
Update the claude_desktop_config.json
file with the following configuration, adjusting the paths to match your local setup:
{ "mcpServers": { "tidb": { "command": "uv", "args": [ "--directory", "/path/to/mcp-server-tidb", "run", "src/main.py" ] } } }
Note: Replace /path/to/mcp-server-tidb
with the actual path to your mcp-server-tidb
directory.
Running in WSL (Windows Subsystem for Linux):
If you're running mcp-server-tidb
within WSL, the claude_desktop_config.json
should be modified as follows:
{ "mcpServers": { "tool-with-env-vars": { "command": "wsl.exe", "args": [ "bash", "-c", "/path/to/uv --directory /path/to/mcp-server-tidb run python src/main.py" ] } } }
This configuration ensures that the command is executed within the WSL environment.
By following this comprehensive guide, you can successfully deploy and configure mcp-server-tidb
, enabling your LLM applications to leverage the power of TiDB. This integration unlocks a wide range of possibilities, from building intelligent chatbots to creating sophisticated AI-powered workflows. Embrace the Model Context Protocol and unlock the full potential of your LLMs.
๐ โ๏ธ Biomedical research server providing access to PubMed, ClinicalTrials.gov, and MyVariant.info.
๐ MCP server that provides SQL analysis, linting, and dialect conversion using [SQLGlot](https://github.com/tobymao/sqlglot)
๐ ๐ All-in-one MCP server for Postgres development and operations, with tools for performance analysis, tuning, and health checks
Supabase MCP Server with support for SQL query execution and database exploration tools