MCP(模型上下文协议)服务器
项目结构
├── client.py # Client-side interaction script
├── server.py # Main MCP server implementation
├── pg_connect.py # PostgreSQL database connection
├── lm_config.py # Language model configuration
│
├── .env.example # Example environment configuration
├── .env.dev # Development environment configuration
├── requirements.txt # Project dependencies
└── .gitignore # Git ignore file先决条件
- Python 3.10+
- PostgreSQL
- API访问人工智能提供商(Anthropic、Google)
安装
1.克隆存储库
git https://github.com/VajraM-dev/Postgres-MCP-Server-With-SSE-Transport.git2.创建虚拟环境
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`3.安装依赖项
pip install -r requirements.txt4.配置环境
- 复制
.env.example向.env.dev - 填写所需配置:
cp .env.example .env.dev
nano .env.dev # or use your preferred text editor配置参数
POSTGRES_USERNAME:PostgreSQL数据库用户名POSTGRES_PASSWORD:PostgreSQL数据库密码POSTGRES_DB_NAME:数据库名称POSTGRES_HOST:数据库主机POSTGRES_PORT:数据库端口MCP_NAME:服务器名称MCP_HOST:服务器主机MCP_PORT:服务器端口TRANSPORT:通信传输(sse/stdio)ANTHROPIC_API_KEY:无烟煤API键GOOGLE_API_KEY:Google API密钥USE_PROVIDER:默认AI提供程序
运行服务器
发展模式
python server.py客户互动
python client.py主要特点
- 🔒 安全配置管理
- 🗃️ PostgreSQL数据库集成
- 🤖 多提供商AI模型支持
- 📡 灵活的通信传输
- 🛡️ 可扩展工具注册
支持的AI提供商
- 拟人(克劳德模型)
- 谷歌(双子座车型)
工具和端点
可用工具
list_tables():检索数据库表- 可以通过装饰器轻松添加自定义工具
端点
/sse:服务器发送事件终结点- 可定制的路线和工具注册
扩展框架
添加新工具
@app.tool()
def custom_tool():
"""Custom tool implementation"""
# Your tool logic here配置AI提供者
修改 lm_config.py 添加或配置新的AI提供商。
