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
| Name | Required | Description | Default |
|---|---|---|---|
| privateKey | Yes | Private key to sign the note with (hex format or nsec format) | |
| content | Yes | Content of the note to create | |
| tags | No | Optional tags to include with the note |
Implementation Reference
- note/note-tools.ts:211-242 (handler)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"}`, }; } }
- note/note-tools.ts:37-42 (schema)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"}`, }, ], }; } }, );
- note/note-tools.ts:192-201 (helper)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; }
- note/note-tools.ts:204-206 (helper)Helper function to derive public key from private key using schnorr.function getPublicKeyFromPrivate(privateKey: string): string { return Buffer.from(schnorr.getPublicKey(privateKey)).toString('hex'); }