数据库连接器

Scansca是一个自托管服务器,通过模型上下文协议(MCP)将大型语言模型(LLM)客户端与数据库系统连接,使用户能够通过自然语言从多样化的数据环境中获取集成见解。

  • by RoyceLeonD
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 royceleond/scansca

使用说明

Scansca-MCP数据库连接器(正在开发中)

Scansca是一个自托管服务器,通过模型上下文协议(MCP)将大型语言模型(LLM)客户端与数据库系统连接起来。它使技术用户能够使用自然语言从不同的数据环境中获得综合见解。

特性

  • 多数据库支持:连接到PostgreSQL(MySQL、SQLite和DynamoDB即将推出)
  • MCP集成:与MCP兼容的LLM客户端无缝集成
  • 自动架构发现:以最少的配置公开数据库结构
  • 简单API:用于数据库操作的RESTful接口
  • Docker就绪:使用Docker Compose轻松部署

快速开始

先决条件

  • 转到1.22+
  • Docker和Docker Compose(可选,用于数据库依赖关系)

安装

# Clone the repository
git clone https://github.com/royceleond/scansca.git
cd scansca

# Install dependencies
make deps

# Start a PostgreSQL database (optional)
make docker-compose

# Build and run the server
make run

基本用法

注册数据库

curl -X POST http://localhost:8080/api/v1/databases \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-postgres",
    "type": "postgresql",
    "connection_string": "postgres://scansca_user:scansca_password@localhost:5432/scansca"
  }'

执行查询

curl -X POST http://localhost:8080/api/v1/query \
  -H "Content-Type: application/json" \
  -d '{
    "database": "my-postgres",
    "query": "SELECT current_database(), current_user"
  }'

与LLM客户端一起使用

对于MCP兼容的LLM客户端,Scansca在以下位置公开端点:

GET  /mcp/v1/tools               # Lists available tools
POST /mcp/v1/tools/:name/invoke  # Invokes a specific tool

文档

通过运行以下命令查看文档:

make docs

这将在端口8080上启动文档服务器(可使用DOCS_port配置)。

有关更多信息,请参阅 在线文档.

建筑

┌──────────────────────────┐
│      MCP Client           │
│  (LLM, CLI, Application)  │
└──────────────┬───────────┘
               │
               ▼
┌──────────────────────────┐
│    Scansca MCP Server     │  HTTP API for database operations
│                           │  and MCP protocol support
├──────────────────────────┤
│    Database Connectors    │  Uniform interface for different
└──────────────┬───────────┘  database systems
               │
               ▼
┌──────────────────────────┐
│      Database Servers     │
│  (Postgres, MySQL, etc.)   │
└──────────────────────────┘

发展

# Build the project
make build

# Run tests
make test

# Start the server
make run

# Start PostgreSQL using Docker Compose
make docker-compose

# Stop Docker Compose services
make docker-compose-down

# Start documentation server
make docs

# Build and publish documentation to a Docker registry
make docs-publish

环境配置

对于Docker注册表URL等敏感设置,Scansca使用 .env git未跟踪的文件:

  1. 复制模板文件以创建配置:

    cp .env.example .env
    
  2. 编辑 .env 使用您的设置文件:

    # Registry settings - Replace with your actual values
    DOCKER_REGISTRY=docker.your-company.com
    
  3. 当您运行make命令时,Makefile将自动加载这些设置

项目结构

scansca/
├── cmd/          # Application entry point
├── config/       # Configuration files
├── docker/       # Docker configurations
├── docs/         # Documentation
├── internal/     # Private implementation
│   ├── db/       # Database connections and models
│   ├── server/   # HTTP server and API
│   └── mcp/      # MCP protocol implementation
└── Makefile      # Build automation

许可证

该项目根据 Scansca软件许可证 这允许:

  • 免费用于非商业目的、非营利组织和小型实体(收入/资产低于10000美元)
  • 商业和政府用途需要作者单独许可

有关完整详细信息,请参阅许可证文件。

贡献

欢迎投稿!请随时提交拉取请求。