Skip to main content
Glama

getKind1Notes

Retrieve text notes from a Nostr user by providing their public key, with options to limit results and specify relays.

Instructions

Get text notes (kind 1) by public key

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pubkeyYesPublic key of the Nostr user (hex format or npub format)
limitNoMaximum number of notes to fetch
relaysNoOptional list of relays to query

Implementation Reference

  • The inline async handler function that implements the getKind1Notes tool logic. It validates the pubkey, queries Nostr relays for kind 1 notes using the snstr pool.querySync method, sorts results by recency, formats them using formatNote, and returns MCP-formatted content.
    async ({ pubkey, limit, relays }, extra) => { // Convert npub to hex if needed const hexPubkey = npubToHex(pubkey); if (!hexPubkey) { return { content: [ { type: "text", text: "Invalid public key format. Please provide a valid hex pubkey or npub.", }, ], }; } // Generate a friendly display version of the pubkey const displayPubkey = formatPubkey(hexPubkey); const relaysToUse = relays || DEFAULT_RELAYS; // Create a fresh pool for this request const pool = getFreshPool(relaysToUse); try { console.error(`Fetching kind 1 notes for ${hexPubkey} from ${relaysToUse.join(", ")}`); // Query for text notes - snstr handles timeout internally const notes = await pool.querySync( relaysToUse, { kinds: [KINDS.Text], authors: [hexPubkey], limit, } as NostrFilter, { timeout: QUERY_TIMEOUT } ); if (!notes || notes.length === 0) { return { content: [ { type: "text", text: `No notes found for ${displayPubkey}`, }, ], }; } // Sort notes by created_at in descending order (newest first) notes.sort((a, b) => b.created_at - a.created_at); const formattedNotes = notes.map(formatNote).join("\n"); return { content: [ { type: "text", text: `Found ${notes.length} notes from ${displayPubkey}:\n\n${formattedNotes}`, }, ], }; } catch (error) { console.error("Error fetching notes:", error); return { content: [ { type: "text", text: `Error fetching notes for ${displayPubkey}: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], }; } finally { // Clean up any subscriptions and close the pool await pool.close(); } }
  • Zod schema defining input parameters and validation for the getKind1Notes tool, imported and used in the registration.
    // Schema for getKind1Notes tool export const getKind1NotesToolConfig = { pubkey: z.string().describe("Public key of the Nostr user (hex format or npub format)"), limit: z.number().min(1).max(100).default(10).describe("Maximum number of notes to fetch"), relays: z.array(z.string()).optional().describe("Optional list of relays to query"), };
  • index.ts:148-227 (registration)
    MCP server.tool() registration of the getKind1Notes tool, specifying name, description, schema, and inline handler function.
    server.tool( "getKind1Notes", "Get text notes (kind 1) by public key", getKind1NotesToolConfig, async ({ pubkey, limit, relays }, extra) => { // Convert npub to hex if needed const hexPubkey = npubToHex(pubkey); if (!hexPubkey) { return { content: [ { type: "text", text: "Invalid public key format. Please provide a valid hex pubkey or npub.", }, ], }; } // Generate a friendly display version of the pubkey const displayPubkey = formatPubkey(hexPubkey); const relaysToUse = relays || DEFAULT_RELAYS; // Create a fresh pool for this request const pool = getFreshPool(relaysToUse); try { console.error(`Fetching kind 1 notes for ${hexPubkey} from ${relaysToUse.join(", ")}`); // Query for text notes - snstr handles timeout internally const notes = await pool.querySync( relaysToUse, { kinds: [KINDS.Text], authors: [hexPubkey], limit, } as NostrFilter, { timeout: QUERY_TIMEOUT } ); if (!notes || notes.length === 0) { return { content: [ { type: "text", text: `No notes found for ${displayPubkey}`, }, ], }; } // Sort notes by created_at in descending order (newest first) notes.sort((a, b) => b.created_at - a.created_at); const formattedNotes = notes.map(formatNote).join("\n"); return { content: [ { type: "text", text: `Found ${notes.length} notes from ${displayPubkey}:\n\n${formattedNotes}`, }, ], }; } catch (error) { console.error("Error fetching notes:", error); return { content: [ { type: "text", text: `Error fetching notes for ${displayPubkey}: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], }; } finally { // Clean up any subscriptions and close the pool await pool.close(); } } );

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/AustinKelsay/nostr-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server