From f126b3f7ee53589b0e1e83205022905608fdf709 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 6 Feb 2026 13:52:15 -0300 Subject: [PATCH] mcp: searching for pubkeys and nip05s returns them directly. --- mcp.go | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/mcp.go b/mcp.go index ca67168..10edde7 100644 --- a/mcp.go +++ b/mcp.go @@ -158,29 +158,40 @@ var mcpServer = &cli.Command{ name := required[string](r, "name") limit, _ := optional[float64](r, "limit") - filter := nostr.Filter{Search: name, Kinds: []nostr.Kind{0}} - if limit > 0 { - filter.Limit = int(limit) - } - res := strings.Builder{} + res.Grow(500) res.WriteString("search results: ") - l := 0 - for result := range sys.Pool.FetchMany(ctx, []string{"relay.nostr.band", "nostr.wine"}, filter, nostr.SubscriptionOptions{ - Label: "nak-mcp-search", - }) { - l++ - pm, _ := sdk.ParseMetadata(result.Event) - res.WriteString(fmt.Sprintf("\n\nResult %d\nUser name: \"%s\"\nPublic key: \"%s\"\nDescription: \"%s\"\n", - l, pm.ShortName(), pm.PubKey.Hex(), pm.About)) - if l >= int(limit) { - break + // check if input is already a valid pubkey + if pubkey, err := nostr.PubKeyFromHex(name); err == nil { + pm := sys.FetchProfileMetadata(ctx, pubkey) + res.WriteString(fmt.Sprintf("\n\nResult 1\nUser name: \"%s\"\nPublic key: \"%s\"\nDescription: \"%s\"\n", + pm.ShortName(), pm.PubKey.Hex(), pm.About)) + } else { + // otherwise try to search + filter := nostr.Filter{Search: name, Kinds: []nostr.Kind{0}} + if limit > 0 { + filter.Limit = int(limit) + } + + l := 0 + for result := range sys.Pool.FetchMany(ctx, []string{"relay.nostr.band", "nostr.wine", "search.nos.social"}, filter, nostr.SubscriptionOptions{ + Label: "nak-mcp-search", + }) { + l++ + pm, _ := sdk.ParseMetadata(result.Event) + res.WriteString(fmt.Sprintf("\n\nResult %d\nUser name: \"%s\"\nPublic key: \"%s\"\nDescription: \"%s\"\n", + l, pm.ShortName(), pm.PubKey.Hex(), pm.About)) + + if l >= int(limit) { + break + } + } + if l == 0 { + return mcp.NewToolResultError("couldn't find anyone with that name."), nil } } - if l == 0 { - return mcp.NewToolResultError("couldn't find anyone with that name."), nil - } + return mcp.NewToolResultText(res.String()), nil })