CM

cuongtl1992/mcp-dbs

数据库管理

本页由 AI 翻译,技术细节请以原文为准。 查看原文

21 stars 6 forks 质量 65 趋势 0MIT

MCP 服务器支持你的大型语言模型与 SQL 数据库集成(SQLite、SQL Server、Postgres SQL)。

概览

一种用于连接和操作各种数据库系统的模型上下文协议(MCP)实现。 - SQLite - PostgreSQL - Microsoft SQL Server - MongoDB MCP数据库服务器可采用两种模式: 默认情况下,服务器在端口3001上以SSE(服务器发送事件)模式运行: 这将启动一个带有 SSE 端点的 HTTP 服务器,节点位于 http://localhost:3001/mcp. 你可以用 --port 选项指定自定义端口: 对于通过标准输入/输出通信的工具,可以使用 --stdio 选项: 你可以通过把mcp-dbs添加到Claude配置文件中,将它集成到Claude Desktop中。

概述(AI 翻译)

一种用于连接和操作各种数据库系统的模型上下文协议(MCP)实现。

支持的数据库

  • SQLite
  • PostgreSQL
  • Microsoft SQL Server
  • MongoDB

安装

用途

MCP数据库服务器可采用两种模式:

SSE模式(默认)

默认情况下,服务器在端口3001上以SSE(服务器发送事件)模式运行:

这将启动一个带有 SSE 端点的 HTTP 服务器 http://localhost:3001/mcp。

自定义移植版

您可以使用 --port 选项指定自定义端口:

STDIO 模式

对于通过标准输入/输出通信的工具,可以使用 --stdio 选项:

Claude桌面集成

你可以通过把mcp-dbs添加到Claude配置文件中,将它集成到Claude Desktop中。

配置步骤

  1. 打开或创建您的Claude Desktop配置文件
  2. 将mcp-dbs配置添加到mcpServers部分:

用你自己的数据库连接信息替换环境变量。

注释

  • command 应为 node
  • 在 args 中,提供 mcp-dbs 安装中 cli.js 文件的绝对路径

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

MCP Database Server

A Model Context Protocol (MCP) implementation for connecting to and working with various database systems.

Supported Databases

  • SQLite
  • PostgreSQL
  • Microsoft SQL Server
  • MongoDB

Installation

npm install -g mcp-dbs

Usage

The MCP Database Server can be used in two modes:

SSE Mode (Default)

By default, the server runs in SSE (Server-Sent Events) mode on port 3001:

npx mcp-dbs

This will start an HTTP server with an SSE endpoint at http://localhost:3001/mcp.

Custom Port

You can specify a custom port using the --port option:

npx mcp-dbs --port 8080

STDIO Mode

For tools that communicate over standard input/output, you can use the --stdio option:

npx mcp-dbs --stdio

Claude Desktop Integration

You can integrate mcp-dbs with Claude Desktop by adding it to your Claude configuration file.

Configuration Steps

  1. Open or create your Claude Desktop configuration file
  2. Add the mcp-dbs configuration to the mcpServers section:
{
  "mcpServers": {
    "mcp-dbs": {
      "command": "node",
      "args": [
        "/path/to/your/mcp-dbs/dist/cli.js",
        "--stdio"
      ],
      "env": {
        "MCP_MONGODB_URI": "mongodb://localhost:27017",
        "MCP_MONGODB_DATABASE": "your-database-name"
      }
    }
  }
}

Replace the environment variables with your own database connection details.

Notes

  • The command should be node
  • In args, provide the absolute path to the cli.js file in your mcp-dbs installation
  • Configure the appropriate environment variables for your database type (see the environment variables section below)
  • You can use environment variables for any of the supported databases (SQLite, PostgreSQL, SQL Server, or MongoDB)

Using with Claude

Once configured, Claude will be able to access your database using the MCP tools described below. You can ask Claude to:

  • Connect to your database
  • Execute queries and get results
  • Explore your database schema
  • Work with tables and data

Tools

  • connect-database: Connect to a database
  • disconnect-database: Disconnect from a database
  • execute-query: Execute a query and return results
  • execute-update: Execute a query without returning results

Resources

  • database-schema: Get the full database schema
  • table-schema: Get the schema for a specific table
  • tables-list: Get a list of all tables

Using environment variables for configuration

You can configure your database connections using environment variables:

SQLite

# Set these environment variables before connecting
export MCP_SQLITE_FILENAME="path/to/database.db"
在 GitHub 查看完整 README

安装

npx mcp-dbs
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "mcp-dbs": { "command": "node", "args": [ "/path/to/your/mcp-dbs/dist/cli.js", "--stdio" ], "env": { "MCP_MONGODB_URI": "mongodb://localhost:27017", "MCP_MONGODB_DATABASE": "your-database-name" } } } }