mcp: searching for pubkeys and nip05s returns them directly.

This commit is contained in:
fiatjaf
2026-02-06 13:52:15 -03:00
parent dc5ffe5129
commit f126b3f7ee
+14 -3
View File
@@ -158,15 +158,24 @@ var mcpServer = &cli.Command{
name := required[string](r, "name")
limit, _ := optional[float64](r, "limit")
res := strings.Builder{}
res.Grow(500)
res.WriteString("search results: ")
// 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)
}
res := strings.Builder{}
res.WriteString("search results: ")
l := 0
for result := range sys.Pool.FetchMany(ctx, []string{"relay.nostr.band", "nostr.wine"}, filter, nostr.SubscriptionOptions{
for result := range sys.Pool.FetchMany(ctx, []string{"relay.nostr.band", "nostr.wine", "search.nos.social"}, filter, nostr.SubscriptionOptions{
Label: "nak-mcp-search",
}) {
l++
@@ -181,6 +190,8 @@ var mcpServer = &cli.Command{
if l == 0 {
return mcp.NewToolResultError("couldn't find anyone with that name."), nil
}
}
return mcp.NewToolResultText(res.String()), nil
})