MCP MariaDB Serverのロゴ

MCP MariaDB Server

組織
MariaDB

MariaDB MCP (Model Context Protocol) server implementation

公開者MariaDB
リポジトリmcp
言語Python
フォーク
85
スター
205
利用可能なツール
0
通信方式stdio
カテゴリ
ライセンスMIT
リンク
  • ツールをAIワークフローに接続

    MCP MariaDB Serverは、対応するAIクライアントやAIエージェントから利用できるMCP機能を提供します。

  • 0個の利用可能なツール

    呼び出し可能なアクションを以下で確認できます。サーバーから提供されている場合は、名前や説明も表示されます。

  • コピーして使える設定

    セットアップ用の設定例を使って、お好みのMCPクライアントにこのサーバーを設定できます。

  • オープンソースの注目度

    リンク先のリポジトリには205件のスターと85件のフォークがあります。

MCP MariaDB Server

The MCP MariaDB Server provides a Model Context Protocol (MCP) interface for managing and querying MariaDB databases, supporting both standard SQL operations and advanced vector/embedding-based search. Designed for use with AI assistants, it enables seamless integration of AI-driven data workflows with relational and vector databases.


Table of Contents


Overview

The MCP MariaDB Server exposes a set of tools for interacting with MariaDB databases and vector stores via a standardized protocol. It supports:

  • Listing databases and tables
  • Retrieving table schemas
  • Executing safe, read-only SQL queries
  • Creating and managing vector stores for embedding-based search
  • Integrating with embedding providers (currently OpenAI, Gemini, and HuggingFace) (optional)

Core Components

  • server.py: Main MCP server logic and tool definitions.
  • config.py: Loads configuration from environment and .env files.
  • embeddings.py: Handles embedding service integration (OpenAI).
  • tests/: Manual and automated test documentation and scripts.

Available Tools

Standard Database Tools

  • list_databases

    • Lists all accessible databases.
    • Parameters: None
  • list_tables

    • Lists all tables in a specified database.
    • Parameters: database_name (string, required)
  • get_table_schema

    • Retrieves schema for a table (columns, types, keys, etc.).
    • Parameters: database_name (string, required), table_name (string, required)
  • get_table_schema_with_relations

    • Retrieves schema with foreign key relations for a table.
    • Parameters: database_name (string, required), table_name (string, required)
  • execute_sql

    • Executes a read-only SQL query (SELECT, SHOW, DESCRIBE).
    • Parameters: sql_query (string, required), database_name (string, optional), parameters (list, optional)
    • Note: Enforces read-only mode if MCP_READ_ONLY is enabled.
  • create_database

    • Creates a new database if it doesn't exist.
    • Parameters: database_name (string, required)

Vector Store & Embedding Tools (optional)

Note: These tools are only available when EMBEDDING_PROVIDER is configured. If no embedding provider is set, these tools will be disabled.

  • create_vector_store

    • Creates a new vector store (table) for embeddings.
    • Parameters: database_name, vector_store_name, model_name (optional), distance_function (optional, default: cosine)
  • delete_vector_store

    • Deletes a vector store (table).
    • Parameters: database_name, vector_store_name
  • list_vector_stores

    • Lists all vector stores in a database.
    • Parameters: database_name
  • insert_docs_vector_store

    • Batch inserts documents (and optional metadata) into a vector store.
    • Parameters: database_name, vector_store_name, documents (list of strings), metadata (optional list of dicts)
  • search_vector_store

    • Performs semantic search for similar documents using embeddings.
    • Parameters: database_name, vector_store_name, user_query (string), k (optional, default: 7)

Embeddings & Vector Store

Overview

The MCP MariaDB Server provides optional embedding and vector store capabilities. These features can be enabled by configuring an embedding provider, or completely disabled if you only need standard database operations.

Supported Providers

  • OpenAI
  • Gemini
  • Open models from Huggingface

Configuration

  • EMBEDDING_PROVIDER: Set to openai, gemini, huggingface, or leave unset to disable
  • OPENAI_API_KEY: Required if using OpenAI embeddings
  • GEMINI_API_KEY: Required if using Gemini embeddings
  • HF_MODEL: Required if using HuggingFace embeddings (e.g., "intfloat/multilingual-e5-large-instruct" or "BAAI/bge-m3")

Model Selection

  • Default and allowed models are configurable in code (DEFAULT_OPENAI_MODEL, ALLOWED_OPENAI_MODELS)
  • Model can be selected per request or defaults to the configured model

Vector Store Schema

A vector store table has the following columns:

  • id: Auto-increment primary key
  • document: Text of the document
  • embedding: VECTOR type (indexed for similarity search)
  • metadata: JSON (optional metadata)

Configuration & Environment Variables

