taskwiring

package
v1.148.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package taskwiring assembles the MCP Tasks extension (#2009) for the platform facade: the `tasks:` configuration section, the capability it advertises, the receiving middleware that turns a declaring client's run_script and export calls into tasks, the tasks/* methods and the caller each is answered for, the runner that executes an export apart from its request, and the task Sources those methods answer from. The facade calls Offered and Install and holds nothing for it; the extension lives here because the facade is at its size budget.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Install

func Install(d Deps) mcp.Middleware

Install assembles the extension where it is offered: it registers the tasks/* methods on the server and the runner on the lifecycle, and returns the receiving middleware, nil where the extension is not offered.

func Offered

func Offered(cfg Config, db *sql.DB) bool

Offered reports whether the extension is offered: enabled, and a database to keep its tasks in.

func Tools

func Tools() map[string]mcptask.Mode

Tools names the calls that become tasks: a run_script run is its own record; an export is executed apart from its request.

Types

type Config

type Config struct {
	Enabled *bool `yaml:"enabled"`
	// RetentionDays is how long an export run as a task is kept, for its
	// caller to read the result; default 7. A run_script task is the run and
	// is kept as long as scripts.run_retention_days keeps the run.
	RetentionDays int `yaml:"retention_days"`
}

Config is the `tasks:` section. A client that declares the extension is answered with a task for run_script and the export tools, and follows the work with tasks/get and tasks/cancel. Enabled by default (nil = enabled) wherever there is a database; enabled: false answers every call directly, as for a client without the extension.

func (Config) IsEnabled

func (c Config) IsEnabled() bool

IsEnabled reports whether the extension is offered, defaulting to true.

func (Config) Retention

func (c Config) Retention() time.Duration

Retention returns how long an export task is kept.

type Deps

type Deps struct {
	DB        *sql.DB
	Config    Config
	Server    *mcp.Server
	Lifecycle Lifecycle
	// Authenticator, Personas and AdminPersona identify the caller of a
	// tasks/* request, which passes none of the tools/call layers that would,
	// the way a completion request is identified.
	Authenticator middleware.Authenticator
	Personas      *persona.Registry
	AdminPersona  string
	// Runs is the script layer's runs as tasks. The script layer is
	// assembled after the server, so it is read when a request arrives.
	Runs func() *scriptlayer.RunTasks
}

Deps is what the extension is assembled from.

type Handle

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

Handle is the assembled extension. A nil Handle offers nothing.

func New

func New(d Deps) *Handle

New assembles the extension, or returns nil where it is not offered.

func (*Handle) Drain

func (h *Handle) Drain(ctx context.Context) error

Drain lets the exports running here finish, within ctx.

func (*Handle) Middleware

func (h *Handle) Middleware() mcp.Middleware

Middleware is the receiving middleware, or nil where the extension is off.

func (*Handle) Register

func (h *Handle) Register(server *mcp.Server) error

Register adds the tasks/* methods to server.

func (*Handle) Start

func (h *Handle) Start(context.Context) error

Start starts the export runner's heartbeat.

func (*Handle) Stop

func (h *Handle) Stop(ctx context.Context) error

Stop ends what is still running, recording that its server shut down.

type Lifecycle

type Lifecycle interface {
	OnComponent(start, stop func(context.Context) error)
	OnDrain(drain func(context.Context) error)
}

Lifecycle is where the export runner's start, stop and shutdown drain are registered.

Jump to

Keyboard shortcuts

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