lewm-mcp
Enables visual anomaly detection for Claude Code agents by computing surprise scores between frames using a ViT encoder, allowing detection of UI changes and video anomalies.
README
lewm-mcp
MCP server for LeWorldModel — visual anomaly detection for Claude Code agents and other MCP clients.
Uses a JEPA-style ViT encoder to compute surprise scores between frames, enabling agents to detect unexpected UI changes, video anomalies, and state mismatches.
Quick start
npx lewm-mcp
Or install globally:
npm install -g lewm-mcp
lewm-mcp
Python requirements
The model runs in a Python subprocess. Install dependencies:
pip install torch transformers Pillow numpy
# For video analysis:
pip install opencv-python
Remote inference: To run on a GPU/MPS server (e.g.
100.105.97.18), startlewm-mcpthere and connect via MCP over SSH or Tailscale.
Tools
load_model
Load the ViT encoder into memory. Call once before other tools.
{ "checkpoint": "/path/to/checkpoint" }
Returns model info (param count, device, embed_dim, status).
get_model_status
Check if the model is loaded, which checkpoint, param count, device (mps/cuda/cpu).
analyze_screenshot
Encode a screenshot and compute surprise vs a previous frame.
{
"source": "/path/to/screenshot.png",
"previous_source": "/path/to/previous.png",
"anomaly_threshold": 2.0
}
source accepts a file path or base64-encoded image data.
Returns: embedding, surprise_score, normalized_surprise, cosine_similarity, mse, anomaly.
compare_states
Compare expected vs actual screen states in embedding space.
{
"expected": "/path/to/expected.png",
"actual": "/path/to/actual.png",
"anomaly_threshold": 0.1
}
Returns: cosine_similarity, mse, surprise_score, match, anomaly.
analyze_video
Extract frames from a video, run through ViT, return surprise timeline.
{
"video_path": "/path/to/recording.mp4",
"frame_sample_rate": 1,
"sigma_threshold": 2.0,
"top_n": 5
}
Returns: timestamps, surprise_scores, normalized_scores, anomaly_windows, top_anomalies.
run_surprise_detection
Full pipeline on a directory of screenshots or a video file.
{
"directory": "/path/to/screenshots/",
"threshold_multiplier": 2.0
}
Returns: timeline, exceeded_threshold, stats.
Architecture
Claude Code agent
│
│ MCP (stdio)
▼
lewm-mcp (TypeScript)
│
│ stdin/stdout JSON protocol
▼
model.py (Python subprocess)
│
▼
transformers ViTModel (tiny: hidden=192, layers=3, patch=16)
runs on: mps → cuda → cpu
The Python process stays alive between tool calls — the model loads once and stays warm.
Configure in Claude Code
Add to ~/.claude/claude_desktop_config.json (or equivalent MCP config):
{
"mcpServers": {
"lewm-mcp": {
"command": "npx",
"args": ["lewm-mcp"]
}
}
}
Model details
Default model: tiny ViT initialized with random weights.
hidden_size: 192num_hidden_layers: 3num_attention_heads: 3patch_size: 16image_size: 224
Pass a checkpoint path to load_model to use a fine-tuned or pretrained checkpoint (must be a transformers ViTModel checkpoint).
Environment variables
| Variable | Default | Description |
|---|---|---|
LEWM_PYTHON |
python3 |
Python executable to use for model subprocess |
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.