mcp

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Overview

Package mcp provides the MCP (Model Context Protocol) server for engram.

Package mcp provides MCP SSE transport handling.

Package mcp provides Streamable HTTP MCP transport (2025-03-26 spec).

Streamable HTTP is the modern MCP transport: a single POST endpoint that accepts JSON-RPC requests and returns JSON-RPC responses inline. Unlike SSE transport, no long-lived connection is needed.

Package mcp provides document/collection MCP tool handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Data    any    `json:"data,omitempty"`
	Message string `json:"message"`
	Code    int    `json:"code"`
}

Error represents a JSON-RPC error.

type MCPHealth added in v1.7.0

type MCPHealth struct {
	// contains filtered or unexported fields
}

MCPHealth tracks in-memory request/error counters for the MCP endpoint.

func NewMCPHealth added in v1.7.0

func NewMCPHealth() *MCPHealth

NewMCPHealth creates a new health monitor.

func (*MCPHealth) HandleHealth added in v1.7.0

func (h *MCPHealth) HandleHealth(w http.ResponseWriter, r *http.Request)

HandleHealth returns the health endpoint handler.

func (*MCPHealth) RecordError added in v1.7.0

func (h *MCPHealth) RecordError()

RecordError increments the error counter.

func (*MCPHealth) RecordRequest added in v1.7.0

func (h *MCPHealth) RecordRequest()

RecordRequest increments the request counter.

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      any             `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request represents a JSON-RPC request.

type Response

type Response struct {
	ID      any    `json:"id"`
	Result  any    `json:"result,omitempty"`
	Error   *Error `json:"error,omitempty"`
	JSONRPC string `json:"jsonrpc"`
}

Response represents a JSON-RPC response.

type SSEHandler

type SSEHandler struct {
	// contains filtered or unexported fields
}

func NewSSEHandler

func NewSSEHandler(server *Server) *SSEHandler

func (*SSEHandler) Close

func (h *SSEHandler) Close()

Close closes all active session channels.

func (*SSEHandler) ServeHTTP

func (h *SSEHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes GET /sse -> handleSSE, POST /message -> handleMessage, OPTIONS -> CORS preflight

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the MCP server that exposes search tools. Field order optimized for memory alignment (fieldalignment).

func NewServer

func NewServer(
	searchMgr *search.Manager,
	version string,
	observationStore *gorm.ObservationStore,
	patternStore *gorm.PatternStore,
	relationStore *gorm.RelationStore,
	sessionStore *gorm.SessionStore,
	vectorClient vector.Client,
	scoreCalculator *scoring.Calculator,
	recalculator *scoring.Recalculator,
	maintenanceService *maintenance.Service,
	collectionRegistry *collections.Registry,
	sessionIdxStore *sessions.Store,
	consolidationScheduler *consolidation.Scheduler,
	documentStore *gorm.DocumentStore,
	embedSvc *embedding.Service,
	chunkManager *chunking.Manager,
) *Server

NewServer creates a new MCP server.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the MCP server loop.

func (*Server) SetBackfillStatusFunc added in v0.4.0

func (s *Server) SetBackfillStatusFunc(fn func() (any, error))

SetBackfillStatusFunc sets the function to retrieve backfill run status.

func (*Server) SetGraphStore

func (s *Server) SetGraphStore(gs graphpkg.GraphStore)

SetGraphStore sets the graph store for graph-related MCP tools.

func (*Server) SetVersionedDocumentStore added in v1.7.0

func (s *Server) SetVersionedDocumentStore(vds *gorm.VersionedDocumentStore)

SetVersionedDocumentStore sets the versioned document store for document MCP tools.

type StreamableHandler

type StreamableHandler struct {
	// contains filtered or unexported fields
}

StreamableHandler implements the MCP Streamable HTTP transport. It accepts POST requests with JSON-RPC payloads, dispatches them to the MCP server, and returns JSON-RPC responses synchronously.

func NewStreamableHandler

func NewStreamableHandler(server *Server, health *MCPHealth) *StreamableHandler

NewStreamableHandler creates a new Streamable HTTP handler.

func (*StreamableHandler) ServeHTTP

func (h *StreamableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles POST requests with JSON-RPC MCP messages.

type TimelineParams

type TimelineParams struct {
	Query     string `json:"query"`
	Project   string `json:"project"`
	ObsType   string `json:"obs_type"`
	Concepts  string `json:"concepts"`
	Files     string `json:"files"`
	Format    string `json:"format"`
	AnchorID  int64  `json:"anchor_id"`
	Before    int    `json:"before"`
	After     int    `json:"after"`
	DateStart int64  `json:"dateStart"`
	DateEnd   int64  `json:"dateEnd"`
}

TimelineParams represents parameters for timeline operations.

type Tool

type Tool struct {
	InputSchema map[string]any `json:"inputSchema"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	// contains filtered or unexported fields
}

Tool represents an MCP tool definition.

type ToolCallParams

type ToolCallParams struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
}

ToolCallParams represents parameters for tools/call method.

Jump to

Keyboard shortcuts

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