mcpserver

package
v0.9.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 17 Imported by: 1 module, 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 a Runefile's non-private tasks to AI agents and IDEs as Model Context Protocol tools. Tools are run through the SAME engine the CLI uses (FR-026); secrets never appear in any tool name, description, schema, or result (FR-029, Principle VII). It is a public package so it can be embedded.

Index

Constants

View Source
const (
	DefaultOutputLimit = 64 << 10
	MinOutputLimit     = 1 << 10
	MaxOutputLimit     = 1 << 30
)

Bounds of the output limit: the bytes of each of stdout and stderr that a tool result carries, truncation marker included.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change added in v0.9.0

type Change struct{ Added, Removed, Changed int }

Change counts what a Replace did to the tool list.

type Engine

type Engine interface {
	// Tasks returns the exposable (non-private) tasks with their metadata.
	Tasks() []TaskInfo
	// Call runs a task by display name with string arguments, capturing output.
	Call(ctx context.Context, name string, args map[string]string) (Result, error)
}

Engine is the host the MCP server runs tasks against. The CLI implements it.

type HTTPConfig

type HTTPConfig struct {
	Addr  string // e.g. 127.0.0.1:7777
	Token string // required bearer token
	// Warn, when set, is called once with a one-line message when the
	// transport has bound an address that is not loopback: without TLS the
	// bearer token then crosses the network in cleartext. It is called before
	// any request is served, on the goroutine that started the transport.
	Warn func(message string)
}

HTTPConfig configures the opt-in Streamable HTTP transport.

type ListEngine added in v0.7.0

type ListEngine interface {
	CallLists(ctx context.Context, name string, args map[string]string, lists map[string][]string) (Result, error)
}

ListEngine is an optional Engine extension. When the engine implements it, array arguments reach it with their elements intact (spec 030); a plain string for a variadic is one element, or none when empty. args still holds every value, arrays joined by single spaces, exactly as Call receives it.

type Options

type Options struct {
	// AllowDestructive names the destructive ([confirm]) tasks that may be
	// called or run. A call is refused before the engine runs when the task
	// itself, or any task in its DestructiveReach, is destructive and not named
	// here. There is no value that permits all of them. The Engine must still
	// approve the confirmation of exactly these tasks, wherever a run reaches
	// them; the rune CLI adapter does.
	AllowDestructive []string
	// AllowDestructiveFlag is the command-line flag that sets AllowDestructive,
	// such as "--allow-destructive". When set, a destructive refusal tells the
	// caller to add the task to it. Leave it empty where no grant is possible,
	// such as the endpoint of a rune agent task: the refusal then offers no
	// remedy.
	AllowDestructiveFlag string
	// AllowList, when non-empty, exposes only these tasks as tools. A task
	// outside it is not listed and cannot be called. It never adds a task the
	// Engine does not offer.
	AllowList []string
	// DenyList names tasks that are not exposed as tools, whether or not
	// AllowList names them.
	DenyList []string
	// OutputLimit caps the bytes of Result.Stdout and of Result.Stderr that a
	// tool result carries, marker included. A result carries each stream
	// twice, in its text and in its structured content (spec 044), and the
	// cap holds for each. Zero or less means DefaultOutputLimit. Other values
	// are raised to MinOutputLimit or lowered to MaxOutputLimit.
	OutputLimit int
	// Version reported to clients.
	Version string
	// Instructions, when non-empty, is delivered to clients as the MCP
	// server instructions in the initialize result. Rune uses it for the
	// [context] hook's project-health text (spec 021 FR-002). It must
	// already be masked; this package never processes it.
	Instructions string
	// Reloadable says the server's tasks may be replaced with Replace. The
	// server then states the tools capability with listChanged from the
	// start, even with no tool.
	Reloadable bool
}

Options configures authorization for the server.

type OutputBuffer added in v0.9.0

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

OutputBuffer is an io.Writer that keeps the beginning and the end of what is written to it and never holds more than its limit in bytes. It is safe for concurrent use. The zero value has DefaultOutputLimit.

func NewOutputBuffer added in v0.9.0

func NewOutputBuffer(limit int) *OutputBuffer

NewOutputBuffer returns a buffer with the given limit, adjusted as Options.OutputLimit is.

func (*OutputBuffer) String added in v0.9.0

func (b *OutputBuffer) String() string

String returns everything written when it is within the limit. Otherwise it returns the beginning, a "[truncated N bytes]" line, and the end, at most limit bytes in all.

func (*OutputBuffer) Write added in v0.9.0

