Skip to main content
Glama

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
NameRequiredDescriptionDefault
contentYesMessage content
recipientPubkeyYesRecipient pubkey (hex or npub)
privateKeyNoPrivate key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured.
relaysNoRelays to publish to

Implementation Reference

  • 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 };
    }
  • 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));
    });

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/jorgenclaw/nostr-mcp-server'

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