Token导航 LogoToken导航

MCP Server · 数据服务

Quadraplex (Neslihaneti)

一个基于Streamlit和LangChain的对话式AI前端,通过Ollama和MCP协议与PostgreSQL数据库交互,实现自然语言查询和管理。

stdio官方级别未说明来源级核验工具 0
自然语言处理数据分析PostgreSQLLangChain

快速开始

作者 / 组织
neslihaneti
提供方
neslihaneti

工具数量

0

来源目录标注

资源数量

0

来源目录标注

提示词数量

0

来源目录标注

GitHub Star

0

仓库热度

收录来源

1 个

MCP World

选型结论

Quadraplex (Neslihaneti) 属于数据服务类 MCP Server,公开资料标注 0 个工具,通过stdio 本地进程接入,客户端适配情况以官方文档为准,有可以直接复制的安装命令;接入前要先准备 会话凭据。

分类

数据服务

传输方式

stdio

认证方式

会话凭据

部署方式

公开资料未说明

安装与配置

安装命令

pip install -r requirements.txt

公开命令不是通用的启动方式,拼不出可靠配置示例;请在客户端 MCP 配置里按官方文档填写 command 和 args。

上手步骤

  1. 1

    准备运行环境

    stdio 服务在本地起进程,需要先装好 对应的运行时,再按安装命令拉取依赖。

  2. 2

    安装服务

    复制下面的安装命令执行;命令里带占位符的位置换成自己的密钥或路径。

  3. 3

    写入客户端配置

    在客户端的 MCP 配置里填启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4

    验证是否可用

    连接成功后客户端会列出 0 个工具,随便调一个只读工具确认能返回结果。

接入前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

详细介绍

🤖 使用MCP代理的数据库聊天机器人

对话式AI聊天机器人前端 溪流 它使用以下方式与PostgreSQL数据库交互 LangChain, 奥拉玛,以及 MCP(模型上下文协议) 工具。

✨ 特性

  • 💬 自然语言聊天界面 -像ChatGPT一样与数据库对话
  • 🤖 AI驱动的查询 -由Ollama提供动力(Qwen3 8B型号)
  • 🔗 MCP集成 -通过MCP服务器访问数据库工具
  • 📊 实时数据库交互 -查询、插入、删除和管理数据
  • 💾 聊天记录 -跟踪对话
  • 🎨 漂亮的UI -具有状态监控功能的现代Streamlit界面
  • ⚡ 异步处理 -具有适当事件循环处理的非阻塞聊天响应
  • 🔄 智能事件循环管理 -无缝处理Streamlit的线程模型
  • 📋 数据库状态监控 -侧边栏中的实时连接和表状态

🏗️ 建筑

┌──────────────────────────────────────────────────────────────┐
│                  Streamlit Frontend                           │
│            (streamlit_chatbot.py)                             │
│  ┌────────────────────────────────────────────────────────┐  │
│  │ • Beautiful chat interface                             │  │
│  │ • Async event loop management (run_async helper)       │  │
│  │ • User input/output handling                           │  │
│  │ • Chat history management                              │  │
│  │ • Database connection status monitoring                │  │
│  └────────────────────────────────────────────────────────┘  │
└────────────────────┬─────────────────────────────────────────┘
                     │
                     ▼
┌──────────────────────────────────────────────────────────────┐
│           LangChain MCP Agent (async)                         │
│  ┌────────────────────────────────────────────────────────┐  │
│  │ • Query understanding & interpretation                 │  │
│  │ • Tool loading from MCP Server                         │  │
│  │ • Tool selection & calling                             │  │
│  │ • Response generation                                  │  │
│  └────────────────────────────────────────────────────────┘  │
└────────────────────┬─────────────────────────────────────────┘
                     │
        ┌────────────┼────────────┬────────────┐
        ▼            ▼            ▼            ▼
    ┌─────────┐ ┌─────────┐ ┌──────────┐ ┌────────────┐
    │ Ollama  │ │ MCP     │ │PostgreSQL│ │ Database   │
    │(LLM)    │ │ Server  │ │(DB)      │ │ Functions  │
    │Qwen3 8B │ │(Tools)  │ │localhost │ │            │
    │:11434   │ │:7452    │ │:5432     │ │list_tables,│
    │         │ │         │ │          │ │get_db_conn │
    └─────────┘ └─────────┘ └──────────┘ └────────────┘

