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 WebSocket service that provides character embedding and semantic search functionality for the Auto-Movie application. Built with FastAPI, Neo4j, and custom embedding generation.
Features
Character Management: Create and store characters with personality and appearance descriptions
Embedding Generation: Automatic text embedding generation for semantic search
Semantic Search: Find similar characters using natural language queries
WebSocket API: Real-time MCP (Model Context Protocol) communication
Project Isolation: Characters are isolated by project ID
Performance Optimized: P95 response time < 1 minute for semantic search
Architecture
FastAPI: Web framework with WebSocket support
Neo4j: Graph database for character storage (optional)
Custom Embedding Service: Deterministic embedding generation (Jina v4 ready)
Pydantic: Data validation and serialization
Pytest: Comprehensive test suite with contract, integration, unit, and performance tests
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
Environment variables:
NEO4J_URI
: Neo4j connection URI (default:neo4j://localhost:7687
)NEO4J_USER
: Neo4j username (default:neo4j
)NEO4J_PASSWORD
: Neo4j password (default:password
)
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:
pytest
Run 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.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables character management and semantic search for the Auto-Movie application through WebSocket communication. Supports creating characters with personality/appearance descriptions and finding similar characters using natural language queries with embedding-based similarity matching.