mcpField
M
MCP Host Client Server SSE

MCP Host Client Server SSE

Local
github.com/HanShan006Developer Tools4Updated 77w ago

About MCP Host Client Server SSE

A natural-language SQL query project demonstrating an MCP host, client, and server architecture for developers exploring MCP and database integration. It connects to SQLite over SSE and uses OpenAI to translate natural language into SQL.

Key features

  1. 01Natural-language to SQL queries
  2. 02MCP host, client, and server example
  3. 03SSE communication
  4. 04SQLite database integration
  5. 05OpenAI/DeepSeek API integration

Use cases

  1. 01Query SQLite data in natural language
  2. 02Inspect user and order records
  3. 03Calculate spending totals by user

MCP support

The project demonstrates communication among an MCP host, client, and server. Its MCP server receives requests over SSE and queries a SQLite database.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

MCP Host Client Server SSE

基于MCP(Model Context Protocol)协议实现的自然语言SQL数据库查询系统,支持通过大语言模型将自然语言转换为SQL查询。本项目展示了如何使用MCP协议构建服务器-客户端架构,并集成OpenAI实现智能查询功能。

功能特点

  • 🚀 基于MCP协议的服务器-客户端架构
  • 📝 支持自然语言转SQL查询
  • 🔄 使用SSE(Server-Sent Events)实现实时通信
  • 📊 SQLite数据库集成
  • 🤖 OpenAI/DeepSeek接口集成
  • 📝 完整的日志记录系统
  • ⚡ 异步操作支持

系统架构

graph TD
    A[用户] -->|自然语言问题| B[MCP Host]
    B -->|API调用| C[OpenAI]
    C -->|SQL查询| B
    B -->|MCP请求| D[MCP Server]
    D -->|查询| E[SQLite DB]
    E -->|结果| D
    D -->|SSE响应| B
    B -->|自然语言解释| A

快速开始

前置要求
  • Python 3.8+
  • pip包管理器
  • OpenAI API密钥
安装步骤
  1. 克隆仓库:
git clone https://github.com/HanShan006/MCP_Host_Client_Server_SSE.git
cd MCP_Host_Client_Server_SSE
  1. 安装依赖:
pip install openai mcp-framework starlette uvicorn
  1. 配置API密钥: 创建config.ini文件并添加以下内容:
[secrets]
API_KEY=your_api_key_here
  1. 创建示例数据库:
python create_database.py
运行服务
  1. 启动MCP服务器:
python mcp_server.py
  1. 运行客户端应用:
python mcp_host.py

数据库结构

users表
字段类型说明
idINTEGER用户ID(主键)
nameTEXT用户名
ageINTEGER年龄
emailTEXT邮箱地址
orders表
字段类型说明
idINTEGER订单ID(主键)
user_idINTEGER用户ID(外键)
product_nameTEXT商品名称
priceREAL价格
order_dateTEXT订单日期

示例查询

系统支持多种自然语言查询,例如:

  1. "查询所有用户的信息"
  2. "显示张三的所有订单"
  3. "统计每个用户的消费总额"
  4. "查询订单金额超过5000元的用户信息"

项目结构

MCP_Host_Client_Server_SSE/
├── mcp_server.py      # MCP服务器实现
├── mcp_client.py      # MCP客户端实现
├── mcp_host.py        # 主机程序(集成OpenAI)
├── create_database.py # 数据库初始化脚本
├── database.db        # SQLite数据库文件
├── config.ini         # 配置文件
└── README.md          # 项目文档

技术栈

  • Python 3.8+
  • MCP Framework
  • SQLite
  • OpenAI API
  • Starlette
  • Server-Sent Events (SSE)
  • Async/Await

版本历史

v1.0.0 (2025-05-07)
  • ✨ 初始版本发布
  • 🎉 实现基础MCP服务器功能
  • 🎉 完成客户端通信模块
  • 🎉 集成OpenAI自然语言处理
  • 🎉 添加SQLite数据库支持
  • 📝 完善项目文档

贡献者

开源协议

本项目采用 MIT 协议开源,详情请参见 LICENSE 文件。

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.