All configuration is via environment variables (typically set in a .env file):

VariableDescriptionRequiredDefault
DB_HOSTMariaDB host addressYeslocalhost
DB_PORTMariaDB portNo3306
DB_USERMariaDB usernameYes
DB_PASSWORDMariaDB passwordYes
DB_NAMEDefault database (optional; can be set per query)No
DB_CHARSETCharacter set for database connection (e.g., cp1251)NoMariaDB default
DB_SSLEnable SSL/TLS for database connection (true/false)Nofalse
DB_SSL_CAPath to CA certificate file for SSL verificationNo
DB_SSL_CERTPath to client certificate file for SSL authenticationNo
DB_SSL_KEYPath to client private key file for SSL authenticationNo
DB_SSL_VERIFY_CERTVerify server certificate (true/false)Notrue
DB_SSL_VERIFY_IDENTITYVerify server hostname identity (true/false)Nofalse
MCP_READ_ONLYEnforce read-only SQL mode (true/false)Notrue
MCP_BLOCK_SENSITIVE_SHOWBlock sensitive SHOW commands (PROCESSLIST, GRANTS, VARIABLES, MASTER/REPLICA STATUS, BINARY LOGS, etc.) that can leak cross-connection query text, credentials/privileges, or replication topology. Set independently of MCP_READ_ONLY (true/false)Notrue
MCP_MAX_POOL_SIZEMax DB connection pool sizeNo10
EMBEDDING_PROVIDEREmbedding provider (openai/gemini/huggingface)NoNone(Disabled)
OPENAI_API_KEYAPI key for OpenAI embeddingsYes (if EMBEDDING_PROVIDER=openai)
GEMINI_API_KEYAPI key for Gemini embeddingsYes (if EMBEDDING_PROVIDER=gemini)
HF_MODELOpen models from HuggingfaceYes (if EMBEDDING_PROVIDER=huggingface)
ALLOWED_ORIGINSComma-separated list of allowed originsNoLong list of allowed origins corresponding to local use of the server
ALLOWED_HOSTSComma-separated list of allowed hostsNolocalhost,127.0.0.1

Note that if using 'http' or 'sse' as the transport, configuring authentication is important for security if you allow connections outside of localhost. Because different organizations use different authentication methods, the server does not provide a default authentication method. You will need to configure your own authentication method. Thankfully FastMCP provides a simple way to do this starting with version 2.12.1. See the FastMCP documentation for more information. We have provided an example configuration below.

Example .env file

With Embedding Support (OpenAI):

dotenv
DB_HOST=localhost
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_PORT=3306
DB_NAME=your_default_database

MCP_READ_ONLY=true
MCP_MAX_POOL_SIZE=10

EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=sk-...
GEMINI_API_KEY=AI...
HF_MODEL="BAAI/bge-m3"

Without Embedding Support:

dotenv
DB_HOST=localhost
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_PORT=3306
DB_NAME=your_default_database
MCP_READ_ONLY=true
MCP_MAX_POOL_SIZE=10

With SSL/TLS Enabled:

dotenv
DB_HOST=your-remote-host.com
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_PORT=3306
DB_NAME=your_default_database

# Enable SSL
DB_SSL=true
DB_SSL_CA=~/.mysql/ca-cert.pem
DB_SSL_CERT=~/.mysql/client-cert.pem
DB_SSL_KEY=~/.mysql/client-key.pem
DB_SSL_VERIFY_CERT=true
DB_SSL_VERIFY_IDENTITY=false

MCP_READ_ONLY=true
MCP_MAX_POOL_SIZE=10

Note on SSL Configuration:

  • All SSL certificate paths support ~ for home directory expansion
  • DB_SSL_CA is used to verify the server's certificate
  • DB_SSL_CERT and DB_SSL_KEY are used for client certificate authentication (mutual TLS)
  • Set DB_SSL_VERIFY_CERT=false only for testing with self-signed certificates
  • Set DB_SSL_VERIFY_IDENTITY=true to enable strict hostname verification

Example Authentication Configuration: This configuration uses external web authentication via GitHub or Google. If you have internal JWT authentication (desired for organizations who manage their own services), you can use the JWT provider instead.

dotenv
# GitHub OAuth
export FASTMCP_SERVER_AUTH=fastmcp.server.auth.providers.github.GitHubProvider
export FASTMCP_SERVER_AUTH_GITHUB_CLIENT_ID="Ov23li..."
export FASTMCP_SERVER_AUTH_GITHUB_CLIENT_SECRET="github_pat_..."

# Google OAuth
export FASTMCP_SERVER_AUTH=fastmcp.server.auth.providers.google.GoogleProvider
export FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_ID="123456.apps.googleusercontent.com"
export FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_SECRET="GOCSPX-..."

Database User Privileges - IMPORTANT

