imc-policy-mcp-server

dbbaskette/imc-policy-mcp-server

3.2

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.

Tools
2
Resources
0
Prompts
0

๐Ÿข IMC Policy MCP Server

Spring AI Spring Boot Java PGVector MCP Apache Tika

๐Ÿš€ 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

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

FeatureDescriptionStatus
๐ŸŽฏ Customer-Scoped RAGSecure document retrieval filtered by customer IDโœ… Production Ready
๐Ÿง  Query RewritingAI-powered query enhancement for better resultsโœ… Configurable
๐Ÿ” Multi-Query ExpansionGenerate diverse query variationsโœ… Optional
๐Ÿ“Š PGVector IntegrationHigh-performance vector similarity searchโœ… HNSW Index
๐Ÿ”ง MCP Tool ExposureStandards-compliant tool interfaceโœ… @McpTool
๐Ÿš€ Auto-ConfigurationZero-config Spring Boot setupโœ… Environment Aware
๐Ÿ“„ PDF ETL PipelineAutomated PDF processing with Tika and chunkingโœ… NEW
๐Ÿ”„ Re-Embedding ServiceUpdate embeddings with new modelsโœ… NEW
๐Ÿ” Debug & DiagnosticsEnhanced 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

ComponentTechnologyPurpose
McpToolServiceSpring AI MCPExposes answerQuery tool via MCP protocol
RagServiceSpring AI RAGProcesses queries with customer-scoped retrieval
Query TransformersSpring AIRewriteQueryTransformer + MultiQueryExpander
VectorStorePGVector768-dimension embeddings with HNSW index
DataLoaderServiceSpring BootCSV ingestion with validation and error handling
RagEtlServiceSpring AI TikaPDF processing and document chunking
ReEmbeddingServiceSpring AIRe-embed documents with new models
DiagnosticControllerSpring MVCDebug 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

ProfileUse CaseDatabaseAI Services
localDevelopmentLocal PostgreSQLOpenAI API
cloudProductionCF PostgreSQLCF 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 requires OPENAI_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

EndpointPurposeExample
/actuator/healthHealth status{"status":"UP"}
/actuator/infoApplication infoBuild details
/actuator/metricsPerformance metricsJVM, 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 TypeStatusDescription
Unit Testsโš ๏ธ SkippedMockito/JDK 24 compatibility issues
Integration Testsโš ๏ธ SkippedApplicationContext loading issues
Manual Testingโœ… AvailableREST 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 policy
  • customerId (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)

EndpointMethodPurpose
/api/test/ragGETTest RAG query processing
/api/test/rag/infoGETGet RAG service configuration
/api/test/healthGETTest controller health check
/api/test/samplesGETGet sample queries and customer IDs
/api/test/rag/debugGETDebug search with custom thresholds
/api/test/rag/directGETDirect vector search without transformations

๐Ÿ” Diagnostic Endpoints (Local Profile Only)

EndpointMethodPurpose
/api/diagnostic/customer/{id}GETCheck documents for specific customer
/api/diagnostic/searchGETSearch documents by keyword
/api/diagnostic/statsGETGet 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

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Make changes and test
  4. Commit with conventional commits: git commit -m "feat: add amazing feature"
  5. 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

๐Ÿ”— Related Projects


๐ŸŒŸ Star this repository if you find it helpful! ๐ŸŒŸ

Made with โค๏ธ by the Insurance MegaCorp Team