4.7 KiB
Server Mode
The server provides automatic file monitoring, MCP functionality, and AG-UI graph streaming.
Starting the Server
The serve command requires at least one service flag. You can enable file monitoring, MCP server, AG-UI server, or any combination:
MCP Server Only
haiku-rag serve --mcp
Transport options:
- Default - Streamable HTTP transport on port 8001
--stdio- Standard input/output transport--mcp-port- Custom port (default: 8001)
File Monitoring Only
haiku-rag serve --monitor
Both Services
haiku-rag serve --monitor --mcp
This will start file monitoring and MCP server on port 8001.
File Monitoring
Configure directories to monitor in your haiku.rag.yaml:
monitor:
directories:
- /path/to/documents
- /another/path
Then start the server:
haiku-rag serve --monitor
Monitoring Features
- Startup: Scans all monitored directories and adds new files
- File Added/Modified: Automatically parses and updates documents
- File Deleted: Removes corresponding documents from database
Filtering Files
You can filter which files to monitor using gitignore-style patterns:
monitor:
directories:
- /path/to/documents
# Ignore patterns (exclude files)
ignore_patterns:
- "*draft*" # Ignore draft files
- "temp/" # Ignore temp directory
- "**/archive/**" # Ignore archive directories
# Include patterns (whitelist files)
include_patterns:
- "*.md" # Only markdown files
- "**/docs/**" # Files in docs directories
Pattern behavior:
- Extension filtering is applied first (only supported file types)
- Include patterns create a whitelist (if specified)
- Ignore patterns exclude files
- Both can be combined for fine-grained control
Supported Formats
The server can parse 40+ file formats including:
- PDF documents
- Microsoft Office (DOCX, XLSX, PPTX)
- HTML and Markdown
- Plain text files
- Code files (Python, JavaScript, etc.)
- Images (processed via OCR)
- And more...
URLs are also supported for web content.
AG-UI Server
The AG-UI server provides HTTP streaming of research graph execution using Server-Sent Events (SSE).
Starting the AG-UI Server
haiku-rag serve --agui
This starts an HTTP server (default: http://0.0.0.0:8000) that exposes:
GET /health- Health check endpointPOST /v1/agent/stream- Research graph streaming endpoint
Configuration
Configure the AG-UI server in your haiku.rag.yaml:
agui:
host: "0.0.0.0"
port: 8000
cors_origins: ["*"]
cors_credentials: true
See Configuration for all available options.
Using the Streaming Endpoint
The /v1/agent/stream endpoint accepts POST requests with research parameters and streams AG-UI events:
Request format:
{
"threadId": "optional-thread-id",
"runId": "optional-run-id",
"state": {
"context": {
"original_question": "What are the key features of haiku.rag?"
}
},
"messages": [],
"config": {}
}
Example with curl:
curl -X POST http://localhost:8000/v1/agent/stream \
-H "Content-Type: application/json" \
-d '{
"state": {
"context": {
"original_question": "What are the key features of haiku.rag?"
}
}
}' \
--no-buffer
The --no-buffer flag ensures curl displays events as they arrive instead of buffering them.
Response: Server-Sent Events stream with AG-UI protocol events:
RUN_STARTED- Graph execution startedSTATE_SNAPSHOT- Current state snapshotSTEP_STARTED- Node execution startedSTEP_FINISHED- Node execution completedACTIVITY_SNAPSHOT- Progress updateRUN_FINISHED- Graph execution completed with resultRUN_ERROR- Error during execution
Example event output:
data: {"type":"RUN_STARTED","threadId":"abc123","runId":"xyz789"}
data: {"type":"STATE_SNAPSHOT","snapshot":{"context":{"original_question":"What are the key features of haiku.rag?"},"iterations":0}}
data: {"type":"STEP_STARTED","stepName":"plan"}
data: {"type":"ACTIVITY_SNAPSHOT","messageId":"msg-1","activityType":"planning","content":"Creating research plan"}
data: {"type":"STEP_FINISHED","stepName":"plan"}
data: {"type":"RUN_FINISHED","threadId":"abc123","runId":"xyz789","result":{"title":"Research Report","executive_summary":"..."}}
The endpoint follows the AG-UI protocol for event streaming.
Running Multiple Services
You can run any combination of services:
# File monitoring + AG-UI
haiku-rag serve --monitor --agui
# MCP + AG-UI
haiku-rag serve --mcp --agui
# All services
haiku-rag serve --monitor --mcp --agui