github.com/rotari-dev/rotari/internal/mcp

Overview

package mcp // import "github.com/rotari-dev/rotari/internal/mcp"

Package mcp exposes rotari state through the Model Context Protocol.

Functions

func NewServer(masterDir string, options Options) *mcpsdk.Server
    NewServer creates an MCP server for the runs and basedirs registered under
    masterDir. options supplies what its tools that change state need.

Types

type ApplyImportInput struct {
	ImportInput
	IfRevision string `json:"if_revision" jsonschema:"revision from rotari_preview_import; the import applies only if the project is still at it"`
}

type ApplyResetInput struct {
	ResetInput
	IfRevision         string `json:"if_revision" jsonschema:"revision from rotari_preview_reset; the reset applies only if the project is still at it"`
	RecoverInterrupted *bool  `json:"recover_interrupted,omitempty" jsonschema:"Deprecated and rejected; use rotari_preview_unlock and rotari_unlock to recover an interrupted run"`
}

type ApplyUnlockInput struct {
	UnlockInput
	IfRevision string `json:"if_revision" jsonschema:"revision from rotari_preview_unlock; the unlock applies only if the project and execution evidence are still at it. Confirm first that the coordinator and all managed executions have stopped"`
}

type CheckProjectInput struct {
	BaseDirRef string `json:"basedir_ref" jsonschema:"basedir_ref of the project, from rotari_list_projects"`
	Project    string `json:"project" jsonschema:"project name"`
}

type CheckProjectOutput struct {
	BaseDirRef string `json:"basedir_ref"`
	Project    string `json:"project"`
	State      string `json:"state" jsonschema:"ready, empty, running, locked (running on another host or in another PID namespace), or interrupted"`
	Runnable   bool   `json:"runnable"`
	Queued     *int   `json:"queued" jsonschema:"queued jobs; null when the queue of an active or interrupted project cannot be read"`
	Lock       string `json:"lock"`
	RunID      string `json:"run_id,omitempty"`
	Revision   string `json:"revision"`
}

type CompareRunsInput struct {
	RunID         string `json:"run_id" jsonschema:"exact ID of the newer run"`
	PreviousRunID string `json:"previous_run_id,omitempty" jsonschema:"exact ID of the older run of the same project; defaults to the run that started just before run_id"`
	AllJobs       bool   `json:"all_jobs,omitempty" jsonschema:"list every job; by default jobs whose result and definition did not change are only counted in hidden_unchanged, and beyond 20 listed jobs those whose only change is their definition are counted in hidden_changed"`
}

type CompareRunsOutput struct {
	BaseDirRef string            `json:"basedir_ref"`
	Project    string            `json:"project"`
	Comparison runlineage.Result `json:"comparison"`
	// HiddenUnchanged counts the unchanged jobs left out of Comparison.Jobs.
	HiddenUnchanged int `json:"hidden_unchanged,omitempty"`
	// HiddenChanged counts the jobs left out beyond the limit, whose only
	// change is their definition.
	HiddenChanged int `json:"hidden_changed,omitempty"`
}

type ControlJobsInput struct {
	RunID  string   `json:"run_id" jsonschema:"exact ID of the running run; the operation fails if it is no longer running"`
	JobIDs []string `json:"job_ids,omitempty" jsonschema:"jobs from rotari_preview_job_control; without them, cancel stops the whole run and suspend or resume every running job"`
}

type ControlJobsOutput struct {
	Project string `json:"project"`
	RunID   string `json:"run_id"`
	Message string `json:"message"`
}

type ExportRunInput struct {
	RunID  string `json:"run_id" jsonschema:"exact run ID"`
	Format string `json:"format,omitempty" jsonschema:"manifest format: yaml (default), json, or toml"`
}

type ExportRunOutput struct {
	BaseDirRef string `json:"basedir_ref"`
	Project    string `json:"project"`
	Format     string `json:"format"`
	// Manifest is the run as a workflow manifest, with environment values,
	// executor options, and paths redacted.
	Manifest string `json:"manifest"`
}

type GetJobInfoInput struct {
	RunID string `json:"run_id" jsonschema:"exact run ID containing the job"`
	JobID string `json:"job_id" jsonschema:"exact job ID to inspect"`
}

type GetJobInfoOutput struct {
	Project string `json:"project"`
	RunID   string `json:"run_id"`
	JobID   string `json:"job_id"`
	Report  string `json:"report"`
}

