Documentation
¶
Overview ¶
Package mcp implements the Model Context Protocol server for Cortex.
This exposes memory tools via MCP stdio transport so agents can use Cortex as a persistent memory server.
Tool profiles allow agents to load only the tools they need:
cortex mcp -> all tools (default) cortex mcp --tools=agent -> ordinary agent tools (cortex_* namespace) cortex mcp --tools=admin -> admin/diagnostic tools cortex mcp --tools=temporal -> temporal/advanced tools
Package mcp provides MCP (Model Context Protocol) server implementation for Cortex, exposing all memory system capabilities as MCP tools.
This package implements the MCP server with tool profiles, error handling, and domain logic delegation to the appropriate services.
Index ¶
- Variables
- func NewServer(stores *Stores) *server.MCPServer
- func NewServerWithTools(stores *Stores, allowlist map[string]bool) *server.MCPServer
- func ResolveTools(input string) map[string]bool
- type RemoteProxy
- type RemoteProxyConfig
- type Stores
- type TemporalToolsHandler
- func (h *TemporalToolsHandler) CreateTemporalEdge(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) CreateTemporalSnapshot(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) EvaluateMemoryQuality(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) GetCurrentFactState(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) GetHealthCheck(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) GetSystemMetrics(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) GetTemporalEdges(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) GetTemporalEvolutionPath(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) GetTemporalRelevant(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
- func (h *TemporalToolsHandler) RecordOperation(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
Constants ¶
This section is empty.
Variables ¶
var ProfileAdmin = map[string]bool{ "cortex_delete": true, "cortex_stats": true, "cortex_timeline": true, "cortex_archive": true, "cortex_merge_projects": true, }
ProfileAdmin contains admin/diagnostic tools for manual curation (TUI, CLI, dashboards). Destructive tools carry destructive-hint annotations.
var ProfileAgent = map[string]bool{ "cortex_save": true, "cortex_search": true, "cortex_context": true, "cortex_session_summary": true, "cortex_session_start": true, "cortex_session_end": true, "cortex_get_observation": true, "cortex_suggest_topic_key": true, "cortex_capture_passive": true, "cortex_save_prompt": true, "cortex_update": true, "cortex_relate": true, "cortex_graph": true, "cortex_graph_relationships": true, "cortex_graph_path": true, "cortex_score": true, "cortex_search_hybrid": true, "cortex_revision_history": true, "cortex_handoff": true, "cortex_get_rules": true, "cortex_save_rule": true, "cortex_ingest_code": true, "cortex_code_scan": true, "cortex_get_blast_radius": true, "cortex_code_impact": true, "cortex_detect_cycles": true, "cortex_analyze_architecture": true, "cortex_code_analyze": true, "cortex_get_code_symbols": true, "cortex_code_symbols": true, "cortex_get_code_graph": true, "cortex_code_graph": true, "cortex_consolidate": true, "cortex_project_dna": true, "cortex_resolve_query": true, "cortex_get_status": true, }
ProfileAgent contains the ordinary agent tool set in the cortex_* namespace. These are the tools an AI agent needs for proactive memory, search, context, and knowledge-graph workflows. Temporal and admin tools are intentionally absent — they belong to separate profiles (REQ-MCP-002).
var ProfileTemporal = map[string]bool{ "cortex_temporal_create_edge": true, "cortex_temporal_create_snapshot": true, "cortex_temporal_evaluate_quality": true, "cortex_temporal_evolution_path": true, "cortex_temporal_fact_state": true, "cortex_temporal_get_edges": true, "cortex_temporal_get_relevant": true, "cortex_temporal_health_check": true, "cortex_temporal_record_operation": true, "cortex_temporal_system_metrics": true, "cortex_search_temporal": true, }
ProfileTemporal contains temporal/advanced tools for bi-temporal graph queries, observability, and point-in-time analysis. These MUST NOT appear in ordinary agent discovery (REQ-MCP-002).
var Profiles = map[string]map[string]bool{ "agent": ProfileAgent, "admin": ProfileAdmin, "temporal": ProfileTemporal, }
Profiles maps profile names to their tool sets.
Functions ¶
func NewServerWithTools ¶
NewServerWithTools creates an MCP server registering only the tools in the allowlist. If allowlist is nil, all tools are registered.
func ResolveTools ¶
ResolveTools takes a comma-separated string of profile names and/or individual tool names and returns the set of tool names to register. An empty input or "all" means register everything.
Types ¶
type RemoteProxy ¶
RemoteProxy owns the remote client and the local stdio-facing MCP server.
func OpenRemoteProxy ¶
func OpenRemoteProxy(ctx context.Context, cfg RemoteProxyConfig) (*RemoteProxy, error)
OpenRemoteProxy connects, negotiates, and snapshots the remote tool catalog. It fails closed so an unavailable or unauthenticated remote cannot silently fall back to a different local memory database.
REM-TRANSPORT-001: the destination is validated against the shared transport policy BEFORE the token is read or any client capable of sending it is constructed — HTTPS for remote hosts, plain HTTP only on strict loopback.
func (*RemoteProxy) Close ¶
func (p *RemoteProxy) Close() error
Close releases the remote Streamable HTTP session.
type RemoteProxyConfig ¶
RemoteProxyConfig describes the remote MCP endpoint used by the local stdio bridge. TokenEnv names the environment variable; secrets are never stored in the Cortex YAML model or copied into tool definitions.
type TemporalToolsHandler ¶
type TemporalToolsHandler struct {
// contains filtered or unexported fields
}
TemporalToolsHandler handles temporal graph and observability MCP tools.
func NewTemporalToolsHandler ¶
func NewTemporalToolsHandler( temporalService *temporal.TemporalService, observabilityService *observability.ObservabilityService, ) *TemporalToolsHandler
NewTemporalToolsHandler creates a new handler for temporal and observability tools.
func (*TemporalToolsHandler) CreateTemporalEdge ¶
func (h *TemporalToolsHandler) CreateTemporalEdge(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
CreateTemporalEdge creates an edge with temporal validity and evolution tracking.
func (*TemporalToolsHandler) CreateTemporalSnapshot ¶
func (h *TemporalToolsHandler) CreateTemporalSnapshot(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
CreateTemporalSnapshot creates a point-in-time snapshot of the knowledge graph.
func (*TemporalToolsHandler) EvaluateMemoryQuality ¶
func (h *TemporalToolsHandler) EvaluateMemoryQuality(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
EvaluateMemoryQuality evaluates the quality of the memory system.
func (*TemporalToolsHandler) GetCurrentFactState ¶
func (h *TemporalToolsHandler) GetCurrentFactState(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
GetCurrentFactState determines the current state of facts related to an observation.
func (*TemporalToolsHandler) GetHealthCheck ¶
func (h *TemporalToolsHandler) GetHealthCheck(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
GetHealthCheck provides system health status.
func (*TemporalToolsHandler) GetSystemMetrics ¶
func (h *TemporalToolsHandler) GetSystemMetrics(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
GetSystemMetrics retrieves system-wide performance metrics.
func (*TemporalToolsHandler) GetTemporalEdges ¶
func (h *TemporalToolsHandler) GetTemporalEdges(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
GetTemporalEdges retrieves edges valid at a specific time point.
func (*TemporalToolsHandler) GetTemporalEvolutionPath ¶
func (h *TemporalToolsHandler) GetTemporalEvolutionPath(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
GetTemporalEvolutionPath retrieves the evolution history of an edge.
func (*TemporalToolsHandler) GetTemporalRelevant ¶
func (h *TemporalToolsHandler) GetTemporalRelevant(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
GetTemporalRelevant retrieves observations relevant at a specific time.
func (*TemporalToolsHandler) RecordOperation ¶
func (h *TemporalToolsHandler) RecordOperation(ctx context.Context, req *protocol.CallToolRequest) (*protocol.CallToolResult, error)
RecordOperation records an operation with performance metrics.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package memorycontract is the shared, pure MCP contract for the durable memory write surface (design RD6, REM-SAVE-001, REM-MCP-001).
|
Package memorycontract is the shared, pure MCP contract for the durable memory write surface (design RD6, REM-SAVE-001, REM-MCP-001). |