
terminal mcp openai
基于 MCP 协议的 PostgreSQL 数据库聊天机器人,使用 OpenAI API 生成 SQL 查询。
Repository Info
About This Server
基于 MCP 协议的 PostgreSQL 数据库聊天机器人,使用 OpenAI API 生成 SQL 查询。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP PostgreSQL Chatbot
A simple chatbot that uses the Model Context Protocol (MCP) to interact with a PostgreSQL database.
Project Structure
openai-agent-mcp/
├── config/
│ └── mcp_config.json # MCP Server configuration
├── src/
│ ├── __init__.py
│ ├── chatbot.py # Main chatbot implementation
│ └── postgres_client.py # PostgreSQL client utilities
├── .env # Environment variables (create from .env.template)
├── .env.template # Template for environment variables
├── requirements.txt # Dependencies
└── main.py # Entry point
Prerequisites
- Node.js and npm installed (for the MCP server)
- Python 3.8+ installed
- An OpenAI API key
- Access to the PostgreSQL database specified in the configuration
Setup Instructions
-
Install Dependencies
pip install -r requirements.txt -
Configure Environment Variables
Copy
.env.templateto.envand add your OpenAI API key:cp .env.template .env # Edit .env to add your API key -
Verify Database Connection
Ensure that the PostgreSQL connection string in
config/mcp_config.jsonis correct and that you have access to the database. -
Run the Chatbot
python main.py
Usage
Once the chatbot is running, you can interact with it by typing messages. The chatbot will:
- Parse your natural language query
- Generate an appropriate SQL query if needed
- Execute the query against the PostgreSQL database
- Format and explain the results
Example queries you can try:
- "What tables are available in the database?"
- "Show me the schema of the [table_name] table"
- "Query all records from [table_name] where [condition]"
- "Count the number of records in [table_name]"
- "Find the average [column] in [table_name]"
Type 'exit' or 'quit' to end the session.
How It Works
The chatbot uses the Model Context Protocol (MCP) to communicate with a PostgreSQL database through a standardized interface. The key components are:
- MCP Configuration: Defines how to connect to the PostgreSQL MCP server
- PostgreSQL Client: Handles communication with the MCP server
- Chatbot: Manages the conversation and uses OpenAI's API to generate responses
- Main Application: Provides a command-line interface for user interaction
The MCP server exposes database operations as tools that the chatbot can use to fulfill user requests. This architecture allows for standardized communication between AI models and various data sources.
Quick Start
Clone the repository
git clone https://github.com/sagivby/terminal-mcp-openaiInstall dependencies
cd terminal-mcp-openai
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.