MCP Knowledge Base Assistant
About
An intro to MCP: an MCP server with a knowledge base tool containerized with Docker and connected to a client-side python application using SSE
Explore
- Exposes a knowledge base as an MCP tool (get_knowledge_base)
- Integrates OpenAI GPT-4o for natural language query processing
- Supports both direct Python execution and Docker containerization
- Proper lifecycle management with async context managers
- Simple JSON-based knowledge base (data/kb.json) for easy customization
- Follows MCP client-host-server architecture with SSE transport on port 8050
- Python 3.11 or higher
- Docker (optional, for containerized server)
- OpenAI API key
With the server running, open a new terminal and run:
python client.py
The client will connect to the server and ask a sample question about the company's equal opportunity policy. You can modify the query in client.py to ask different questions about company policies.
Example output:
Connected to server with tools:
- get_knowledge_base: Retrieve the entire knowledge base as a formatted string.
Query: What is the company's equal opportunity policy?
Response: The company's equal opportunity policy is as follows: The company is an equal opportunity employer and prohibits discrimination based on race, gender, age, religion, disability, or any other protected characteristic.
You can add more tools to the server by defining additional functions with the @mcp.tool() decorator in server.py.
A demonstration of the Model Context Protocol (MCP) that connects an OpenAI-powered client to a knowledge base server. This project showcases how to build a simple but powerful AI assistant that can answer questions about company policies by accessing a knowledge base through MCP.
π Overview
This project demonstrates:
1. How to build an MCP server that exposes a knowledge base as a tool
2. How to create an MCP client that connects to the server
3. How to integrate OpenAI's API to create a natural language interface
4. How to use Docker to containerize the server component
The system allows users to ask questions in natural language about company policies, and the AI will retrieve relevant information from the knowledge base to provide accurate answers.
ποΈ Architecture
The project follows the MCP client-host-server architecture:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β β β β
β OpenAI Model βββββββ€ MCP Client βββββββ€ MCP Server β
β (GPT-4o) β β (client.py) β β (server.py) β
β β β β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β β
β Knowledge Base β
β (kb.json) β
β β
βββββββββββββββββββ
- MCP Server: Exposes the knowledge base as a tool that can be queried
- MCP Client: Connects to the server and integrates with OpenAI's API
- OpenAI Model: Processes natural language queries and generates responses
- Knowledge Base: JSON file containing Q&A pairs about company policies
π Getting Started
Prerequisites
- Python 3.11 or higher
- Docker (optional, for containerized server)
- OpenAI API key
Installation
1. Clone the repository:
git clone <repository-url>
cd MCP-Get-Started
2. Create a virtual environment and install dependencies:
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
pip install -r requirements.txt
3. Create a .env file in the project root with your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here
Running the Server
Option 1: Run directly with Python
python server.py
Option 2: Run with Docker
```
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



