mcpserver

package
v0.198.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 26 Imported by: 0 modules, 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 the gofer control plane as a stdio MCP server (plan P8). It reuses the same job.Service / project / agent registries as the HTTP control plane, so the MCP tools never duplicate execution logic — they are a thin, structured-IO wrapper over the existing contracts.

All tool input/output structs use snake_case json tags: the SDK infers the tool input/output JSON schema from these tags, so the MCP schema stays aligned with the HTTP API field names (e.g. project_key, exit_code, result_dir).

This package must NOT import internal/commands (commands wires mcpserver into the `mcp` CLI command, so importing back would create a cycle). It depends only on internal/job, internal/project, internal/agent, internal/store and internal/jobstore (plan grouping views).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(b Backend) *mcp.Server

New builds an MCP server whose gofer_* tools are backed by the given Backend (localBackend for the in-process standalone path, clientBackend for forwarding to a central serve — E28). Handlers own input validation + view projection; the Backend owns the actual backend access. The server is returned unconnected; call Run (or Serve) to start serving over a transport.

func NewLocal

func NewLocal(jobs *job.Service, projects *project.Registry, agents *agent.Registry) *mcp.Server

NewLocal is the compatibility constructor for the in-process (standalone) path: it wires a localBackend over the given registries/job service and returns the MCP server. Equivalent to New(newLocalBackend(...)).

func Serve

func Serve(ctx context.Context, b Backend, scoped string) error

Serve builds the MCP server over the given Backend and runs it over stdio. It blocks until stdin EOF or ctx cancellation. Nothing is written to stdout outside the MCP protocol (stdout is the transport), so callers must not print to stdout either.

func ServeLocal

func ServeLocal(ctx context.Context, jobs *job.Service, projects *project.Registry, agents *agent.Registry, scoped string) error

ServeLocal builds the MCP server over an in-process localBackend and runs it over stdio. Convenience wrapper for the standalone path so callers (commands/ mcp.go) need not reach for newLocalBackend; equivalent to Serve(ctx, newLocalBackend(...)).

Types

type Backend

