Skip to main content

YDB MCP


License PyPI version

Model Context Protocol server for YDB. It allows to work with YDB databases from any LLM that supports MCP. This integration enables AI-powered database operations and natural language interactions with your YDB instances.

YDB MCP server

Usage

Via uvx

uvx, which is an allias for uv run tool, allows you to run various python applications without explicitly installing them. Below are examples of how to configure YDB MCP using uvx.

Example: Using Anonymous Authentication

{
  "mcpServers": {
    "ydb": {
      "command": "uvx",
      "args": [
        "ydb-mcp",
        "--ydb-endpoint", "grpc://localhost:2136",
        "--ydb-database", "/local"
      ]
    }
  }
}

Via pipx

pipx allows you to run various applications from PyPI without explicitly installing each one. However, it must be installed first. Below are examples of how to configure YDB MCP using pipx.

Example: Using Anonymous Authentication

{
  "mcpServers": {
    "ydb": {
      "command": "pipx",
      "args": [
        "run", "ydb-mcp",
        "--ydb-endpoint", "grpc://localhost:2136",
        "--ydb-database", "/local"
      ]
    }
  }
}

Via pip

YDB MCP can be installed using pip, Python's package installer. The package is available on PyPI and includes all necessary dependencies.

pip install ydb-mcp

To get started with YDB MCP, you'll need to configure your MCP client to communicate with the YDB instance. Below are example configuration files that you can customize according to your setup and then put into MCP client's settings. Path to the Python interpreter might also need to be adjusted to the correct virtual environment that has the ydb-mcp package installed.

Example: Using Anonymous Authentication

{
  "mcpServers": {
    "ydb": {
      "command": "python3",
      "args": [
        "-m", "ydb_mcp",
        "--ydb-endpoint", "grpc://localhost:2136",
        "--ydb-database", "/local"
      ]
    }
  }
}

Authentication

Regardless of the usage method (uvx, pipx or pip), you can configure authentication for your YDB installation. To do this, pass special command line arguments.

Using Login/Password Authentication

To use login/password authentication, specify the --ydb-auth-mode, --ydb-login, and --ydb-password arguments:

{
  "mcpServers": {
    "ydb": {
      "command": "uvx",
      "args": [
        "ydb-mcp",
        "--ydb-endpoint", "grpc://localhost:2136",
        "--ydb-database", "/local",
        "--ydb-auth-mode", "login-password",
        "--ydb-login", "<your-username>",
        "--ydb-password", "<your-password>"
      ]
    }
  }
}

Using Access Token Authentication

To use access token authentication, specify the --ydb-auth-mode and --ydb-access-token arguments:

{
  "mcpServers": {
    "ydb": {
      "command": "uvx",
      "args": [
        "ydb-mcp",
        "--ydb-endpoint", "grpc://localhost:2136",
        "--ydb-database", "/local",
        "--ydb-auth-mode", "access-token",
        "--ydb-access-token", "qwerty123"
      ]
    }
  }
}

Using Service Account Authentication

Service account authentication requires the yandexcloud package, which is not installed by default. Make sure it is available in the environment that runs YDB MCP:

  • uvx: add it on the fly with --with yandexcloud (passed before ydb-mcp).
  • pipx: install YDB MCP with the extra package using pipx install ydb-mcp followed by pipx inject ydb-mcp yandexcloud.
  • pip: install it alongside YDB MCP with pip install ydb-mcp yandexcloud.

To use service account authentication, specify the --ydb-auth-mode and --ydb-sa-key-file arguments:

{
  "mcpServers": {
    "ydb": {
      "command": "uvx",
      "args": [
        "--with", "yandexcloud",
        "ydb-mcp",
        "--ydb-endpoint", "grpc://localhost:2136",
        "--ydb-database", "/local",
        "--ydb-auth-mode", "service-account",
        "--ydb-sa-key-file", "~/sa_key.json"
      ]
    }
  }
}

TLS Connections

Use a grpcs:// endpoint to connect over TLS. If the cluster certificate is issued by a private CA, pass a path to the PEM file with its root certificates via --ydb-root-certificates; otherwise the system trust store is used:

{
  "mcpServers": {
    "ydb": {
      "command": "uvx",
      "args": [
        "ydb-mcp",
        "--ydb-endpoint", "grpcs://localhost:2135",
        "--ydb-database", "/local",
        "--ydb-root-certificates", "~/ydb_ca.pem"
      ]
    }
  }
}

Available Tools

YDB MCP provides the following tools for interacting with YDB databases:

  • ydb_query: Run a SQL query against a YDB database

    • Parameters:
      • sql: SQL query string to execute
  • ydb_query_with_params: Run a parameterized SQL query with JSON parameters

    • Parameters:
      • sql: SQL query string with parameter placeholders
      • params: JSON string containing parameter values
  • ydb_explain_query: Explain a SQL query (returns the execution plan)

    • Parameters:
      • sql: SQL query string to explain
  • ydb_explain_query_with_params: Explain a parameterized SQL query

    • Parameters:
      • sql: SQL query string with parameter placeholders
      • params: JSON string containing parameter values
  • ydb_list_directory: List directory contents in YDB

    • Parameters:
      • path: YDB directory path to list
  • ydb_describe_path: Get detailed information about a YDB path (table, directory, etc.)

    • Parameters:
      • path: YDB path to describe
  • ydb_status: Get the current status of the YDB connection

Building Custom MCP Servers

YDBMCPServer is designed to be subclassed. You can add your own tools on top of an established YDB connection and, optionally, disable the built-in generic tools to expose only the queries your application needs.

