server

package
v0.0.0-...-3bd64bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server exposes the memory over MCP (streamable HTTP, loopback) with nine tools.

Index

Constants

View Source
const (
	QuotaWiki   = 2
	QuotaMemory = 1
	QuotaGlobal = 1
	HitChars    = 600
	Version     = "0.1.0"
	// MaxQuery is the longest recall query, in characters; a longer one is cut.
	MaxQuery = 2000
)

Quotas per layer for an unrestricted recall, and the cap on one hit's text.

Variables

This section is empty.

Functions

func VectorLine

func VectorLine(ctx context.Context, db *index.DB, emb index.Embedder) string

VectorLine is the vector state for stats: on with the model and the number of embedded chunks, off, or unavailable with the reason. It asks the embedder (at most 10 s); with no embedder it makes no call.

func VectorsHeader

func VectorsHeader(reason error) string

VectorsHeader is the one line that goes first in an answer that had to use keywords only.

Types

type FactIn

type FactIn struct {
	Text     string  `json:"text" jsonschema:"one durable fact"`
	Project  string  `json:"project,omitempty" jsonschema:"project name; empty means global"`
	Category string  `json:"category,omitempty" jsonschema:"for example user_pref, project, tool, general"`
	Trust    float64 `json:"trust,omitempty" jsonschema:"0 to 1, default 0.5"`
}

type FeedbackIn

type FeedbackIn struct {
	ID      string `json:"id" jsonschema:"short id recall printed"`
	Rating  string `json:"rating" jsonschema:"helpful or unhelpful"`
	Session string `json:"session" jsonschema:"required: a stable name for this conversation or run; only a session's last rating counts"`
	Project string `json:"project,omitempty" jsonschema:"restrict the lookup to this project"`
}

type LearnIn

type LearnIn struct {
	Text       string `json:"text" jsonschema:"one learning, a sentence or two (cut at 500 characters)"`
	Project    string `json:"project,omitempty" jsonschema:"project name; empty means global"`
	Kind       string `` /* 182-byte string literal not displayed */
	Supersedes string `json:"supersedes,omitempty" jsonschema:"short id (or unique prefix) of the note this one replaces"`
}

type ListIn

type ListIn struct {
	Project string `json:"project,omitempty" jsonschema:"the project whose notes to list; required without tokens"`
	Status  string `json:"status,omitempty" jsonschema:"empty for all, unverified or active"`
	Limit   int    `json:"limit,omitempty" jsonschema:"notes per page, default 50, at most 200"`
	Offset  int    `json:"offset,omitempty" jsonschema:"notes to skip, default 0"`
}

type RecallIn

type RecallIn struct {
	Query   string `json:"query" jsonschema:"what to look for, in plain words"`
	Project string `json:"project,omitempty" jsonschema:"project name; empty searches every project"`
	Layer   string `json:"layer,omitempty" jsonschema:"auto (default), wiki, memory or fact"`
	Budget  int    `json:"budget,omitempty" jsonschema:"maximum characters in the answer (0 means no limit)"`
	// contains filtered or unexported fields
}

type RetireIn

type RetireIn struct {
	ID      string `json:"id" jsonschema:"short id recall prints, or a unique prefix of it (at least 4 characters)"`
	Reason  string `json:"reason,omitempty" jsonschema:"why the note is withdrawn"`
	Project string `json:"project,omitempty" jsonschema:"restrict the lookup to this project"`
}

type Server

type Server struct {
	St  *store.Store
	DB  *index.DB
	Emb index.Embedder
	// TokensDir, if set, turns token mode on: /mcp needs a bearer token listed in a file there (see package access).
	TokensDir string
	// contains filtered or unexported fields
}

Server holds what the tools need. The vector matrix is loaded once and reloaded after a write.

func New

func New(st *store.Store, db *index.DB, emb index.Embedder) (*Server, error)

func NewReader

func NewReader(db *index.DB, emb index.Embedder) (*Server, error)

NewReader makes a server that can only answer recall: no store, no writes. The command-line context format uses it.

func (*Server) CatchUp

func (s *Server) CatchUp(ctx context.Context, interval time.Duration)

CatchUp embeds the chunks that have no vector, once now and then every interval, until ctx ends. It runs beside the service and never holds the write lock: a write or a recall does not wait for it. A failing embedder is not an error here; the next round tries again. After a round that embedded something the vector matrix is reloaded.

func (*Server) ContextBlock

func (s *Server) ContextBlock(ctx context.Context, query, project string, budget int) (block string, warn error)

ContextBlock is the text a harness hook adds in front of a prompt: only real hits, no empty-state lines (a prompt that finds nothing adds nothing). It is empty when there is nothing to add. warn is why vectors were not used, for the caller to put on standard error; it is never part of the block.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler builds the MCP HTTP handler. Each connection gets its own MCP server object over the shared state.

func (*Server) Recall

func (s *Server) Recall(ctx context.Context, in RecallIn) string

Recall answers a query. It never returns an error to the caller: an empty index, no result and a failing part are three different lines (`not built`, `no results`, `unavailable: <reason>`).

func (*Server) Reload

func (s *Server) Reload() error

Reload reads the vectors again (after a rescan or a write).

func (*Server) Rights

func (s *Server) Rights(req *mcp.CallToolRequest) (*access.Rights, error)

Rights returns the rights of the token of a call: nil in open mode, so that a caller can ask "is there a token" by testing for nil. It is the accessor for the rights of the current call. In token mode a call without rights is an error, never open access.

func (*Server) Stats

func (s *Server) Stats(ctx context.Context, in StatsIn) string

Stats is also the connection health check: it reports the state of every part the other tools depend on.

type StatsIn

type StatsIn struct {
	Project string `json:"project,omitempty" jsonschema:"project name; empty counts everything"`
}

type VerifyIn

type VerifyIn struct {
	ID      string `json:"id" jsonschema:"short id recall prints, or a unique prefix of it (at least 4 characters)"`
	Project string `json:"project,omitempty" jsonschema:"restrict the lookup to this project"`
}

type WikiReadIn

type WikiReadIn struct {
	Path string `json:"path" jsonschema:"path under wiki/ (project/Page Title.md) or a page title (Page Title, or project/Page Title)"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL