Skip to content

Menu

TiDB MCP Server logo

TiDB MCP Server

Published · Updated

At a glance

Category
Databases
GitHub repository
pingcap/pytidb
Watch out for
db_execute runs any write or DDL statement, including DROP, so connect with a user whose privileges match what you want the agent to touch.

The TiDB MCP Server is published by PingCAP and ships inside pytidb, the company's Python SDK for TiDB. It lives in the pytidb repository under pytidb/ext/mcp and is installed as an optional extra, so you never clone anything: uvx pulls pytidb[mcp] and runs the tidb-mcp-server entry point.

It connects to any TiDB cluster, and the docs point new users at a TiDB Cloud Starter cluster. Connection details come from five environment variables, and the server also reads TIDB_DATABASE_URL if you prefer a single connection string. By default it runs over stdio. The --transport flag also accepts sse and streamable-http, with --host and --port (127.0.0.1 and 8000 by default) for the network modes.

The server gives the model plain SQL access rather than a narrow set of canned queries. Its built-in instructions tell the model to use TiDB syntax instead of MySQL syntax and include an example of TiDB's VECTOR column type and vector index, which makes it handy for prototyping vector search tables.

How it connects

Your AI app

An assistant or agent that supports MCP

TiDB MCP Server

Runs as

  • Python (uv / pip)

Gives the agent

  • Browse databases and tables
  • Switch databases
  • Read-only queries
  • Writes and DDL
  • User management
  • Network transports

TiDB

Signs in with

  • Username and password
Your AI app talks to TiDB MCP Server over the Model Context Protocol, and the server carries out the work. Built from the setup and capability sections on this page.

What it can do

Browse databases and tables
show_databases lists the databases in the cluster and show_tables lists tables in the current one.
Switch databases
switch_database moves the session to another database, optionally with a different username and password.
Read-only queries
db_query runs SELECT, SHOW, DESCRIBE and EXPLAIN statements and returns the rows.
Writes and DDL
db_execute runs INSERT, UPDATE, DELETE, CREATE or DROP statements. It takes one statement or an array, and runs them in the same transaction.
User management
db_create_user creates a database user and returns the name with the cluster prefix, and db_remove_user deletes one.
Network transports
Besides stdio, the server can run with --transport sse or streamable-http so several clients can share one process.

Setting it up

You need Python 3.10 or later, uv, and a TiDB cluster. On TiDB Cloud Starter, open the cluster, click Use with AI Tools, pick the branch and database, set the root password, then copy the command or click the install button on the tab for your client. For Claude Code by hand, run: claude mcp add --transport stdio TiDB --env TIDB_HOST='<YOUR_TIDB_HOST>' --env TIDB_PORT=<YOUR_TIDB_PORT> --env TIDB_USERNAME='<YOUR_TIDB_USERNAME>' --env TIDB_PASSWORD='<YOUR_TIDB_PASSWORD>' --env TIDB_DATABASE='<YOUR_TIDB_DATABASE>' -- uvx --from 'pytidb[mcp]' 'tidb-mcp-server'. For Cursor, add a TiDB entry to .cursor/mcp.json with "command": "uvx --from pytidb[mcp] tidb-mcp-server" and the same five variables in env. VS Code with Copilot (.mcp.json at the workspace root), Windsurf (mcp_config.json) and Claude Desktop (claude_desktop_config.json, via Settings, Developers, Edit Config) use the same server definition. To share a single process, put the variables in a .env file, start it with uvx --from "pytidb[mcp]" tidb-mcp-server --transport sse, and point the client at http://localhost:8000/sse. If Cursor logs spawn uvx ENOENT, uvx is not on your PATH.

Where each client keeps its MCP config file, and the JSON it expects (cheat sheet)

Where it helps

  • Ask the agent to describe the tables in a database and write a correct join for a report you need.
  • Create a table with a VECTOR column and vector index, load sample embeddings and test a similarity query.
  • Check a slow statement by having the agent run EXPLAIN through db_query and suggest an index.
  • Seed a development database with test rows using a batch of INSERT statements in one transaction.
  • Create a scoped database user for a new service and remove it when the experiment ends.

Limitations and things to watch

  • db_execute runs any write or DDL statement, including DROP, so connect with a user whose privileges match what you want the agent to touch.
  • The read-only split between db_query and db_execute is guidance in the tool descriptions, not enforced by the server, so database permissions are your real guardrail.
  • Connection credentials, including the password, sit in plain text in the client config or .env file.
  • The docs require Python 3.10 or later and uv on the machine that launches the server.
  • The SSE and streamable-http modes bind to 127.0.0.1:8000 by default.

Sources

Written from the project's own documentation, checked November 2026.

How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…