Skip to content

Latest commit

 

History

History
106 lines (88 loc) · 2.89 KB

File metadata and controls

106 lines (88 loc) · 2.89 KB
type hypernote
title Counter
description Simple counter using MCP hypermedia elements
name counter
$counter_value
kinds authors #d limit pipe
30078
19f5b5cd2fce663a3b4916b42c378c0280cce2bffd0af384380e91356fcff1d6
counter-value
1
first
get
content
default
0
#counter_ui naddr1qvzqqqrldqpzqx04khxjlnnx8ga5j9459smccq5qen3tllg27wzrsr53x4huluwkqy28wumn8ghj7un9d3shjtnyv9kh2uewd9hszrthwden5te0dehhxtnvdakqz9nhwden5te0wfjkccte9ec8y6tdv9kzumn9wsqq5cm0w4h8getj946kjghtjhh
@increment
kind json tags
25910
jsonrpc id method params
2.0
{time.now}
tools/call
name arguments
addone
a
{$counter_value or 0}
p
19f5b5cd2fce663a3b4916b42c378c0280cce2bffd0af384380e91356fcff1d6
@decrement
kind json tags
25910
jsonrpc id method params
2.0
{time.now}
tools/call
name arguments
minusone
a
{$counter_value or 0}
p
19f5b5cd2fce663a3b4916b42c378c0280cce2bffd0af384380e91356fcff1d6
@initialize
kind json tags
25910
jsonrpc id method params
2.0
{time.now}
tools/call
name arguments
initialize_counter
value
0
p
19f5b5cd2fce663a3b4916b42c378c0280cce2bffd0af384380e91356fcff1d6

Hypermedia Counter

This counter demonstrates the power of hypermedia - the MCP server publishes complete UI elements as Nostr events!

Two Views of the Same Data:

View 1: Data-Based (kind 30078)

[div class="p-4 bg-green-50 rounded-lg mb-4 text-center"]

Count: {$counter_value or "--"}

Simple data query from kind 30078 [/div]

View 2: Hypermedia Element (kind 32616)

[div class="p-4 bg-blue-50 rounded-lg mb-4"] Rendered Hypernote element from MCP: [#counter_ui] [/div]

Controls

[div class="flex gap-4 justify-center"] [form @increment] [button class="bg-green-500 hover:bg-green-600 text-white px-6 py-3 rounded-lg text-xl font-bold"]+1[/button] [/form]

[form @decrement] [button class="bg-red-500 hover:bg-red-600 text-white px-6 py-3 rounded-lg text-xl font-bold"]-1[/button] [/form]

[form @initialize] [button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded"]Reset to 0[/button] [/form] [/div]

How it Works

Unlike the old counter with complex query→trigger→action chains:

  1. User clicks button → Sends increment/decrement action to MCP
  2. MCP calculates new value → Publishes Hypernote UI element
  3. Live subscription updates → UI refreshes automatically

No triggers, no callbacks, just hypermedia! 🚀