MCP Knowledge Base Assistant

by kofiadom

314 downloads
Not rated
GitHub

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

Details

Author
kofiadom
Downloads
314
Categories
Knowledge Base

- 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

Install prerequisites (Python 3.11+, OpenAI API key), clone the repo, create a virtual environment, install dependencies, and set OPENAI_API_KEY in a .env file. Run the server with python server.py (or Docker), then run python client.py in another terminal. The client sends a sample query; modify client.py to ask different questions.

MCP Knowledge Base Assistant

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

```

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.