setRelayList
Publish a relay list (NIP-65 kind 10002) to configure read and write relays for Nostr network communication.
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 handler function that processes the setRelayList request by creating a kind 10002 Nostr event and publishing it.
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)The Zod schema defining the input arguments for the setRelayList tool.
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)Registration of the setRelayList tool with the MCP server.
server.tool('setRelayList', 'Publish a relay list (NIP-65 kind 10002)', setRelayListSchema.shape, async (params) => { return textResult(await setRelayList(params)); });