YDB MCP is a Model Context Protocol (MCP) server provided by the YDB platform, designed to enable any large language model (LLM) that supports MCP to interact with a YDB database, achieving AI-driven database operations and natural language interaction.
Purpose
As an MCP server, YDB MCP exposes the capabilities of a YDB database to LLM clients, enabling the model to perform database queries, view execution plans, browse directory structures, and other operations through standardized tool calls.
Main capabilities
YDB MCP provides the following built-in tools:
- ydb_query: Executes an SQL query; the parameter is sql (the SQL query string to execute).
- ydb_query_with_params: Executes a parameterized SQL query with JSON parameters; the parameters are sql (the SQL query string containing parameter placeholders) and params (a JSON string containing parameter values).
- ydb_explain_query: Explains an SQL query and returns the execution plan; the parameter is sql.
- ydb_explain_query_with_params: Explains a parameterized SQL query; the parameters are sql and params.
- ydb_list_directory: Lists the contents of a directory in YDB; the parameter is path (the YDB directory path to list).
- ydb_describe_path: Retrieves detailed information about a YDB path (table, directory, etc.); the parameter is path.
- ydb_status: Retrieves the current YDB connection status.
By default, the server runs in read-only mode. Read-only queries use YDB native snapshot read-only transactions, so data and schema writes are rejected by YDB itself, rather than relying on SQL text matching. This mode applies to the built-in query tools as well as custom tools that call YDBMCPServer.execute(). To explicitly allow write queries, set the --ydb-allow-write parameter, or enable it via the environment variable YDB_ALLOW_WRITE=true. Enable it only when writes are actually needed, and it is recommended to use read-only YDB credentials as an additional permission boundary when the server does not need to modify data.
Usage
YDB MCP can be installed via uvx, pipx, or pipand run.
Using uvx (an alias for uv run tool, which runs Python applications without explicit installation): For configuration examples, refer to the official documentation and write the YDB MCP configuration into the MCP client settings.
Using pipx (pipx must be installed first): For configuration examples, refer to the official documentation.
Using pip (the Python package installer): The package is published on PyPI and includes all necessary dependencies.
When configuring the MCP client, adjust the Python interpreter path according to the actual environment, pointing to the virtual environment where the ydb-mcp package is installed.
Authentication configuration: Regardless of which method is used (uvx, pipx, or pip), YDB authentication can be configured through command-line parameters.
- Login/password authentication: Specify the --ydb-auth-mode, --ydb-login, and --ydb-password parameters.
- Access token authentication: Specify the --ydb-auth-mode and --ydb-access-token parameters.
- Service account authentication: Requires the yandexcloud package (not installed by default).
- uvx: Add it dynamically via --with yandexcloud (placed before ydb-mcp).
- pipx: First run pipx install ydb-mcp, then run pipx inject ydb-mcp yandexcloud.
- pip: pip install ydb-mcp yandexcloud. Then specify the --ydb-auth-mode and --ydb-sa-key-file parameters.
TLS connection: Use a grpcs:// endpoint to connect via TLS. If the cluster certificate is issued by a private CA, pass the path to a PEM file containing the root certificate via --ydb-root-certificates; otherwise, the system trust store is used.
Building a custom MCP server
YDBMCPServer is designed to be inheritable. Developers can add their own tools on top of an established YDB connection and optionally disable the built-in generic tools, exposing only the queries the application needs.
Reasons to build a custom server:
- Security: Restrict the LLM to a fixed set of read-only queries instead of exposing arbitrary SQL execution.
- Domain specificity: For the modelProvide tools that match business logic, rather than raw database primitives.
- Simplicity: fewer tools means less model ambiguity.
Available methods: override or call these methods in subclasses. The params argument is a plain dictionary; keys without a $ prefix are automatically prefixed. To specify an explicit YDB type, use a (value, "TypeName") tuple, for example {"id": (42, "Int64")}.
Controlling generic tools: Use the generic_tools class attribute to control which built-in tools are registered. YDBGenericTool is a string enum; available values include: QUERY, QUERY_WITH_PARAMS, EXPLAIN, EXPLAIN_WITH_PARAMS, STATUS, LIST_DIRECTORY, DESCRIBE_PATH.
Run directly: Or connect it as an MCP server in the client configuration.
Development
The project uses Make as the primary development tool, providing a consistent interface for development tasks.
Available Make commands:
- make all: runs clean, lint, and test in sequence (default target).
- make clean: deletes all build artifacts and temporary files.
- make test: runs all tests using pytest. Configurable via environment variables: LOG_LEVEL (default WARNING) controls test output verbosity (DEBUG, INFO, WARNING, ERROR).
- make unit-tests: runs only unit tests with detailed output. Configurable via LOG_LEVEL.
- make integration-tests: runs only integration tests with detailed output. Configurable via environment variables: YDB_ENDPOINT (default grpc://localhost:2136), YDB_DATABASE (default /local), MCP_HOST (default 127.0.0.1), MCP_PORT (default 8989), LOG_LEVEL (default WARNING).
- make run-server: starts the YDB MCP server. Configurable via environment variables: YDB_ENDPOINT (default grpc://localhost:2136), YDB_DATABASE (default /local). Additional arguments can be passed via ARGS="your args".
- make lint: runs all lint checks (flake8, mypy, black, isort).
- make format: formats code using black and isort.
- make install: installs the package in development mode.
- make dev: installs the package and all development dependencies in development mode.
Test verbosity control: By default, tests run with minimal output (WARNING level) to keep output clean. Test output verbosity can be controlled via the LOG_LEVEL environment variable:
- DEBUG: shows all debug messages, suitable for detailed test flows.
- INFO: shows informational messages and above.
- WARNING: shows only warnings and errors (default).
- ERROR: shows only error messages.
Use cases
- Let an LLM query a YDB database via natural language.
- Integrate YDB data access capabilities into AI applications.
- Build domain-specific database tools that restrict the operations the model can perform.
- Database interaction scenarios that require read-only access or controlled writes.
Limitations
- Read-only by default; writes must be explicitly enabled.
- Service account authentication requires additionally installing the yandexcloud package.
- When using TLS and the cluster certificate is issued by a private CA, a root certificate PEM file must be provided.
- Custom servers must inherit from YDBMCPServer and implement the tool logic themselves.