Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sandwichfarm/nostr-watch/llms.txt
Use this file to discover all available pages before exploring further.
@nostr-watch/rstate is the aggregation layer for the nostr-watch system. It ingests NIP-66 relay check events published by relaymon instances, computes aggregated scores and state across multiple independent monitors, and serves the results through a REST API. It is built on the ContextVM SDK for decentralized computation and exposes 21 MCP tools over a Nostr transport, allowing AI agents to query relay intelligence directly. OpenAPI documentation is available at /docs when the REST API is enabled.
Prerequisites
- Node.js >=20
- A
config.yamlfile (copy fromconfig.sample.yaml)
Environment variables
Environment variables take precedence over their correspondingconfig.yaml values.
| Variable | Required | Description | Example |
|---|---|---|---|
CVM_RELAYS | Yes (if CVM enabled) | Comma-separated relay URLs for ContextVM transport | wss://relay.damus.io |
INGEST_RELAYS | Yes | Comma-separated relay URLs for NIP-66 event ingestion | wss://history.nostr.watch |
CVM_SERVER_NSEC | Yes (if CVM enabled) | Server private key for signing ContextVM responses | nsec1... |
REST_ENABLED | No | Enable the REST API | true |
REST_PORT | No | REST API listen port | 3000 |
LOG_LEVEL | No | Logging verbosity | info |
Installation
Install dependencies
From the monorepo root, install all workspace dependencies:Or install from the app directory directly:
Quick start
http://localhost:3000. OpenAPI documentation is at http://localhost:3000/docs.
Configuration reference
Configuration uses YAML as the primary format with environment variable overrides. Set the config file path via theCONFIG_FILE environment variable or the --config CLI flag (defaults to config.yaml).
Configuration sections
| Section | Key | Description |
|---|---|---|
server | host | Bind address for the REST API server |
server | port | Listen port for the REST API (also overridden by REST_PORT) |
cvm | relays | Relay URLs used for the ContextVM Nostr transport |
cvm | nsec | Server private key for signing ContextVM responses (use CVM_SERVER_NSEC env var in production) |
ingest | relays | Relay URLs from which NIP-66 check events are ingested |
cache | maxSize | Maximum number of relay entries to hold in memory |
cache | ttlSeconds | Cache entry time-to-live in seconds |
aggregation | lookbackSeconds | Lookback window for aggregating check events (default: 21600 = 6 hours) |
aggregation | quorum | Fraction of monitors that must agree for a value to be included (default: 0.5) |
logging | level | Logging verbosity: debug, info, warn, error |
REST API endpoint groups
WhenREST_ENABLED=true, rstate exposes the following endpoints:
| Method | Endpoint | Description |
|---|---|---|
GET | /health/ping | Server health check with cache statistics |
GET | /relays | List relays with pagination and sorting |
GET | /relays/state | Get aggregated state for a specific relay URL |
POST | /relays/search | Filter relays by network, NIPs, software, labels, or latency |
GET | /relays/nearby | Find relays near coordinates (lat/lon/radius) |
GET | /relays/by/software | Group relays by software family |
GET | /relays/by/network | Group relays by network type (clearnet, Tor, I2P) |
GET | /relays/by/nip | Group relays by NIP support |
GET | /relays/by/country | Group relays by country |
POST | /relays/compare | Side-by-side comparison of multiple relays |
GET | /monitors | List known monitors with reliability scores |
GET | /policy | Get the current aggregation policy |
POST | /subscriptions | Create a relay state subscription |
GET | /subscriptions/events | Server-Sent Events (SSE) stream for real-time updates |
/docs.
MCP tools via ContextVM
Whencvm.relays and cvm.nsec are configured, rstate registers 21 MCP tools accessible to AI agents over the Nostr transport. These tools expose the same relay intelligence as the REST API in a format consumable by MCP-compatible clients.
MCP tools are accessed via the ContextVM (CVM) Nostr transport, not via HTTP. See the CVM and MCP documentation for client setup details.