Flask Webapplicatie met LLM-integratie en MCP-tools

by fbeunder

MCP Client
  • other

Flask webapplicatie met LLM-integratie en MCP-tools voor het verwerken van prompts via verschillende AI-modellen en contextuele tools.

About

What is Flask Webapplicatie met LLM-integratie en MCP-tools?

Flask Webapplicatie met LLM-integratie en MCP-tools is a local Flask web application that provides a browser-based interface to access OpenAI GPT-3.5 and Anthropic Claude 2 LLMs. It integrates MCP (Model Context Protocol) servers for Brave Search and GitHub, automatically enriching user prompts with context from these tools before sending them to the selected model. Built with Python 3.7+, it runs on Windows, macOS, and Linux and is intended for developers who want to combine LLMs with live external data.

How to use Flask Webapplicatie met LLM-integratie en MCP-tools?

1. Clone the repository, create a Python virtual environment, and install dependencies via pip install -r requirements.txt.
2. Configure API keys either in a .env file (OPENAI_API_KEY, ANTHROPIC_API_KEY, BRAVE_API_KEY, optional GITHUB_TOKEN) or as environment variables.
3. Run the application with python app.py – it will start on http://localhost:5000.
4. In the web interface, optionally start the Brave Search and/or GitHub MCP servers, select an LLM model, type a prompt, and click “Verstuur naar AI” to get an enriched answer. You can also view the full prompt with added context.

Key features of Flask Webapplicatie met LLM-integratie en MCP-tools

- Choose between OpenAI GPT-3.5 and Anthropic Claude 2 models
- Input prompts and receive LLM responses directly in the browser
- Start and stop external MCP tools (Brave Search, GitHub) from the web interface
- Automatically enrich prompts with relevant context from active MCP servers
- View the complete prompt including the added context before the LLM answers

Use cases of Flask Webapplicatie met LLM-integratie en MCP-tools

- Retrieve live web search results via Brave Search and include them as context for a more informed LLM answer
- Look up GitHub repositories, issues, or pull requests and have the LLM generate summaries or insights based on that data
- Compare responses from GPT-3.5 and Claude 2 when both are enriched with the same external context
- Prototype or demonstrate how MCP servers can enhance LLM prompts without requiring a complex backend setup

FAQ from Flask Webapplicatie met LLM-integratie en MCP-tools

What is MCP and why is it used here?

MCP (Model Context Protocol) is an open protocol that allows AI models to securely interact with external resources via standardised server interfaces. In this app, MCP servers gather extra context (e.g., web search results or GitHub data) based on the user prompt and add it to the request before it reaches the LLM.

Which API keys are required to run the application?

You need an OpenAI API key for GPT-3.5, an Anthropic API key for Claude 2, and a Brave Search API key for the Brave Search MCP server. A GitHub personal access token is optional (used for higher API rate limits). All keys can be set via a .env file or as environment variables.

Does it work on Windows, macOS, and Linux?

Yes. The application is pure Python with standard Flask and requests dependencies, and the README provides shell and PowerShell commands for setting up virtual environments and environment variables on all three platforms.

Is this application ready for production?

No. The README explicitly notes that the MCP server implementations are simplified for demonstration purposes and recommends better error handling and security measures for production use.

What are the known limitations?

The MCP servers are simplifications, the app requires valid API keys for every external service, and there is no built-in user authentication or advanced error recovery. The application is intended for local prototyping and learning.

Details

Author
fbeunder
Category
other
Repository
fbeunder/mcp_flask

Flask Webapplicatie met LLM-integratie en MCP-tools

Deze Flask-webapplicatie stelt gebruikers in staat om:

- LLM-modellen (OpenAI en Anthropic) te benaderen via een eenvoudige webinterface
- Prompts in te voeren en antwoorden te ontvangen
- MCP-servers (Model Context Protocol) voor GitHub en Brave Search te starten en stoppen
- De prompt automatisch te verrijken met context uit deze tools voordat deze naar het LLM wordt gestuurd