type ImportInput struct {
	BaseDirRef string `json:"basedir_ref" jsonschema:"basedir_ref of the destination state directory, from rotari_list_projects"`
	Project    string `json:"project" jsonschema:"destination project; created if it does not exist"`
	Manifest   string `json:"manifest" jsonschema:"workflow manifest text, as rotari export writes it"`
	Format     string `json:"format,omitempty" jsonschema:"manifest format: yaml (default), json, or toml"`
	Overwrite  bool   `json:"overwrite,omitempty" jsonschema:"replace a queue that already has jobs"`
	Detail     bool   `json:"detail,omitempty" jsonschema:"also return the full plan, with each job's command and each task's source attempt"`
}

type ImportOutput struct {
	workflowstate.PlanSummary
	Plan *workflowstate.Plan `json:"plan,omitempty"`
}
    ImportOutput is an import plan's summary and, when asked for, the plan.

type JobControlInput struct {
	RunID     string   `json:"run_id" jsonschema:"exact ID of the running run"`
	Operation string   `json:"operation" jsonschema:"cancel, suspend, or resume"`
	JobNames  []string `json:"job_names,omitempty" jsonschema:"only the unfinished jobs with these names; an array's or matrix's name selects its members. By default every job the operation reaches"`
}

type JobControlPreview struct {
	Project   string   `json:"project"`
	RunID     string   `json:"run_id"`
	Operation string   `json:"operation"`
	JobIDs    []string `json:"job_ids" jsonschema:"the unfinished jobs the operation reaches: running and pending ones for cancel, running ones for suspend and resume"`
}

type ListProjectsInput struct{}

type ListProjectsOutput struct {
	Projects []ProjectOverview `json:"projects"`
	// Unreadable lists registered basedirs whose projects could not be read.
	Unreadable []UnreadableBaseDir `json:"unreadable,omitempty"`
}

type Options struct {
	// NewJobID returns a fresh job ID for an imported queue.
	NewJobID func() string
	// StartRun starts a supervisor for paths' project and sends it request,
	// returning its response. Without it, runs cannot be started.
	StartRun func(paths state.ProjectPaths, request server.Request) (server.Response, error)
	// Actor labels the runs this server starts (ROTARI_ACTOR); empty leaves
	// them unlabelled.
	Actor string
}
    Options supplies what the tools that change state need from the rotari
    process that serves them.

type PlannedJob struct {
	ID   string `json:"id"`
	Name string `json:"name,omitempty"`
	// DependsOnRerun names the dependency that executes, for a job the
	// selection left out but that executes because of it.
	DependsOnRerun string `json:"depends_on_rerun,omitempty" jsonschema:"for a job that executes only because a job it depends on executes: that dependency"`
}

type ProjectOverview struct {
	BaseDirRef  string `json:"basedir_ref" jsonschema:"path-free reference to the project's state directory"`
	BaseDirName string `json:"basedir_name" jsonschema:"last element of the state directory's path"`
	Project     string `json:"project"`
	State       string `json:"state" jsonschema:"idle, running, or interrupted"`
	Queued      int    `json:"queued"`
	Runs        int    `json:"runs"`
	LastRunID   string `json:"last_run_id,omitempty"`
	LastStatus  string `json:"last_run_status,omitempty"`
	LastJobs    int    `json:"last_run_jobs,omitempty"`
	LastFailed  int    `json:"last_run_failed,omitempty"`
}

type ResetInput struct {
	BaseDirRef string `json:"basedir_ref" jsonschema:"basedir_ref of the project, from rotari_list_projects"`
	Project    string `json:"project" jsonschema:"project name"`
}

type ResetOutput struct {
	Project  string `json:"project"`
	Cleared  int    `json:"cleared" jsonschema:"queued jobs the reset removes"`
	Revision string `json:"revision" jsonschema:"for a preview, the revision to pass to rotari_reset; after a reset, the new revision"`
}

type RunInput struct {
	BaseDirRef string `json:"basedir_ref" jsonschema:"basedir_ref of the project, from rotari_list_projects"`
	Project    string `json:"project" jsonschema:"project name"`
	RunID      string `json:"run_id,omitempty" jsonschema:"settled source run ID, or latest; build the new run from it without changing the next queue"`
	Retry      bool   `json:"retry,omitempty" jsonschema:"run only failed and unfinished jobs and carry other results, as rotari retry does: use a non-empty next queue as-is, or build a run snapshot from the last run when the queue is empty"`
}

type RunPreviewOutput struct {
	Project           string       `json:"project"`
	Execute           []PlannedJob `json:"execute" jsonschema:"jobs the run would execute"`
	Jobs              int          `json:"jobs" jsonschema:"jobs in the run snapshot"`
	Carried           int          `json:"carried" jsonschema:"results the run would carry forward instead of executing"`
	SourceRun         string       `json:"source_run,omitempty" jsonschema:"saved run whose results the selection references"`
	OmittedSourceJobs []string     `json:"omitted_source_jobs,omitempty" jsonschema:"failed or unfinished jobs in the latest run not represented in a non-empty queue"`
	Revision          string       `json:"revision" jsonschema:"revision to pass to rotari_start_run"`
}

