Skip to content

Commit 65453b0

Browse files
committed
feat: server statistics with the beacon sdk
1 parent 2de3c85 commit 65453b0

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,47 @@ await myCanister.withdraw(
145145
);
146146
```
147147

148+
## Proof-of-Use and Usage Mining (Beacon SDK)
149+
150+
The SDK includes a built-in "beacon" system to participate in the Prometheus Protocol's "Proof-of-Use" usage mining program. This allows your server to automatically and securely report tool usage statistics, making it eligible for `preMCPT` rewards.
151+
152+
The system consists of two parts:
153+
154+
1. **The `UsageTracker` Canister**: A central, on-chain canister that securely aggregates usage data from all participating MCP servers. Its security model is based on an allowlist of audited Wasm hashes, ensuring that only compliant servers can submit data. The reference implementation can be found in the `canisters/usage_tracker` directory of this repository.
155+
2. **The Beacon SDK**: The logic integrated into this SDK. It acts as the "beacon" that periodically sends batched usage reports to the `UsageTracker`.
156+
157+
### Enabling the Beacon
158+
159+
Enabling the beacon is done via a single configuration object in your `McpConfig`. You must declare a stable `BeaconContext` variable in your actor and pass it to the configuration.
160+
161+
```motoko
162+
import Beacon "mo:mcp_sdk/beacon";
163+
import McpTypes "mo:mcp_sdk/Types";
164+
import Principal "mo:base/Principal";
165+
166+
persistent actor class MyMcpServer {
167+
// 1. Declare the beacon's state as a stable variable.
168+
var beaconContext = Beacon.init();
169+
Beacon.startTimer<system>(beaconContext);
170+
171+
// 2. Configure the beacon in your McpConfig.
172+
let mcpConfig : McpTypes.McpConfig = {
173+
// ... other config (serverInfo, tools, etc.)
174+
beacon = ?beaconContext;
175+
};
176+
177+
// 3. The SDK handles the rest.
178+
let mcp_server = Mcp.createServer(mcpConfig);
179+
// ...
180+
}
181+
```
182+
183+
### How it Works
184+
185+
Once enabled, the SDK will **automatically** track every successful, **authenticated** tool call. This is a deliberate security measure to prevent Sybil attacks (spamming public endpoints) and ensure that rewards are distributed based on legitimate user interactions.
186+
187+
You do not need to add any extra `track_call` functions to your tool implementations; the SDK handles it for you.
188+
148189
## Connection Management
149190

150191
The SDK uses a low-cost `Timer` to automatically clean up stale client connections, preventing memory leaks and keeping hosting costs low. You simply need to start the timer when your canister initializes.

0 commit comments

Comments
 (0)