remove_contact
Remove a provider from the active agent's contacts list using their npub identifier.
Instructions
Remove a provider from the active agent's contacts list.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| npub | Yes |
Implementation Reference
- The actual handler function for the remove_contact tool. Decodes the npub, calls removeContact from storage, and returns success or not-found message.
async handler(ctx, input) { ctx.toolRateLimiter.check(); checkLen('npub', input.npub, MAX_NPUB_LEN); const agent = ctx.active(); if (!agent.agentDir) { return errorResult('Active agent is ephemeral; nothing to remove.'); } let pubkey: string; try { pubkey = decodeNpub(input.npub); } catch (e) { return errorResult(`Invalid npub: ${e instanceof Error ? e.message : String(e)}`); } const removed = await removeContact(agent.agentDir, pubkey); return removed ? textResult(`Removed contact ${input.npub}.`) : textResult(`No contact found for ${input.npub}.`); }, - Zod schema for remove_contact input: expects a single 'npub' string field (min 1, max MAX_NPUB_LEN).
const RemoveContactSchema = z.object({ npub: z.string().min(1).max(MAX_NPUB_LEN), }); - packages/mcp/src/tools/feedback-contacts.ts:193-196 (registration)Registration of remove_contact as a ToolDefinition with name 'remove_contact', description, schema, and handler.
defineTool({ name: 'remove_contact', description: "Remove a provider from the active agent's contacts list.", schema: RemoveContactSchema, - The removeContact storage helper function that reads .contacts.json, filters out the contact by pubkey, and writes the file atomically. Returns true if a contact was removed.
export async function removeContact(agentDir: string, pubkey: string): Promise<boolean> { const path = pathFor(agentDir); return withLock(path, async () => { const data = await readRaw(path); const before = data.contacts.length; data.contacts = data.contacts.filter((existing) => existing.pubkey !== pubkey); if (data.contacts.length === before) { return false; } await writeRaw(path, data); return true; }); }