sendDmNip44
Send encrypted direct messages using NIP-44 protocol to Nostr recipients by specifying content, recipient public key, and optional relays.
Instructions
Send a NIP-44 direct message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Message content | |
| recipientPubkey | Yes | Recipient pubkey (hex or npub) | |
| privateKey | No | Private key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured. | |
| relays | No | Relays to publish to |
Implementation Reference
- src/tools/dm-tools.ts:130-159 (handler)The `sendDmNip44Fn` function implements the core logic for sending a NIP-44 direct message, including encryption, event creation, and publishing.
export async function sendDmNip44Fn({ content, recipientPubkey, privateKey, relays }: z.infer<typeof sendDmNip44Schema>) { const recipient = normalizePubkey(recipientPubkey); let encrypted: string; if (isBunkerMode()) { encrypted = await nip44EncryptWithBunker(recipient, content); } else { if (!privateKey) throw new Error('privateKey is required when NOSTR_BUNKER_URI is not configured'); const sk = normalizePrivateKey(privateKey); const conversationKey = nip44.v2.utils.getConversationKey(sk, recipient); encrypted = nip44.v2.encrypt(content, conversationKey); } const template: EventTemplate = { kind: KINDS.DM, content: encrypted, tags: [['p', recipient]], created_at: Math.floor(Date.now() / 1000), }; let signed: VerifiedEvent; if (isBunkerMode()) { signed = await signEventWithBunker(template); } else { signed = finalizeEvent(template, normalizePrivateKey(privateKey!)); } const result = await publishEvent(signed, relays ?? DEFAULT_RELAYS); return { event: signed, published: result }; } - src/tools/dm-tools.ts:51-56 (schema)The `sendDmNip44Schema` defines the input validation for the tool.
export const sendDmNip44Schema = z.object({ content: z.string().describe('Message content'), recipientPubkey: z.string().describe('Recipient pubkey (hex or npub)'), privateKey: z.string().optional().describe(privateKeyDesc), relays: z.array(z.string()).optional().describe('Relays to publish to'), }); - src/index.ts:145-147 (registration)The tool `sendDmNip44` is registered in the MCP server within `src/index.ts`.
server.tool('sendDmNip44', 'Send a NIP-44 direct message', sendDmNip44Schema.shape, async (params) => { return textResult(await sendDmNip44Fn(params)); });