server

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Overview

The admin console's read-only JSON API at /api, ported from 8f2af2e:src/keepsake/server/api.py.

The HTTP entry point, which verifies the database first. Ported from 8f2af2e:src/keepsake/server/app.py.

The admin session, ported from 8f2af2e:src/keepsake/server/auth.py: one password, one signed cookie.

Bundle uploads: a gzipped tar of OKF files, read as `keepsake import` reads a directory.

Who a /mcp request acts as. Auth mode none binds one tenant at startup; jwt mode takes the tenant from an HS256 token on every request, so one server serves many tenants.

The MCP wiring, ported from 2de90d2:src/keepsake/server/tools.py's register and 8f2af2e:src/keepsake/server/app.py's streamable HTTP app.

Prometheus metrics, served on their own port so a public Ingress to /mcp never exposes them.

The seven advertised tools, ported from 2de90d2:src/keepsake/server/tools.py's _TOOLS in wire key order.

The seven tool bodies, ported from 2de90d2:src/keepsake/server/tools.py. The tenant comes from the request's caller, so no tool takes one, and no tool returns a body the agent could not read.

Index

Constants

View Source
const MaxLimit = 200

MaxLimit caps and advertises a call's results, so one call cannot return the whole corpus.

View Source
const MaxVersion = 1<<53 - 1

MaxVersion is the largest integer a JSON number carries exactly, far below bigint's maximum.

View Source
const Version = "0.5.0"

Version is this release. scripts/release.sh sets it to Chart.yaml's appVersion.

Variables

This section is empty.

Functions

func AdminPassword

func AdminPassword() (string, error)

AdminPassword reads KEEPSAKE_ADMIN_PASSWORD, refusing when the console is on without one.

func BuildApp

func BuildApp(ctx context.Context, cfg Config) (app, metrics http.Handler, closeApp func(), err error)

BuildApp returns the app, its metrics handler and a closer, or fails when the database does not isolate tenants.

func FixedTenant added in v0.3.0

func FixedTenant(tenant uuid.UUID) func(http.Handler) http.Handler

FixedTenant serves every request as tenant, for auth mode none.

func NewAPI

func NewAPI(cs *store.ConceptStore, a *Auth) http.Handler

NewAPI serves the admin API. Mount it at /api with the prefix stripped.

func NewMCPHandler

func NewMCPHandler(t *Tools) http.Handler

NewMCPHandler serves the seven keepsake tools over stateless streamable HTTP with JSON responses.

func UIEnabled

func UIEnabled() bool

UIEnabled reports whether the admin console is on. It defaults to on.

Types

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

Auth is the one admin account. The password is the whole credential.

func NewAuth

func NewAuth(password string) *Auth

NewAuth derives the cookie key from the password with scrypt, so a password change revokes every cookie.

func (*Auth) CheckPassword

func (a *Auth) CheckPassword(supplied string) bool

func (*Auth) Issue

func (a *Auth) Issue(ttl time.Duration) string

Issue returns a cookie of the form "<expiry>.<hexdigest>".

func (*Auth) Valid

func (a *Auth) Valid(cookie string) bool

type Config

type Config struct {
	DSN    string
	Schema string
	// Auth binds each /mcp and /bundle request to its tenant: FixedTenant or JWT.Middleware.
	Auth func(http.Handler) http.Handler
}

type JWT added in v0.3.0

type JWT struct {
	Issuer, Audience string
	Secrets          [][]byte
}

JWT verifies HS256 tokens from one trusted issuer. Secrets[0] signs; every secret verifies, for rotation.

func JWTFromEnv added in v0.3.0

func JWTFromEnv() (*JWT, error)

JWTFromEnv reads KEEPSAKE_JWT_ISSUER, KEEPSAKE_JWT_AUDIENCE and one secret per line of KEEPSAKE_JWT_SECRET_FILE.

func (*JWT) Middleware added in v0.3.0

func (j *JWT) Middleware(next http.Handler) http.Handler

Middleware binds the verified caller, or answers 401 for a bad token and 403 for a token naming no tenant.

func (*JWT) Mint added in v0.3.0

func (j *JWT) Mint(tenant uuid.UUID, sub string, ttl time.Duration, scopes ...string) string

Mint signs a token for tenant, acting as sub, that expires after ttl and carries scopes.

type MisconfiguredAdmin

type MisconfiguredAdmin struct{ Msg string }

MisconfiguredAdmin is returned at startup. An enabled console with no password is worse than none.

func (*MisconfiguredAdmin) Error

func (e *MisconfiguredAdmin) Error() string

type ToolError

type ToolError struct{ Msg string }

ToolError is surfaced to the agent. It MUST NOT contain a concept body.

func (*ToolError) Error

func (e *ToolError) Error() string

type Tools

type Tools struct {
	// contains filtered or unexported fields
}

func NewTools

func NewTools(cs *store.ConceptStore, tenant uuid.UUID, actor string) *Tools

func (*Tools) Create

func (t *Tools) Create(ctx context.Context, path string, kw map[string]any) (writeResult, error)

func (*Tools) Grep

func (t *Tools) Grep(ctx context.Context, pattern string, limit int) ([]grepHit, error)

func (*Tools) List

func (t *Tools) List(ctx context.Context, prefix string) (listing, error)

func (*Tools) Read

func (t *Tools) Read(ctx context.Context, path string) (*concept, error)

Read returns nil when nothing is stored at path.

func (*Tools) Relate

func (t *Tools) Relate(ctx context.Context, fromPath, toPath string) (any, error)

Relate appends the edge, retrying past concurrent writers, since appending a link commutes.

func (*Tools) Search

func (t *Tools) Search(ctx context.Context, query string, limit int, prefix *string) ([]card, error)

func (*Tools) Update

func (t *Tools) Update(ctx context.Context, path string, expectedVersion *int, kw map[string]any) (any, error)

Update returns a writeResult, or a conflictResult when expectedVersion is stale.

Jump to

Keyboard shortcuts

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