mcp

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package mcp is 012 mcp: a Model Context Protocol server on one workbook (see docs/agents/mcp.md). Its tools, resources and prompts are a thin layer over internal/headless, the same code 012 get, set and describe run, so agents' changes go through the workbook's one mutation path (Batch) and the same checks as a person's, and are shown by 012 diff. The workbook stands behind a Backend: a file here, and for live mode a session.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Name is what the workbook is called, for titles: its file's name.
	Name() string
	// View runs fn on the workbook as it is, which fn must not change.
	View(ctx context.Context, fn func(*sheet.Workbook) error) error
	// Scratch runs fn on a copy of the workbook that is thrown away.
	Scratch(ctx context.Context, fn func(*sheet.Workbook) error) error
	// Change runs fn on the workbook inside one Batch, labelled label,
	// and returns what it changed. The change is kept unless fn fails or
	// dryRun is set; a failed change leaves the workbook as it was.
	Change(ctx context.Context, label string, dryRun bool, fn func(*sheet.Workbook) error) ([]diff.Change, error)
}

Backend is where the tools' workbook lives. The tools only read it, work on a copy thrown away, or change it through the workbook's one mutation path (Batch), so the file backend here and a live session's (a workbook open on the screen, changed as a participant's operations) can stand behind the same tools.

type Changed

type Changed struct {
	Saved    bool              `json:"saved"`
	Changes  []headless.Change `json:"changes"`
	Warnings []string          `json:"warnings"`
}

Changed is what a write returns: whether it was kept, what changed as 012 diff lists it, and warnings of entries a rule marks invalid.

type FileBackend

type FileBackend struct {
	Path string
	// Prepare, when set, runs on the workbook once opened, before fn:
	// what the server's flags allow (answering JEV functions).
	Prepare func(context.Context, *headless.File) error
	// Save writes a changed workbook; nil is File.Save.
	Save func(*headless.File) error
	// contains filtered or unexported fields
}

FileBackend is a workbook file, opened afresh for every call so edits made meanwhile by others (the screen, git, 012 set) are seen, and saved atomically after each change, as 012 set saves it.

func (*FileBackend) Change

func (b *FileBackend) Change(ctx context.Context, label string, dryRun bool, fn func(*sheet.Workbook) error) ([]diff.Change, error)

func (*FileBackend) Name

func (b *FileBackend) Name() string

Name is the file's name without its folder.

func (*FileBackend) Scratch

func (b *FileBackend) Scratch(ctx context.Context, fn func(*sheet.Workbook) error) error

Scratch is View: every call opens its own copy of the file.

func (*FileBackend) View

func (b *FileBackend) View(ctx context.Context, fn func(*sheet.Workbook) error) error

type Options

type Options struct {
	// Version is 012's, which the server reports.
	Version string
	// ReadOnly leaves out every tool that changes the workbook.
	ReadOnly bool
	// Force lets writes change protected ranges, as 012 set --force.
	Force bool
	// Notebooks, when set, lets run_notebook_cell run cells with nu, as
	// --notebooks does; nil leaves the tool out. MayRun says why a
	// workbook's cells may not run here (trust, the shell setting), and
	// may mark it trusted, as the command line's --trust does.
	Notebooks *headless.NotebookOptions
	MayRun    func(*sheet.Workbook) error
}

Options say what the server may do beyond reading and writing cells.

type Server

type Server struct {
	*sdk.Server
	// contains filtered or unexported fields
}

Server is the MCP server on a backend.

func New

func New(b Backend, o Options) *Server

New makes the server with its tools, resources and prompts.

Jump to

Keyboard shortcuts

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