mcpserver

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 13 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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
}

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, narrows callable tasks to these names.
	AllowList []string
	// 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
}

Options configures authorization for the server.

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   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. Empty means
	// no section is rendered.
	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 non-private tasks as tools.

func (*Server) MCP

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

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

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), requires a bearer token before any list/call (SC-010), and refuses a non-localhost bind unless the address is explicit.

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) 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