func (b *OutputBuffer) Write(p []byte) (int, error)

Write keeps what fits and drops the rest. It always returns len(p), nil.

type ParamInfo

type ParamInfo struct {
	Name     string
	Required bool
	Variadic bool
	// Kind is the declared constraint kind: "", "string", "number", "boolean",
	// "path", or "enum". "" means unannotated and produces the pre-023 schema
	// byte-for-byte (spec 023).
	Kind string
	// Enum is the closed value list when Kind is "enum", in source order.
	Enum []string
	// Description is the author's [param-doc] text for this parameter.
	Description string
}

ParamInfo describes a task parameter for input-schema derivation.

type Result

type Result struct {
	// Stdout and Stderr must already be masked by the engine: this package
	// only caps them, and every tool's output schema tells clients they hold
	// no secret (spec 044).
	Stdout   string
	Stderr   string
	ExitCode int
	// FixSuggestion is the captured output of the task's || failure hooks
	// (spec 022). Like Options.Instructions, it must already be masked and
	// size-capped by the engine; this package never processes it, only
	// renders it as a delimited section after the exit marker and returns it
	// as the fixSuggestion field of the structured content (spec 044). Empty
	// means no section and no field.
	FixSuggestion string
}

Result is the outcome of running a task on behalf of an agent.

type Server

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

Server wraps an mcp.Server built from a Runefile's tasks.

func New

func New(engine Engine, opts Options) *Server

New builds an MCP server exposing engine's tasks as tools, except those opts.AllowList and opts.DenyList hide.

func (*Server) Exposure added in v0.9.0

func (s *Server) Exposure() (exposed, exposable int)

Exposure reports how many tasks are exposed as tools and how many the Engine offered.

func (*Server) MCP

func (s *Server) MCP() *mcp.Server

MCP returns the underlying mcp.Server (for transports/tests).

func (*Server) Replace added in v0.9.0

func (s *Server) Replace(engine Engine, outputLimit int) Change

Replace makes engine the server's engine and its tasks the server's tools, under the Options given to New. outputLimit is as Options.OutputLimit. Calls in progress finish on the engine they started with. Connected clients are notified when the tool list differs. Safe for concurrent use.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(ctx context.Context, cfg HTTPConfig) error

ServeHTTP starts the Streamable HTTP transport. It binds the configured address (localhost by default) and requires a bearer token before any list/call (SC-010). An address that is not loopback is bound as asked, not refused: the transport has no TLS, so the token then crosses the network in cleartext, and cfg.Warn is told.

func (*Server) ServeStdio

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

ServeStdio runs the MCP server over stdio (always available, auth inherited from the local process/session).

func (*Server) SetInstructions added in v0.9.0

func (s *Server) SetInstructions(text string)

SetInstructions sets the instructions that sessions started from now on receive. It must already be masked, as Options.Instructions.

func (*Server) StartHTTP

func (s *Server) StartHTTP(cfg HTTPConfig) (addr string, stop func(), err error)

StartHTTP binds and serves the HTTP transport in a background goroutine, returning the bound address and a stop function. Used by the (agent) executor to expose project tasks to the agent it drives.

type TaskInfo

type TaskInfo struct {
	Name   string // display name (namespaced mod::task becomes mod__task as a tool)
	Doc    string
	Params []ParamInfo
	// Destructive marks the task itself destructive. A call is refused unless
	// the task is granted, and the tool advertises DestructiveHint.
	Destructive bool
	// DestructiveReach names the destructive tasks a run of this task can
	// reach through its dependencies and hooks: each once, not the task
	// itself, in the order a run first reaches them. A call is refused unless
	// every one is granted, and a non-empty list sets DestructiveHint. Nil
	// leaves the engine alone to decline such a task when a run reaches it.
	DestructiveReach []string
	// Network says the task, or anything a run of it can reach, uses the
	// network. The tool advertises OpenWorldHint.
	Network bool
	// ReadOnly says the task declares itself read-only. The tool advertises
	// ReadOnlyHint. A descriptor that leaves it false makes no read-only claim.
	ReadOnly bool
	// Returns is the task's [returns] outcome description (spec 023 US3),
	// composed into the tool description as a "Returns:" trailer so agents can
	// verify results against it. Like Doc and Instructions, it must already be
	// masked and size-capped by the engine; this package never processes it.
	Returns string
}

TaskInfo is the agent-facing view of a task. Private tasks are never included. Params lists the only argument names a call may use: a call naming any other is refused before the engine runs (spec 032).

Jump to

Keyboard shortcuts

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