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
| Name | Required | Description | Default |
|---|---|---|---|
| pubkeyToFollow | Yes | Pubkey (hex or npub) to unfollow | |
| privateKey | No | Private key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured. | |
| relays | No | Relays to publish to |
Implementation Reference
- src/tools/social-tools.ts:89-111 (handler)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 }; } - src/tools/social-tools.ts:17-19 (schema)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));