Skip to main content
Glama

follow

Add a pubkey to your contact list by updating kind 3 events on the Nostr protocol. Specify the pubkey to follow and optional relays for publishing.

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 function that executes the follow logic by modifying the contact list (NIP-02).
    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 };
    }
  • Validation schema for the 'follow' tool input.
    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'),
    });
  • src/index.ts:99-100 (registration)
    Registration of the 'follow' tool in the MCP server.
    server.tool('follow', 'Follow a pubkey (updates kind 3 contact list)', followSchema.shape, async (params) => {
      return textResult(await follow(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