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

功能

  • 多数据库支持: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 连接将返回一个明确的错误,指示你改用 npxnode

开发

# 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

-
security - not tested
F
license - not found
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/NakiriYuuzu/sql-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server