package app import ( "context" "encoding/json" "fmt" "html" "net" "net/http" "net/netip" "slices" "strconv" "strings" "sync" "time" ) // publicGate limits the public endpoint: a fixed one-minute window per client // address and, when daily is above zero, a daily count of tool calls across all // public clients. type publicGate struct { mu sync.Mutex perMinute int daily int minute int64 perClient map[netip.Addr]int day string callsToday int now func() time.Time } func newPublicGate(perMinute, daily int) *publicGate { return &publicGate{perMinute: perMinute, daily: daily, perClient: map[netip.Addr]int{}, now: time.Now} } // admit counts one request from client. work marks a request that runs a tool; // only those count toward the daily limit. It returns the seconds to wait when // the request is refused. func (g *publicGate) admit(client netip.Addr, work bool) (ok bool, retryAfter int) { g.mu.Lock() defer g.mu.Unlock() now := g.now().UTC() if minute := now.Unix() / 60; minute != g.minute { g.minute, g.perClient = minute, map[netip.Addr]int{} } if day := now.Format(time.DateOnly); day != g.day { g.day, g.callsToday = day, 0 } // An IPv6 host usually holds a whole /64, so count the /64. if client.Is6() { client = netip.PrefixFrom(client, 64).Masked().Addr() } if g.perClient[client] >= g.perMinute { return false, 60 - int(now.Unix()%60) } if work && g.daily > 0 && g.callsToday >= g.daily { midnight := now.Truncate(24 * time.Hour).Add(24 * time.Hour) return false, int(midnight.Sub(now).Seconds()) + 1 } g.perClient[client]++ if work { g.callsToday++ } return true, 0 } // clientAddr is the caller's address. A trusted proxy's X-Forwarded-For is // believed, using its last entry, which that proxy appended itself. func clientAddr(r *http.Request, trusted []netip.Prefix) netip.Addr { host, _, err := net.SplitHostPort(r.RemoteAddr) if err != nil { host = r.RemoteAddr } peer, err := netip.ParseAddr(host) if err != nil { return netip.Addr{} } peer = peer.Unmap() for _, p := range trusted { if !p.Contains(peer) { continue } forwarded := strings.Split(r.Header.Get("X-Forwarded-For"), ",") if addr, err := netip.ParseAddr(strings.TrimSpace(forwarded[len(forwarded)-1])); err == nil { return addr.Unmap() } break } return peer } // contributes reports whether a public caller opted in to having its calls // logged: the X-Contribute header, or the /mcp/contribute endpoint. func contributes(r *http.Request) bool { if r.URL.Path == "/mcp/contribute" { return true } v, err := strconv.ParseBool(strings.TrimSpace(r.Header.Get("X-Contribute"))) return err == nil && v } // runsTool reports whether a request does work: any REST call, or an MCP // tools/call. MCP handshakes and listings are free. func runsTool(path string, body []byte) bool { if path != "/mcp" { return true } var msg struct { Method string `json:"method"` } if json.Unmarshal(body, &msg) != nil { return true } return msg.Method == "tools/call" } // decider is the decision model for a call: the public one for public callers // when it is configured. func (s *Service) decider(ctx context.Context) *Jev { if callInfo(ctx).Public && s.publicJev != nil { return s.publicJev } return s.jev } // publicStyle is shared by the notice and the API page. const publicStyle = ` ` const publicNotice = ` search.nkp.pet ` + publicStyle + `

search.nkp.pet

A web search and page reading tool for AI agents, shared with friends. It searches the web, reads pages, keeps the parts that answer your question, and can summarize them. No account needed.

Use it

Add an MCP server over streamable HTTP:

https://search.nkp.pet/mcp

Tools: web_search, web_contents, web_answer and a few single-page shortcuts. Each address can make 20 requests a minute. All tools and HTTP endpoints.

How it works

Search results come from a self-hosted SearXNG. Pages are read in a real browser. Deciding which results and passages are relevant is done by Cloudflare-hosted Clef-Flash; it will move to a self-hosted Jev-like model at some point. Summaries and answers are written by Bonsai 2 27B, a 1-bit model run on a home server, not fine-tuned yet. Expect it to be slower and rougher than a big hosted model.

Your data

By default nothing is kept: your queries, the pages read and the answers are not stored.

If you want to help, you can opt in. Opted-in calls are saved (the query, the page excerpts and the model's answers) and used for one thing: fine-tuning the model that writes the summaries, so they get better. Send the header X-Contribute: 1, or use https://search.nkp.pet/mcp/contribute instead.

This is run by one person. The data is never sold or shared, and nobody reads through it; it only goes into training.

Please don't send anything private through it either way: it fetches pages and talks to model providers on your behalf.

` // publicDocs renders the API page from the MCP tool schemas, so it lists what // the server actually accepts. var publicDocs = sync.OnceValue(func() []byte { var tools []struct { Name string `json:"name"` Description string `json:"description"` InputSchema struct { Required []string `json:"required"` Properties map[string]json.RawMessage `json:"properties"` } `json:"inputSchema"` } if err := json.Unmarshal(toolsSchema, &tools); err != nil { panic(err) } var b strings.Builder b.WriteString("\n\nsearch.nkp.pet API\n" + publicStyle + `

search.nkp.pet API

Back. No authentication. 20 requests a minute per address; past that you get 429 with Retry-After. Nothing is stored unless you opt in with X-Contribute: 1 (or /mcp/contribute).

Endpoints

endpoint
POST /mcpMCP over streamable HTTP (JSON-RPC): initialize, tools/list, tools/call.
POST /mcp/contributeThe same, with this call's data kept for training.
POST /searchThe web_search tool as plain JSON: send its arguments as the body.
POST /contentsThe web_contents tool as plain JSON.
POST /answerThe web_answer tool as plain JSON.
POST /v1/extract, /v1/preview, /v1/summarizeThe single-page tools as plain JSON.
GET /healthzLiveness.

Example:

curl https://search.nkp.pet/search -H 'content-type: application/json' \
  -d '{"query":"what is the atproto firehose","numResults":3,"contents":{"highlights":true}}'

MCP tools

`) for _, tool := range tools { fmt.Fprintf(&b, "

%s

\n

%s

\n\n\n", html.EscapeString(tool.Name), html.EscapeString(tool.Description)) names := make([]string, 0, len(tool.InputSchema.Properties)) for name := range tool.InputSchema.Properties { names = append(names, name) } slices.Sort(names) for _, name := range names { var p struct { Type any `json:"type"` Description string `json:"description"` OneOf []any `json:"oneOf"` } _ = json.Unmarshal(tool.InputSchema.Properties[name], &p) kind := fmt.Sprint(p.Type) if p.Type == nil { kind = "object" if p.OneOf != nil { kind = "boolean or object" } } if slices.Contains(tool.InputSchema.Required, name) { kind += ", required" } fmt.Fprintf(&b, "\n", html.EscapeString(name), html.EscapeString(kind), html.EscapeString(p.Description)) } b.WriteString("
argumenttype
%s%s%s
\n") } b.WriteString("\n") return []byte(b.String()) })