Functionaliteiten

- LLM-model selectie: Kies tussen OpenAI GPT-3.5 en Anthropic Claude 2
- Prompt invoer: Voer een vraag of prompt in om door het gekozen model te laten beantwoorden
- MCP-tools beheer: Start en stop externe tools (Brave Search en GitHub) vanuit de webinterface
- Contextverrijking: De applicatie verrijkt je prompt automatisch met relevante informatie uit actieve tools
- Volledige prompt weergave: Bekijk de volledige prompt inclusief toegevoegde context

Installatie

Vereisten

- Python 3.7 of hoger

Stappen

1. Clone de repository

   git clone https://github.com/Fbeunder/MCP_FLASK.git
   cd MCP_FLASK
   

2. Maak een virtuele omgeving aan (aanbevolen)

   # Windows
   python -m venv venv
   venv\Scripts\activate
   
   # macOS/Linux
   python3 -m venv venv
   source venv/bin/activate
   

3. Installeer de vereiste pakketten

   # Aanbevolen: installeer alle afhankelijkheden via requirements.txt
   pip install -r requirements.txt
   
   # Alternatief: installeer alleen de specifieke pakketten die je nodig hebt
   pip install flask requests
   
   # Voor OpenAI model-toegang
   pip install openai
   
   # Voor Anthropic model-toegang
   pip install anthropic
   
   # Voor .env bestandsondersteuning
   pip install python-dotenv
   

4. Configureer de API-sleutels

Je kunt API-sleutels configureren via omgevingsvariabelen of een .env bestand.

Optie 1: Maak een .env bestand

Kopieer het .env.example bestand en pas het aan:

   # Windows
copy .env.example .env

# macOS/Linux
cp .env.example .env


Bewerk vervolgens het .env bestand en vul je API-sleutels in.

Optie 2: Stel omgevingsvariabelen in

Stel de volgende omgevingsvariabelen in:

- OPENAI_API_KEY: Je OpenAI API-sleutel (voor GPT-modellen)
- ANTHROPIC_API_KEY: Je Anthropic API-sleutel (voor Claude-modellen)
- BRAVE_API_KEY: Je Brave Search API-sleutel (voor Brave Search MCP-server)
- GITHUB_TOKEN: Je GitHub Personal Access Token (optioneel, voor hogere limieten)

Bijvoorbeeld in Linux/macOS:

   export OPENAI_API_KEY="jouw-openai-api-sleutel"
   export ANTHROPIC_API_KEY="jouw-anthropic-api-sleutel"
   export BRAVE_API_KEY="jouw-brave-api-sleutel"
   export GITHUB_TOKEN="jouw-github-token"
   

Of in Windows:

   set OPENAI_API_KEY=jouw-openai-api-sleutel
   set ANTHROPIC_API_KEY=jouw-anthropic-api-sleutel
   set BRAVE_API_KEY=jouw-brave-api-sleutel
   set GITHUB_TOKEN=jouw-github-token
   

Gebruik

De applicatie starten

Start de Flask-app:

python app.py

De applicatie zal standaard draaien op http://localhost:5000.

Werken met de webinterface

1. Open de webinterface in je browser: http://localhost:5000

2. Start MCP-tools (optioneel):
- Klik op "Start Brave Search" om de Brave Search-tool te starten
- Klik op "Start GitHub" om de GitHub-tool te starten

3. Voer een prompt in:
- Selecteer het gewenste LLM-model uit de keuzelijst
- Typ je vraag of prompt in het tekstvak
- Klik op "Verstuur naar AI"

4. Bekijk het antwoord:
- Het antwoord van het AI-model wordt getoond
- Je kunt optioneel op "Toon volledige prompt met context" klikken om te zien hoe de extra context is toegevoegd

MCP-servers

De applicatie gebruikt twee MCP-servers die automatisch gestart kunnen worden vanuit de interface:

