mcp

package
v2.4.19 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 39 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. Discovery metadata (supported vs retired profile names) is declared exactly once via SupportedProfiles and RetiredProfiles below; docs and tool output must derive from those declarations instead of copying the names:

cortex mcp                        -> all tools (default)
cortex mcp --tools=agent          -> ordinary agent tools (cortex_* namespace)
cortex mcp --tools=dev            -> golden dev suite (11 tools: memory + AST impact)
cortex mcp --tools=minimal        -> essential core memory (5 tools: minimal token footprint)
cortex mcp --tools=admin          -> retired profile (explicit use only, never discovered)
cortex mcp --tools=temporal       -> retired profile (explicit use only, never discovered)

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

View Source
const (
	VectorIndexEnabled  = "enabled"
	VectorIndexDegraded = "degraded"
	VectorIndexDisabled = "disabled"
)

Vector index capability states advertised by the status tool. They mirror the verdict cortex doctor prints so status output and doctor output report one reality.

Variables

View Source
var ProfileAdmin = map[string]bool{
	"cortex_delete":         true,
	"cortex_stats":          true,
	"cortex_timeline":       true,
	"cortex_score":          true,
	"cortex_consolidate":    true,
	"cortex_merge_projects": true,
}

ProfileAdmin contains administrative maintenance tools. DEPRECATED FOR AGENTS: Destructive and administrative operations (cortex_delete, cortex_merge_projects, cortex_consolidate) belong to operator interfaces (CLI, TUI, Web UI) and must NOT be exposed to autonomous agents.

View Source
var ProfileAgent = map[string]bool{

	"cortex_save":            true,
	"cortex_update":          true,
	"cortex_get_observation": true,
	"cortex_context":         true,
	"cortex_session_summary": true,

	"cortex_search":            true,
	"cortex_get_agent_context": true,

	"cortex_relate":     true,
	"cortex_graph":      true,
	"cortex_graph_path": true,

	"cortex_get_rules": true,
	"cortex_save_rule": true,

	"cortex_ingest_code":      true,
	"cortex_get_blast_radius": true,
	"cortex_code_tests":       true,
	"cortex_get_code_symbols": true,
	"cortex_detect_cycles":    true,

	"cortex_analyze_architecture": true,
	"cortex_code_map":             true,
	"cortex_get_status":           true,

	"cortex_revision_history": true,
	"cortex_handoff":          true,
}

ProfileAgent contains the consolidated agent tool set in the cortex_* namespace. These are the orthogonal, unified tools an AI agent needs for proactive memory, intelligent hybrid search, context packs, knowledge graphs, and codebase AST intelligence.

View Source
var ProfileDev = map[string]bool{
	"cortex_save":              true,
	"cortex_search":            true,
	"cortex_context":           true,
	"cortex_session_summary":   true,
	"cortex_get_observation":   true,
	"cortex_get_agent_context": true,
	"cortex_relate":            true,
	"cortex_get_rules":         true,
	"cortex_ingest_code":       true,
	"cortex_get_blast_radius":  true,
	"cortex_code_tests":        true,
}

ProfileDev contains the golden 11-tool suite for local software development: essential memory plus codebase AST analysis, blast radius, and test impact.

View Source
var ProfileMinimal = map[string]bool{
	"cortex_save":            true,
	"cortex_search":          true,
	"cortex_context":         true,
	"cortex_session_summary": true,
	"cortex_get_observation": true,
}

ProfileMinimal contains the 5 core memory tools for ultra-low token footprint and fast model inference (e.g. local models, Haiku, Flash).

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 bi-temporal graph queries and telemetry tools. DEPRECATED FOR AGENTS: Infrastructure telemetry (memory usage, execution duration) and manual bitemporal timestamps belong to internal middleware and APM, not agentic LLM context. Use topic_key upserts and cortex_revision_history instead.

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

Profiles maps profile names to their tool sets, including the "coder" alias for ProfileDev. It is the registry that discovery metadata derives from; profile names must not be enumerated in any other declaration.

View Source
var RetiredProfiles = map[string]bool{
	"admin":    true,
	"temporal": true,
}

RetiredProfiles marks non-agentic profiles that stay resolvable through ResolveTools for backward compatibility but are rejected from standard discovery surfaces such as the status tool output.

Functions

func NewServer

func NewServer(stores *Stores) *server.MCPServer

NewServer creates an MCP server with ProfileAgent tools registered by default.

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" resolves to ProfileAgent (the full canonical agent suite). Retired profiles remain resolvable here for explicit backward-compatible requests; only discovery surfaces (see SupportedProfiles) exclude them.

func SupportedProfiles added in v2.4.0

func SupportedProfiles() []string

SupportedProfiles returns the sorted profile names advertised by standard discovery. Deriving the list from Profiles minus RetiredProfiles keeps a single source of truth so a stale copy cannot reappear in tool output.

func VectorIndexState added in v2.4.0

func VectorIndexState(ctx context.Context, idx domain.VectorIndex) string

VectorIndexState derives the vector_index capability state from the live VectorIndex health port. The enabled verdict delegates to domain.IsVectorIndexHealthy — the exact check cortex doctor gates on — so this cannot become a second copy of detection logic; the health status is only read afterwards to separate a degraded index from an absent or unhealthy one.

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