server

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Direct codegraph MCP tools.

Before this file existed, the MCP bridge to celeste's codegraph went through the celeste chat tool: the caller sent a natural-language prompt, a chat LLM decided to call code_review (or code_search, ...) as a function-call, the tool ran against the graph, and the chat LLM summarized the result back to the caller — with all the usual LLM costs: latency, token spend, and an output ceiling that truncated large findings mid-response.

The tools here skip the chat LLM entirely. Each MCP tool is a direct handler that pulls the per-workspace Indexer from the Server cache, invokes the underlying celeste codegraph tool, and returns the tool result verbatim as an MCP ContentBlock. No model in the middle, no output ceiling — the client receives exactly what celeste computed.

Indexing is explicit: none of these tools auto-reindex. If the caller's workspace has changed and the cached graph is stale, the caller must first call celeste_index with operation="update" (or "rebuild" for a full re-scan). This matches the user's mental model — "index once, serve the graph for many queries" — and avoids the silent-reindex latency spike that plagued the old chat-routed path.

Progress notification plumbing for the MCP server. Tool handlers that need to stream status back to the client (long reindex runs, expensive codegraph queries, etc.) pull a Notifier out of the request context and call it with JSON-RPC method + params.

The transport layer binds a concrete Notifier implementation to the context before dispatching the request — stdio writes notifications as single-line JSON to the same stdout the response will later use; SSE pushes them to the per-connection event stream. Handlers never talk to the transport directly.

Handlers that don't need progress simply don't pull the notifier. The zero-cost path is a nil lookup.

Package server implements a Model Context Protocol (MCP) server that exposes Celeste's capabilities to external clients such as Claude Code, Codex, or any MCP-compatible tool orchestrator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProgressTokenFromContext added in v1.9.0

func ProgressTokenFromContext(ctx context.Context) progressToken

ProgressTokenFromContext returns the client-supplied progress token, or nil if the client didn't request progress.

func RegisterHandlers

func RegisterHandlers(s *Server)

RegisterHandlers registers all MCP tool handlers on the server. Persona tools (celeste / celeste_content / celeste_status) route through a chat LLM and are kept for the "ask Celeste a question" use case. Direct codegraph tools (celeste_index + celeste_code_* family) skip the LLM and serve queries straight from the cached graph — use those for tool-driven workflows that need verbatim results.

func SendProgress added in v1.9.0

func SendProgress(ctx context.Context, message string, percent float64)

SendProgress is a convenience for tool handlers: if a notifier + token are both present, it dispatches a notifications/progress event with the given payload. Otherwise it's a no-op. Callers never need to branch on notifier presence themselves.

func WithNotifier added in v1.9.0

func WithNotifier(ctx context.Context, n Notifier) context.Context

WithNotifier attaches a Notifier to the context so downstream tool handlers can stream progress back to the client.

func WithProgressToken added in v1.9.0

func WithProgressToken(ctx context.Context, token progressToken) context.Context

WithProgressToken attaches the client-supplied progress token (if any) to the context.

Types

type Config

type Config struct {
	// Transport mode: "stdio" or "sse"
	Transport string

	// SSE-specific settings
	Port      int
	BindAddr  string // default "127.0.0.1"
	Remote    bool   // if true, bind to BindAddr (possibly 0.0.0.0)
	CertFile  string // TLS certificate for mTLS
	KeyFile   string // TLS private key for mTLS
	TokenFile string // path to bearer token file (default ~/.celeste/server.token)
	RateLimit int    // requests per minute (default 60)

	// Celeste config for creating LLM clients
	CelesteConfig *config.Config
	Workspace     string
}

Config holds MCP server configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type ContentBlock

type ContentBlock = mcp.ContentBlock

ContentBlock is a content item in a tool call response. Re-exported from the mcp package for handler convenience.

type Notifier added in v1.9.0

type Notifier func(method string, params any) error

Notifier sends a single JSON-RPC notification back to the MCP client. Used by tool handlers for progress updates and interim status.

func NotifierFromContext added in v1.9.0

func NotifierFromContext(ctx context.Context) Notifier

NotifierFromContext returns the Notifier attached to ctx, or nil if none is present. Handlers MUST nil-check the return value.

type Server

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

Server is the MCP server that exposes Celeste tools to external clients.

func New

func New(cfg Config) *Server

New creates a new MCP server with the given configuration.

func (*Server) Close added in v1.9.0

func (s *Server) Close() error

Close releases resources held by the server. Must be called on shutdown — the indexer cache holds SQLite connections that won't flush otherwise. Safe to call multiple times; second and subsequent calls are no-ops.

func (*Server) RegisterTool

func (s *Server) RegisterTool(def mcp.MCPToolDef, handler ToolHandler)

RegisterTool adds a tool definition and its handler to the server.

func (*Server) Serve

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

Serve starts the MCP server using the configured transport. It blocks until the context is cancelled or the server is shut down.

type ToolHandler

type ToolHandler func(ctx context.Context, args map[string]any) ([]mcp.ContentBlock, error)

ToolHandler processes a tool call and returns content blocks.

Jump to

Keyboard shortcuts

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