server

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package server implements the MCP server that exposes ctx context files as resources, tools, and prompts over JSON-RPC 2.0 on stdin/stdout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is an MCP server that exposes ctx context over JSON-RPC 2.0.

It reads JSON-RPC requests from stdin and writes responses to stdout, following the Model Context Protocol specification.

Thread-safety: outMu serialises all writes to out (main loop and poller goroutine). The main loop itself is single-threaded, so request dispatch and session mutations need no additional locking.

func NewServer

func NewServer(contextDir, version string) *Server

NewServer creates a new MCP server for the given context directory.

Parameters:

  • contextDir: path to the .context/ directory
  • version: binary version string for the server info response

Returns:

  • *Server: a configured MCP server ready to serve

func (*Server) Serve

func (s *Server) Serve() error

Serve starts the MCP server, reading from stdin and writing to stdout.

It blocks until stdin is closed or an unrecoverable error occurs. Each line from stdin is expected to be a JSON-RPC 2.0 request.

Returns:

  • error: non-nil if an I/O error prevents continued operation

Directories

Path Synopsis
Package catalog maps context files to MCP resource URIs and builds the immutable resource list returned by the server.
Package catalog maps context files to MCP resource URIs and builds the immutable resource list returned by the server.
def
prompt
Package prompt defines MCP prompt definitions and entry builders.
Package prompt defines MCP prompt definitions and entry builders.
tool
Package tool defines MCP tool definitions and shared property builders.
Package tool defines MCP tool definitions and shared property builders.
Package dispatch routes MCP requests to domain-specific handlers based on method name.
Package dispatch routes MCP requests to domain-specific handlers based on method name.
Package extract converts raw MCP tool arguments into typed Go values.
Package extract converts raw MCP tool arguments into typed Go values.
Package io writes serialized JSON-RPC messages to an io.Writer with mutex-guarded concurrency.
Package io writes serialized JSON-RPC messages to an io.Writer with mutex-guarded concurrency.
Package out builds JSON-RPC response structs for success, error, and tool result payloads.
Package out builds JSON-RPC response structs for success, error, and tool result payloads.
Package parse unmarshals raw JSON bytes into MCP request structs, filtering out notifications.
Package parse unmarshals raw JSON bytes into MCP request structs, filtering out notifications.
Package ping responds to MCP ping requests with an empty success result.
Package ping responds to MCP ping requests with an empty success result.
Package poll watches subscribed resources for file changes and emits update notifications.
Package poll watches subscribed resources for file changes and emits update notifications.
Package resource handles MCP resource requests including list, read, subscribe, and unsubscribe.
Package resource handles MCP resource requests including list, read, subscribe, and unsubscribe.
route
fallback
Package fallback returns method-not-found errors for unrecognized MCP methods.
Package fallback returns method-not-found errors for unrecognized MCP methods.
initialize
Package initialize handles the MCP initialize handshake and advertises server capabilities.
Package initialize handles the MCP initialize handshake and advertises server capabilities.
prompt
Package prompt dispatches MCP prompt list and get requests to the appropriate builders.
Package prompt dispatches MCP prompt list and get requests to the appropriate builders.
tool
Package tool dispatches MCP tool list and call requests to the appropriate handler functions.
Package tool dispatches MCP tool list and call requests to the appropriate handler functions.
Package stat provides session statistics helpers for the MCP server.
Package stat provides session statistics helpers for the MCP server.

Jump to

Keyboard shortcuts

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