- Brave Search MCP-server: Draait op poort 5001 en biedt webzoekfunctionaliteit
- GitHub MCP-server: Draait op poort 5002 en biedt GitHub-zoekfunctionaliteit

Wanneer deze servers actief zijn, wordt de context van deze tools automatisch toegevoegd aan je prompts.

Problemen oplossen

Virtuele omgeving problemen

Als je een foutmelding krijgt over ontbrekende modules (zoals Flask) terwijl je zeker weet dat deze zijn geïnstalleerd, kan dit te maken hebben met problemen met virtuele omgevingen. Hier zijn enkele stappen om dit op te lossen:

Windows virtuele omgeving problemen

1. Controleer of de virtuele omgeving is geactiveerd:

Je moet de virtuele omgeving activeren in elke nieuwe terminal-sessie:

   venv\Scripts\activate


Je zou (venv) aan het begin van je command prompt moeten zien.

2. Controleer welke Python-executable wordt gebruikt:

   where python


Het eerste pad moet wijzen naar de python.exe in je virtuele omgeving (bijv. \path\to\project\venv\Scripts\python.exe).

3. Problemen met subprocess in Windows:

De laatste versie van de applicatie gebruikt nu automatisch dezelfde Python-executable voor het starten van MCP-servers als de hoofdapplicatie, wat problemen met virtuele omgevingen voorkomt.

Linux/macOS virtuele omgeving problemen

1. Controleer of de virtuele omgeving is geactiveerd:

   source venv/bin/activate


Je zou (venv) aan het begin van je command prompt moeten zien.

2. Controleer welke Python-executable wordt gebruikt:

   which python


Het pad moet wijzen naar de python in je virtuele omgeving (bijv. /path/to/project/venv/bin/python).

ModuleNotFoundError: No module named 'flask'

Als je deze fout nog steeds ziet wanneer je de applicatie of MCP-servers probeert te starten, probeer dan het volgende:

1. Controleer de installatie:

   pip list | grep flask


Je zou Flask in de lijst moeten zien.

2. Herinstalleer Flask:

   pip uninstall flask
pip install flask

3. Gebruik absolute paden voor het uitvoeren:

   # Vind het volledige pad naar Python in je virtuele omgeving
# Windows
echo %VIRTUAL_ENV%\Scripts\python.exe

# Linux/macOS
echo $VIRTUAL_ENV/bin/python

# Gebruik dit pad om de applicatie te starten
/volledig/pad/naar/venv/bin/python app.py

4. Controleer PYTHONPATH:

In sommige gevallen kan de PYTHONPATH omgevingsvariabele verstoord raken:

   # Windows
echo %PYTHONPATH%

# Linux/macOS
echo $PYTHONPATH


Als het een waarde heeft die niet zinvol is voor je project, overweeg om het tijdelijk te wissen:
   # Windows
set PYTHONPATH=

# Linux/macOS
unset PYTHONPATH

Andere package-gerelateerde fouten

Als je andere ModuleNotFoundError-meldingen ziet, controleer dan of:
- Alle packages zijn geïnstalleerd via pip install -r requirements.txt
- Je Python-omgeving correct is ingesteld
- Je geen oudere of incompatibele versies van packages hebt geïnstalleerd

Model Context Protocol (MCP)

MCP (Model Context Protocol) is een open protocol dat AI-modellen in staat stelt om via gestandaardiseerde serverinterfaces veilig met externe bronnen te interageren. In deze applicatie worden MCP-servers gebruikt om:

1. Extra context te verzamelen op basis van de gebruikersprompt
2. Deze context toe te voegen aan de prompt voordat deze naar het LLM wordt gestuurd
3. Zo het antwoord te verrijken met actuele of specifieke informatie

Opmerkingen

- De MCP-serverimplementaties zijn vereenvoudigd voor demonstratiedoeleinden
- Voor productiegerbruik is een betere foutafhandeling en beveiliging aanbevolen
- De applicatie heeft API-sleutels nodig voor elke dienst (OpenAI, Anthropic, Brave Search)

Licentie

MIT