dbbaskette/imc-policy-mcp-server
If you are the rightful owner of imc-policy-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A comprehensive Model Context Protocol (MCP) server built with Spring AI and Spring Boot, providing a solid foundation for building MCP-enabled applications.
๐ข IMC Policy MCP Server
๐ Enterprise-Grade RAG-Powered Insurance Policy Document Retrieval via Model Context Protocol
Intelligent document search with customer-scoped retrieval, query rewriting, and multi-query expansion
๐ Table of Contents
- ๐ฏ Overview
- โจ Features
- ๐๏ธ Architecture
- ๐ Quick Start
- โ๏ธ Configuration
- ๐ง Development
- ๐ณ Deployment
- ๐ Monitoring
- ๐งช Testing
- ๐ API Documentation
๐ฏ Overview
The IMC Policy MCP Server is a production-ready Model Context Protocol (MCP) server that provides intelligent insurance policy document retrieval using advanced Retrieval-Augmented Generation (RAG) techniques. Built with Spring AI 1.1.0-SNAPSHOT, it offers customer-scoped document search with enterprise-grade performance and security.
๐จ Key Highlights
graph TB
A[๐ MCP Client Query] --> B[๐ง Query Transformation]
B --> C[๐ฏ Customer-Scoped Search]
C --> D[๐ PGVector Similarity]
D --> E[๐ Document Assembly]
E --> F[โ
Structured Response]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#fff3e0
style D fill:#e8f5e8
style E fill:#fce4ec
style F fill:#e3f2fd
โจ Features
๐ฅ Core Capabilities
Feature | Description | Status |
---|---|---|
๐ฏ Customer-Scoped RAG | Secure document retrieval filtered by customer ID | โ Production Ready |
๐ง Query Rewriting | AI-powered query enhancement for better results | โ Configurable |
๐ Multi-Query Expansion | Generate diverse query variations | โ Optional |
๐ PGVector Integration | High-performance vector similarity search | โ HNSW Index |
๐ง MCP Tool Exposure | Standards-compliant tool interface | โ @McpTool |
๐ Auto-Configuration | Zero-config Spring Boot setup | โ Environment Aware |
๐ PDF ETL Pipeline | Automated PDF processing with Tika and chunking | โ NEW |
๐ Re-Embedding Service | Update embeddings with new models | โ NEW |
๐ Debug & Diagnostics | Enhanced debugging and search testing tools | โ NEW |
๐ก๏ธ Enterprise Features
- ๐ Security: Customer data isolation with metadata filtering
- ๐ Performance: Optimized vector search with configurable similarity thresholds
- ๐ Scalability: Cloud Foundry and containerization support
- ๐ Monitoring: Comprehensive logging and health checks
- ๐งช Testing: Full test suite with disabled integration tests
- ๐ Documentation: Auto-generated API documentation
๐๏ธ Architecture
๐๏ธ System Architecture
graph TB
subgraph "๐ Client Layer"
MC[MCP Client<br/>๐ฑ Chat Interface]
end
subgraph "๐ฏ MCP Server"
MT[McpToolService<br/>๐ ๏ธ @McpTool]
RS[RagService<br/>๐ง Query Processing]
QT[Query Transformers<br/>โจ AI Enhancement]
end
subgraph "๐พ Data Layer"
VS[VectorStore<br/>๐ PGVector]
PG[(PostgreSQL<br/>๐ + pgvector)]
end
subgraph "๐ค AI Services"
OAI[OpenAI<br/>๐จ Embeddings + Chat]
CF[Cloud Foundry<br/>โ๏ธ Bound Services]
end
MC -->|MCP Protocol| MT
MT --> RS
RS --> QT
RS --> VS
VS --> PG
RS -.->|Query Rewrite| OAI
QT -.->|Multi-Query| OAI
style MC fill:#e3f2fd
style MT fill:#f3e5f5
style RS fill:#e8f5e8
style VS fill:#fff3e0
style OAI fill:#fce4ec
๐งฉ Component Overview
Component | Technology | Purpose |
---|---|---|
McpToolService | Spring AI MCP | Exposes answerQuery tool via MCP protocol |
RagService | Spring AI RAG | Processes queries with customer-scoped retrieval |
Query Transformers | Spring AI | RewriteQueryTransformer + MultiQueryExpander |
VectorStore | PGVector | 768-dimension embeddings with HNSW index |
DataLoaderService | Spring Boot | CSV ingestion with validation and error handling |
RagEtlService | Spring AI Tika | PDF processing and document chunking |
ReEmbeddingService | Spring AI | Re-embed documents with new models |
DiagnosticController | Spring MVC | Debug and troubleshooting endpoints |
๐ Quick Start
๐ Prerequisites
# Required Software
โ๏ธ Java 21+
โ๏ธ Docker & Docker Compose
โ๏ธ Maven 3.8+
โ๏ธ PostgreSQL 15+ (with pgvector extension)
โก 1-Minute Setup
# 1๏ธโฃ Clone and navigate
git clone https://github.com/dbbaskette/imc-policy-mcp-server
cd imc-policy-mcp-server
# 2๏ธโฃ Configure environment
cp .env.example .env
# Edit .env with your OpenAI API key and ensure OPENAI_TEMPERATURE=1.0 for gpt-5-nano
# 3๏ธโฃ Start everything with one command! ๐
./mcp-server.sh --build --local --docker
๐ฏ Manual Setup
Click to expand manual setup instructions
# Build the application
mvn clean package -DskipTests
# Start PostgreSQL with pgvector
docker-compose up -d
# Run the server
java -Dspring.profiles.active=local -jar target/imc-policy-mcp-server-*.jar
โ๏ธ Configuration
๐ Environment Profiles
Profile | Use Case | Database | AI Services |
---|---|---|---|
local | Development | Local PostgreSQL | OpenAI API |
cloud | Production | CF PostgreSQL | CF Bound Services |
๐๏ธ Key Configuration Options
# ๐ง RAG Configuration
app.rag.top-k: 5 # Number of documents to retrieve
app.rag.similarity-threshold: 0.7 # Minimum similarity score
app.rag.query-rewrite: true # Enable AI query enhancement
app.rag.multi-query: false # Enable query expansion
app.rag.multi-query-count: 3 # Number of query variations
# ๐ Vector Store Configuration
spring.ai.vectorstore.pgvector.dimensions: 768
spring.ai.vectorstore.pgvector.distance-type: COSINE_DISTANCE
spring.ai.vectorstore.pgvector.index-type: HNSW
# ๐ง Data Loading
app.data.load-sample-data: true # Load CSV data on startup
๐ Environment Variables
Create .env
file from .env.example
:
โ ๏ธ Important: The
gpt-5-nano
model requiresOPENAI_TEMPERATURE=1.0
as it doesn't support custom temperature values. The server will automatically configure this for query rewriting and multi-query expansion.
# ๐ค OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-5-nano
OPENAI_TEMPERATURE=1.0
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
# ๐พ Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=imc_policy
DB_USER=imc_user
DB_PASSWORD=imc_password
# ๐ฏ RAG Tuning
RAG_TOP_K=5
RAG_SIMILARITY_THRESHOLD=0.7
RAG_QUERY_REWRITE=true
๐ PDF ETL Pipeline (NEW)
The application now includes a powerful ETL pipeline for processing PDF documents:
Features
- Automated PDF Processing: Uses Apache Tika for robust PDF extraction
- Intelligent Chunking: TokenTextSplitter for optimal document segmentation
- Customer Mapping: Automatically extracts customer IDs from filenames (format:
{customerId}-{policyId}.pdf
) - Batch Processing: Efficient batch loading into vector store
Usage
Place PDF files in local_data/source/
directory with naming convention:
100001-200001.pdf
- Customer ID: 100001, Policy ID: 200001- Files are automatically processed on startup when enabled
Configuration
# Enable/disable PDF ETL on startup
app.etl.enabled: false
app.etl.source-directory: local_data/source
๐ Re-Embedding Service (NEW)
Update existing document embeddings when switching embedding models:
Features
- Model Migration: Seamlessly update embeddings when changing models
- Backup & Restore: Automatic CSV backup before re-embedding
- Progress Tracking: Real-time progress logging
- Batch Processing: Efficient re-embedding in batches
Usage
The service automatically detects when re-embedding is needed and can be triggered manually via command line runner.
๐ง Development
๐ ๏ธ Development Commands
# ๐จ Build and test
./mcp-server.sh --build --skip-tests
# ๐งช Run with test database
./mcp-server.sh --local --docker
# ๐ Build and run everything
./mcp-server.sh --build --local --docker
# ๐งน Stop Docker services
./mcp-server.sh --stop-docker
# โ๏ธ Deploy to Cloud Foundry
./mcp-server.sh --build --cf
๐ Health Checks & Testing
# ๐ฅ Health check
curl http://localhost:8080/actuator/health
# ๐งช Test RAG functionality (local profile only)
curl "http://localhost:8080/api/test/rag?query=What is covered?&customerId=100001"
# ๐ Get service info
curl http://localhost:8080/api/test/rag/info
# ๐ Sample queries
curl http://localhost:8080/api/test/samples
๐ฏ MCP Tool Usage
The server exposes the answerQuery
tool that can be called by MCP clients:
{
"tool": "answerQuery",
"parameters": {
"query": "What does my auto insurance policy cover?",
"customerId": 100001
}
}
Response:
{
"success": true,
"query": "What does my auto insurance policy cover?",
"customerId": 100001,
"context": "Document 1:\nAuto insurance policy coverage details...",
"processingTimeMs": 1250,
"timestamp": 1699123456789
}
๐ณ Deployment
๐๏ธ Local Development
# Quick development setup
docker-compose up -d # Start PostgreSQL
./mcp-server.sh --local --docker # Run application
โ๏ธ Cloud Foundry Deployment
# Deploy to Cloud Foundry
./mcp-server.sh --build --cf
# Monitor deployment
cf apps
cf logs imc-policy-mcp-server --recent
๐ Docker Deployment
Docker deployment instructions
# Dockerfile (not included, but you can create one)
FROM openjdk:21-jdk-slim
COPY target/imc-policy-mcp-server-*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
# Build and run
docker build -t imc-policy-mcp-server .
docker run -p 8080:8080 -e SPRING_PROFILES_ACTIVE=local imc-policy-mcp-server
๐ Monitoring
๐ Actuator Endpoints
Endpoint | Purpose | Example |
---|---|---|
/actuator/health | Health status | {"status":"UP"} |
/actuator/info | Application info | Build details |
/actuator/metrics | Performance metrics | JVM, HTTP stats |
๐ Logging Configuration
# Debug logging for development
logging.level.com.insurancemegacorp.policymcpserver: DEBUG
logging.level.org.springframework.ai.vectorstore: DEBUG
# Production logging
logging.level.com.insurancemegacorp.policymcpserver: INFO
logging.level.org.springframework.ai: WARN
๐ Performance Metrics
Monitor these key metrics:
- Query Response Time: Typical 500-2000ms
- Vector Search Performance: Sub-100ms for similarity search
- Document Retrieval: 5-10 documents per query
- Memory Usage: ~512MB heap for typical workloads
๐งช Testing
๐ฏ Test Strategy
# Run all tests (currently skipped due to JDK compatibility)
mvn test
# Run specific test suites
mvn test -Dtest=*Service*
mvn test -Dtest=*Controller*
๐งช Test Categories
Test Type | Status | Description |
---|---|---|
Unit Tests | โ ๏ธ Skipped | Mockito/JDK 24 compatibility issues |
Integration Tests | โ ๏ธ Skipped | ApplicationContext loading issues |
Manual Testing | โ Available | REST endpoints for manual testing |
๐ Sample Test Queries
# Test with different customer IDs
curl "http://localhost:8080/api/test/rag?query=What is my deductible?&customerId=100001"
curl "http://localhost:8080/api/test/rag?query=Claims process&customerId=100002"
curl "http://localhost:8080/api/test/rag?query=Coverage details&customerId=100003"
๐ API Documentation
๐ ๏ธ MCP Tools
answerQuery
Description: Answer questions about customer's insurance policy documents using RAG
Parameters:
query
(string, required): Customer's question about their policycustomerId
(integer, required): Customer ID for document filtering
Returns: PolicyQueryResult
with context and metadata
Example:
{
"success": true,
"query": "What is covered under my policy?",
"customerId": 100001,
"context": "Document 1:\nYour auto insurance policy covers...",
"processingTimeMs": 1250,
"timestamp": 1699123456789
}
๐งช Test Endpoints (Local Profile Only)
Endpoint | Method | Purpose |
---|---|---|
/api/test/rag | GET | Test RAG query processing |
/api/test/rag/info | GET | Get RAG service configuration |
/api/test/health | GET | Test controller health check |
/api/test/samples | GET | Get sample queries and customer IDs |
/api/test/rag/debug | GET | Debug search with custom thresholds |
/api/test/rag/direct | GET | Direct vector search without transformations |
๐ Diagnostic Endpoints (Local Profile Only)
Endpoint | Method | Purpose |
---|---|---|
/api/diagnostic/customer/{id} | GET | Check documents for specific customer |
/api/diagnostic/search | GET | Search documents by keyword |
/api/diagnostic/stats | GET | Get vector store statistics |
๐ฏ Data Model
๐ Document Structure
{
"id": "550e8400-e29b-41d4-a716-446655440001",
"content": "Auto insurance policy coverage details...",
"metadata": {
"customerId": 100001,
"policyType": "auto",
"policyNumber": "POL-2024-001",
"documentType": "coverage",
"effectiveDate": "2024-01-15"
},
"embedding": [0.1, 0.2, ...] // 768-dimensional vector
}
๐ Customer Filtering
Documents are filtered using metadata.refnum1 == customerId
ensuring secure, customer-scoped retrieval.
๐ค Contributing
๐ง Development Setup
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature
- Make changes and test
- Commit with conventional commits:
git commit -m "feat: add amazing feature"
- Push and create PR:
git push origin feature/amazing-feature
๐ Code Standards
- โ Java 21 features and best practices
- โ Spring Boot 3.x conventions
- โ Comprehensive error handling
- โ Clear, concise documentation
- โ Performance-optimized implementations
๐ License
This project is licensed under the MIT License - see the file for details.
๐โโ๏ธ Support
๐ Getting Help
- ๐ง Email: support@insurancemegacorp.com
- ๐ Issues: GitHub Issues
- ๐ Documentation: Spring AI Docs
๐ Related Projects
- Spring AI - AI Integration Framework
- PGVector - Vector Database Extension
- Model Context Protocol - MCP Specification
๐ Star this repository if you find it helpful! ๐
Made with โค๏ธ by the Insurance MegaCorp Team