📋 先决条件

所需服务

  • PostgreSQL 12+ -数据库(本地或Docker)
  • 奥拉玛 -LLM推理机
  • MCP 服务器 -数据库工具(server.py)

系统要求

  • Python 3.10+
  • 最低8GB RAM(适用于Ollama)
  • 5GB磁盘空间(适用于Ollama型号)

🚀 安装和设置

步骤1:克隆/设置项目

cd /Users/neslihaneti/Desktop/MCP_agent_db_streamlit

步骤2:安装Python依赖项

pip install -r requirements.txt

依赖关系:

  • 流式照明>=1.28.0
  • langchain>=1.2.6
  • langchain mcp适配器>=0.2.1
  • 郎链胶原蛋白>=1.0.1
  • psycopg>=3.3.2
  • fastmcp>=2.14.3

步骤3:启动PostgreSQL

使用Docker Compose:

docker-compose up -d

使用本地PostgreSQL:

# Make sure PostgreSQL is running on localhost:5432

默认凭据:

Host: localhost
Port: 5432
Database: postgres
User: postgres
Password: postgres

步骤4:安装并运行Olama

  1. 下载Ollama:

- 访问https://ollama.ai - 为您的操作系统下载并安装

  1. 启动Ollama服务器:
   ollama serve

(在终端中保持此运行)

  1. 拉动模型:

在另一个终端中:

   ollama pull qwen3:8b-fp16

⏱️ 首次下载大约需要5-10分钟

步骤5:启动MCP服务器

在新终端中:

python server.py

预期产量:

INFO:     Uvicorn running on http://0.0.0.0:7452

步骤6:启动Streamlit聊天机器人

选项A:使用启动脚本(推荐)

chmod +x streamlit_run.sh
./streamlit_run.sh

选项B:使用紫外线直接发射(项目使用紫外线)

uv run streamlit run streamlit_chatbot.py

选项C:使用pip直接启动

streamlit run streamlit_chatbot.py

🎉 应用程序打开时间: http://localhost:8501

初始负载

  • 代理初始化时,首次加载可能需要30-60秒
  • Ollama在首次使用时将模型加载到内存中
  • 后续请求将更快
  • 检查侧边栏中的服务状态指示器

💬 使用指南

开始对话

  1. 打开http://localhost:8501在浏览器中
  2. 在聊天输入中键入您的问题或命令
  3. 按Enter键或单击发送
  4. 等待AI处理(显示“Agent正在思考…”)
  5. 阅读回复和任何结果

示例问题

查看数据
"Show me all tables in the database"
"What data is in the users table?"
"List all records from the orders table"
"Show me the first 10 products"
筛选和搜索
"Find users from New York"
"Show active accounts"
"Get all orders from this month"
"Search for users with name John"
添加数据
"Add a new user named Alice"
"Insert a new product"
"Create a new order"
获取信息
"What columns does the users table have?"
"Tell me about the database structure"
"How many tables are in the database?"

聊天界面

用户消息 (蓝色,右对齐)

  • 您的问题和命令
  • 显示在聊天气泡中

助理回应 (灰色,左对齐)

  • AI的答案和解释
  • 数据库结果(如适用)

控制

  • 🔄 按钮:清除聊天记录
  • 输入框:键入您的消息
  • 侧边栏:检查服务状态和可用表格

🔧 配置

数据库连接

在中编辑连接设置 streamlit_chatbot.py:

