Skip to main content
Glama

follow

Add a pubkey to your Nostr contact list by updating kind 3 events, enabling you to follow users on the decentralized social network.

Instructions

Follow a pubkey (updates kind 3 contact list)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pubkeyToFollowYesPubkey (hex or npub) to follow
privateKeyNoPrivate key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured.
relaysNoRelays to publish to

Implementation Reference

  • The handler implementation for the "follow" tool. It retrieves the current contact list, adds the new pubkey as a 'p' tag, and publishes the updated contact list event.
    export async function follow({ pubkeyToFollow, privateKey, relays }: z.infer<typeof followSchema>) {
      const targetPubkey = normalizePubkey(pubkeyToFollow);
      const myPubkey = resolveSigningPubkey(privateKey);
    
      // Fetch current contact list
      const existing = await queryEvent(
        { kinds: [KINDS.CONTACT_LIST], authors: [myPubkey], limit: 1 },
        relays ?? DEFAULT_RELAYS,
      );
    
      let tags: string[][] = existing?.tags.filter(t => t[0] === 'p') ?? [];
      if (tags.some(t => t[1] === targetPubkey)) {
        return { message: 'Already following this pubkey', pubkey: targetPubkey };
      }
      tags.push(['p', targetPubkey]);
    
      const template: EventTemplate = {
        kind: KINDS.CONTACT_LIST,
        content: existing?.content ?? '',
        tags,
        created_at: Math.floor(Date.now() / 1000),
      };
    
      const signed = await signTemplate(template, privateKey);
      const result = await publishEvent(signed, relays ?? DEFAULT_RELAYS);
      return { event: signed, published: result };
    }
  • The input validation schema for the "follow" tool.
    export const followSchema = z.object({
      pubkeyToFollow: z.string().describe('Pubkey (hex or npub) to follow'),
      privateKey: z.string().optional().describe(privateKeyDesc),
      relays: z.array(z.string()).optional().describe('Relays to publish to'),
    });

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