apiSQL-MCP logo

apiSQL-MCP

Community
apisql-dev

一个 MCP Server 连接你的所有数据库,数据库 MCP Server 的瑞士军刀。One MCP Server for all your databases. The Swiss Army Knife of Database MCP Servers.

Publisherapisql-dev
Repositoryapisql-mcp
LanguageJavaScript
Forks
7
Stars
41
Available tools
1
Transport typestdio, streamable-http
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    apiSQL-MCP exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 1 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    41 stars and 7 forks from the linked repository.

apiSQL-MCP

npm version License: MIT Node.js Version

banner

一个 MCP Server 连接所有数据库,数据库 MCP Server 的瑞士军刀。

✨ 功能特性

  • 一个 MCP,连接多种数据库 —— 支持 MySQL、PostgreSQL、SQL Server、Oracle、SQLite、StarRocks、达梦、DuckDB、OceanBase、Trino、Presto 以及任何兼容 JDBC 的数据库
  • 动态数据源切换 —— 无需重启 MCP 服务器,即可在运行时切换不同数据库
  • 随时随地可访问 —— 通过apiSQL网关,轻松从互联网访问到内网数据库,需无内网穿透,无需公网IP、端口映射等繁杂配置
  • 完整 SQL 支持 —— 支持 DDL 和 DML操作,执行存储过程和函数UDF。
  • 安全和可观测性 —— 通过 apiSQL 平台提供APIkey授权、内置日志记录和审记。
  • 多种传输模式 —— 支持 STDIO 和 Streamable HTTP 传输方式

🏗️ 整体架构说明

🗄️ 支持的数据库

数据库类型说明
MySQL / MariaDBOLTP完整支持,包括存储过程
PostgreSQLOLTP完整支持,包括 JSON 操作
SQL ServerOLTP支持 T-SQL
OracleOLTP支持 11g、12c、19c、20c+
SQLite嵌入式文件型数据库
StarRocksOLAP高性能分析型数据库
Apache DorisOLAP实时分析型数据库
TiDB分布式MySQL 兼容的分布式 SQL
DuckDB分析型进程内分析型数据库
OceanBase分布式分布式关系型数据库
Trino / Presto查询引擎联邦查询支持
Dameng国产信创达梦数据库
自定义 JDBC多种任何 JDBC 兼容的数据库

⚠️ 安全提醒

apiSQL-mcp 提供完整的数据库访问权限,包括结构修改和数据操作。请务必遵循以下安全准则:

  1. 最小权限原则:

    • 创建具有最小所需权限的专用数据库用户
    • 生产环境使用只读访问权限
    • 通过视图限制对特定数据库/表的访问
  2. 推荐配置:

    • 从测试环境开始
    • 启用 apiSQL平台 的访问控制策略(IP 白名单、API Key)

🚀 快速开始

一分钟上手

1、以ChatBox配置为例: 设置 -> MCP 设置

MCP

2、复制以下内容

json
{
  "mcpServers": {
    "apisql-mcp": {
      "command": "npx",
      "args": ["-y", "apisql-mcp"],
      "env": {
        "APISQL_MCP_API_URL": "https://open.apisql.cn/api/mytest/$sudb",
        "APISQL_MCP_API_KEY": "Bearer <REDACTED>",
        "APISQL_MCP_DS": "mysql"
      }
    }
  }
}

3、选择 从剪贴板中的josn导入,即可完成配置 添加自定义服务器

4、启用刚配置的MCP

5、可以向默认的mysql数据库提问

 你帮看一下有没有DW开头的表?

6、测试基于3张数据库,写个数据分析报告,运行中

你是数据分析师,你来分析一下这3张表,写一个简单的数据分析报告。

7、切换一个 oracle11g 操作

8、顺便解释一下,这里的oracle数据源是一个临时内网数据库,后续公开演示只有 mysql 和 postgresql 两个数据源)

9、切换至postgresql进行sql操作

再切换到 postgresql 数据库,看一下都有什么表?

10、可以正常查询postgresql数据库

11、以及在apiSQL后台可以查看日志

这样一个MCP Server,可以查询N个数据库。 在最佳实践中一般将数据源名称写入提示词,

接入自有数据库前提条件

运行

bash
# 全局安装(可选)
npm install -g apisql-mcp

# 或直接通过 npx 运行
npx -y apisql-mcp

配置

环境变量

变量名是否必需说明可测试的示例
APISQL_MCP_API_URL是apiSQL API 端点地址https://open.apisql.cn/api/mytest/$sudb
APISQL_MCP_API_KEY是API 认证密钥(Bearer token)Bearer <REDACTED>
APISQL_MCP_DS否默认数据源名称mysql

