contextvm-sdk
Rust SDK for the ContextVM protocol — MCP over Nostr.
A complete implementation enabling Model Context Protocol (MCP) servers and clients to communicate over the Nostr network with decentralized discovery, cryptographic identity, and optional end-to-end encryption.
Architecture
┌──────────────────────────────────────────────────────────┐
│ Your Application │
├──────────────┬───────────────┬────────────────────────────┤
│ Gateway │ Proxy │ Discovery │
│ (server → │ (nostr → │ (find servers & │
│ nostr) │ client) │ capabilities) │
├──────────────┴───────────────┴────────────────────────────┤
│ Transport Layer │
│ NostrServerTransport / NostrClientTransport │
├───────────────────────────────────────────────────────────┤
│ Core │ Encryption │ Relay │ Signer │
│ (types, │ (NIP-44, │ (pool │ (key │
│ JSON-RPC, │ NIP-59 │ mgmt) │ mgmt) │
│ validation) │ gift wrap) │ │ │
├────────────────┴─────────────────┴───────────┴────────────┤
│ Nostr Network (relays) │
└───────────────────────────────────────────────────────────┘
Protocol
ContextVM maps MCP's JSON-RPC 2.0 messages onto Nostr events:
| Kind | Name | Type | Description |
|---|---|---|---|
25910 |
ContextVM Messages | Ephemeral | MCP request/response/notification |
1059 |
Gift Wrap (NIP-59) | Regular | Encrypted MCP messages |
11316 |
Server Announcement | Addressable | Server identity & metadata |
11317 |
Tools List | Addressable | Published tool capabilities |
11318 |
Resources List | Addressable | Published resource capabilities |
11319 |
Resource Templates | Addressable | Published resource template list |
11320 |
Prompts List | Addressable | Published prompt capabilities |
Messages are routed using Nostr p tags (recipient pubkey) and correlated with e tags (request event ID).
Installation
Add to your Cargo.toml:
[]
= { = "https://github.com/k0sti/rust-contextvm-sdk" }
Or clone and use as a path dependency:
[]
= { = "../rust-contextvm-sdk" }
Quick Start
Gateway — Expose a Local MCP Server via Nostr
use ;
use NostrServerTransportConfig;
use ;
use signer;
async
Proxy — Connect to a Remote MCP Server via Nostr
use ;
use NostrClientTransportConfig;
use EncryptionMode;
use signer;
async
Discovery — Find MCP Servers on Nostr
use ;
async
Documentation
The in-repo Rust SDK guides live in docs/README.md:
-
For most users, the main pattern is: build an
rmcpserver or client, then attachNostrServerTransportorNostrClientTransport.
Module Overview
| Module | Description |
|---|---|
core |
Protocol constants, JSON-RPC types, error types, validation |
transport |
Client/server Nostr transports with event loop and correlation |
gateway |
High-level gateway bridging local MCP servers to Nostr |
proxy |
High-level proxy connecting to remote MCP servers via Nostr |
discovery |
Server/capability discovery via addressable Nostr events |
encryption |
NIP-44 encryption and NIP-59 gift wrapping |
relay |
Nostr relay pool management (connect, publish, subscribe) |
signer |
Key generation and management utilities |
Configuration
Encryption Modes
| Mode | Behavior |
|---|---|
Optional |
Encrypt responses if the incoming request was encrypted |
Required |
All messages must be encrypted (rejects plaintext) |
Disabled |
No encryption; all messages sent as plaintext kind 25910 |
Encryption uses NIP-44 for payload encryption and NIP-59 (Gift Wrap) for metadata-private delivery. Server announcements (kinds 11316–11320) are always public.
Server Transport Config
| Field | Default | Description |
|---|---|---|
relay_urls |
["wss://relay.damus.io"] |
Nostr relays to connect to |
encryption_mode |
Optional |
Encryption policy |
server_info |
None |
Server metadata for announcements |
is_announced_server |
false |
Whether to publish announcements (CEP-6) |
allowed_public_keys |
[] (allow all) |
Client pubkey allowlist (hex) |
excluded_capabilities |
[] |
Methods exempt from allowlist |
session_timeout |
300s |
Inactive session expiry |
Client Transport Config
| Field | Default | Description |
|---|---|---|
relay_urls |
["wss://relay.damus.io"] |
Nostr relays to connect to |
server_pubkey |
(required) | Target server's public key (hex) |
encryption_mode |
Optional |
Encryption policy |
is_stateless |
false |
Emulate initialize locally |
timeout |
30s |
Response timeout |
References
- ContextVM Specification
- ContextVM TypeScript SDK
- Model Context Protocol
- Nostr Protocol
- NIP-44 Encryption
- NIP-59 Gift Wrap