数据库 MCP 服务器
模型上下文协议 (MCP) 服务器提供用于连接和与各种数据库系统交互的工具。
特征
- 多数据库支持:连接到 SQLite、PostgreSQL、MySQL/MariaDB 和 SQL Server 数据库
- 统一接口:跨所有受支持的数据库类型的数据库操作的通用工具
- 数据库特定扩展:在需要时,提供针对数据库特定功能的特定工具
- 模式管理:创建、修改和删除表和索引
- 查询执行:执行原始 SQL 查询或使用结构化查询工具
- 事务支持:开始、提交和回滚事务
安装
先决条件
- Python 3.8 或更高版本
- 所需的 Python 包(使用 pip 自动安装):
- SQLAlchemy
- 各种数据库驱动程序,取决于您要使用的数据库:
- SQLite(包含在 Python 中)
- PostgreSQL:
psycopg2-binary
- MySQL/MariaDB:
mysql-connector-python
- SQL 服务器:
pyodbc
从源代码安装
配置
可以使用环境变量、配置文件或在运行时提供连接详细信息来配置服务器。
环境变量
DB_CONFIG_PATH
:JSON 配置文件的路径DB_CONNECTIONS
:以逗号分隔的连接 ID 列表或包含连接详细信息的 JSON 字符串
配置文件格式
用法
运行服务器
作为 Claude 的 MCP 服务器
作为独立 Web 服务器(适用于任何 LLM)
可用的 MCP 工具
连接管理
add_connection
:添加新的数据库连接test_connection
:测试数据库连接list_connections
:列出所有数据库连接remove_connection
:删除数据库连接
查询执行
execute_query
SQL 查询get_records
:从表中获取记录insert_record
:将记录插入表中update_record
:更新表中的记录delete_record
:从表中删除记录
模式管理
list_tables
:列出数据库中的所有表get_table_schema
:获取表的模式create_table
:创建新表drop_table
:删除表create_index
:在表上创建索引drop_index
:删除索引alter_table
:更改表结构
交易管理
begin_transaction
:开始交易commit_transaction
:提交事务rollback_transaction
:回滚事务
示例
添加连接
执行查询
创建表
插入记录
发展
运行测试
与其他法学硕士 (LLM) 的联系
当作为独立的 Web 服务器运行时,其他 LLM(例如 Llama 3)可以通过 HTTP 连接到数据库 MCP 服务器。该服务器公开以下端点:
端点
/list_tools
- GET 或 POST:返回所有可用工具及其描述和输入模式的列表/call_tool
- POST:执行特定的数据库工具
示例:来自另一个法学硕士的电话
要将此服务器与其他 LLM 一起使用,请让 LLM 生成发送到该服务器的 HTTP 请求。以下是为 Llama 3 等 LLM 构建提示的示例:
客户端集成的示例 Python 代码
执照
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
模型上下文协议服务器,提供通过统一接口连接和与各种数据库系统(SQLite、PostgreSQL、MySQL/MariaDB、SQL Server)交互的工具。
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server that provides database interaction capabilities through SQLite, enabling users to run SQL queries, analyze business data, and automatically generate business insight memos.Last updated -17MIT License
- -securityFlicense-qualityA Model Context Protocol server that enables SQL operations (SELECT, INSERT, UPDATE, DELETE) and table management through a standardized interface with SQLite databases.Last updated -37
- AsecurityAlicenseAqualityA Model Context Protocol server that enables executing SQL queries and managing connections with Microsoft SQL Server databases.Last updated -1565MIT License