# ==================== Configuration ====================
DB_HOST = "localhost"      # Database host
DB_PORT = 5432            # Database port
DB_NAME = "postgres"      # Database name
DB_USER = "postgres"      # Database user
DB_PASSWORD = "postgres"  # Database password
MCP_SERVER_URL = "http://localhost:7452/mcp"  # MCP Server URL

Ollama配置

编辑 streamlit_chatbot.py:

llm = ChatOllama(
    model="qwen3:8b-fp16",        # Model name
    temperature=0,                # Creativity (0=deterministic, 1=creative)
    base_url="http://localhost:11434"  # Ollama server URL
)

更改Olama模型

可用型号:

ollama pull qwen2:7b           # Smaller, faster
ollama pull qwen3:8b-fp16      # Current (8B parameters)
ollama pull neural-chat:latest # Alternative

然后更新 streamlit_chatbot.py:

model="neural-chat:latest"  # Change this line

📊 系统状态

侧边栏显示所有组件的实时状态:

📊 System Status
✅ MCP Agent Ready        - LangChain agent initialized
✅ LLM (Ollama) Ready     - Ollama service running
✅ MCP Server Ready       - Database tools available
✅ Database Connected     - PostgreSQL accessible

Tables: 5                 - Number of tables in DB
📋 Available Tables       - List of tables

状态指示器:

  • ✅ 绿色=服务正在运行
  • ❌ 红色=服务未运行
  • 🟡 黄色=连接问题

� 异步事件循环管理

聊天机器人使用自定义 run_async() help函数用于正确管理Streamlit多线程环境中的异步事件循环。

运作原理

def run_async(coroutine):
    """Helper function to run async code in Streamlit context"""
    try:
        loop = asyncio.get_event_loop()
        if loop.is_running():
            # If loop is already running, create new loop
            new_loop = asyncio.new_event_loop()
            asyncio.set_event_loop(new_loop)
            return new_loop.run_until_complete(coroutine)
        else:
            return loop.run_until_complete(coroutine)
    except RuntimeError:
        # No event loop exists, create one
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        try:
            return loop.run_until_complete(coroutine)
        finally:
            loop.close()

使用Async的关键组件

  1. 代理初始化 - initialize_mcp_agent()

- 加载MCP客户端 - 从MCP服务器获取工具 - 创建LangChain代理 - 处理方式: agent_config = run_async(initialize_mcp_agent())

  1. 查询处理 - process_user_query_with_agent()

- 处理用户输入 - 呼叫代理工具 - 生成响应 - 处理方式: response_data = run_async(process_user_query_with_agent(...))

  1. 工具调用 -MCP工具被异步调用

- 防止阻止UI - 保持响应能力 - 显示“代理正在思考…”旋转器

�🐛 故障排除

“代理未初始化”

❌ Error: Failed to initialize MCP Agent

解决方案:

  1. 检查所有服务是否正在运行:
   # Check Ollama
   curl http://localhost:11434

   # Check MCP Server
   curl http://localhost:7452

   # Check PostgreSQL
   psql -U postgres -h localhost
  1. 重新启动Streamlit:按 Ctrl+C 并重新运行

“特工在想……”花了太长时间

可能的原因:

  • Ollama模型尚未加载
  • 系统RAM已满
  • 网络/CPU速度慢

解决方案:

  • 等待1-2分钟进行第一次查询(模型加载)
  • 确保8GB+RAM可用
  • 检查CPU使用情况 top 或任务管理器

“数据库连接失败”

解决方案:

# Test PostgreSQL connection
psql -U postgres -h localhost -d postgres

# Or restart Docker container
docker-compose restart mcp-pg-unified

“Ollama服务没有响应”

解决方案:

# Install Ollama if not present
# https://ollama.ai

# Start Ollama server
ollama serve

# In another terminal, pull model
ollama pull qwen3:8b-fp16

“MCP服务器连接被拒绝”

解决方案:

# Start the MCP server
python server.py

# Check if running
curl http://localhost:7452/health

# Or check logs
tail -f ~/.ollama/logs

“端口已在使用中”

Error: Address already in use

