MCP Brain Service
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.
README
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:
git clone <repository-url>
cd mcp-brain-service
- Install dependencies:
pip install -r requirements.txt
pip install -r requirements-dev.txt
Running the Service
- Start the WebSocket server:
python -m uvicorn src.main:app --host 0.0.0.0 --port 8002 --reload
- The service will be available at:
- WebSocket endpoint:
ws://localhost:8002/ - Health check:
http://localhost:8002/health
- WebSocket endpoint:
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:
{
"tool": "create_character",
"project_id": "your_project_id",
"name": "Gandalf",
"personality_description": "A wise and powerful wizard, mentor to Frodo Baggins.",
"appearance_description": "An old man with a long white beard, a pointy hat, and a staff."
}
Response:
{
"status": "success",
"message": "Character created successfully.",
"character_id": "unique_character_id"
}
Find Similar Characters
Send a WebSocket message to find similar characters:
{
"tool": "find_similar_characters",
"project_id": "your_project_id",
"query": "A powerful magic user"
}
Response:
{
"status": "success",
"results": [
{
"id": "character_id",
"name": "Gandalf",
"similarity_score": 0.95
}
]
}
Error Handling
All errors return a consistent format:
{
"status": "error",
"message": "Error description"
}
Testing
Run the complete test suite:
# All tests
pytest
# Contract tests
pytest tests/contract/
# Integration tests
pytest tests/integration/
# Unit tests
pytest tests/unit/
# Performance tests
pytest tests/performance/
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
src/
├── models/ # Pydantic data models
├── services/ # Business logic services
├── lib/ # Database and utility components
└── main.py # FastAPI application entry point
tests/
├── contract/ # API contract tests
├── integration/ # End-to-end tests
├── unit/ # Unit tests
└── performance/ # Performance tests
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
# Start the service
python src/main.py
# In another terminal, run tests
pytest tests/contract/test_websocket.py -v
Production Deployment
Docker (Recommended)
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY src/ ./src/
EXPOSE 8002
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8002"]
Environment Variables
Required for production:
NEO4J_URI=neo4j://your-neo4j-host:7687
NEO4J_USER=your-username
NEO4J_PASSWORD=your-password
Health Monitoring
The service provides a health endpoint at /health for monitoring:
curl http://localhost:8002/health
# Response: {"status": "healthy"}
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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。