Uses LangChain for LLM orchestration and chaining within the RAG pipeline to process queries and generate responses.
Implements a state machine architecture for the RAG pipeline with multi-stage processing including guardrails, Cypher generation, retrieval, and response generation.
Provides a RAG system that converts natural language queries into Cypher queries to retrieve information from a Neo4j graph database, with support for dynamic graph schema configuration and intelligent query routing.
Integrates OpenAI models for dual LLM strategy: fast models for guardrails decision-making and accurate models for Cypher query generation and answering.
SOLVRO MCP - Knowledge Graph RAG System
A production-ready Model Context Protocol (MCP) server implementing a Retrieval-Augmented Generation (RAG) system with Neo4j graph database backend. The system intelligently converts natural language queries into Cypher queries, retrieves relevant information from a knowledge graph, and provides contextual answers about Wroclaw University of Science and Technology.
Table of Contents
Architecture Overview
The system consists of three main components:
MCP Server - FastMCP-based server exposing knowledge graph tools
MCP Client - CLI interface for querying the knowledge graph
Data Pipeline - Multi-threaded ETL pipeline for loading documents into Neo4j
Data Flow
Key Technologies
FastMCP: Model Context Protocol server implementation
LangChain: LLM orchestration and chaining
LangGraph: State machine for RAG pipeline
Neo4j: Graph database for knowledge storage
Langfuse: Observability and tracing
OpenAI/DeepSeek: LLM providers for query generation and answering
Features
Intelligent Query Routing
Guardrails System: Automatically determines if queries are relevant to the knowledge base
Fallback Mechanism: Returns graceful responses for out-of-scope queries
Session Tracking: Full trace tracking across the entire query lifecycle
Advanced RAG Pipeline
Multi-Stage Processing: Guardrails → Cypher Generation → Retrieval → Response
State Machine Architecture: Built with LangGraph for predictable execution flow
Error Handling: Robust error recovery with fallback strategies
Caching: Schema caching for improved performance
Dual LLM Strategy
Fast LLM (gpt-5-nano): Quick decision-making for guardrails
Accurate LLM (gpt-5-mini): Precise Cypher query generation
Observability
Langfuse Integration: Complete trace and session tracking
Mermaid Visualization: Graph flow visualization for debugging
Structured Logging: Comprehensive logging throughout the pipeline
Data Pipeline
Multi-threaded Processing: Configurable thread pool for parallel document processing
PDF Support: Extract and process PDF documents
Dynamic Graph Schema: Configurable nodes and relationships via JSON
Database Management: Built-in database clearing and initialization
Prerequisites
Python 3.12 or higher
Neo4j database instance (local or cloud)
OpenAI API key or DeepSeek API key
Langfuse account (for observability)
uvpackage manager (recommended) orpip
Installation
1. Clone the Repository
2. Install Dependencies
Using uv (recommended):
Using pip:
3. Set Up Neo4j
Option A: Docker Compose
Option B: Neo4j Desktop or Aura
Follow Neo4j's installation guide for your platform.
4. Configure Environment Variables
Create a .env file in the project root:
Configuration
Graph Schema Configuration
Edit graph_config.json to define your knowledge graph structure:
Usage
Running the MCP Server
Start the FastMCP server on port 8005:
The server will initialize the RAG system and expose the knowledge_graph_tool.
Querying via CLI Client
Query the knowledge graph using natural language:
Example queries:
Data Pipeline
Load Documents into Neo4j
Clear Database and Reload
Manual Pipeline Execution
Parameters:
data/- Input directory containing PDF filesgraph_config.json- Graph schema configuration4- Number of parallel threads--clear-db- (Optional) Clear database before loading
Project Structure
Development
Code Quality
The project uses Ruff for linting and formatting:
Configuration
Ruff Settings (in pyproject.toml):
Line length: 100 characters
Target: Python 3.13
Selected rules: E, F, I, N, W
Adding New Tools
To add a new MCP tool:
Create a new function in
src/mcp_server/server.pyDecorate with
@mcp.toolAdd documentation and type hints
Update the README
Example:
API Reference
MCP Server
knowledge_graph_tool
Query the knowledge graph with natural language.
Parameters:
user_input(str): User's question or querytrace_id(str, optional): Trace ID for observability
Returns:
str: JSON string containing retrieved context or "W bazie danych nie ma informacji"
Example:
RAG System
RAG.ainvoke()
Async method to query the RAG system.
Parameters:
message(str): User's questionsession_id(str): Session identifier (default: "default")trace_id(str): Trace identifier (default: "default")callback_handler(CallbackHandler): Langfuse callback handler
Returns:
Dict[str, Any]: Dictionary containing:answer(str): JSON context or "W bazie danych nie ma informacji"metadata(dict):guardrail_decision(str): Routing decisioncypher_query(str): Generated Cypher querycontext(list): Retrieved data from Neo4j
Data Pipeline
DataPipe.load_data_from_directory()
Load and process PDF documents from a directory.
Parameters:
directory(str): Path to directory containing PDF files
Returns:
None (processes documents in-place)
Observability
Langfuse Integration
The system provides comprehensive observability through Langfuse:
Session Tracking: All queries within a session are grouped together
Trace Hierarchy: Multi-level traces showing:
Guardrails decision
Cypher generation
Neo4j retrieval
Final answer generation
Metadata Tagging: Traces tagged with component identifiers
Performance Metrics: Latency and token usage tracking
Viewing Traces
Log in to your Langfuse dashboard
Navigate to "Sessions" to see grouped queries
Click on individual traces for detailed execution flow
Use filters to search by tags:
mcp_client,knowledge_graph,guardrails, etc.
Graph Visualization
The RAG system includes Mermaid graph visualization:
This outputs a Mermaid diagram showing the state machine flow.
Error Handling
Common Issues
1. Connection Refused (Neo4j)
Solution: Ensure Neo4j is running:
2. API Key Issues
Solution: Check your .env file contains all required keys.
3. Import Errors
Solution: This import is not available in standard Langfuse. Use session tracking through function parameters.
Performance Tuning
Thread Configuration
Adjust parallel processing threads in the pipeline:
Recommended thread counts:
CPU-bound: Number of CPU cores
I/O-bound: 2-4x CPU cores
Neo4j Optimization
Indexing: Create indexes on frequently queried properties
LIMIT Clauses: Pipeline automatically adds LIMIT to queries
Connection Pooling: FastMCP handles connection management
LLM Configuration
Adjust model parameters in rag.py:
AI Coding Guidelines
For AI coding assistants and developers, see .github/agents.md for detailed coding guidelines and patterns.
Fork the repository
Create a feature branch:
git checkout -b feature/new-featureFollow the coding guidelines in
.github/agents.mdMake changes and ensure tests pass
Run linting:
just lintCommit changes:
git commit -m "feat: Add new feature"Push to branch:
git push origin feature/new-featureOpen a Pull Request // ...existing code...
Contributing
Fork the repository
Create a feature branch:
git checkout -b feature/new-featureMake changes and ensure tests pass
Run linting:
just lintCommit changes:
git commit -m "Add new feature"Push to branch:
git push origin feature/new-featureOpen a Pull Request
License
[Add your license here]
Acknowledgments
Built for Wroclaw University of Science and Technology
Powered by FastMCP, LangChain, and Neo4j
Observability by Langfuse
Support
For issues and questions:
Open an issue on GitHub
Contact the development team
Check the documentation at [link]
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables querying a Neo4j knowledge graph about Wroclaw University of Science and Technology using natural language. Converts user questions into Cypher queries and retrieves contextual information through an intelligent RAG pipeline with LLM-powered query routing.