⚠️ The only way to guarantee 100% read-only access with absolute certainty is to configure the MariaDB user with appropriate privileges. The READ_ONLY flag is a best effort attempt to prevent write operations, but it is based upon a whitelist of allowed queries and against a truly adversarial user it is not a substitute for proper database user privileges.

For production use, you should create a dedicated database user with minimal privileges. This is also recommended to show the LLM only the data it may need to perform its task even outside of read-only mode.

Installation & Setup

Requirements

  • Python 3.11 (see .python-version)
  • uv (dependency manager; install instructions)
  • MariaDB server (local or remote)

Steps

  1. Clone the repository

  2. Install uv (if not already):

    bash
    pip install uv
  3. Install dependencies

    bash
    uv lock
    uv sync
  4. Create .env in the project root (see Configuration)

  5. Run the server

    Standard Input/Output (default):

    bash
    uv run server.py

    SSE Transport:

    bash
    uv run server.py --transport sse --host 127.0.0.1 --port 9001

    HTTP Transport (streamable HTTP):

    bash
    uv run server.py --transport http --host 127.0.0.1 --port 9001 --path /mcp

Usage Examples

Standard SQL Query

python
{
  "tool": "execute_sql",
  "parameters": {
    "database_name": "test_db",
    "sql_query": "SELECT * FROM users WHERE id = %s",
    "parameters": [123]
  }
}

Create Vector Store

python
{
  "tool": "create_vector_store",
  "parameters": {
    "database_name": "test_db",
    "vector_store_name": "my_vectors",
    "model_name": "text-embedding-3-small",
    "distance_function": "cosine"
  }
}

Insert Documents into Vector Store

python
{
  "tool": "insert_docs_vector_store",
  "parameters": {
    "database_name": "test_db",
    "vector_store_name": "my_vectors",
    "documents": ["Sample text 1", "Sample text 2"],
    "metadata": [{"source": "doc1"}, {"source": "doc2"}]
  }
}

Semantic Search

python
{
  "tool": "search_vector_store",
  "parameters": {
    "database_name": "test_db",
    "vector_store_name": "my_vectors",
    "user_query": "What is the capital of France?",
    "k": 5
  }
}

Integration - Claude desktop/Cursor/Windsurf/VSCode

Option 1: Direct Command (stdio)

json
{
  "mcpServers": {
    "MariaDB_Server": {
      "command": "uv",
      "args": [
        "--directory",
        "path/to/mariadb-mcp-server/",
        "run",
        "server.py"
        ],
        "envFile": "path/to/mcp-server-mariadb-vector/.env"      
    }
  }
}

Option 2: SSE Transport

json
{
  "servers": {
    "mariadb-mcp-server": {
      "url": "http://{host}:9001/sse",
      "type": "sse"
    }
  }
}

Option 3: HTTP Transport

json
{
  "servers": {
    "mariadb-mcp-server": {
      "url": "http://{host}:9001/mcp",
      "type": "streamable-http"
    }
  }
}

Option 4: Docker container

json
{
  "servers": {
    "mariadb-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-p",
        "9001:9001",
        "-e",
        "DB_HOST=",
        "-e",
        "DB_PORT=",
        "-e",
        "DB_USER=",
        "-e",
        "DB_PASSWORD=",
        "-e",
        "DB_NAME=",
        "mariadb-mcp-server",
        "python",
        "src/server.py",
        "--host",
        "0.0.0.0",
        "--transport",
        "stdio"
      ]
    }
  }
}

Logging

  • Logs are written to logs/mcp_server.log by default.
  • Log messages include tool calls, configuration issues, embedding errors, and client requests.
  • Log level and output can be adjusted in the code (see config.py and logger setup).

Testing

  • Tests are located in the src/tests/ directory.
  • See src/tests/README.md for an overview.
  • Tests cover both standard SQL and vector/embedding tool operations.

インストール

TypingMind
{
  "mcpServers": {
    "mariadb-mcp": {
      "command": "python",
      "args": [
        "server.py"
      ]
    }
  }
}

MCP MariaDB ServerのMCPを複数のAIモデルで活用

TypingMindはワークスペース単位でMCPツールに接続します。そのため、一度MCP MariaDB Serverに接続すれば、モデルごとに個別に設定することなく、TypingMind内のさまざまなAIモデルで利用できます。 このMCPは、デバイス上のTypingMind MCPコネクタを通じてローカルで動作します。

ローカルコネクタのセットアップガイド

MCPサーバーが、お使いのコンピューター上のローカルファイル、アプリ、非公開リソースにアクセスする必要がある場合は、この方法を使います。

1

MCP設定を開く

