Documentation
¶
Overview ¶
Package mcpserver builds Ken's Model Context Protocol server: the AI-facing interface (kb_search, kb_get, kb_propose_enhancement, kb_save, kb_flag_stale) over streamable HTTP, behind scoped bearer-token auth.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Deps ¶
type Deps struct {
Store *store.Store
DedupSecret []byte // HMAC key for the search->save dedup token
Embedder embed.Embedder // optional; when set, kb_search adds a semantic arm
TokenLimiter ratelimit.Limiter // optional; per-token rate limit (nil = unlimited)
Metrics *metrics.Registry // optional; records per-tool call counts + auth failures
// CurationLangs, when non-empty, are the normalized language codes the human
// curator reads (settings.curation_langs). They are interpolated into the AI
// instructions so agents author in a language the curator can promote. Refresh
// live via (*Handler).SetCurationLangs.
CurationLangs []string
// CommProvenance, when non-nil, reports whether the calling ACTOR has recently
// RECEIVED an inter-session message. Versions authored by such a token are
// marked as possible hearsay so the curator can ask for a first-hand citation
// before promoting (docs/COMM.md §7).
//
// A FUNCTION rather than a *comm.Store on purpose: this package must not import
// the optional subsystem — the knowledge base's hot path stays free of it, and
// the two databases stay decoupled behind a boolean. Nil (COMM off) means no
// marking, which reads as "no signal", never "known first-hand".
// Keyed on the actor rather than the token because a COMM token must be
// dedicated — the token that receives messages is never the one that authors an
// entry, so a token-keyed check could never fire.
CommProvenance func(ctx context.Context, actorID int64) bool
// ResourceMetadataURL, when set (OAuth enabled), builds the RFC 9728
// protected-resource-metadata URL advertised in the 401 WWW-Authenticate
// header so an OAuth client can discover the authorization server. nil ⇒ the
// 401 stays a plain challenge (OAuth off; static bearer tokens only).
ResourceMetadataURL func(*http.Request) string
}
Deps are the collaborators an MCP server needs.
type Handler ¶
Handler is the /mcp endpoint. It wraps a streamable-HTTP MCP server whose AI-facing instructions can be swapped live (SetCurationLangs) without dropping the endpoint: the server is held in an atomic pointer and read per request, so an in-flight request never observes a half-built server. It implements http.Handler (the auth-wrapped handler is embedded).
func NewHTTPHandler ¶
func (*Handler) SetCurationLangs ¶
SetCurationLangs rebuilds the MCP server so connecting agents receive instructions naming the current curation language(s). Cheap and rare (fires only on a settings edit); existing connections keep working and pick up the new instructions on their next initialize.