mcpserver

package
v0.0.0-...-ea53456 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcpserver exposes the Section 19.2 tool surface of codectx over the Model Context Protocol, using the pinned official Go SDK for every wire concern.

Import rule — checkable by a reviewer

This package imports exactly:

  • the standard library;
  • github.com/modelcontextprotocol/go-sdk/mcp — and no other SDK package. In particular never auth, oauthex, sse, streamable or jsonrpc: Section 19.3 scopes V1 to tools over stdio, so "no HTTP listener, authentication server, sampling loop or remote transport" is enforced as an import rule rather than promised in prose, and golang-jwt/oauth2 stay out of the build graph;
  • github.com/google/jsonschema-go/jsonschema — for the ONE input-schema helper in registry.go only. It is the schema library the SDK itself infers with, not a second protocol implementation;
  • internal/model — the request, response and error contracts;
  • internal/config — the Section 20 bounds;
  • internal/app — ONLY for the four narrow facade interfaces and their model-typed signatures. app.OpenWorkspace belongs to internal/cli/mcp.go, not here.

internal/app must not import this package, and this package must not import internal/cli: the CLI envelope and exit codes are a different adapter's shape, and there is no second error-code table.

Channel discipline

stdout is reserved for SDK framing. There is no fmt.Print, no banner and no log line on stdout anywhere in this package; every diagnostic goes to the stderr *slog.Logger carried on handlers. A single stray stdout write corrupts the stdio session.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Index   app.IndexService
	Explore app.ExploreService
	Context app.ContextService

	// Config supplies the Section 20 bounds limitMiddleware and readSource
	// enforce. A zero value is not accepted: see New.
	Config config.Config
	// Build supplies the schema version every result envelope carries.
	Build model.BuildInfo
	// Spans registers a function to be called with every stage of an
	// indexing run as it finishes, and is how codectx_refresh_index reports
	// progress and logs stages while a run is going. It takes the rows in
	// their model shape rather than a recorder of its own, so what a client
	// is told a stage cost is the same row codectx_index_status returns and
	// the CLI prints -- there is no second accounting here.
	//
	// It is called ONCE, while the server is built. Nil is a server that
	// reports no progress, which is what a composition that records nothing
	// should be: the tools are unaffected.
	Spans func(func(model.StageRecord))
	// IndexRun answers with the identifier of the indexing run this process
	// is recording at this moment, and false when it is recording none. It is
	// what lets a call that is following one run tell that run's stages from
	// the stages of the per-process overlay run a language server's start
	// opens, which is recorded concurrently with an indexing run in this same
	// process: without it, a server start would advance the progress bar of a
	// run it has nothing to do with.
	//
	// It is required whenever Spans is set, and refused otherwise: a span
	// source with no way to name its indexing run could only report every
	// run's stages as this call's progress.
	IndexRun func() (string, bool)
	// Logger MUST write to stderr. stdout is the SDK's framing channel; a
	// single byte of ours on it corrupts the session. Nil means "build the
	// stderr logger yourself".
	Logger *slog.Logger
}

Options is everything mcpserver.New needs. The three facade fields are the NARROW INTERFACES of internal/app, never *app.Services: *Services is a concrete struct and cannot be faked, and it satisfies all three, so internal/cli/mcp.go hands ws.Services() to each field while tests hand an in-package fake. There is no Diagnose field: Section 19.2 registers no doctor tool, so the server would hold a service no handler could call.

type Server

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

Server is the codectx MCP server: the SDK server with the 23 Section 19.2 tools registered and the Section 19.3 bounds installed as receiving middleware.

It owns no wire code. The SDK owns framing, dispatch, schema validation and tool-error packing (Section 19.1); writing an adapter beside it would be the duplicate implementation Section 30.1 forbids.

func New

func New(opts Options) (*Server, error)

New builds the server: metadata, options, the bounds middleware, then the 23 tools. It registers no prompts, resources or completion handlers — Section 19.3 scopes V1 to tools — and sets no KeepAlive, which the SDK documents as unavailable for protocol versions >= 2026-07-28.

func (*Server) Serve

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

Serve runs the server over stdio until ctx is canceled or the client disconnects.

A canceled context is a CLEAN shutdown, not a failure: the SDK's Run returns ctx.Err() in that case, and turning it into a non-zero exit would make every ordinary SIGINT look like a crash. Only cancellation is treated that way — a serve context that expired is a truncated session, not a shutdown, and every other error is the caller's to report.

Jump to

Keyboard shortcuts

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