Provides character storage and retrieval capabilities using Neo4j graph database, with optional integration that allows graceful degradation when database is unavailable
MCP Brain Service
A Python-based service that provides embedding generation, semantic search, and AI-powered content analysis for the Auto-Movie application. Built with FastAPI, Neo4j, Jina AI, and OpenRouter LLM integration.
π Latest Updates
v1.2.1 - Production Stability Fix (October 2025)
β Fixed DELETE Endpoint - Resolved 405 Method Not Allowed error
β Improved PM2 Configuration - Proper environment variable loading
β Production Stability - Disabled auto-reload in production
β Enhanced Documentation - Added troubleshooting guide
v1.1.0 - Batch Endpoints
β Batch Node Creation - Create up to 50 nodes in a single request
β Duplicate Detection - Find semantically similar content
β Department Context - Aggregate insights with AI theme extraction
β Coverage Analysis - Identify gaps with LLM-powered recommendations
π View Full Changelog | π API Documentation | π§ Troubleshooting
Features
Core Capabilities
Character Management: Create and store characters with personality and appearance descriptions
Embedding Generation: Automatic text embedding using Jina AI (v4)
Semantic Search: Find similar content using natural language queries
Batch Operations: Efficient bulk node creation and processing
Duplicate Detection: Semantic similarity-based duplicate identification
AI-Powered Analysis: LLM-based theme extraction and coverage analysis
Content Validation: Automatic rejection of invalid/error data (NEW!)
Node Deletion: API endpoint and bulk cleanup tools (NEW!)
WebSocket API: Real-time MCP (Model Context Protocol) communication
REST API: Comprehensive HTTP endpoints for all operations
Project Isolation: Complete data isolation by project ID
Performance Optimized: Fast response times with parallel processing
Architecture
Technology Stack
FastAPI: Web framework with WebSocket and REST API support
Neo4j: Graph database for knowledge graph storage
Jina AI: State-of-the-art embedding generation (v4)
OpenRouter: LLM integration (Claude Sonnet 4.5, Qwen backup)
PayloadCMS: Department configuration management
Pydantic: Data validation and serialization
Pytest: Comprehensive test suite (contract, integration, unit, performance)
Services
Gather Service: Batch operations, duplicate detection, context aggregation, coverage analysis
Knowledge Service: Document storage and retrieval
Character Service: Character management and search
LLM Client: AI-powered theme extraction and analysis
PayloadCMS Client: Department configuration fetching
Quick Start
Prerequisites
Python 3.11+
Neo4j (optional - service runs without database)
Installation
Clone the repository:
Install dependencies:
Running the Service
Start the WebSocket server:
The service will be available at:
WebSocket endpoint:
ws://localhost:8002/Health check:
http://localhost:8002/health
Configuration
Create a .env file with required environment variables:
See Deployment Guide for complete configuration details.
API Endpoints
π Batch Endpoints (v1.1.0)
1. Batch Node Creation
2. Duplicate Search
3. Department Context
4. Coverage Analysis
π Full API Documentation: Batch Endpoints Guide
π Data Quality & Deletion Features
Content Validation (Automatic)
All node creation requests are automatically validated:
β Rejects empty content
β Rejects error messages ("Error:", "no user message", etc.)
β Rejects invalid data ("undefined", "null", "[object Object]", "NaN")
β Enforces minimum content length (10 characters)
Delete Node
Bulk Cleanup Script
π Full Documentation: Deletion & Validation Guide
Legacy Endpoints
WebSocket API Usage
Create Character
Send a WebSocket message to create a new character:
Response:
Find Similar Characters
Send a WebSocket message to find similar characters:
Response:
Error Handling
All errors return a consistent format:
Testing
Run the complete test suite:
Test Categories
Contract Tests: WebSocket API contract validation
Integration Tests: End-to-end user story validation
Unit Tests: Input validation and model testing
Performance Tests: Response time and concurrency testing
Development
Project Structure
Code Quality
Linting: Configured with Ruff
Type Hints: Full type annotation coverage
Validation: Pydantic models with comprehensive validation
Error Handling: Structured error responses and logging
Running Tests in Development
Production Deployment
Docker (Recommended)
Environment Variables
Required for production:
Health Monitoring
The service provides a health endpoint at /health for monitoring:
Performance Characteristics
P95 Response Time: < 1 minute for semantic search (typically < 10ms)
Concurrency: Supports multiple concurrent WebSocket connections
Memory Usage: Optimized for embedding storage and similarity calculations
Database: Optional Neo4j integration with graceful degradation
Contributing
Follow TDD principles - write tests first
Ensure all tests pass:
pytestRun linting:
ruff check src/ tests/Update documentation for API changes
License
[Your License Here]
Support
For issues and questions, please refer to the project's issue tracker.