解决方案:

# Kill process on port 8501
lsof -i :8501 | grep LISTEN | awk '{print $2}' | xargs kill -9

# Or use different port
streamlit run streamlit_chatbot.py --server.port 8502

“运行时错误:没有当前事件循环”

RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'

解决方案:

  • 这是由自动处理的 run_async() 辅助函数
  • 如果您看到此错误,则可能无法正确使用帮助程序
  • 确保所有异步函数都被调用 run_async() 包装器
  • 重新启动Streamlit: Ctrl+C 并重新运行

📈 性能提示

为了更快的响应

  1. 使用较小的模型:
   ollama pull qwen2:7b
   # Update streamlit_chatbot.py: model="qwen2:7b"
  1. 增强Ollama的记忆力:
   export OLLAMA_NUM_THREAD=8
   ollama serve
  1. 在GPU上运行(如果可用):

- Ollama自动检测GPU - 包括Nvidia/金属支持

为了获得更好的响应

  1. 使用较大型号:
   ollama pull qwen3:14b  # Larger, more accurate
  1. 提高创造力的温度:
   temperature=0.7  # More creative responses

🔒 安全注意事项

仅限开发

此设置是 可生产的.生产:

  1. 使用环境变量:
   from dotenv import load_dotenv
   DB_USER = os.getenv("DB_USER")
   DB_PASSWORD = os.getenv("DB_PASSWORD")
  1. 添加身份验证:
   import streamlit_authenticator as stauth
   # Implement user login
  1. 使用HTTPS:

- 反向代理后部署(nginx) - 使用SSL证书

  1. 限制访问:

- 白名单IP地址 - 使用VPN/防火墙规则

  1. 审核日志记录:

- 记录所有数据库查询 - 监控AI响应

📚 文件结构

MCP_agent_db_streamlit/
├── streamlit_chatbot.py        # Main Streamlit app
├── server.py                   # MCP Server (backend)
├── mcp_agent.py               # AI Agent (backend)
├── streamlit_run.sh           # Launch script
├── requirements.txt           # Python dependencies
├── docker-compose.yml         # Docker configuration
├── Dockerfile                 # Container build
├── README.md                  # This file
└── pg_data/                   # PostgreSQL data volume

🎓 运作原理

对话流程

User Input (Chat Interface)
    ↓
Streamlit receives message
    ↓
run_async() creates/manages event loop
    ↓
initialize_mcp_agent() (if first time)
    ├─ Initialize ChatOllama LLM
    ├─ Initialize MCP Client
    └─ Load tools from MCP Server
    ↓
process_user_query_with_agent()
    ├─ Load tools asynchronously
    ├─ Pass to LangChain agent
    └─ Execute with Ollama model
    ↓
Ollama LLM generates response
    ├─ Understands intent
    ├─ Selects tools
    └─ Generates natural language response
    ↓
Results formatted & displayed
    ↓
Chat history updated

异步执行流程

Agent Query Processing:
1. User message → run_async(process_user_query_with_agent())
2. Async function awaits:
   - await client.get_tools()  (fetch MCP tools)
   - await agent.ainvoke()     (run LangChain agent)
3. run_async() helper:
   - Checks for existing event loop
   - Creates new loop if needed
   - Executes coroutine
   - Returns result to Streamlit
4. UI updates with response

工具调用

当您询问数据时,代理:

  1. 理解你的意图
  2. 调用MCP工具:

- list_tables() -获取可用的桌子 - search_documents_dynamic() -查询数据 - insert_data() -添加记录 - create_custom_table() -创建表格 - delete_records_dynamic() -删除数据

  1. 流程结果
  2. 生成自然语言响应

🚀 高级功能

自定义系统提示

编辑代理的行为:

system_prompt="""You are a database expert...
Your instructions here"""

添加自定义工具

在 server.py,创建新的MCP工具:

@mcp.tool()
async def my_custom_tool(param: str):
    """Custom tool description"""
    # Your code here
    return result