获取 API 凭证

  1. 在 open.apisql.cn 注册账号
  2. 创建项目并安装数据网关
  3. 将你的数据库添加为数据源
  4. 在项目设置中启用 SUDB 功能
  5. 创建访问控制策略,选择API Key 分配权限可访问SUDB
  6. 从策略页面复制 API URL 和 Key

🔧 MCP 客户端配置示例

Claude Desktop / Claude Code

将以下内容添加到 Claude Desktop 配置文件(macOS: ~/Library/Application Support/Claude/claude_desktop_config.json,Windows: %APPDATA%/Claude/claude_desktop_config.json):

json
{
  "mcpServers": {
    "apisql-mcp": {
      "command": "npx",
      "args": ["-y", "apisql-mcp"],
      "env": {
        "APISQL_MCP_API_URL": "https://open.apisql.cn/api/mytest/$sudb",
        "APISQL_MCP_API_KEY": "Bearer <REDACTED>",
        "APISQL_MCP_DS": "mysql"
      }
    }
  }
}

使用 Claude Code CLI:

bash
claude mcp add apisql-mcp --scope user -- npx apisql-mcp

Cursor

在 Cursor 设置 → MCP → 添加 MCP 服务器:

json
{
  "name": "apisql-mcp",
  "command": "npx",
  "args": ["-y", "apisql-mcp"],
  "env": {
    "APISQL_MCP_API_URL": "https://open.apisql.cn/api/mytest/$sudb",
    "APISQL_MCP_API_KEY": "Bearer <REDACTED>",
    "APISQL_MCP_DS": "mysql"
  }
}

VS Code / Copilot

添加到 VS Code 的 settings.json:

json
{
  "mcp": {
    "servers": {
      "apisql-mcp": {
        "command": "npx",
        "args": ["-y", "apisql-mcp"],
        "env": {
          "APISQL_MCP_API_URL": "https://open.apisql.cn/api/mytest/$sudb",
          "APISQL_MCP_API_KEY": "Bearer <REDACTED>",
          "APISQL_MCP_DS": "mysql"
        }
      }
    }
  }
}

Cline

添加到 Cline 的 MCP 设置:

json
{
  "mcpServers": {
    "apisql-mcp": {
      "command": "npx",
      "args": ["-y", "apisql-mcp"],
      "env": {
        "APISQL_MCP_API_URL": "https://open.apisql.cn/api/mytest/$sudb",
        "APISQL_MCP_API_KEY": "Bearer 你的api-key",
        "APISQL_MCP_DS": "mysql"
      }
    }
  }
}

Windsurf

添加到 ~/.codeium/windsurf/mcp_config.json:

json
{
  "mcpServers": {
    "apisql-mcp": {
      "command": "npx",
      "args": ["-y", "apisql-mcp"],
      "env": {
        "APISQL_MCP_API_URL": "https://open.apisql.cn/api/mytest/$sudb",
        "APISQL_MCP_API_KEY": "Bearer <REDACTED>"
      }
    }
  }
}

HTTP 传输模式(高级)

对于基于 HTTP 的 MCP 客户端,使用 Streamable HTTP 模式启动:

bash
APISQL_MCP_API_URL=https://open.apisql.cn/api/mytest/$sudb \
APISQL_MCP_API_KEY="Bearer <REDACTED>" \
APISQL_MCP_DS=mysql \
npx apisql-mcp --transport streamable-http --port 9090 --host 0.0.0.0

然后配置 MCP 客户端连接到:

http://localhost:9090/mcp

可用选项:

  • --transport <type>:传输类型(stdio 或 streamable-http,默认:stdio)
  • --port <number>:HTTP 服务器端口(默认:9090)
  • --host <host>:HTTP 服务器主机(默认:127.0.0.1)

💡 使用示例

基础查询(使用默认数据源)

json
{
  "name": "execute_sql",
  "arguments": {
    "sc": "SELECT * FROM user LIMIT 10"
  }
}

动态切换数据源

json
// 查询 MySQL
{
  "name": "execute_sql",
  "arguments": {
    "sc": "SELECT * FROM orders WHERE status = 'pending'",
    "ds": "mysql"
  }
}

// 切换到 PostgreSQL
{
  "name": "execute_sql",
  "arguments": {
    "sc": "SELECT * FROM customers WHERE created_at > NOW() - INTERVAL '7 days'",
    "ds": "postgresql"
  }
}

// 切换到 Oracle
{
  "name": "execute_sql",
  "arguments": {
    "sc": "SELECT * FROM employees WHERE ROWNUM <= 10",
    "ds": "oracle"
  }
}

支持的 SQL 操作

  • 查询:SELECT、WITH(CTE)、JOIN、子查询
  • 插入:INSERT INTO ... VALUES、INSERT INTO ... SELECT
  • 更新:UPDATE ... SET ... WHERE
  • 删除:DELETE FROM ... WHERE
  • 结构:CREATE TABLE、ALTER TABLE、DROP TABLE、CREATE INDEX
  • 存储过程:执行存储过程和函数

