Skip to main content

SmartDB is a universal database gateway that implements the Model Context Protocol (MCP) server interface.SmartDB not only provides basic database connection and exploration capabilities but also adds advanced features such as OAuth 2.0 authentication , health checks, SQL optimization, and index health detection, making database management and maintenance more secure and intelligent.

Project description

简体中文 English

image

SmartDB

SmartDB is a universal database gateway that implements the Model Context Protocol (MCP) server interface. This gateway allows MCP-compatible clients to connect and explore different databases.

Compared to similar products, SmartDB not only provides basic database connection and exploration capabilities but also adds advanced features such as OAuth 2.0 authentication , health checks, SQL optimization, and index health detection, making database management and maintenance more secure and intelligent.

image

Currently Supported Databases

Database Support Description
MySQL Supports MySQL 5.6+, MariaDB 10+
PostgreSQL Supports PostgreSQL 9.6+, YMatrix
Oracle Oracle 12+
SQL Server Microsoft SQL Server 2012+

Tool List

Tool Name Description
execute_sql SQL execution tool that can execute ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP", "TRUNCATE"] commands based on permission configuration
get_db_health Analyzes database health status (connection status, transaction status, running status, lock detection) and outputs professional diagnostic reports and solutions
get_table_desc Searches for table structures in the database based on table names, supports multi-table queries
get_table_index Searches for table indexes in the database based on table names, supports multi-table queries
get_table_name Database table name query tool. Used to query all table names in the database or search for corresponding table names based on Chinese table names or table descriptions
get_db_version Database version query tool
sql_creator SQL query generation tool that generates corresponding SQL query statements based on different database types

Usage

Environment Configuration File Description

# Database configuration file path
DATABASE_CONFIG_FILE=/Volumes/SmartDB/src/config/database_config.json

#========OAuth2========
# OAuth2 client ID
CLIENT_ID=smart_db_client_id
# OAuth2 client secret
CLIENT_SECRET=smart_db_client_secret
# Access token expiration time (minutes)
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Refresh token expiration time (days)
REFRESH_TOKEN_EXPIRE_DAYS=30
# Token encryption key
TOKEN_SECRET_KEY=smart_db_token_secret
# Username
OAUTH_USER_NAME=admin
# Password
OAUTH_USER_PASSWORD=wenb1n

Note: If you adjust the client ID and key in the oauth configuration, please also modify the corresponding configuration in the static/config file in the previous code

Database Connection Configuration Description

{
  "default": {
    "host": "192.168.xxx.xxx",
    "port": 3306,
    "user": "root",
    "password": "root",
    "database": "a_llm",
    "role": "readonly",
    "pool_size": 10,
    "max_overflow": 20,
    "pool_recycle": 3600,
    "pool_timeout": 30,
    "type": "mysql"
  },
  "postgresql": {
    "host": "192.168.xxx.xxx",
    "port": 5432,
    "user": "postgres",
    "password": "123456",
    "database": "postgres",
    "schema": "public",
    "role": "readonly",
    "pool_size": 5,
    "max_overflow": 10,
    "pool_recycle": 3600,
    "pool_timeout": 30,
    "type": "postgresql"
  },
  "oracle": {
    "host": "192.168.xxx.xxx",
    "port": 1521,
    "user": "U_ORACLE",
    "password": "123456",
    "database": "123456",
    "service_name": "ORCL",
    "role": "readonly",
    "pool_size": 5,
    "max_overflow": 10,
    "pool_recycle": 3600,
    "pool_timeout": 30,
    "type": "oracle"
  },
  "mssql": {
    "host": "192.168.xxx.xxx",
    "port": 1433,
    "user": "test",
    "password": "123456",
    "database": "TEST",
    "schema": "dbo",
    "role": "readonly",
    "pool_size": 5,
    "max_overflow": 10,
    "pool_recycle": 3600,
    "pool_timeout": 30,
    "type": "mssqlserver"
  }
}
  • Database Connection Parameter Description

The following table details the meaning and usage of each parameter in the database connection configuration file:

Parameter Required Type Description
host Yes string Database server address
port Yes integer Database server port number
user Yes string Database username
password Yes string Database user password
database Yes string Database name to connect to
role Yes string User role, such as "readonly" for read-only permissions
pool_size Yes integer Connection pool size
max_overflow Yes integer Maximum overflow connections in connection pool
pool_recycle Yes integer Connection pool recycle time (seconds)
pool_timeout Yes integer Connection pool timeout time (seconds)
type Yes string Database type, such as "mysql", "postgresql", "oracle", "mssqlserver"
  • Additional Parameters for Specific Databases