多回合对话

聊天机器人记住上下文:

User: "Show me active users"
Bot: [displays active users]

User: "How many are there?"
Bot: "There are X active users from the previous query"

📞 支持和问题

获取帮助

  1. 检查上面的故障排除部分
  2. 查看终端日志
  3. 检查侧边栏中的服务状态

常见问题检查表

  • \[\]所有服务都在运行吗?(检查侧边栏状态)
  • \[\]正确的端口? (5432, 7452, 11434, 8501)
  • \[\]模型已下载? (ollama list)
  • \[\]互联网连接?(用于模型下载)
  • \[\]足够的RAM?(建议8GB+)

📄 许可证

该项目是为教育和发展目的而提供的。

🎉 你都准备好了!

您的数据库聊天机器人已准备好使用:

# 1. Start all services
docker-compose up -d          # PostgreSQL
ollama serve                  # Ollama (separate terminal)
python server.py              # MCP Server (separate terminal)

# 2. Launch chatbot
./streamlit_run.sh            # Or: streamlit run streamlit_chatbot.py

# 3. Open browser
# http://localhost:8501

享受与您的数据库聊天! 🤖

工具与能力

工具数量

0

资源数量

0

提示词数量

0

能力标签

自然语言处理Python本地部署数据库管理AI聊天机器人PostgreSQLLangChain

数量来自来源目录的标注,具体工具清单以官方文档为准。

典型使用场景

用自然语言查库

不用手写 SQL,直接问数据,让模型组织查询语句。

数据巡检

定期拉指标、做对比,把异常项整理成一段说明。

打通业务数据

把数据库、数仓和接口接进同一个上下文,减少导出再上传。

选择建议

值得选的地方

  • 只提供 0 个工具,职责集中,接入后不容易误操作。
  • 有现成的安装命令,不用自己找入口,照着跑就能起服务。
  • 公开说明写得比较完整,接入前能看清能力边界。

先想清楚的地方

  • stdio 方式要求本地装好 运行环境,换机器要重新装一遍。
  • 需要自备会话凭据,没有凭据没法直接试。
  • 第三方目录整理,版本更新和行为细节以官方仓库为准。

更适合

  • 需要在数据服务场景里让模型直接调用外部能力的人。
  • 想先快速试一下、能接受在本地跑服务的人。

不太适合

  • 完全不想在本地装环境的人。
  • 暂时拿不到会话凭据的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

5 个同类
MCP Server工具数传输方式安装命令收录来源最后核验
Quadraplex (Neslihaneti)

MCP World · 本页

0stdio有1 个2026-05-17
Memory 9d25f64e

MCP World

9未说明未标注1 个2026-05-17
Prisma MCP Server

MCP World

0stdio有3 个2026-05-17
Astr Bot

MCP World

0stdio有1 个2026-05-17
Getzep MCP

MCP World

9stdio有1 个2026-05-17

按同分类和工具数量挑出最接近的几条,字段以各自详情页为准。

常见问题

5 条

Quadraplex (Neslihaneti) 怎么安装?

公开资料给出的安装命令是 pip install -r requirements.txt,运行环境为 未标注。装完后按客户端要求写进 MCP 配置,重启客户端生效。

Quadraplex (Neslihaneti) 怎么在 Claude Desktop、Cursor 里配置?

它是stdio 本地进程,客户端配置里要写启动命令和参数,运行环境是 未标注;保存后完全退出客户端再打开,配置才会生效。

Quadraplex (Neslihaneti) 收费吗?

本站只整理公开资料,不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

Quadraplex (Neslihaneti) 需要 API Key 吗?

公开资料标注的认证方式是会话凭据,也就是要先拿到凭据才能连上;凭据只填在自己本地的配置里,不要写进公开仓库。

Quadraplex (Neslihaneti) 支持哪些客户端?

公开资料没有标注具体客户端;能配置本地 MCP 命令的客户端都能接,配置方式参照官方文档。

来源信息

继续浏览同类 MCP