Skip to main content
Glama

unfollow

Remove a pubkey from your following list on the Nostr network by publishing an unfollow event to specified relays.

Instructions

Unfollow a pubkey

Input Schema

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

Implementation Reference

  • Implementation of the unfollow logic which fetches the current contact list, removes the target pubkey, and publishes the updated contact list.
    export async function unfollow({ pubkeyToFollow: pubkeyToUnfollow, privateKey, relays }: z.infer<typeof unfollowSchema>) {
      const targetPubkey = normalizePubkey(pubkeyToUnfollow);
      const myPubkey = resolveSigningPubkey(privateKey);
    
      const existing = await queryEvent(
        { kinds: [KINDS.CONTACT_LIST], authors: [myPubkey], limit: 1 },
        relays ?? DEFAULT_RELAYS,
      );
    
      if (!existing) throw new Error('No contact list found');
      const tags = existing.tags.filter(t => !(t[0] === 'p' && t[1] === 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 };
    }
  • Zod schema definition for the unfollow tool input.
    export const unfollowSchema = followSchema.extend({
      pubkeyToFollow: z.string().describe('Pubkey (hex or npub) to unfollow'),
    });
  • src/index.ts:103-104 (registration)
    Registration of the 'unfollow' tool within the MCP server.
    server.tool('unfollow', 'Unfollow a pubkey', unfollowSchema.shape, async (params) => {
      return textResult(await unfollow(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