Documentation
krabnet is a real-time graph context engine. It maintains materialized views over your graph data so that reads are always instant, regardless of how frequently your graph changes.
You interact with krabnet through two interfaces: a gRPC server for backend services, or an MCP server for AI agent integration.
Installation
krabnet requires Rust. Install via Cargo:
cargo install krabnet
This installs two binaries:
krabnet-server— gRPC server for backend integrationkrabnet-mcp— MCP server for AI agent integration
Core Concepts
Graph Events
krabnet ingests your graph as a stream of mutation events. Five event types are supported:
- NodeAdded — a node is created with a type
- NodeRemoved — a node is deleted
- EdgeAdded — a directed edge is created between two nodes
- EdgeRemoved — an edge is deleted
- PropertyChanged — a property on a node is updated
Frames
A frame is a declared query over your graph — anchored at a specific node, with a pattern of hops to follow. Once registered, krabnet continuously maintains the frame's results as your graph changes. Querying a frame returns the current answer immediately, without traversal.
Hop Patterns
Frames are defined by a sequence of hops. Each hop specifies:
- Direction — outgoing, incoming, or any
- Edge type (optional) — filter by edge type
- Target type (optional) — filter by target node type
Multi-hop patterns let you express neighborhood queries, path queries, and structural patterns over your graph.
gRPC Server
Start the gRPC server:
krabnet-server
The server listens on [::1]:50051 by default. It provides
bidirectional streaming, crash recovery via write-ahead logging, and
automatic state replay on restart.
Quick Start
Connect with any gRPC client. Here's an example using grpcurl:
1. Ingest some data
# Add nodes
grpcurl -plaintext -d '{
"node_added": {"node_id": 1, "type_id": 100}
}' [::1]:50051 krabnet.KrabnetService/IngestEvent
grpcurl -plaintext -d '{
"node_added": {"node_id": 2, "type_id": 200}
}' [::1]:50051 krabnet.KrabnetService/IngestEvent
# Add an edge between them
grpcurl -plaintext -d '{
"edge_added": {"edge_id": 1, "source": 1, "target": 2, "type_id": 10}
}' [::1]:50051 krabnet.KrabnetService/IngestEvent
2. Register a frame
# Register a 1-hop outgoing frame anchored at node 1
grpcurl -plaintext -d '{
"anchor_node_id": 1,
"pattern": [{"direction": "DIRECTION_OUTGOING"}],
"epoch": 0
}' [::1]:50051 krabnet.KrabnetService/RegisterFrame
3. Query the frame
grpcurl -plaintext -d '{"frame_id": 0}' \
[::1]:50051 krabnet.KrabnetService/QueryFrame
4. Subscribe to updates
# Stream real-time updates as the graph changes
grpcurl -plaintext -d '{"frame_id": 0}' \
[::1]:50051 krabnet.KrabnetService/SubscribeFrame
MCP Server
The MCP server lets AI agents interact with krabnet directly as a tool. It communicates over stdio using the Model Context Protocol.
Configuration
Add krabnet to your MCP client configuration. For Claude Desktop:
{
"mcpServers": {
"krabnet": {
"command": "krabnet-mcp"
}
}
}
For Claude Code, add to your settings:
{
"mcpServers": {
"krabnet": {
"command": "krabnet-mcp",
"type": "stdio"
}
}
}
Available Tools
Once connected, the agent has access to five tools:
krabnet_ingest— ingest graph mutation eventskrabnet_register_frame— register a maintained framekrabnet_query_frame— query a frame's current resultskrabnet_register_template— register an automatic pattern templatekrabnet_stats— get engine statistics
Example: Building a Graph
An AI agent can build and query a graph through natural tool calls:
# Agent calls krabnet_ingest to add entities
krabnet_ingest({
"event_type": "NodeAdded",
"node_id": 1,
"type_id": 100
})
krabnet_ingest({
"event_type": "EdgeAdded",
"edge_id": 1,
"source": 1,
"target": 2,
"type_id": 10
})
# Agent registers a frame for ongoing context
krabnet_register_frame({
"anchor_node_id": 1,
"pattern": [{"direction": "Outgoing"}],
"epoch": 0
})
# Agent queries the frame — instant results
krabnet_query_frame({"frame_id": 0})
gRPC API Reference
The KrabnetService exposes the following RPCs:
IngestEvent
Ingest a single graph mutation event.
| Field | Type | Description |
|---|---|---|
| node_added | NodeAddedEvent | Add a node with node_id and type_id |
| node_removed | NodeRemovedEvent | Remove a node by node_id |
| edge_added | EdgeAddedEvent | Add an edge with edge_id, source, target, type_id |
| edge_removed | EdgeRemovedEvent | Remove an edge by edge_id, source, target |
| property_changed | PropertyChangedEvent | Update a property on a node |
Returns: epoch (u64) — the event's sequence number
RegisterFrame
Register a new materialized frame.
| Field | Type | Description |
|---|---|---|
| anchor_node_id | u64 | The node to anchor the frame at |
| pattern | HopSpec[] | Sequence of hops defining the query |
| epoch | u64 | Registration epoch |
Returns: frame_id (u64)
QueryFrame
Query a frame's current materialized paths.
| Field | Type | Description |
|---|---|---|
| frame_id | u64 | Frame to query |
Returns: paths — array of node ID sequences
SubscribeFrame
Subscribe to real-time updates for a frame. Server-streaming RPC.
| Field | Type | Description |
|---|---|---|
| frame_id | u64 | Frame to subscribe to |
Returns: Stream of FrameUpdate with paths and epoch
ListFrames
List all registered frames with metadata.
Returns: Array of FrameInfo (id, anchor, tier, tuple_count)
EvictFrame
Remove a frame from the engine.
| Field | Type | Description |
|---|---|---|
| frame_id | u64 | Frame to evict |
Returns: success (bool)
GetStats
Get engine statistics including node/edge/frame counts, tier distribution, and compaction metrics.
MCP Tools Reference
krabnet_ingest
Ingest a graph mutation event.
| Parameter | Type | Required | Description |
|---|---|---|---|
| event_type | string | Yes | "NodeAdded", "NodeRemoved", "EdgeAdded", "EdgeRemoved", "PropertyChanged" |
| node_id | integer | Varies | Node ID (for node and property events) |
| type_id | integer | Varies | Type ID (for NodeAdded, EdgeAdded) |
| edge_id | integer | Varies | Edge ID (for edge events) |
| source | integer | Varies | Source node (for edge events) |
| target | integer | Varies | Target node (for edge events) |
| key | integer | Varies | Property key (for PropertyChanged) |
| value_type | string | Varies | "Integer", "Float", "Text", "Boolean" |
| value | any | Varies | Property value |
krabnet_register_frame
Register a maintained frame.
| Parameter | Type | Required | Description |
|---|---|---|---|
| anchor_node_id | integer | Yes | Anchor node for the frame |
| pattern | array | Yes | Hop specs: [{direction, edge_type?, target_type?}] |
| epoch | integer | Yes | Registration epoch |
krabnet_query_frame
Query a frame's current results.
| Parameter | Type | Required | Description |
|---|---|---|---|
| frame_id | integer | Yes | Frame ID to query |
krabnet_register_template
Register an automatic pattern template for emergent pattern detection.
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer | Yes | Template ID |
| pattern | array | Yes | Hop specs for the pattern |
| threshold | number | Yes | Completion ratio for promotion (0.0–1.0) |
| max_candidates | integer | Yes | Maximum candidates per template |
| stale_window | integer | Yes | Epochs before pruning stale candidates |
krabnet_stats
Get engine statistics. Takes no parameters.
Returns: Node/edge/frame counts, tier distribution, tuple counts, compaction metrics.
Configuration
gRPC Server
| Environment Variable | Default | Description |
|---|---|---|
| ANTHROPIC_API_KEY | — | Enables LLM-powered analysis. Uses mock if unset. |
| KRABNET_LLM_MODEL | claude-sonnet-4-6 | Model for deep analysis |
| KRABNET_LLM_MAX_TOKENS | 1024 | Max tokens for LLM responses |
MCP Server
| Environment Variable | Default | Description |
|---|---|---|
| KRABNET_MCP_WAL | krabnet-mcp.wal | Path to write-ahead log file |
Both servers persist state via write-ahead logging and automatically replay on restart for crash recovery.