type Backend interface {
	ListProjects() ([]projectEntry, error)
	ListAgents() ([]agentEntry, error)
	RunJob(req job.JobRequest) (job.JobResult, error)
	GetJob(id string) (job.JobResult, error)
	SetJobTitle(id, title string) (job.JobResult, error)
	TailLog(id, stream string, maxBytes int64) (string, error)
	CancelJob(id string) (job.JobResult, error)
	SayJob(id, message string) (job.JobResult, error)
	EndJob(id string) (job.JobResult, error)
	// RejectJob records this caller's REFUSAL of a job awaiting人工验收 (GATE-01 S3)
	// and returns the rejected job plus, with resume, the continuation it started.
	// There is deliberately NO AcceptJob: an agent (which is what speaks MCP) must
	// never sign off its own work — accepting is a human action (web / CLI / HTTP).
	RejectJob(id, note string, resume bool) (job.ReviewOutcome, error)
	GetInteractions(id string) ([]job.Interaction, error)
	// AnswerInteraction answers a pending interaction (unattributed: stamped as human).
	AnswerInteraction(id, iid, answer string) (job.Interaction, error)
	// PuntInteraction marks a pending interaction as needs_human — the通用 sup's "高危/拿不准,
	// 留给人处理" decision (y5wt). It leaves the interaction pending (a human answers later) but
	// excludes it from the sup demand signal so the reconciler stops re-waking a sup for it.
	PuntInteraction(id, iid string) error
	// ListPendingInteractions lists pending interactions across active jobs (E25
	// supervisor discovery, gofer_list_pending_interactions).
	ListPendingInteractions() ([]job.Interaction, error)
	GetArtifacts(id string) ([]artifactView, error)
	GetResult(id string) (string, error)
	// ListTemplates returns the task-book templates a project can be driven with
	// (SUP-01 P5) — the project's .gofer/templates first, then the server's global
	// <config-dir>/templates. Read-only; the template NAME travels on RunJob's
	// request (job.JobRequest.Template), so there is no write side here.
	ListTemplates(project string) ([]template.Info, error)

	// Plan grouping (plan-orchestration P2). The source shapes differ between
	// local (jobstore.Plan) and client (client.Plan), so backends return the
	// mcpserver view type directly.
	CreatePlan(title, description string, tags ...[]string) (planView, error)
	CreatePlanWithSupervisorSession(title, description, supervisorSessionID string, tags ...[]string) (planView, error)
	// CreatePlanForCurrentSession creates a plan bound to the agent session the MCP
	// server runs under (session id from the env the agent CLI passed down), falling
	// back to an unbound plan; the view's SupervisorNote says what happened.
	CreatePlanForCurrentSession(title, description string, tags []string) (planView, error)
	SetPlanSupervisorSessionID(planID, supervisorSessionID string) (planView, error)
	// SetPlanNotify flips a plan's end-notification switch (gofer-3db4): on|off. With it
	// on, every job the plan dispatches tells the plan's supervisor session that it
	// ended. The plan must exist; an unknown one is an error.
	SetPlanNotify(planID, notify string) (planView, error)
	UpdatePlanTags(planID string, tags *[]string, untag []string) (planView, error)
	ListPlans(tags []string, q string) ([]planView, error)
	AttachJob(planID, jobID string) (planView, error)
	GetPlan(planID string) (planView, error)
	GetPlanHandoff(planID string, version int) (jobstore.PlanHandoff, error)
	SetPlanHandoff(planID, body string, expectedVersion int) (jobstore.PlanHandoff, error)
	AddTodo(planID, title, jobID, note string, patch jobstore.TodoPatch) (todoView, error)
	// UpdateTodo moves a todo along its lifecycle (status ""=keep) and/or
	// updates its note (nil=keep) or APPENDS a line to it (appendNote != ""),
	// and/or applies a dispatch-field patch (PLAN-02 P2). Note and appendNote are
	// mutually exclusive; see jobstore.UpdateTodoStatus and jobstore.AppendTodoNote
	// for the semantics each carries.
	//
	// A write that makes the item dispatchable (status ready, or an assignee) also runs
	// the PLAN-02 dispatcher, exactly like the HTTP/CLI paths — "指派即派发" belongs to the
	// todo write, not to one interface.
	UpdateTodo(todoID, status string, note *string, appendNote string, patch jobstore.TodoPatch) (todoView, error)
	// DispatchTodo explicitly dispatches a todo's assignee (PLAN-02 P2), ignoring the
	// item's status but not its assignee / a live job.
	DispatchTodo(todoID string) (todoDispatchView, error)
	// RunPlan starts a plan's dependency chain (PLAN-03): it releases a pause and a
	// block, queues every pending item whose dependencies are satisfied and that has an
	// assignee, and answers with the plan header as it stands.
	RunPlan(planID string) (planView, error)

	// JOB-09 wakeups (gofer_wakeup_create|list|disable). CreateWakeup registers an
	// event subscription or timer on a job; ListWakeups reads a job's registrations;
	// SetWakeupEnabled flips the switch (enabling a timer re-arms it from now).
	CreateWakeup(jobID string, spec job.WakeupSpec) (wakeupView, error)
	ListWakeups(jobID string) ([]wakeupView, error)
	SetWakeupEnabled(wakeupID string, enabled bool) (wakeupView, error)

	// Decision channel (Part C §C3, gofer_ask_human). Exactly two methods —
	// there is NO active ExpireDecision (plan H1): expiry is lazy inside the
	// store's read/answer paths. AskDecision raises an OPEN decision and
	// returns it with the store-generated id + clamped timeout; GetDecision
	// reads one back (lazy expiry already applied — a past-deadline decision
	// comes back EXPIRED), ok=false when the id is unknown.
	AskDecision(planID, title, question string, options []string, timeoutSec int64) (jobstore.PlanDecision, error)
	GetDecision(id string) (jobstore.PlanDecision, bool, error)

	// MCP-05 阶段 A comment threads (gofer_comment / gofer_list_comments). Comment
	// records one comment on scope (job|plan|todo) + id as the agent of asJob — the
	// author kind is derived from that job, never from the caller's word — and returns
	// the stored row plus whatever its @-mentions dispatched (always empty for an agent
	// author). ListComments reads a thread back, oldest first.
	Comment(scope, id, body, asJob string) (commentView, error)
	ListComments(scope, id string) ([]commentView, error)
	// W1 work items (gofer_work_*) and the read-only session view (gofer_session_*). The
	// work methods return the work package's view types (both ends share them); the
	// session ones return the mcpserver view because local (jobstore) and client
	// (HTTP) source shapes differ.
	ListWorkItems(o jobstore.WorkListOpts) ([]work.ItemView, work.Summary, error)
	GetWorkItem(id string) (work.DetailView, error)
	UpdateWorkItem(id string, p jobstore.WorkItemPatch, rev int64) (work.DetailView, error)
	// AddWorkNote appends a journal note; level is milestone | detail | "" (default).
	AddWorkNote(id, text, level string) error
	ReportWork(id string, in work.ReportInput, sessionID string) (work.DetailView, error)
	// W2a request ledger: ListWorkRequests reads it; RequestWorkReport asks the item's
	// running session(s) to report / write a hand-over through it; SummarizeWork starts a
	// tidy-up. The last two need a running server (the local backend has no session
	// relay or summarizer and refuses).
	ListWorkRequests(id string, activeOnly bool, limit int) ([]jobstore.WorkRequest, error)
	RequestWorkReport(id, sessionID, kind string) ([]work.RequestOutcome, error)
	SummarizeWork(id string) (jobstore.WorkRequest, error)
	// CaptureWork records one capture-box item (gofer_work_capture).
	CaptureWork(in work.CaptureInput) (work.DetailView, error)
	ListSessionViews(o jobstore.ListSessionsOpts) ([]sessionToolView, error)
	GetSessionView(id string) (sessionToolView, error)
	// W2b steward tools. They need a running server (the local backend refuses): the
	// steward's MCP always runs as a client of it.
	SessionTail(id string, bytes int64) (work.SessionTailResult, error)
	ListJobViews(project, status string, limit int) ([]job.JobResult, error)
	SuggestWorkMerge(targetID, sourceID, reason string) (jobstore.WorkMergeSuggestion, bool, error)
	StewardNotesGet(version int) (stewardNotesOutput, error)
	StewardNotesHistory() (stewardNotesOutput, error)
	StewardNotesSet(body string, version int) (stewardNotesOutput, error)
	StewardReviewSummary(text string) error
	// N3 T4: the 「今天」 queue the steward reads and its advice on a card (server only).
	TodayQueue(includeExec bool) (today.Response, error)
	TodayAdvise(in today.AdviceInput) (today.Advice, error)
	// P4 memory hygiene: the server-side doctor findings and a cleanup proposal (server only).
	MemoryFindings(trackerID string, all bool) ([]today.MemoryFinding, error)
	SuggestMemory(in today.MemorySuggestInput) (today.MemorySuggestion, bool, error)
	// gofer-3nxa.2 knowledge candidates: list them, accept one (it becomes a scoped
	// memory) or reject one. The server refuses a decision from a job credential.
	ListMemoryCandidates(f jobstore.MemoryCandidateFilter) ([]jobstore.MemoryCandidate, error)
	AcceptMemoryCandidate(id int64, in job.AcceptMemoryCandidateInput) (job.MemoryCandidateDecision, error)
	RejectMemoryCandidate(id int64) (jobstore.MemoryCandidate, error)
	// X2: SessionAsk delivers a message to a running session; IssueList / IssueGet read the
	// server's tracker mirror (read-only). All three need a running server.
	SessionAsk(sid, text, workID string) (work.AskResult, error)
	// Session topics: SetSessionTopic edits a session's topic / scope (sid "" = the session the
	// MCP process runs in, from its environment); FindSessions finds sessions by topic / scope.
	// Both need a running server.
	SetSessionTopic(sid string, p client.SessionTopicPatch) (client.AgentSession, error)
	FindSessions(o client.SessionFindOpts) ([]client.SessionFound, error)
	IssueList(o client.IssueListOpts) (client.IssueListResp, error)
	IssueGet(id, trackerID string) (client.IssueGetResp, error)
	// The gofer mailbox (plan M3): all of it needs a running server.
	SendMail(to []string, body string, urgent bool) (client.MailSent, error)
	ListMail(o client.MailListOpts) ([]client.Mail, error)
	ReadMail(id int64) (client.Mail, error)
	ReplyMail(id int64, body string, urgent bool) (client.MailSent, error)
	CancelMail(id int64) (client.Mail, error)

	ListScopedMemories(scope, scopeKey, keyword string, tags []string) ([]jobstore.ScopedMemory, error)
	GetScopedMemory(scope, scopeKey, key string) (jobstore.ScopedMemory, error)
	PutScopedMemory(scope, scopeKey, key, content string, tags []string, title string) (jobstore.ScopedMemory, error)
	DeleteScopedMemory(scope, scopeKey, key string) error
	// FlagScopedMemory reports a scoped memory out of date (gofer_memory_flag). There is
	// deliberately no unflag: clearing a flag is the human review (CLI / HTTP).
	FlagScopedMemory(scope, scopeKey, key, reason, jobID string) (jobstore.ScopedMemory, error)
}

Backend abstracts the backend operations behind the 10 gofer_* MCP tools so the handlers can target either an in-process job.Service + registries (localBackend, the original standalone path) or a remote central serve via internal/client (clientBackend, P3). This is the seam introduced by E28: the handlers keep input validation (e.g. tail_log stream defaulting/checking) and view projection (jobView / interactionView / projectEntry …), while the Backend returns domain types (job.JobResult / job.Interaction) or — where the two ends' source shapes differ (projects / agents / artifacts) — the mcpserver view types directly. Signatures mirror design §7.

func NewClientBackend

func NewClientBackend(cli *client.Client) Backend

NewClientBackend wires a Backend that forwards to the central serve at cli.

Jump to

Keyboard shortcuts

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