Skip to main content
Glama
deepan2003

Database-MCP

by deepan2003

🏢 Company Database AI Manager

📖 概述

Company Database AI Manager 是一个面向企业数据库的自然语言接口。用户无需编写复杂的 SQL 查询来插入、更新或检索数据,只需用简单的英语输入命令即可(例如:“添加一个 IT 部门并为其分配 5 名员工”)。

该系统使用 Model Context Protocol (MCP) 将基于 Groq 的 LangGraph 代理安全地连接到本地 Python 数据库服务器。AI 会自动推理用户的提示词,选择合适的数据库工具,执行 SQL 操作,并在简洁的 Streamlit Web 界面中返回结果。

Related MCP server: PySqlitMCP

⚙️ 架构与工作原理

本项目采用真正的 Server/Client 架构,将数据库逻辑与 AI 逻辑分离:

  1. 服务端(server.py 和 models.py):运行一个独立的 FastMCP 服务器,托管 SQLite 数据库工具(setup_database、add_record、search_database)。

  2. 客户端(client.py 和 app.py):运行一个由 Groq 的 llama-3.3-70b-versatile 或 openai/gpt-oss-120b 提供支持的 LangGraph 代理。

  3. 协议(MCP):客户端通过标准输入/输出(stdio)安全地连接到服务器。它会向服务器请求可用的工具,将这些工具传递给 LangGraph 代理,并在不直接导入 Python 函数的情况下触发这些函数。

📂 文件夹结构

📦 llm-db-mcp
 ┣ 📜 .env                # Stores secure API keys (Do NOT commit to GitHub)
 ┣ 📜 .gitignore          # Prevents sensitive files from being pushed to Git
 ┣ 📜 app.py              # The Streamlit web UI for interacting with the AI
 ┣ 📜 client.py           # The terminal-based LangGraph agent script
 ┣ 📜 company.db          # The automatically generated SQLite database file
 ┣ 📜 models.py           # SQLAlchemy schemas (Departments, Roles, Employees, Projects)
 ┣ 📜 requirements.txt    # Project dependencies and version numbers
 ┗ 📜 server.py           # The FastMCP server hosting the database tools

🚀 设置与安装

1. 前提条件

Python 3.10 或更高版本。

一个免费的 Groq API 密钥。

2. 环境设置

创建并激活虚拟环境(建议使用 Conda):

conda create -n db_mcp python=3.11
conda activate db_mcp

3. 安装依赖

安装 requirements.txt 文件中的所有必需软件包:

pip install -r requirements.txt

4. 配置 API 密钥

在根目录下创建一个 .env 文件,并添加你的 Groq API 密钥:

GROQ_API_KEY=gsk_your_api_key_here

🖥️ 使用方法

选项 1:运行 Web 界面(推荐)

要启动交互式聊天界面,请运行:

streamlit run app.py

选项 2:运行终端客户端

要仅通过命令行运行代理:

🛠️ 可以尝试的示例提示词

应用运行后,请尝试在聊天框中输入以下提示词:

“设置数据库表。”(请先运行此提示词!)

“添加一个 IT 部门。”

“添加一位名叫 John Doe 的新员工,薪资为 75000,所属部门为 IT 部门。”

“显示所有薪资超过 50000 的员工。”

🔒 安全说明

切勿将你的 .env 文件或 API 密钥提交到版本控制中。

.gitignore 文件已预先配置,可阻止 .env 和 company.db 被上传到 GitHub。

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables natural language database operations and semantic document search through SQLite and vector database integration. Converts plain English instructions into SQL queries and provides RAG capabilities for uploaded documents.
    -
  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    Enables comprehensive SQLite database management through natural language, including database creation, table operations, data CRUD operations, backup/restore functionality, and CSV import/export capabilities.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables LLM agents to perform complete database operations on SQLite databases, including creating tables, executing queries, and managing data through CRUD operations with schema inspection capabilities.
    12 npm
    MIT