Skip to main content

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.

CVM (ContextVM) is MCP (Model Context Protocol) running over Nostr relays instead of HTTP. It exposes 21 structured tools for querying NIP-66 relay monitoring data. Your client sends a tool call as a Nostr event; the rstate server processes it and returns the result as another Nostr event. No IP addresses are exposed, no API keys are needed, and the entire stack is self-hostable.

How MCP over Nostr works

Standard MCP runs over HTTP. CVM replaces the HTTP transport with Nostr relay transport:
  1. Your client connects to one or more CVM relay(s) using a Nostr keypair
  2. The client sends a tool call as a signed Nostr event addressed to the server’s pubkey
  3. The rstate server receives the event, processes the tool call, and publishes the response as a Nostr event
  4. Your client receives the response event and extracts the tool output
The result is a fully functional MCP server accessible over the Nostr network. Communication is identified by Nostr pubkeys rather than IP addresses, which means no client IP is exposed to the server.

Getting started with Claude Desktop

The fastest way to use CVM is through Claude Desktop. Add the following to your Claude Desktop MCP configuration:
{
  "mcpServers": {
    "relayvm": {
      "command": "npx",
      "args": ["-y", "@nostr-watch/relayvm"],
      "env": {
        "CVM_RELAYS": "wss://relay.damus.io,wss://relay.nostr.band",
        "INGEST_RELAYS": "wss://history.nostr.watch",
        "CVM_SERVER_NSEC": "nsec1..."
      }
    }
  }
}
Once configured, Claude can answer natural language questions about relay data by calling the appropriate CVM tools automatically:
Find all relays that support NIP-42 authentication

List the top 10 most reliable relays by uptime

Show me relays within 100km of San Francisco

Compare relay.damus.io and relay.nostr.band

Find all relays running strfry software

Show me offline relays that were recently seen

Programmatic usage

You can call CVM tools directly from code using the CVM SDK, which handles the Nostr transport for you.
// The CVM SDK handles the Nostr transport
const result = await cvmClient.callTool('relays/list', {
  limit: 10,
  sortBy: 'updated',
  sortOrder: 'desc',
  format: 'detailed'
})

console.log(result.relays) // Array of relay state objects
console.log(result.total)  // Total relay count

Available tools

CVM provides 21 tools organized into eight groups:

Relay query tools

ToolDescription
relays/listGet a paginated list of all relays. Supports limit, offset, sortBy, sortOrder, and format.
relays/stateGet state for a specific relay URL. Pass relayUrl (required) and format.
relays/searchSearch relays by network, nips, software, labels, maxLatency, and minSupport.

Geospatial tools

ToolDescription
relays/nearbyFind relays near a geographic point. Pass lat, lon, radius (km), and maxResults. Each result includes a distance field in km.
relays/bboxFind relays within a bounding box. Pass sw and ne as { lat, lon } objects.

Label tools

ToolDescription
relays/labelsGet labels for a specific relay. Pass relayUrl and optional namespace filter.
relays/labels/listList all available labels across all relays. Optional namespace filter.
relays/by/labelGet relays with a specific label. Pass namespace and value (both required).

Aggregation tools

ToolDescription
relays/by/softwareGroup relays by software family. Optional family filter.
relays/by/networkGroup relays by network type (clearnet, Tor, I2P, hybrid).
relays/by/nipGroup relays by NIP support. Optional nip filter and minSupport threshold.
relays/by/countryGroup relays by country. Optional countryCode filter (ISO 3166-1 alpha-2).

Availability tools

ToolDescription
relays/onlineList relays considered online. Optional onlineWindowSeconds, filters, pagination.
relays/offlineList relays that are offline but not yet dead. Configurable offlineThresholdSeconds.
relays/deadList relays not seen for a long time. Default threshold: 7 days.
relays/compareCompare 2–10 relays side-by-side. Returns common NIPs, requirements, and differences.

Monitor tools

