Skip to main content
Glama

createNote

Create and sign text notes for the Nostr decentralized social network by providing content and a private key.

Instructions

Create a new kind 1 note event (unsigned)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
privateKeyYesPrivate key to sign the note with (hex format or nsec format)
contentYesContent of the note to create
tagsNoOptional tags to include with the note

Implementation Reference

  • The core handler function that creates an unsigned Nostr kind 1 note event. Normalizes private key, derives public key, and uses createEvent from snstr library.
    export async function createNote( privateKey: string, content: string, tags: string[][] = [] ): Promise<{ success: boolean, message: string, noteEvent?: any, publicKey?: string }> { try { // Normalize private key const normalizedPrivateKey = normalizePrivateKey(privateKey); // Derive public key from private key const publicKey = getPublicKeyFromPrivate(normalizedPrivateKey); // Create the note event template const noteTemplate = createEvent({ kind: 1, // kind 1 is a text note content, tags }, publicKey); return { success: true, message: 'Note event created successfully (unsigned)', noteEvent: noteTemplate, publicKey: publicKey, }; } catch (error) { return { success: false, message: `Error creating note: ${error instanceof Error ? error.message : "Unknown error"}`, }; } }
  • Zod input schema defining parameters for the createNote tool: privateKey, content, and optional tags.
    // Schema for createNote tool export const createNoteToolConfig = { privateKey: z.string().describe("Private key to sign the note with (hex format or nsec format)"), content: z.string().describe("Content of the note to create"), tags: z.array(z.array(z.string())).optional().describe("Optional tags to include with the note"), };
  • index.ts:1405-1457 (registration)
    MCP server registration of the createNote tool, importing and calling the core handler, handling response formatting for MCP protocol.
    server.tool( "createNote", "Create a new kind 1 note event (unsigned)", createNoteToolConfig, async ({ privateKey, content, tags }) => { try { const result = await createNote(privateKey, content, tags); if (result.success) { let response = `Note event created successfully!\n\n`; response += `${result.message}\n`; if (result.publicKey) { response += `Author: ${formatPubkey(result.publicKey)}\n`; } response += `Content: "${content}"\n`; if (tags && tags.length > 0) { response += `Tags: ${JSON.stringify(tags)}\n`; } response += `\nNote Event (unsigned):\n${JSON.stringify(result.noteEvent, null, 2)}`; return { content: [ { type: "text", text: response, }, ], }; } else { return { content: [ { type: "text", text: `Failed to create note: ${result.message}`, }, ], }; } } catch (error) { console.error("Error in createNote tool:", error); return { content: [ { type: "text", text: `Error creating note: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], }; } }, );
  • Helper function to normalize private key input, converting nsec bech32 to hex format.
    function normalizePrivateKey(privateKey: string): string { if (privateKey.startsWith('nsec')) { const decoded = nip19decode(privateKey as `${string}1${string}`); if (decoded.type !== 'nsec') { throw new Error('Invalid nsec format'); } return decoded.data; } return privateKey; }
  • Helper function to derive public key from private key using schnorr.
    function getPublicKeyFromPrivate(privateKey: string): string { return Buffer.from(schnorr.getPublicKey(privateKey)).toString('hex'); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AustinKelsay/nostr-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server