signNostrEvent
Sign Nostr events to authenticate and publish content on decentralized social networks. Provide an unsigned event template and private key to generate a valid signed event.
Instructions
Sign any unsigned Nostr event
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| unsignedEvent | Yes | Unsigned event template | |
| privateKey | No | Private key (nsec or hex). Optional when NOSTR_BUNKER_URI is configured. |
Implementation Reference
- src/tools/event-tools.ts:49-63 (handler)The implementation of the signNostrEvent tool, which handles either bunker-based signing or standard private key signing.
export async function signNostrEvent({ unsignedEvent, privateKey }: z.infer<typeof signNostrEventSchema>): Promise<VerifiedEvent> { const template: EventTemplate = { kind: unsignedEvent.kind, content: unsignedEvent.content, tags: unsignedEvent.tags, created_at: unsignedEvent.created_at, }; if (isBunkerMode()) { return signEventWithBunker(template); } if (!privateKey) throw new Error('privateKey is required when NOSTR_BUNKER_URI is not configured'); const sk = normalizePrivateKey(privateKey); return finalizeEvent(template, sk); } - src/tools/event-tools.ts:17-25 (schema)The schema definition for the signNostrEvent tool input.
export const signNostrEventSchema = z.object({ unsignedEvent: z.object({ kind: z.number(), content: z.string(), tags: z.array(z.array(z.string())), created_at: z.number(), }).describe('Unsigned event template'), privateKey: z.string().optional().describe(privateKeyDesc), }); - src/index.ts:79-80 (registration)The registration of the signNostrEvent tool in the MCP server instance.
server.tool('signNostrEvent', 'Sign any unsigned Nostr event', signNostrEventSchema.shape, async (params) => { return textResult(await signNostrEvent(params));