Skip to main content
Glama

publishNostrEvent

Publish a signed Nostr event to selected relays. Supply the event object with signature and optional relay URLs to broadcast the event across the network.

Instructions

Publish a signed event to relays

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
signedEventYesSigned event to publish
relaysNoRelays to publish to

Implementation Reference

  • src/index.ts:83-85 (registration)
    Registers the MCP tool 'publishNostrEvent' on the server, wiring it to the handler and schema.
    server.tool('publishNostrEvent', 'Publish a signed event to relays', publishNostrEventSchema.shape, async (params) => {
      return textResult(await publishNostrEvent(params));
    });
  • Zod schema defining the input validation for publishNostrEvent: 'signedEvent' (full event object with id, kind, content, tags, created_at, pubkey, sig) and optional 'relays' array.
    export const publishNostrEventSchema = z.object({
      signedEvent: z.object({
        id: z.string(),
        kind: z.number(),
        content: z.string(),
        tags: z.array(z.array(z.string())),
        created_at: z.number(),
        pubkey: z.string(),
        sig: z.string(),
      }).describe('Signed event to publish'),
      relays: z.array(z.string()).optional().describe('Relays to publish to'),
    });
  • The main handler function that publishes a signed Nostr event to the specified relays (or defaults). Delegates to the 'publishEvent' helper.
    export async function publishNostrEvent({ signedEvent, relays }: z.infer<typeof publishNostrEventSchema>) {
      return publishEvent(signedEvent as any, relays ?? DEFAULT_RELAYS);
    }
  • Core helper function that does the actual publishing: sends the event to each relay using SimplePool.publish, collects successes and failures, and throws if none succeeded.
    export async function publishEvent(
      event: Event,
      relays: string[] = DEFAULT_RELAYS,
    ): Promise<{ successes: string[]; failures: string[] }> {
      const pool = getPool();
      const successes: string[] = [];
      const failures: string[] = [];
    
      const results = await Promise.allSettled(
        relays.map(async (relay) => {
          await pool.publish([relay], event);
          return relay;
        }),
      );
    
      for (const result of results) {
        if (result.status === 'fulfilled') {
          successes.push(result.value);
        } else {
          failures.push(String(result.reason));
        }
      }
    
      if (successes.length === 0) {
        throw new Error(`Failed to publish to any relay: ${failures.join(', ')}`);
      }
    
      return { successes, failures };
    }
  • Default relay list used when no relays are provided to publishNostrEvent.
    export const DEFAULT_RELAYS = [
      'wss://relay.damus.io',
      'wss://relay.primal.net',
      'wss://nos.lol',
      'wss://relay.nostr.band',
      'wss://purplepag.es',
      'wss://relay.snort.social',
    ];
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the action. It does not disclose whether the tool waits for relay responses, handles errors, or requires prior signing.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, no wasted words, and the core action is front-loaded. Perfectly concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers the basic action but lacks information about return values, error handling, or prerequisites. Minimal for a tool with no output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already provides descriptions for both parameters (100% coverage), so the description adds no extra meaning beyond what is already structured.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the verb 'publish' and resource 'signed event' to 'relays', but does not explicitly distinguish itself from sibling tools like publishNote, which may publish a specific event type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives such as publishNote. The description is a single statement without context or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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