Skip to main content
Glama

@yuuzu/sql-mcp

CI npm version

一个用于 MSSQL、PostgreSQL 和 SQLite 数据库操作的模型上下文协议 (MCP) 服务器。

安装

# Using bunx (recommended)
bunx @yuuzu/sql-mcp

# Using npx
npx @yuuzu/sql-mcp

Related MCP server: Database MCP Server

功能

  • 多数据库支持:MSSQL、PostgreSQL 和 SQLite(通过 better-sqlite3)

  • 8 个工具用于数据库操作

  • 三种查询模式:safe(安全)、write(写入)、full(完全)

  • 高级身份验证:Windows 身份验证 (MSSQL)、SSL 证书 (PostgreSQL)

工具

工具

描述

connect-database

连接到数据库服务器

disconnect

断开当前连接

connection-status

检查连接状态和查询模式

list-databases

列出服务器上的所有数据库

switch-database

切换到不同的数据库

list-tables

列出所有表和视图

describe-table

获取表结构详情

execute-query

执行 SQL 查询

查询模式

通过 SQL_MCP_MODE 环境变量控制查询权限:

模式

允许的操作

描述

safe (默认)

SELECT, WITH, EXPLAIN

只读,最安全

write

+ INSERT, UPDATE, DELETE

允许数据修改

full

+ CREATE, DROP, ALTER, TRUNCATE

完全访问,请谨慎使用

注意: PRAGMA 语句(例如 PRAGMA table_info(users))在所有模式(包括 safe)下都是允许的,因为它们是通常与 SQLite 一起使用的只读元数据查询。

# Example: Enable write mode
SQL_MCP_MODE=write bunx @yuuzu/sql-mcp

使用示例

Claude Desktop 配置

添加到你的 claude_desktop_config.json:

{
    "mcpServers": {
        "sql-mcp": {
            "command": "bunx",
            "args": ["@yuuzu/sql-mcp"],
            "env": {
                "SQL_MCP_MODE": "safe"
            }
        }
    }
}

连接到 MSSQL

{
    "tool": "connect-database",
    "arguments": {
        "engine": "mssql",
        "server": "localhost",
        "port": 1433,
        "user": "sa",
        "password": "your_password",
        "database": "master"
    }
}

连接到 PostgreSQL

{
    "tool": "connect-database",
    "arguments": {
        "engine": "postgres",
        "server": "localhost",
        "port": 5432,
        "user": "postgres",
        "password": "your_password",
        "database": "postgres"
    }
}

使用 Windows 身份验证连接 (MSSQL)

{
    "tool": "connect-database",
    "arguments": {
        "engine": "mssql",
        "server": "localhost",
        "windowsAuth": true
    }
}

使用 SSL 连接 (PostgreSQL)

{
    "tool": "connect-database",
    "arguments": {
        "engine": "postgres",
        "server": "your-server.com",
        "user": "postgres",
        "password": "your_password",
        "ssl": {
            "rejectUnauthorized": true,
            "ca": "/path/to/ca-certificate.crt"
        }
    }
}

连接到 SQLite (文件)

{
    "tool": "connect-database",
    "arguments": {
        "engine": "sqlite",
        "filename": "/absolute/path/to/database.db"
    }
}

连接到 SQLite (内存中)

适用于测试、演示或临时工作区。

{
    "tool": "connect-database",
    "arguments": {
        "engine": "sqlite",
        "filename": ":memory:"
    }
}

连接到 SQLite (只读)

{
    "tool": "connect-database",
    "arguments": {
        "engine": "sqlite",
        "filename": "/absolute/path/to/database.db",
        "readonly": true,
        "fileMustExist": true
    }
}

SQLite 运行时说明: SQLite 支持使用 better-sqlite3,它需要 Node.js。当通过 bunx 运行时,MSSQL 和 PostgreSQL 可以正常工作,但 SQLite 连接将返回一个明确的错误,指示你改用 npx 或 node。

开发

# Install dependencies
bun install

# Run in development mode
bun run dev

# Run tests
bun test

# Run tests with coverage
bun test --coverage

# Build
bun run build

# Type check
bun run typecheck

发布

发布通过 GitHub Actions 自动化。要创建新版本:

# Create and push a version tag
git tag v1.0.0
git push origin v1.0.0

这将:

  1. 构建项目

  2. 发布到带有来源证明的 npm

  3. 创建带有自动生成发行说明的 GitHub Release

要求:在你的 GitHub 仓库设置中设置 NPM_TOKEN 密钥。

许可证

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    A Model Context Protocol server that enables secure interaction with Microsoft SQL Server databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
    10
    1
    394
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that provides tools for connecting to and interacting with various database systems (SQLite, PostgreSQL, MySQL/MariaDB, SQL Server) through a unified interface.
    3
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that enables Large Language Models to access and interact with database connections, including viewing schemas and performing CRUD operations on connected databases.
    -
  • F
    license
    Not graded
    quality
    C
    maintenance
    A Model Context Protocol server that allows Large Language Models like Claude to execute SQL queries, explore database schemas, and maintain persistent connections to SQL Server databases.
    -