Documentation
¶
Overview ¶
Package mcpserver's session instructions and the read-only decision behind them. They live here rather than in a command because they describe this package's tools, and because more than one transport now needs them: the stdio binary builds them at startup from a token query, and an in-process HTTP server will build them per request from the caller's identity (#173 follow-on, docs/mcp-http-transport-scope.md).
Package mcpserver provides an MCP (Model Context Protocol) server that exposes a memstore-backed persistent memory system as MCP tools. It is designed to give Claude (or any MCP client) durable, searchable memory across sessions via hybrid FTS5 + vector search.
Index ¶
- Constants
- func FormatTaskRow(fnc fence.Fence, f memstore.Fact) string
- func Instructions(readOnly bool) string
- func NewFence() (fence.Fence, error)
- func ResolveReadOnly(flagReadOnly bool, who memstore.WhoAmIResponse, err error) bool
- type AgentScore
- type BatchResult
- type Config
- type ConfirmInput
- type ConfirmResult
- type CurateContextInput
- type CurateContextResult
- type DeleteInput
- type DeleteResult
- type FactResult
- type GetContextInput
- type GetContextResult
- type GetLinksInput
- type GetLinksResult
- type HistoryEntry
- type HistoryInput
- type HistoryResult
- type LinkEntry
- type LinkInput
- type LinkResult
- type ListInput
- type ListResult
- type ListSubsystemsInput
- type ListSubsystemsResult
- type MemoryServer
- func (ms *MemoryServer) HandleCurateContext(ctx context.Context, _ *mcp.CallToolRequest, input CurateContextInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) HandleGetContext(ctx context.Context, _ *mcp.CallToolRequest, input GetContextInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) HandleGetLinks(ctx context.Context, _ *mcp.CallToolRequest, input GetLinksInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) HandleHistory(ctx context.Context, _ *mcp.CallToolRequest, input HistoryInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) HandleList(ctx context.Context, _ *mcp.CallToolRequest, input ListInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) HandleListSubsystems(ctx context.Context, _ *mcp.CallToolRequest, input ListSubsystemsInput) (*mcp.CallToolResult, ListSubsystemsResult, error)
- func (ms *MemoryServer) HandleRateContext(ctx context.Context, _ *mcp.CallToolRequest, input RateContextInput) (*mcp.CallToolResult, RateContextResult, error)
- func (ms *MemoryServer) HandleRerankSettings(_ context.Context, _ *mcp.CallToolRequest, _ RerankSettingsInput) (*mcp.CallToolResult, RerankSettingsResult, error)
- func (ms *MemoryServer) HandleSearch(ctx context.Context, _ *mcp.CallToolRequest, input SearchInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) HandleStatus(ctx context.Context, _ *mcp.CallToolRequest, _ StatusInput) (*mcp.CallToolResult, StatusResult, error)
- func (ms *MemoryServer) HandleSuggestAgent(ctx context.Context, _ *mcp.CallToolRequest, input SuggestAgentInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) HandleTaskList(ctx context.Context, _ *mcp.CallToolRequest, input TaskListInput) (*mcp.CallToolResult, fence.Envelope, error)
- func (ms *MemoryServer) Register(s *mcp.Server)
- func (ms *MemoryServer) SetEmbedCeiling(n int)
- type Metadata
- type RateContextInput
- type RateContextResult
- type RerankSettingsInput
- type RerankSettingsResult
- type SearchInput
- type SearchResult
- type StatusInput
- type StatusResult
- type StoreBatchInput
- type StoreBatchResult
- type StoreInput
- type StoreResult
- type SuggestAgentInput
- type SuggestAgentResult
- type SupersedeInput
- type SupersedeResult
- type TaskCreateInput
- type TaskCreateResult
- type TaskListInput
- type TaskListResult
- type TaskResult
- type TaskUpdateInput
- type TaskUpdateResult
- type UnlinkInput
- type UnlinkResult
- type UpdateInput
- type UpdateLinkInput
- type UpdateLinkResult
- type UpdateResult
- type WriteServer
- func (ws *WriteServer) HandleConfirm(ctx context.Context, _ *mcp.CallToolRequest, input ConfirmInput) (*mcp.CallToolResult, ConfirmResult, error)
- func (ws *WriteServer) HandleDelete(ctx context.Context, _ *mcp.CallToolRequest, input DeleteInput) (*mcp.CallToolResult, DeleteResult, error)
- func (ws *WriteServer) HandleLink(ctx context.Context, _ *mcp.CallToolRequest, input LinkInput) (*mcp.CallToolResult, LinkResult, error)
- func (ws *WriteServer) HandleStore(ctx context.Context, _ *mcp.CallToolRequest, input StoreInput) (*mcp.CallToolResult, StoreResult, error)
- func (ws *WriteServer) HandleStoreBatch(ctx context.Context, _ *mcp.CallToolRequest, input StoreBatchInput) (*mcp.CallToolResult, StoreBatchResult, error)
- func (ws *WriteServer) HandleSupersede(ctx context.Context, _ *mcp.CallToolRequest, input SupersedeInput) (*mcp.CallToolResult, SupersedeResult, error)
- func (ws *WriteServer) HandleTaskCreate(ctx context.Context, _ *mcp.CallToolRequest, input TaskCreateInput) (*mcp.CallToolResult, TaskCreateResult, error)
- func (ws *WriteServer) HandleTaskUpdate(ctx context.Context, _ *mcp.CallToolRequest, input TaskUpdateInput) (*mcp.CallToolResult, TaskUpdateResult, error)
- func (ws *WriteServer) HandleUnlink(ctx context.Context, _ *mcp.CallToolRequest, input UnlinkInput) (*mcp.CallToolResult, UnlinkResult, error)
- func (ws *WriteServer) HandleUpdate(ctx context.Context, _ *mcp.CallToolRequest, input UpdateInput) (*mcp.CallToolResult, UpdateResult, error)
- func (ws *WriteServer) HandleUpdateLink(ctx context.Context, _ *mcp.CallToolRequest, input UpdateLinkInput) (*mcp.CallToolResult, UpdateLinkResult, error)
- func (ws *WriteServer) Register(s *mcp.Server)
Constants ¶
const ( CitationMarker = "[fact 1234]" CitationPattern = `\[fact (\d+)\]` )
baseInstructions is the standing warning that recalled content is data. CitationMarker is the form shown to the model, and CitationPattern is what reads it back out of a transcript. They are declared together because the signal is worthless if the form written is not the form parsed.
The id is deliberately the memstore fact id, so a citation joins directly against memstore_facts with no lookup table.
The form must NOT match how recall labels injected facts, which is "[id=1234]" (see formatRecallContext). A transcript contains both the injected block and the assistant's reply, so a shared form would make every injected fact look cited and the signal would read 100% compliance no matter what the model did. "[fact N]" versus "[id=N]" keeps what was offered distinguishable from what was used, which is the entire measurement.
Variables ¶
This section is empty.
Functions ¶
func FormatTaskRow ¶
FormatTaskRow renders a single task fact for display in HandleTaskList output. Every visible field is read from the fact's stored metadata — never from request parameters — so the row faithfully reflects what is in the store.
The task's content is stored text like any other fact, so it goes inside fnc rather than inline in the row. That costs the one-line row format: the metadata stays on the header line and the content follows it, fenced.
func Instructions ¶
Instructions returns the server instructions for the session. In read-only mode it says so: without that, a model told to store things it cannot store will keep looking for a tool that was never registered.
func NewFence ¶
NewFence mints a content fence for one response. Callers rendering rows with FormatTaskRow need one; see the fence package for what it protects against.
func ResolveReadOnly ¶
func ResolveReadOnly(flagReadOnly bool, who memstore.WhoAmIResponse, err error) bool
ResolveReadOnly decides whether to register the store-mutating tools.
The flag is a floor, not the whole answer: --read-only always wins, and the token can only tighten from there. The tool list is derived from what the credential may actually do, so what the model sees matches what the daemon will permit, instead of advertising writes that return 403.
An error is NOT read as "no permissions". A daemon predating /v1/whoami returns 404, and a network blip returns a transport error; treating either as read-only would silently strip capability from a session that has it. The configured value stands and the reason is logged.
Types ¶
type AgentScore ¶
type AgentScore struct {
Name string `json:"name"`
Confidence string `json:"confidence"`
Score int `json:"score"`
Rationale string `json:"rationale"`
Content string `json:"content"`
}
AgentScore represents a single agent suggestion.
type BatchResult ¶
type BatchResult struct {
Index int `json:"index"`
Status string `json:"status"`
ID int64 `json:"id,omitempty"`
Superseded *int64 `json:"superseded_by,omitempty"`
Error string `json:"error,omitempty"`
}
BatchResult represents a single batch operation result.
type Config ¶
type Config struct {
// Curator selects the most relevant subset of candidates for a given task.
// If nil, memory_curate_context uses NopCurator (returns candidates unfiltered).
Curator memstore.Curator
// Generator produces text completions for LLM-based operations.
Generator memstore.Generator
// Embed grants vector-write authority for facts this server inserts, so a
// new fact is searchable immediately rather than at the next queue drain.
// Nil means embed-on-insert is skipped and the async backfill covers it,
// which is what every daemon-backed deployment already does -- there the
// embedder is nil and memstored owns embedding.
//
// It is granted here rather than derived from the writable handle. Asserting
// a WritableStore up to an EmbedStore would be the same move ReadOnly exists
// to prevent, run in the other direction: authority discovered by type
// assertion is authority nobody decided to give.
Embed memstore.EmbedStore
// SessionStore enables the memory_rate_context tool for injection feedback.
// Only RecordFeedback is required; httpclient.Client satisfies this.
// If nil, memory_rate_context is not registered.
SessionStore memstore.FeedbackStore
// RerankMode and RerankThreshold seed the server's default rerank policy for
// memory_search and memory_get_context. RerankMode off (the default) leaves
// rerank disabled until a call overrides it. Both can be overridden per call
// by memory_search and memory_get_context; neither is mutable at runtime.
RerankMode memstore.RerankMode
RerankThreshold float64
// RerankCandidates and RerankRecallCandidates seed the candidate-pool caps
// for memory_search and memory_get_context respectively (0 = the store's
// built-in default). Operator settings: they trade latency against recall
// for every caller, and no tool call changes them.
RerankCandidates int
RerankRecallCandidates int
// RerankDocBytes and RerankRecallDocBytes seed the per-document truncation
// budgets for memory_search and memory_get_context (0 = the store's default).
// Operator settings, like the candidate pools above.
RerankDocBytes int
RerankRecallDocBytes int
}
Config holds optional configuration for MemoryServer.
type ConfirmInput ¶
type ConfirmInput struct {
ID int64 `json:"id" jsonschema:"the fact ID to confirm"`
}
ConfirmInput is the input schema for the memory_confirm tool.
type ConfirmResult ¶
type ConfirmResult struct {
Status string `json:"status"`
ID int64 `json:"id"`
ConfirmedCount int `json:"confirmed_count"`
Content string `json:"content"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
ConfirmResult is the structured output for memory_confirm.
type CurateContextInput ¶
type CurateContextInput struct {
Task string `json:"task" jsonschema:"description of the task being worked on; used to rank candidate facts by relevance"`
FactIDs []int64 `json:"fact_ids" jsonschema:"IDs of candidate facts to evaluate; fetch via memory_get_context or memory_search first"`
MaxOutput int `json:"max_output,omitempty" jsonschema:"max facts to return (default 5)"`
}
CurateContextInput is the input schema for the memory_curate_context tool.
type CurateContextResult ¶
type CurateContextResult struct {
Task string `json:"task"`
Selected int `json:"selected"`
Candidates int `json:"candidates"`
Rationale string `json:"rationale"`
Facts []FactResult `json:"facts"`
}
CurateContextResult is the structured output for memory_curate_context.
type DeleteInput ¶
type DeleteInput struct {
ID int64 `json:"id" jsonschema:"the fact ID to delete"`
}
DeleteInput is the input schema for the memory_delete tool.
type DeleteResult ¶
type DeleteResult struct {
Status string `json:"status"`
ID int64 `json:"id"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
DeleteResult is the structured output for memory_delete.
type FactResult ¶
type FactResult struct {
ID int64 `json:"id"`
Subject string `json:"subject"`
Category string `json:"category"`
Kind string `json:"kind,omitempty"`
Subsystem string `json:"subsystem,omitempty"`
Content string `json:"content"`
Score float64 `json:"score"`
RerankScore float64 `json:"rerank_score,omitempty"`
UseCount int `json:"use_count"`
ConfirmedCount int `json:"confirmed_count"`
SupersededBy *int64 `json:"superseded_by,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
}
FactResult represents a single search result with typed fields.
type GetContextInput ¶
type GetContextInput struct {
Task string `json:"task" jsonschema:"description of the task or feature being worked on"`
Subject string `json:"subject,omitempty" jsonschema:"optional subject to scope context loading (e.g. a project name)"`
Limit int `json:"limit,omitempty" jsonschema:"max total facts in the relevant context section (default 20)"`
RerankMode string `` /* 137-byte string literal not displayed */
Threshold *float64 `json:"threshold,omitempty" jsonschema:"override the relevance threshold [0,1] for this call (omit = configured default)"`
Weight *float64 `json:"weight,omitempty" jsonschema:"override the balanced-fusion weight [0,1] for this call (omit = configured default)"`
Candidates *int `` /* 136-byte string literal not displayed */
DocBytes *int `` /* 129-byte string literal not displayed */
TimeoutSeconds *float64 `` /* 140-byte string literal not displayed */
}
GetContextInput is the input schema for the memory_get_context tool.
type GetContextResult ¶
type GetContextResult struct {
Task string `json:"task"`
Subject string `json:"subject,omitempty"`
Invariants []FactResult `json:"invariants"`
FailureModes []FactResult `json:"failure_modes"`
Triggers []FactResult `json:"triggers"`
Relevant []FactResult `json:"relevant"`
Subsystems []string `json:"subsystems,omitempty"`
// FloorDropped and FloorTopDropped report what the relevance floor removed
// from Relevant, on the same terms as SearchResult (#170). They matter more
// here: this tool is called by someone who does not yet know what to look
// for, so a thin section reads as "nothing is stored" unless the floor says
// otherwise (#173). The other sections are listed, not searched, and no
// floor applies to them.
FloorDropped int `json:"floor_dropped,omitempty"`
FloorTopDropped float64 `json:"floor_top_dropped,omitempty"`
}
GetContextResult is the structured output for memory_get_context.
type GetLinksInput ¶
type GetLinksInput struct {
FactID int64 `json:"fact_id" jsonschema:"ID of the fact to get links for"`
Direction string `json:"direction,omitempty" jsonschema:"outbound (default), inbound, or both"`
LinkType string `json:"link_type,omitempty" jsonschema:"filter to a specific link type (empty = all types)"`
}
GetLinksInput is the input schema for the memory_get_links tool.
type GetLinksResult ¶
GetLinksResult is the structured output for memory_get_links.
type HistoryEntry ¶
type HistoryEntry struct {
ID int64 `json:"id"`
Position int `json:"position"`
ChainLength int `json:"chain_length"`
Subject string `json:"subject"`
Category string `json:"category"`
Status string `json:"status"`
CreatedAt string `json:"created_at"`
Content string `json:"content"`
Metadata Metadata `json:"metadata,omitempty"`
UseCount int `json:"use_count"`
ConfirmedCount int `json:"confirmed_count"`
}
HistoryEntry represents a single history entry.
type HistoryInput ¶
type HistoryInput struct {
ID int64 `json:"id,omitempty" jsonschema:"fact ID to show the supersession chain for"`
Subject string `json:"subject,omitempty" jsonschema:"subject to show all facts for (including superseded)"`
}
HistoryInput is the input schema for the memory_history tool.
type HistoryResult ¶
type HistoryResult struct {
Entries []HistoryEntry `json:"entries"`
}
HistoryResult is the structured output for memory_history.
type LinkEntry ¶
type LinkEntry struct {
ID int64 `json:"link_id"`
SourceID int64 `json:"source_id"`
TargetID int64 `json:"target_id"`
LinkType string `json:"link_type"`
Bidirectional bool `json:"bidirectional,omitempty"`
Label string `json:"label,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
NeighborID int64 `json:"neighbor_id"`
NeighborSubject string `json:"neighbor_subject"`
NeighborContent string `json:"neighbor_content"`
}
LinkEntry represents a single link with neighbor info.
type LinkInput ¶
type LinkInput struct {
SourceID int64 `json:"source_id" jsonschema:"ID of the source fact"`
TargetID int64 `json:"target_id" jsonschema:"ID of the target fact"`
LinkType string `` /* 127-byte string literal not displayed */
Bidirectional bool `json:"bidirectional,omitempty" jsonschema:"if true, edge is traversable in both directions"`
Label string `json:"label,omitempty" jsonschema:"human-readable description of this connection"`
Metadata Metadata `json:"metadata,omitempty" jsonschema:"domain-specific properties for this edge"`
}
LinkInput is the input schema for the memory_link tool.
type LinkResult ¶
type LinkResult struct {
Status string `json:"status"`
LinkID int64 `json:"link_id"`
SourceID int64 `json:"source_id"`
TargetID int64 `json:"target_id"`
LinkType string `json:"link_type"`
Bidirectional bool `json:"bidirectional"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
LinkResult is the structured output for memory_link.
type ListInput ¶
type ListInput struct {
Subject string `json:"subject,omitempty" jsonschema:"filter by subject entity"`
Category string `json:"category,omitempty" jsonschema:"filter by category"`
Kind string `` /* 128-byte string literal not displayed */
Subsystem string `json:"subsystem,omitempty" jsonschema:"filter by subsystem (e.g. feeds, auth)"`
Limit int `json:"limit,omitempty" jsonschema:"maximum number of results (default 20)"`
Metadata Metadata `json:"metadata,omitempty" jsonschema:"filter by metadata fields (equality match, e.g. {\"source\": \"conversation\"})"`
}
ListInput is the input schema for the memory_list tool.
type ListResult ¶
type ListResult struct {
Facts []FactResult `json:"facts"`
}
ListResult is the structured output for memory_list.
type ListSubsystemsInput ¶
type ListSubsystemsInput struct {
Subject string `json:"subject,omitempty" jsonschema:"filter to a specific subject entity (empty = all subjects)"`
}
ListSubsystemsInput is the input schema for the memory_list_subsystems tool.
type ListSubsystemsResult ¶
type ListSubsystemsResult struct {
Subsystems []string `json:"subsystems"`
}
ListSubsystemsResult is the structured output for memory_list_subsystems.
type MemoryServer ¶
type MemoryServer struct {
// contains filtered or unexported fields
}
MemoryServer bridges MCP tool calls to a memstore.ReadableStore. It serves the retrieval tools and nothing else -- not by policy, but because a ReadableStore has no mutating methods to call. A write tool cannot be registered here either: its handler is a method on WriteServer, so Register would not compile.
func NewMemoryServer ¶
func NewMemoryServer(store memstore.ReadableStore, embedder embedding.Embedder) *MemoryServer
NewMemoryServer creates a server backed by the given store and embedder. The embedder is used to compute embeddings at insert time so search always works. Both parameters are required.
func NewMemoryServerWithConfig ¶
func NewMemoryServerWithConfig(store memstore.ReadableStore, embedder embedding.Embedder, cfg Config) *MemoryServer
NewMemoryServerWithConfig is like NewMemoryServer but accepts additional configuration (curator, generator, session store, rerank defaults).
func (*MemoryServer) HandleCurateContext ¶
func (ms *MemoryServer) HandleCurateContext(ctx context.Context, _ *mcp.CallToolRequest, input CurateContextInput) (*mcp.CallToolResult, fence.Envelope, error)
func (*MemoryServer) HandleGetContext ¶
func (ms *MemoryServer) HandleGetContext(ctx context.Context, _ *mcp.CallToolRequest, input GetContextInput) (*mcp.CallToolResult, fence.Envelope, error)
textResult builds a CallToolResult with a single text content block.
func (*MemoryServer) HandleGetLinks ¶
func (ms *MemoryServer) HandleGetLinks(ctx context.Context, _ *mcp.CallToolRequest, input GetLinksInput) (*mcp.CallToolResult, fence.Envelope, error)
func (*MemoryServer) HandleHistory ¶
func (ms *MemoryServer) HandleHistory(ctx context.Context, _ *mcp.CallToolRequest, input HistoryInput) (*mcp.CallToolResult, fence.Envelope, error)
func (*MemoryServer) HandleList ¶
func (ms *MemoryServer) HandleList(ctx context.Context, _ *mcp.CallToolRequest, input ListInput) (*mcp.CallToolResult, fence.Envelope, error)
func (*MemoryServer) HandleListSubsystems ¶
func (ms *MemoryServer) HandleListSubsystems(ctx context.Context, _ *mcp.CallToolRequest, input ListSubsystemsInput) (*mcp.CallToolResult, ListSubsystemsResult, error)
func (*MemoryServer) HandleRateContext ¶
func (ms *MemoryServer) HandleRateContext(ctx context.Context, _ *mcp.CallToolRequest, input RateContextInput) (*mcp.CallToolResult, RateContextResult, error)
func (*MemoryServer) HandleRerankSettings ¶
func (ms *MemoryServer) HandleRerankSettings(_ context.Context, _ *mcp.CallToolRequest, _ RerankSettingsInput) (*mcp.CallToolResult, RerankSettingsResult, error)
HandleRerankSettings gets and sets the session's retrieval tunables. Omitted fields are left unchanged; with no fields it just reports the current values, so the same tool both reads and writes. The model uses it to self-tune from observed performance — fusion mode/threshold/weight, the search and get_context candidate pools, and a rerank timeout — without restarting or touching the daemon's env defaults.
func (*MemoryServer) HandleSearch ¶
func (ms *MemoryServer) HandleSearch(ctx context.Context, _ *mcp.CallToolRequest, input SearchInput) (*mcp.CallToolResult, fence.Envelope, error)
func (*MemoryServer) HandleStatus ¶
func (ms *MemoryServer) HandleStatus(ctx context.Context, _ *mcp.CallToolRequest, _ StatusInput) (*mcp.CallToolResult, StatusResult, error)
func (*MemoryServer) HandleSuggestAgent ¶
func (ms *MemoryServer) HandleSuggestAgent(ctx context.Context, _ *mcp.CallToolRequest, input SuggestAgentInput) (*mcp.CallToolResult, fence.Envelope, error)
triggerMatches returns true if any word from taskWords appears in the trigger content. HandleSuggestAgent recommends specialist agents for a task based on stored agent-routing facts. Scores agents by domain keyword overlap with the task.
func (*MemoryServer) HandleTaskList ¶
func (ms *MemoryServer) HandleTaskList(ctx context.Context, _ *mcp.CallToolRequest, input TaskListInput) (*mcp.CallToolResult, fence.Envelope, error)
func (*MemoryServer) Register ¶
func (ms *MemoryServer) Register(s *mcp.Server)
Register adds the retrieval tools to the given MCP server. A *MemoryServer registers these and only these; the write tools are not omitted by choice here, they are unreachable -- their handlers are methods on WriteServer.
func (*MemoryServer) SetEmbedCeiling ¶
func (ms *MemoryServer) SetEmbedCeiling(n int)
SetEmbedCeiling sets the hard byte bound on any single embed request, normally the configured embedder's effective budget (embedding.Config.Limits().MaxBytes). Zero leaves chunk sizing to the retrieval target alone.
type Metadata ¶
Metadata is domain-specific key-value data attached to a fact, link, or task, and the single type both tool inputs and tool results declare it as.
It is deliberately open. Callers attach whatever their domain needs -- provenance (cwd, session_id, source), task state (status, scope, project), or anything else -- and the store round-trips it verbatim. The schema this infers must therefore permit unknown keys, which rules out a struct: jsonschema-go gives structs additionalProperties:false, so a fact carrying any key the struct didn't declare would fail output validation. It also rules out a []byte-backed type such as json.RawMessage, which infers an array schema for what marshals as an object.
type RateContextInput ¶
type RateContextInput struct {
RefID string `json:"ref_id" jsonschema:"fact ID or session turn UUID to rate"`
RefType string `json:"ref_type" jsonschema:"type of the ref: 'fact' or 'turn'"`
SessionID string `json:"session_id" jsonschema:"current session ID"`
Score int `json:"score" jsonschema:"rating: +1 (useful) or -1 (not useful)"`
Reason string `json:"reason,omitempty" jsonschema:"brief explanation of the rating"`
}
RateContextInput is the input schema for the memory_rate_context tool.
type RateContextResult ¶
type RateContextResult struct {
Status string `json:"status"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
RateContextResult is the structured output for memory_rate_context.
type RerankSettingsInput ¶
type RerankSettingsInput struct{}
RerankSettingsInput is the input schema for the memory_rerank_settings tool. It is empty: the tool reports the policy in force and cannot change it.
type RerankSettingsResult ¶
type RerankSettingsResult struct {
Mode string `json:"mode"`
Threshold float64 `json:"threshold"`
Weight float64 `json:"weight,omitempty"`
SearchCandidates int `json:"search_candidates"`
RecallCandidates int `json:"recall_candidates"`
SearchDocBytes int `json:"search_doc_bytes"`
RecallDocBytes int `json:"recall_doc_bytes"`
Timeout string `json:"timeout,omitempty"`
}
RerankSettingsResult is the structured output for memory_rerank_settings.
type SearchInput ¶
type SearchInput struct {
Query string `json:"query" jsonschema:"natural language search query"`
Subject string `json:"subject,omitempty" jsonschema:"filter results to a specific subject entity"`
Category string `json:"category,omitempty" jsonschema:"filter results to a specific category"`
Kind string `` /* 128-byte string literal not displayed */
Subsystem string `json:"subsystem,omitempty" jsonschema:"filter by subsystem (e.g. feeds, auth)"`
Limit int `json:"limit,omitempty" jsonschema:"maximum number of results (default 10)"`
IncludeSuperseded bool `json:"include_superseded,omitempty" jsonschema:"if true, include superseded facts in results (tagged with [SUPERSEDED])"`
Metadata Metadata `json:"metadata,omitempty" jsonschema:"filter by metadata fields (equality match, e.g. {\"source\": \"conversation\"})"`
RerankMode string `` /* 137-byte string literal not displayed */
Threshold *float64 `` /* 156-byte string literal not displayed */
Weight *float64 `` /* 166-byte string literal not displayed */
Candidates *int `` /* 176-byte string literal not displayed */
DocBytes *int `` /* 167-byte string literal not displayed */
TimeoutSeconds *float64 `` /* 189-byte string literal not displayed */
}
SearchInput is the input schema for the memory_search tool.
type SearchResult ¶
type SearchResult struct {
Query string `json:"query"`
Results []FactResult `json:"results"`
// FloorDropped and FloorTopDropped report what the relevance floor removed,
// omitted when it removed nothing. A result set the floor trimmed otherwise
// looks identical to one that was always that short, which is the whole
// reason the floor needs to account for itself (#170). FloorTopDropped is
// the closest miss: several facts dropped just under the floor argue it is
// set too high, several dropped far below argue it is working.
FloorDropped int `json:"floor_dropped,omitempty"`
FloorTopDropped float64 `json:"floor_top_dropped,omitempty"`
}
SearchResult is the structured output for memory_search.
type StatusInput ¶
type StatusInput struct{}
StatusInput is the input schema for the memory_status tool.
type StatusResult ¶
type StatusResult struct {
ActiveCount int64 `json:"active_count"`
Categories map[string]int `json:"categories,omitempty"`
Kinds map[string]int `json:"kinds,omitempty"`
// Subjects holds at most statusMaxSubjects entries, the highest-count
// ones, matching what the text rendering shows. A live corpus reached
// 2,560 subjects, which serialized past the MCP result cap and spilled
// the whole call to a file (#150). SubjectCount reports the true total
// so a truncated map is never mistaken for the whole picture.
Subjects map[string]int `json:"subjects,omitempty"`
SubjectCount int `json:"subject_count,omitempty"`
SubjectsTruncated bool `json:"subjects_truncated,omitempty"`
}
StatusResult is the structured output for memory_status.
type StoreBatchInput ¶
type StoreBatchInput struct {
Facts []StoreInput `json:"facts" jsonschema:"array of facts to store (max 20)"`
}
StoreBatchInput is the input schema for the memory_store_batch tool.
type StoreBatchResult ¶
type StoreBatchResult struct {
Stored int `json:"stored"`
Total int `json:"total"`
Results []BatchResult `json:"results"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
StoreBatchResult is the structured output for memory_store_batch.
type StoreInput ¶
type StoreInput struct {
Content string `json:"content" jsonschema:"the factual claim or memory to store"`
Subject string `json:"subject" jsonschema:"the entity this fact is about (e.g. a person or project)"`
Category string `` /* 141-byte string literal not displayed */
Kind string `` /* 143-byte string literal not displayed */
Subsystem string `json:"subsystem,omitempty" jsonschema:"optional project subsystem this fact belongs to (e.g. feeds, auth, storage)"`
Metadata Metadata `json:"metadata,omitempty" jsonschema:"optional key-value metadata to attach"`
Supersedes *int64 `json:"supersedes,omitempty" jsonschema:"ID of an existing fact that this new fact replaces (preserves history unlike delete)"`
}
StoreInput is the input schema for the memory_store tool.
type StoreResult ¶
type StoreResult struct {
Status string `json:"status"`
ID int64 `json:"id,omitempty"`
Superseded *int64 `json:"superseded_by,omitempty"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
StoreResult is the structured output for memory_store.
type SuggestAgentInput ¶
type SuggestAgentInput struct {
Task string `json:"task" jsonschema:"description of the work to be done"`
Subject string `` /* 139-byte string literal not displayed */
}
SuggestAgentInput is the input schema for the memory_suggest_agent tool.
type SuggestAgentResult ¶
type SuggestAgentResult struct {
Task string `json:"task"`
Suggestions []AgentScore `json:"suggestions"`
}
SuggestAgentResult is the structured output for memory_suggest_agent.
type SupersedeInput ¶
type SupersedeInput struct {
OldID int64 `json:"old_id" jsonschema:"ID of the fact being replaced"`
NewID int64 `json:"new_id" jsonschema:"ID of the fact that replaces it"`
}
SupersedeInput is the input schema for the memory_supersede tool.
type SupersedeResult ¶
type SupersedeResult struct {
Status string `json:"status"`
OldID int64 `json:"old_id"`
NewID int64 `json:"new_id"`
OldContent string `json:"old_content"`
NewContent string `json:"new_content"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
SupersedeResult is the structured output for memory_supersede.
type TaskCreateInput ¶
type TaskCreateInput struct {
Content string `json:"content" jsonschema:"what needs to be done"`
Scope string `json:"scope" jsonschema:"task owner: matthew, claude, or collaborative"`
Priority string `json:"priority,omitempty" jsonschema:"task priority: high, normal, or low (default: normal)"`
Project string `json:"project,omitempty" jsonschema:"project name for grouping tasks"`
Due string `json:"due,omitempty" jsonschema:"due date (free-form, e.g. 2026-03-01)"`
}
TaskCreateInput is the input schema for the memory_task_create tool.
type TaskCreateResult ¶
type TaskCreateResult struct {
Status string `json:"status"`
ID int64 `json:"id"`
Scope string `json:"scope"`
Priority string `json:"priority"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
TaskCreateResult is the structured output for memory_task_create.
type TaskListInput ¶
type TaskListInput struct {
Scope string `json:"scope,omitempty" jsonschema:"filter by scope: matthew, claude, or collaborative"`
Status string `json:"status,omitempty" jsonschema:"filter by status (default: pending)"`
Project string `json:"project,omitempty" jsonschema:"filter by project name"`
}
TaskListInput is the input schema for the memory_task_list tool.
type TaskListResult ¶
type TaskListResult struct {
Tasks []TaskResult `json:"tasks"`
}
TaskListResult is the structured output for memory_task_list.
type TaskResult ¶
type TaskResult struct {
ID int64 `json:"id"`
Status string `json:"status"`
Scope string `json:"scope"`
Priority string `json:"priority"`
Content string `json:"content"`
Due string `json:"due,omitempty"`
}
TaskResult represents a single task fact.
type TaskUpdateInput ¶
type TaskUpdateInput struct {
ID int64 `json:"id" jsonschema:"the task fact ID to update"`
Status string `json:"status" jsonschema:"new status: pending, in_progress, completed, or cancelled"`
Note string `json:"note,omitempty" jsonschema:"optional transition note (e.g. reason for cancellation)"`
}
TaskUpdateInput is the input schema for the memory_task_update tool.
type TaskUpdateResult ¶
type TaskUpdateResult struct {
Status string `json:"status"`
ID int64 `json:"id"`
OldStatus string `json:"old_status,omitempty"`
NewStatus string `json:"new_status"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
TaskUpdateResult is the structured output for memory_task_update.
type UnlinkInput ¶
type UnlinkInput struct {
LinkID int64 `json:"link_id" jsonschema:"ID of the link to delete"`
}
UnlinkInput is the input schema for the memory_unlink tool.
type UnlinkResult ¶
type UnlinkResult struct {
Status string `json:"status"`
LinkID int64 `json:"link_id"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
UnlinkResult is the structured output for memory_unlink.
type UpdateInput ¶
type UpdateInput struct {
ID int64 `json:"id" jsonschema:"the fact ID to update"`
Metadata Metadata `json:"metadata" jsonschema:"metadata keys to set (non-nil) or delete (nil)"`
}
UpdateInput is the input schema for the memory_update tool.
type UpdateLinkInput ¶
type UpdateLinkInput struct {
LinkID int64 `json:"link_id" jsonschema:"ID of the link to update"`
Label string `json:"label,omitempty" jsonschema:"new label (empty leaves existing label unchanged)"`
Metadata Metadata `json:"metadata,omitempty" jsonschema:"metadata keys to set (non-nil) or delete (nil)"`
}
UpdateLinkInput is the input schema for the memory_update_link tool.
type UpdateLinkResult ¶
type UpdateLinkResult struct {
Status string `json:"status"`
LinkID int64 `json:"link_id"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
UpdateLinkResult is the structured output for memory_update_link.
type UpdateResult ¶
type UpdateResult struct {
Status string `json:"status"`
ID int64 `json:"id"`
// Error names a caller-side mistake; empty on every other path.
Error string `json:"error,omitempty"`
}
UpdateResult is the structured output for memory_update.
type WriteServer ¶
type WriteServer struct {
*MemoryServer
// contains filtered or unexported fields
}
WriteServer is a MemoryServer that also holds a WritableStore, and serves the tools that mutate stored content.
The two types are the authorization boundary. A caller entitled only to read is given a *MemoryServer, which has no writable handle to reach and no write handler to call; a caller entitled to write is given a *WriteServer, built from a handle the scoper agreed to issue. There is no runtime check because there is nothing to check: the decision was made when the handle was minted, and the type carries it from there.
It embeds *MemoryServer, so a write-capable server answers the read tools too, and store shadows the embedded read handle for the write handlers.
func NewWriteServer ¶
func NewWriteServer(store memstore.WritableStore, embedder embedding.Embedder) *WriteServer
NewWriteServer creates a write-capable server. Obtain the store from StoreScoper.WritableFor rather than passing a full backend directly: that call is where the entitlement is decided, and passing around it defeats the point of the split.
func NewWriteServerWithConfig ¶
func NewWriteServerWithConfig(store memstore.WritableStore, embedder embedding.Embedder, cfg Config) *WriteServer
NewWriteServerWithConfig is NewWriteServer with the additional configuration NewMemoryServerWithConfig takes.
func (*WriteServer) HandleConfirm ¶
func (ws *WriteServer) HandleConfirm(ctx context.Context, _ *mcp.CallToolRequest, input ConfirmInput) (*mcp.CallToolResult, ConfirmResult, error)
func (*WriteServer) HandleDelete ¶
func (ws *WriteServer) HandleDelete(ctx context.Context, _ *mcp.CallToolRequest, input DeleteInput) (*mcp.CallToolResult, DeleteResult, error)
func (*WriteServer) HandleLink ¶
func (ws *WriteServer) HandleLink(ctx context.Context, _ *mcp.CallToolRequest, input LinkInput) (*mcp.CallToolResult, LinkResult, error)
func (*WriteServer) HandleStore ¶
func (ws *WriteServer) HandleStore(ctx context.Context, _ *mcp.CallToolRequest, input StoreInput) (*mcp.CallToolResult, StoreResult, error)
func (*WriteServer) HandleStoreBatch ¶
func (ws *WriteServer) HandleStoreBatch(ctx context.Context, _ *mcp.CallToolRequest, input StoreBatchInput) (*mcp.CallToolResult, StoreBatchResult, error)
func (*WriteServer) HandleSupersede ¶
func (ws *WriteServer) HandleSupersede(ctx context.Context, _ *mcp.CallToolRequest, input SupersedeInput) (*mcp.CallToolResult, SupersedeResult, error)
func (*WriteServer) HandleTaskCreate ¶
func (ws *WriteServer) HandleTaskCreate(ctx context.Context, _ *mcp.CallToolRequest, input TaskCreateInput) (*mcp.CallToolResult, TaskCreateResult, error)
func (*WriteServer) HandleTaskUpdate ¶
func (ws *WriteServer) HandleTaskUpdate(ctx context.Context, _ *mcp.CallToolRequest, input TaskUpdateInput) (*mcp.CallToolResult, TaskUpdateResult, error)
func (*WriteServer) HandleUnlink ¶
func (ws *WriteServer) HandleUnlink(ctx context.Context, _ *mcp.CallToolRequest, input UnlinkInput) (*mcp.CallToolResult, UnlinkResult, error)
func (*WriteServer) HandleUpdate ¶
func (ws *WriteServer) HandleUpdate(ctx context.Context, _ *mcp.CallToolRequest, input UpdateInput) (*mcp.CallToolResult, UpdateResult, error)
func (*WriteServer) HandleUpdateLink ¶
func (ws *WriteServer) HandleUpdateLink(ctx context.Context, _ *mcp.CallToolRequest, input UpdateLinkInput) (*mcp.CallToolResult, UpdateLinkResult, error)
func (*WriteServer) Register ¶
func (ws *WriteServer) Register(s *mcp.Server)
Register adds the retrieval tools and the tools that mutate stored content.
This is the whole of what "may write" means at the MCP layer. There is no flag consulted here and no check inside the handlers: reaching this method at all required a memstore.WritableStore, and the only supplier of one is StoreScoper.WritableFor, which refuses a principal that may not write.