Parameter Database Type Required Type Description
schema PostgreSQL, SQL Server No string Database schema
service_name Oracle No string Oracle service name
  • Note

"default" is the default database connection configuration and must be configured. Other database configurations should be added as needed.

Docker Startup

Quick Start

1. Build and Start Service

# Start service using docker-compose
docker-compose up -d

# Check service status
docker-compose ps

# View logs
docker-compose logs -f smartdb

2. Manual Image Building

# Build image
docker build -t smartdb-mcp:latest .

# Run container
docker run -d \
  --name smartdb-mcp-server \
  -p 3000:3000 \
  -e DATABASE_CONFIG_FILE=/app/src/config/database_config.json \
  -e CLIENT_ID=smart_db_client_id \
  -e CLIENT_SECRET=smart_db_client_secret \
  -e TOKEN_SECRET_KEY=your_secret_key \
  -v $(pwd)/src/config:/app/src/config:ro \
  -v $(pwd)/logs:/app/logs \
  smartdb-mcp:latest

Code Startup

Local Development Streamable Http Mode

  • Start service using uv

Add the following content to your MCP client tools, such as cursor, cline, etc.

MCP JSON as follows:

{
  "mcpServers": {
    "smartdb": {
      "name": "smartdb",
      "type": "streamableHttp",
      "description": "",
      "isActive": true,
      "url": "http://localhost:3000/mcp/"
    }
  }
}

Start command:

# Download dependencies
uv sync

# Start
uv run -m core.server

# Custom env file location
uv run -m core.server --envfile /path/to/.env

Local Development SSE Mode

  • Start service using uv

Add the following content to your MCP client tools, such as cursor, cline, etc.

MCP JSON as follows:

{
  "mcpServers": {
    "smartdb": {
      "name": "smartdb",
      "description": "",
      "isActive": true,
      "url": "http://localhost:9000/sse"
    }
  }
}

Start command:

# Download dependencies
uv sync

# Start
uv run -m mysql_mcp_server_pro.server --mode sse

# Custom env file location
uv run -m mysql_mcp_server_pro.server --mode sse --envfile /path/to/.env

Local Development STDIO Mode

Add the following content to your MCP client tools, such as cursor, cline, etc.

MCP JSON as follows:

{
  "mcpServers": {
      "smartdb": {
          "name": "smartdb",
          "type": "stdio",
          "isActive": false,
          "registryUrl": "",
          "command": "uv",
          "args": [
            "--directory",
            "/Volumes/python/SmartDB/",
            "run",
            "-m",
            "core.server",
            "--mode",
            "stdio"
          ],
          "env": {
            "DATABASE_CONFIG_FILE": "/Volumes/database_config.json"
          }
      }
    }
  }
}

OAuth 2.0 Authentication Support

  1. Start authentication service. By default, it uses the built-in OAuth 2.0 password mode authentication. You can modify your own authentication service address in the env file.
uv run -m core.server --oauth=true
  1. Access the authentication service at http://localhost:3000/login. Default account and password are configured in the env file.
image
  1. Copy the token and add it to the request header, for example:
image
{
  "mcpServers": {
    "smartdb": {
      "name": "smartdb",
      "type": "streamableHttp",
      "description": "",
      "isActive": true,
      "url": "http://localhost:3000/mcp/",
      "headers": {
        "authorization": "bearer TOKEN_VALUE"
      }
    }
  }
}

Usage Examples

  1. Query the table data of the default connection pool
image
  1. Query the table data of the others connection pool
image
  1. Query data from tables in other connection pools and other databases
image
  1. Query database health status
image

Project details


Download files

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

Source Distribution

smartdb_mcp-1.0.0.tar.gz (144.6 kB view details)

Uploaded Source

Built Distribution

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

smartdb_mcp-1.0.0-py3-none-any.whl (184.4 kB view details)

Uploaded Python 3

File details

Details for the file smartdb_mcp-1.0.0.tar.gz.

File metadata

  • Download URL: smartdb_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 144.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for smartdb_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 900171f4f242c885feef3a571cb6b7513592acacceab0386a5a1d7fed4123e96
MD5 47d1cbfb9b6d78d2ddf24d7c149f53b2
BLAKE2b-256 8e8ab6246ae8543e30a11922bf30a8421f760ef89b1df4412a4bfb2119ff7656

See more details on using hashes here.

File details

Details for the file smartdb_mcp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: smartdb_mcp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 184.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for smartdb_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a97a43f9e8fd96d735ffc956165912289c36c286aa15282c4db95021a04cb0b
MD5 e753d26ee85a30186f7e699d835d4efd
BLAKE2b-256 931475dabf84b56f6b44ffda94fb44093dbb22513b896c411477fb1cf05ad6fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page