ToolDescription
monitors/getGet information about a specific monitor by pubkey. Returns monitor data and reliability analytics.
monitors/listList all known monitors with reliability scores, sorted by last seen.

System tools

ToolDescription
health/pingCheck server health, version, uptime, relay connection counts, and cache stats.
policy/getGet current aggregation policy (quorum, labelQuorum, madScale, weights).
policy/setUpdate aggregation policy (requires authorization).

Subscription tools

ToolDescription
relays/subscribe_stateSubscribe to relay state change notifications. Supports rich filters: relay URLs, network, NIPs, software, labels, geo area, and change thresholds.
relays/unsubscribeCancel a state change subscription by subscriptionId.

Response formats

All relay query tools accept a format parameter:
FormatReturnsUse when
fullAll fields including per-monitor attributionYou need to see which monitors reported what
detailedAggregated values without attribution (default)Most use cases
simpleRelay URLs onlyYou just need a list of addresses

Payments

CVM supports optional micro-payments via the CEP-8 pricing protocol. Most tools are free. When a CVM server has payment gating enabled:
  1. The client calls a tool
  2. The server returns a payment request with amount, currency, and payment method
  3. The client pays via L402 (Lightning) or P2PK (Cashu)
  4. The server processes the tool call after payment confirmation
The public nostr.watch CVM does not currently charge for basic queries. When self-hosting, you control pricing via a PRICING_YAML configuration file. Free tools do not need entries in the pricing file.
Only entries with amount > 0 in the pricing file activate payment gating. All other tools remain free regardless of whether a pricing file is present.

Self-hosting

Running your own rstate instance gives you full sovereignty — you ingest raw NIP-66 events directly from Nostr relays and no trust in nostr.watch is required. Prerequisites: Node.js >= 20 and a Nostr private key (nsec) for the server identity.
1

Clone and install

git clone https://github.com/sandwichfarm/nostr-watch.git
cd nostr-watch
pnpm install
cd apps/rstate
2

Configure

cp config.sample.yaml config.yaml
Edit config.yaml:
cvm:
  enabled: true
  relays:
    - 'wss://relay.damus.io'
    - 'wss://relay.nostr.band'
  encryptionMode: OPTIONAL
  allowedPubkeys: []  # empty = allow all clients

ingestRelays:
  - 'wss://history.nostr.watch'
  - 'wss://relay.nostr.watch'

rest:
  enabled: false  # set to true to also enable the REST API

aggregation:
  quorum: 0.5
  labelQuorum: 0.3
  madScale: 3.0
3

Build and start

npm run build
npm start
4

Verify

curl http://localhost:3000/health/ping | jq '.'
Look for status: "ok", relayCount.ingestion > 0, and observationCount > 0.
Environment variables (override YAML config values):
VariableRequiredDescription
CVM_RELAYSYesComma-separated relay URLs for CVM transport
INGEST_RELAYSYesRelay URLs for NIP-66 event ingestion
CVM_SERVER_NSECYesServer private key for signing responses
REST_ENABLEDNoEnable REST API alongside CVM
REST_PORTNoREST API port (default: 3000)
LOG_LEVELNoLogging verbosity
Keep CVM_SERVER_NSEC private. It is the server’s identity key — compromise means someone can impersonate your instance. Use allowedPubkeys to restrict access if running a private instance.

Trust model

CVM operates on a verify-or-self-host model. When using the public nostr.watch CVM, you trust that the rstate instance is honestly aggregating NIP-66 data. The aggregation logic is open source, but you cannot independently verify the results without running your own instance. Self-hosting eliminates this trust requirement entirely.

Next steps

CVM tools reference

Full parameter schemas and output descriptions for all 21 tools.

REST API

Standard HTTP endpoints for relay intelligence without Nostr.

Raw NIP-66

Trustless event subscription directly from Nostr relays.

Overview

Compare all three interfaces and choose the right one.

Build docs developers (and LLMs) love