🛠️ 开发指南

bash
# 克隆仓库
git clone https://github.com/apisql-dev/apisql-mcp.git
cd apisql-mcp

# 安装依赖
npm install

# 编译 TypeScript
npm run build

# 开发模式(监听文件变化)
npm run dev

# 运行测试
npm test

# 启动服务器
npm start

🔍 故障排除

"APISQL_MCP_API_URL environment variable is required"

  • 确保正确设置了环境变量
  • 检查 URL 是否以 /$sudb 结尾(SUDB 功能必需,固定地址,非变量)

"API error: 数据源不存在"

  • 验证数据源名称是否完全匹配(区分大小写)
  • 确保数据源已创建且网关在线
  • 对于多环境数据源,检查是否需要指定 dsEnv

连接问题

  • 验证 apiSQL 网关是否运行并连接到平台
  • 如果在本地运行网关,检查防火墙设置
  • 确保 API Key 具有必要的权限

中文乱码问题

  • 确保数据库连接字符集设置为 UTF-8
  • 在 SQL 语句中使用 SET NAMES utf8mb4(MySQL)

📚 相关链接

📄 许可证

MIT © apiSQL

Installation

TypingMind
{
  "mcpServers": {
    "apisql-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "apisql-mcp"
      ],
      "env": {
        "APISQL_MCP_API_URL": "<APISQL_MCP_API_URL>",
        "APISQL_MCP_API_KEY": "<APISQL_MCP_API_KEY>"
      }
    }
  }
}

Available Tools

  • execute_sql

    Execute a SQL query on the specified or default data source. Supports MySQL, PostgreSQL, SQL Server, Oracle, SQLite, StarRocks, Dameng, DuckDB, OceanBase, Trino, Presto, custom JDBC data sources and more. You can specify a different data source in the ds parameter or use the default from APISQL_MCP_DS env var.

Use apiSQL-MCP MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once apiSQL-MCP is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. You can run MCP locally on your device or connect to a remote MCP server URL.

Option 1: Use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add apiSQL-MCP as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the apiSQL-MCP MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "apisql-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "apisql-mcp"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the apiSQL-MCP MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the apiSQL-MCP MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use apiSQL-MCP to help me with this task?
apiSQL-MCP
Sure. I read it.
Here is what I found using apiSQL-MCP.

Option 2: Add an MCP server URL

Use this when apiSQL-MCP is already hosted remotely or your team wants one shared connector that multiple users can access.

1

Open MCP connectors

In TypingMind, go to Plugins, open MCP connectors, then choose Add URL.

  1. Open TypingMind in your browser.
  2. Go to Plugins.
  3. Open MCP connectors.
  4. Click Add URL.
TypingMind Add Custom MCP Server URL form
2

Paste the server URL

Enter the MCP server URL from the provider in the Server URL field. Add a connection name, description, icon, custom HTTP headers, or OAuth client settings if the server requires them.

  1. Paste the MCP server URL from the provider into the Server URL field.
  2. Enter a connection name for apiSQL-MCP.
  3. Add a description and icon if you want it to be easier to identify.
  4. Add custom HTTP headers or OAuth client details if the server requires authentication.
3

Create the connection

Click Create connection, then return to the Plugins list and confirm the new MCP connection is active.

  1. Click Create connection.
  2. Return to the MCP connectors list.
  3. Confirm the apiSQL-MCP connection appears as active.
  4. Refresh the plugin list if the connection does not appear immediately.
4

Switch models without reconnecting

Start a chat with your preferred model, enable the apiSQL-MCP tools from Plugins, and switch to another model whenever needed. The MCP connection stays available to the TypingMind workspace.

  1. Start a new chat in TypingMind.
  2. Select the AI model you want to use.
  3. Enable the apiSQL-MCP tools from Plugins.
  4. Ask the model to use the tool when needed.
  5. Switch to another AI model and reuse the same MCP connection.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use apiSQL-MCP to help me with this task?
apiSQL-MCP
Sure. I read it.
Here is what I found using apiSQL-MCP.

Frequently asked questions

What is the apiSQL-MCP MCP server used for?

apiSQL-MCP is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use apiSQL-MCP MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use apiSQL-MCP with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use apiSQL-MCP MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With apiSQL-MCP connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect apiSQL-MCP MCP to TypingMind?

apiSQL-MCP can be connected in TypingMind with the local MCP connector or by adding a remote MCP server URL. Use the local connector when the server needs access to files, apps, or private resources on your device, and use a server URL when the MCP server is hosted remotely.

What tools does apiSQL-MCP MCP provide in TypingMind?

apiSQL-MCP exposes 1 MCP tools that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use apiSQL-MCP MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If apiSQL-MCP requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