mcp

package
v2.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 30 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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).

View Source
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).

View Source
var Profiles = map[string]map[string]bool{
	"agent":    ProfileAgent,
	"admin":    ProfileAdmin,
	"temporal": ProfileTemporal,
}

Profiles maps profile names to their tool sets.

Functions

func NewServer

func NewServer(stores *Stores) *server.MCPServer

NewServer creates an MCP server with ALL tools registered.

func NewServerWithTools

func NewServerWithTools(stores *Stores, allowlist map[string]bool) *server.MCPServer

NewServerWithTools creates an MCP server registering only the tools in the allowlist. If allowlist is nil, all tools are registered.

func ResolveTools

func ResolveTools(input string) map[string]bool

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

type RemoteProxy struct {
	Server *mcpserver.MCPServer
	// contains filtered or unexported fields
}

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

type RemoteProxyConfig struct {
	URL      string
	TokenEnv string
	Timeout  time.Duration
}

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 Stores

type Stores = bundle.Stores

Stores is an alias for bundle.Stores.

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

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

GetCurrentFactState determines the current state of facts related to an observation.

func (*TemporalToolsHandler) GetHealthCheck

GetHealthCheck provides system health status.

func (*TemporalToolsHandler) GetSystemMetrics

GetSystemMetrics retrieves system-wide performance metrics.

func (*TemporalToolsHandler) GetTemporalEdges

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

GetTemporalRelevant retrieves observations relevant at a specific time.

func (*TemporalToolsHandler) RecordOperation

RecordOperation records an operation with performance metrics.

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).

Jump to

Keyboard shortcuts

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