SQLite数据库操作服务器

一个模块化的SQLite数据库操作服务器,提供HTTP API支持,适用于数据库管理和AI代理集成。

  • by iven86
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 iven86/sqlite-mcp-server

使用说明

SQLite MCP服务器

用于SQLite数据库操作的模块化模型上下文协议(MCP)服务器,支持HTTP API。

项目信息

  • 版本: 1.0.0
  • 许可证: CC BY-NC-SA 4.0(非商业)
  • python 3.8+(在3.12.3上测试)
  • 依赖关系: 仅限Python标准库

概述

SQLite MCP Server实现了用于安全SQLite数据库操作的模型上下文协议规范。它提供了一个RESTful HTTP API,与VS Code和AI代理无缝集成,用于数据库管理任务。

主要特点

  • 模块化架构 -通过专用模块实现关注点的清晰分离
  • HTTP API -遵循MCP协议的RESTful端点
  • 安全第一 -SQL注入保护、查询验证、超时控制
  • 系统集成 -全面的日志记录、优雅的关机、systemd支持
  • 多数据库 -支持多个SQLite数据库连接
  • 人工智能集成 -与用于AI代理交互的VS Code MCP设置兼容

快速开始

先决条件

  • Python 3.8+(在Python 3.12.3上测试)
  • 不需要外部依赖

安装和基本使用

# Start the server
python3 main.py

# Or use the start script (Linux/macOS)
chmod +x scripts/start_server.sh
./scripts/start_server.sh

快速测试

# Health check
curl http://localhost:9999/health

# List available tools
curl -X POST http://localhost:9999/ \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "tools/list", "id": "1"}'

可用工具

工具 描述 用例
connect_database 连接到SQLite数据库文件 数据库连接
query 使用参数执行SQL查询 数据检索和操作
get_tables 列出数据库中的所有表 架构探索
get_schema 获取表架构信息 架构检查
create 将新记录插入表 数据创建
read 通过过滤和排序读取记录 数据检索
update 更新现有记录 数据修改
delete 从表中删除记录 数据删除
analyze_table 获取表统计和分析 性能分析
search_data 跨多个表搜索 数据发现

VS代码集成

添加到您的VS代码 settings.json:

{
  "mcp": {
    "servers": {
      "sqlite-database": {
        "url": "http://localhost:9999"
      }
    }
  }
}

然后问AI代理:

  • “显示数据库中的所有表”
  • “执行此SQL查询:SELECT*FROM用户限制10”
  • “产品表的模式是什么?”

建筑

该项目采用模块化结构:

sqlite_mcp_server/
├── LICENSE              # MIT license file
├── main.py              # Entry point and CLI parsing
├── README.md            # Project documentation
├── requirements.txt     # Python dependencies
├── src/                 # Core MCP modules
│   ├── __init__.py      # Package initialization
│   ├── server.py        # Core MCP server implementation
│   ├── tools.py         # MCP tool definitions and handlers
│   ├── http_handler.py  # HTTP request/response handling
│   ├── database.py      # Database operations and utilities
│   ├── models.py        # Data models and error classes
│   └── utils.py         # Common utility functions
├── scripts/
│   ├── start_server.sh  # Server startup script
│   └── deploy.sh        # System deployment script
├── logs/               # Server logs directory
└── wiki/               # Documentation files
    ├── API-Reference
    ├── Configuration
    ├── Contributing
    ├── Examples
    ├── Getting-Started
    ├── Production-Deployment
    └── Troubleshooting

文档

访问我们的完整 Wiki文档 了解更多信息。

系统部署

# Deploy as systemd service
sudo ./scripts/deploy.sh

# Service management
sudo systemctl start sqlite-mcp-server
sudo systemctl enable sqlite-mcp-server
sudo systemctl status sqlite-mcp-server

安全功能

  • 使用参数化查询的SQL注入保护
  • 查询验证和超时控制
  • 防止内存耗尽的结果大小限制
  • 数据库安全的文件访问控制
  • 请求大小限制以防止DoS攻击

贡献

请参阅 贡献指南 用于开发设置、代码标准、测试要求和拉取请求过程。

许可证

本项目根据知识共享署名-非商业性相同方式共享4.0国际许可协议获得许可。商业使用需要作者的明确许可。请参阅 许可证 文件以获取详细信息。

链接


如需帮助,请查看 故障排除指南.


支持项目