Why build a custom server?

  • Security — restrict the LLM to a fixed set of read-only queries instead of exposing arbitrary SQL execution.
  • Domain specificity — give the model tools that match your business logic rather than raw database primitives.
  • Simplicity — fewer tools means less ambiguity for the model.

Available methods

Override or call these in your subclass:

Method Description
await self.execute(sql, params=None) Run a SQL query. Returns list[dict], each dict has "columns" and "rows".
await self.explain(sql, params=None) Return the query execution plan as a dict.
await self.list_directory(path) List a YDB directory. Returns dict with "path" and "items".
await self.describe_path(path) Describe a YDB path (table schema, directory, etc.). Returns a dict.

The params argument is a plain dict. Keys without a $ prefix get it added automatically. To specify an explicit YDB type, use a (value, "TypeName") tuple — e.g. {"id": (42, "Int64")}.

Controlling generic tools

Use the generic_tools class attribute to control which built-in tools are registered:

Value Effect
set(YDBGenericTool) All built-in tools (default)
set() No built-in tools — only your own
{YDBGenericTool.QUERY, YDBGenericTool.STATUS} Only the listed tools

YDBGenericTool is a string enum — available values: QUERY, QUERY_WITH_PARAMS, EXPLAIN, EXPLAIN_WITH_PARAMS, STATUS, LIST_DIRECTORY, DESCRIBE_PATH.

Example

# my_server.py
from ydb_mcp import YDBMCPServer, YDBGenericTool, serialize_ydb_response


class OrdersServer(YDBMCPServer):
    """Minimal read-only MCP server for the orders service."""

    generic_tools = {YDBGenericTool.STATUS}  # keep status check for diagnostics

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        @self.tool()
        async def get_order(order_id: str) -> str:
            """Fetch a single order by ID."""
            rows = await self.execute(
                "SELECT * FROM orders WHERE id = $id",
                {"id": order_id},
            )
            return serialize_ydb_response(rows)

        @self.tool()
        async def list_recent_orders(limit: int = 10) -> str:
            """Return the most recent orders."""
            rows = await self.execute(
                "SELECT * FROM orders ORDER BY created_at DESC LIMIT $limit",
                {"limit": limit},
            )
            return serialize_ydb_response(rows)


if __name__ == "__main__":
    OrdersServer(
        endpoint="grpc://localhost:2136",
        database="/local",
    ).run()

Run it directly:

python my_server.py

Or wire it up as an MCP server in your client config:

{
  "mcpServers": {
    "orders": {
      "command": "python",
      "args": ["my_server.py"]
    }
  }
}

Development

The project uses Make as its primary development tool, providing a consistent interface for common development tasks.

Available Make Commands

The project includes a comprehensive Makefile with various commands for development tasks. Each command is designed to streamline the development workflow and ensure code quality:

  • make all: Run clean, lint, and test in sequence (default target)
  • make clean: Remove all build artifacts and temporary files
  • make test: Run all tests using pytest
    • Can be configured with environment variables:
      • LOG_LEVEL (default: WARNING) - Control test output verbosity (DEBUG, INFO, WARNING, ERROR)
  • make unit-tests: Run only unit tests with verbose output
    • Can be configured with environment variables:
      • LOG_LEVEL (default: WARNING) - Control test output verbosity (DEBUG, INFO, WARNING, ERROR)
  • make integration-tests: Run only integration tests with verbose output
    • Can be configured with 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) - Control test output verbosity (DEBUG, INFO, WARNING, ERROR)
  • make run-server: Start the YDB MCP server
    • Can be configured with environment variables:
      • YDB_ENDPOINT (default: grpc://localhost:2136)
      • YDB_DATABASE (default: /local)
    • Additional arguments can be passed using ARGS="your args"
  • make lint: Run all linting checks (flake8, mypy, black, isort)
  • make format: Format code using black and isort
  • make install: Install the package in development mode
  • make dev: Install the package in development mode with all development dependencies

Test Verbosity Control

By default, tests run with minimal output (WARNING level) to keep the output clean. You can control the verbosity of test output using the LOG_LEVEL environment variable:

# Run all tests with debug output
make test LOG_LEVEL=DEBUG

# Run integration tests with info output
make integration-tests LOG_LEVEL=INFO

# Run unit tests with warning output (default)
make unit-tests LOG_LEVEL=WARNING

Available log levels:

  • DEBUG: Show all debug messages, useful for detailed test flow
  • INFO: Show informational messages and above
  • WARNING: Show only warnings and errors (default)
  • ERROR: Show only error messages

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ydb_mcp-0.2.2.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ydb_mcp-0.2.2-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file ydb_mcp-0.2.2.tar.gz.

File metadata

  • Download URL: ydb_mcp-0.2.2.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for ydb_mcp-0.2.2.tar.gz
Algorithm Hash digest
SHA256 f347a0e1e6d923a069d44636cd44c018dab50db3fa04961ccfa72e50f8ac99aa
MD5 65261aac3aa91daa6745ba765cf380af
BLAKE2b-256 f972c175724f3c18f553dc73b11c3b29a667515eba6f49c6bac42eaabe9e82ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for ydb_mcp-0.2.2.tar.gz:

Publisher: python-publish.yml on ydb-platform/ydb-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ydb_mcp-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: ydb_mcp-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for ydb_mcp-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d819724168faeaa7e6dc6bf364bd1b15ebc4261233b3d94eeead6d90d0820db5
MD5 e989a2324db6e0ac7ad2fa6d660e266f
BLAKE2b-256 3d8e0aceced891a1818233e09892680ecf977c1b3d3eec1130d39cf26e4610c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ydb_mcp-0.2.2-py3-none-any.whl:

Publisher: python-publish.yml on ydb-platform/ydb-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page