UNPKG

@contextvm/ctxcn

Version:

A command-line utility inspired by shadcn that streamlines the integration of ContextVM (CVM) servers into your TypeScript projects

53 lines 1.9 kB
import { Client } from "@modelcontextprotocol/sdk/client"; import { NostrClientTransport, PrivateKeySigner, ApplesauceRelayPool, } from "@contextvm/sdk"; export class DemoServerClient { static SERVER_PUBKEY = "ada13b4dbc773890a5e8e468b72418b9fffb51c40b78236819a721971b14fed1"; client; transport; constructor(options = {}) { this.client = new Client({ name: "DemoServerClient", version: "1.0.0", }); const { privateKey, relays = ["ws://localhost:10547"], signer = new PrivateKeySigner(privateKey), relayHandler = new ApplesauceRelayPool(relays), ...rest } = options; this.transport = new NostrClientTransport({ serverPubkey: DemoServerClient.SERVER_PUBKEY, signer, relayHandler, isStateless: true, ...rest, }); // Auto-connect in constructor this.client.connect(this.transport).catch((error) => { console.error(`Failed to connect to server: ${error}`); }); } async disconnect() { await this.transport.close(); } async call(name, args) { const result = await this.client.callTool({ name, arguments: { ...args }, }); return result.structuredContent; } /** * Add two numbers * @param {number} a The first number to add * @param {number} b The second number to add * @returns {Promise<{ result: number; }>} The result of the add operation */ async add(a, b) { return this.call("add", { a, b }); } /** * Echoes a given input * @param {string} input The input value to be echoed * @returns {Promise<{ [k: string]: unknown; }>} The result of the echo operation */ async echo(input) { return this.call("echo", { input }); } } //# sourceMappingURL=DemoServerClient.js.map