TypingMindで「設定」、「詳細設定」、「MCP」の順に進み、「コネクタを設定」を選択してください。

  1. ブラウザでTypingMindを開いてください。
  2. 設定アイコンをクリックしてください。
  3. 「詳細設定」に移動してください。
  4. 「MCP」セクションを開いてください。
  5. 「コネクタを設定」をクリックし、「このデバイス」を選択してください。
「このデバイス」が選択されたTypingMindのMCPコネクタ設定画面
2

コネクタのコマンドを実行

「このデバイス」を選択し、TypingMindからコマンドをコピーしてターミナルで実行してください。MCPの使用中は、プロセスを実行したままにしてください。

  1. TypingMindに表示されるセットアップコマンドをコピーしてください。
  2. macOSではターミナルを、WindowsではWindows Terminalを開いてください。
  3. コマンドを貼り付けて実行してください。
  4. ターミナルで続行の確認を求められた場合は、パッケージのインストールを承認してください。
  5. MCPツールの使用中は、ターミナルウィンドウを開いたまま、プロセスの実行を継続してください。
3

MCP MariaDB Serverをサーバーとして追加

コネクタのステータスが「準備完了」になったら、「サーバーを編集」をクリックし、MCPサーバーの設定を貼り付けてください。

  1. コネクタのステータスが「準備完了」になるまでお待ちください。
  2. 「サーバーを編集」をクリックしてください。
  3. MCP MariaDB ServerのMCPサーバー設定を貼り付けてください。
  4. サーバー一覧を保存してください。
  5. コネクタが引き続き使用可能か確認するには、更新してください。
稼働中のサーバーと「サーバーを編集」ボタンが表示されたTypingMindのMCP設定画面
{
  "mcpServers": {
    "mariadb-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

複数のモデルで同じ接続を使用

サーバー一覧を保存し、「プラグイン」を開いてMCP MariaDB ServerのMCPツールを有効にしてください。その後、TypingMindで対応するAIモデルを選択し、チャットでツールを使うか、AIエージェントに割り当ててください。

  1. TypingMindの「プラグイン」ページを開いてください。
  2. MCP MariaDB ServerのMCPツールを有効にしてください。
  3. チャットを開始し、使用するAIモデルを選択してください。
  4. MCPツールをチャットで使うか、AIエージェントに割り当ててください。
  5. MCPに再接続することなく、必要に応じて別のAIモデルに切り替えられます。
選択したAIモデルと有効なMCPツールを使用したTypingMindのチャット
MCP MariaDB Serverを使ってこのタスクを手伝ってもらえますか?
MCP MariaDB Server
はい、読みました。
MCP MariaDB Serverで調べた結果をお伝えします。

よくある質問

MCP MariaDB Server MCPサーバーは何に使いますか?

MCP MariaDB Serverは、対応するAIクライアントを外部ツールやコンテキストに接続するためのMCPサーバーです。TypingMindでは、このMCPサーバーを一度追加するだけで、AIワークスペース内でそのツールを利用できるようになります。

TypingMindでMCP MariaDB Server MCPを複数のAIモデルと併用できますか?

はい。TypingMindはワークスペース単位でMCPツールに接続するため、モデルごとにMCPサーバーを設定する必要はありません。Claude、ChatGPT、Geminiや、TypingMindで設定したその他のAIモデルでMCP MariaDB Serverを利用できます。

TypingMindでMCP MariaDB Server MCPを使うメリットは何ですか?

TypingMindは、複数のAIモデル、プロンプト、プラグイン、AIエージェント、APIキー、MCPツールを1つのワークスペースにまとめられる、LLMチャット向けの優れたフロントエンドです。MCP MariaDB Serverを接続すると、TypingMindでチャットのワークフローを整理しながら、お好みのモデルでそのMCPツールを利用できます。

MCP MariaDB Server MCPをTypingMindに接続するにはどうすればよいですか?

MCP MariaDB ServerはTypingMindのローカルMCPコネクタ経由で動作します。MCPサーバーがコンピューター上のローカルファイル、デスクトップアプリ、コマンドラインツール、プライベートリソースにアクセスする必要がある場合に最適です。

TypingMindでMCP MariaDB Server MCPのどのようなツールを利用できますか?

MCP MariaDB ServerはMCP機能を提供しています。TypingMindのプラグインページで有効にすると、チャットで使用したり、AIエージェントに割り当てたりできます。

MCP MariaDB Server MCPを使うには、APIキーをTypingMindと共有する必要がありますか?

いいえ。TypingMindはローカルファーストの設計で、モデルプロバイダー、APIキー、プロンプト、MCP設定をご自身で管理できます。MCP MariaDB Serverで認証が必要な場合は、接続の作成時に、そのMCPサーバーに必要なヘッダー、OAuth設定、またはローカル設定を追加してください。

関連するMCPサーバー

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