type RunSummaryInput struct {
	RunID   string `json:"run_id" jsonschema:"exact run ID"`
	AllJobs bool   `json:"all_jobs,omitempty" jsonschema:"list every job of each failure group; by default the first 10, with the rest counted in jobs_omitted"`
}

type RunSummaryOutput struct {
	BaseDirRef string                `json:"basedir_ref"`
	Project    string                `json:"project"`
	State      project.RunPhase      `json:"state" jsonschema:"running, interrupted (its supervisor stopped while it ran), finished, or ended (stopped without a summary); counts change only while running"`
	Summary    runlineage.RunSummary `json:"summary"`
}

type StartRunInput struct {
	RunInput
	IfRevision string `json:"if_revision" jsonschema:"revision from rotari_preview_run; the run starts only if the project is still at it"`
	RunName    string `json:"run_name,omitempty" jsonschema:"label for the run"`
	Note       string `json:"note,omitempty" jsonschema:"why the run is made, recorded with it and shown by rotari show and lineage"`
}

type StartRunOutput struct {
	Project           string   `json:"project"`
	RunID             string   `json:"run_id"`
	SourceRun         string   `json:"source_run,omitempty"`
	OmittedSourceJobs []string `json:"omitted_source_jobs,omitempty"`
}

type UnlockInput struct {
	BaseDirRef    string `json:"basedir_ref" jsonschema:"basedir_ref of the project, from rotari_list_projects"`
	Project       string `json:"project" jsonschema:"project name"`
	RunID         string `json:"run_id,omitempty" jsonschema:"the interrupted run to recover; by default the one the project's lock or metadata names"`
	AssumeStopped bool   `json:"assume_stopped,omitempty" jsonschema:"explicit attestation that unverifiable coordinator and managed executions stopped; required for unknown execution evidence; never overrides verified live ownership or execution"`
}

type UnlockOutput struct {
	ExecutionChecked bool                          `json:"execution_checked" jsonschema:"true only for a nonempty inventory whose executions all have active/stopped probe evidence within their stated scope; true does not imply stopped or recovery allowed; unknown evidence remains false"`
	Project          string                        `json:"project"`
	InterruptedRunID string                        `json:"interrupted_run_id,omitempty" jsonschema:"the interrupted run the unlock recovers; empty when the project has none and nothing changes"`
	InterruptedRun   string                        `json:"interrupted_run,omitempty" jsonschema:"what the interrupted run's jobs last reported"`
	JobsMayBeRunning bool                          `json:"jobs_may_be_running,omitempty" jsonschema:"some jobs of the interrupted run are active or unknown and may still be running; confirm they stopped before recovering"`
	Revision         string                        `json:"revision" jsonschema:"for a preview, the revision to pass to rotari_unlock; after an unlock, the new revision"`
	Coordinator      project.CoordinatorAssessment `json:"coordinator"`
	Allowed          bool                          `json:"allowed"`
	Applied          bool                          `json:"applied"`
	RefusalCode      string                        `json:"refusal_code,omitempty"`
	AssumeStopped    bool                          `json:"assume_stopped"`
	Action           string                        `json:"action,omitempty" jsonschema:"finalize a complete recorded run or release it to collecting without synthesizing results"`
	Repair           project.RepairAssessment      `json:"repair"`
}

type UnreadableBaseDir struct {
	BaseDirRef  string `json:"basedir_ref"`
	BaseDirName string `json:"basedir_name"`
	Error       string `json:"error"`
}

type WaitRunInput struct {
	RunID          string `json:"run_id" jsonschema:"exact run ID, such as rotari_start_run returns"`
	TimeoutSeconds int    `json:"timeout_seconds,omitempty" jsonschema:"how long to wait, 1 to 300 seconds; default 30. Call again to keep waiting."`
	UntilFailure   bool   `json:"until_failure,omitempty" jsonschema:"also return as soon as a job has failed with no retry left, as rotari wait --until-failure does"`
	AllJobs        bool   `json:"all_jobs,omitempty" jsonschema:"list every job of each failure group, as rotari_run_summary does with all_jobs"`
}

type WaitRunOutput struct {
	RunSummaryOutput
	Reason string `json:"reason" jsonschema:"why the wait returned: settled (the run is no longer running), failure (with until_failure, a job failed while the run goes on), or timeout (still running)"`
}