Documentation
¶
Overview ¶
Package mcp is 012 mcp: a Model Context Protocol server on the workbooks in the folders open to it (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. Each workbook stands behind a Backend: a file here, and for live mode a session.
Index ¶
- func NewRoots(dirs []string) ([]confine.Root, error)
- type Backend
- type Changed
- type FileBackend
- func (b *FileBackend) Change(ctx context.Context, label string, dryRun bool, fn func(*sheet.Workbook) error) ([]diff.Change, error)
- func (b *FileBackend) Name() string
- func (b *FileBackend) Scratch(ctx context.Context, fn func(*sheet.Workbook) error) error
- func (b *FileBackend) View(ctx context.Context, fn func(*sheet.Workbook) error) error
- type ImportBackend
- func (b *ImportBackend) Change(context.Context, string, bool, func(*sheet.Workbook) error) ([]diff.Change, error)
- func (b *ImportBackend) Name() string
- func (b *ImportBackend) Scratch(ctx context.Context, fn func(*sheet.Workbook) error) error
- func (b *ImportBackend) View(ctx context.Context, fn func(*sheet.Workbook) error) error
- type Options
- type RangeRead
- type Server
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) Name ¶
func (b *FileBackend) Name() string
Name is the file's name without its folder.
type ImportBackend ¶ added in v0.5.0
ImportBackend is a file in a format 012 imports (CSV, XLSX, SQLite and the rest), read afresh for every call as the app opens it. It is read only: 012 writes a workbook as a .012 file, which create_workbook makes from it.
func (*ImportBackend) Name ¶ added in v0.5.0
func (b *ImportBackend) Name() string
Name is the file's name without its folder or extension.
type Options ¶
type Options struct {
// Version is 012's, which the server reports.
Version string
// ReadOnly leaves out every tool that changes a 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(path string, w *sheet.Workbook) error
// Roots are the folders workbooks may be in when the client shares
// none of its own (NewRoots makes them).
Roots []confine.Root
// Default, an absolute path, is the workbook of tools called without
// a path, open wherever it is; "" makes the path required.
Default string
// Prepare, when set, runs on every workbook once opened (answering
// JEV functions); Save writes a changed one, nil being File.Save.
Prepare func(context.Context, *headless.File) error
Save func(*headless.File) error
}
Options say where the server's workbooks are and what it may do beyond reading and writing cells.
type RangeRead ¶ added in v0.5.0
RangeRead is headless.Range under another name, which a struct embedding it can have beside its own field Range.
type View ¶ added in v0.5.0
type View struct {
Title string `json:"title"`
Name string `json:"name,omitempty"`
Where string `json:"where"`
HTML string `json:"html"`
}
View is what a view draws of a result, in its _meta under viewKey: the workbook's name, what the name box shows before a cell is pointed at (a chart's data), the range or the chart's kind, sheet and data, and the grid or chart as the HTML export draws it.