setRelayList
Publish a relay list for reading and writing on the Nostr network to manage data flow and connectivity.
Instructions
Publish a relay list (NIP-65 kind 10002)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| readRelays | No | Relays for reading | |
| writeRelays | No | Relays for writing | |
| readWriteRelays | No | Relays for both read and write | |
| privateKey | No | Private key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured. | |
| relays | No | Relays to publish the list to |
Implementation Reference
- src/tools/relay-tools.ts:19-49 (handler)The main handler function for the 'setRelayList' tool, responsible for creating, signing (using local private key or bunker), and publishing the relay list event.
export async function setRelayList({ readRelays, writeRelays, readWriteRelays, privateKey, relays }: z.infer<typeof setRelayListSchema>) { const tags: string[][] = []; for (const r of readWriteRelays ?? []) { tags.push(['r', r]); } for (const r of readRelays ?? []) { tags.push(['r', r, 'read']); } for (const r of writeRelays ?? []) { tags.push(['r', r, 'write']); } const template: EventTemplate = { kind: KINDS.RELAY_LIST, content: '', tags, created_at: Math.floor(Date.now() / 1000), }; let signed: VerifiedEvent; if (isBunkerMode()) { signed = await signEventWithBunker(template); } else { if (!privateKey) throw new Error('privateKey is required when NOSTR_BUNKER_URI is not configured'); signed = finalizeEvent(template, normalizePrivateKey(privateKey)); } const result = await publishEvent(signed, relays ?? DEFAULT_RELAYS); return { event: signed, published: result }; } - src/tools/relay-tools.ts:11-17 (schema)Zod schema definition for validating the input parameters of 'setRelayList'.
export const setRelayListSchema = z.object({ readRelays: z.array(z.string()).optional().describe('Relays for reading'), writeRelays: z.array(z.string()).optional().describe('Relays for writing'), readWriteRelays: z.array(z.string()).optional().describe('Relays for both read and write'), privateKey: z.string().optional().describe(privateKeyDesc), relays: z.array(z.string()).optional().describe('Relays to publish the list to'), }); - src/index.ts:151-153 (registration)Tool registration for 'setRelayList' in the MCP server instance within src/index.ts.
server.tool('setRelayList', 'Publish a relay list (NIP-65 kind 10002)', setRelayListSchema.shape, async (params) => { return textResult(await setRelayList(params)); });