Skip to main content
Glama

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
NameRequiredDescriptionDefault
readRelaysNoRelays for reading
writeRelaysNoRelays for writing
readWriteRelaysNoRelays for both read and write
privateKeyNoPrivate key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured.
relaysNoRelays to publish the list to

Implementation Reference

  • 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 };
    }
  • 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));
    });

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