Documentation
¶
Overview ¶
Package tools is the tool framework: Spec/Action/Registry, schema generation, help, version gating and the Call context (DESIGN.md sections 2 and 4).
Index ¶
- Constants
- Variables
- func BuildInputSchema(s Spec, allowed []Action) (*jsonschema.Schema, error)
- func CheckMinVersion(tool, action string, declared int, v forgejo.Version) string
- func HelpText(s Spec, allowed []Action, action string) string
- func HostOf(raw string) string
- func Instructions(in InstructionsInfo) string
- func MinMajorFor(tool, action string, declared int) int
- func ResolveToolsets(spec string) (map[string]bool, error)
- type Action
- type ActionOpt
- func Endpoints(eps ...string) ActionOpt
- func Hint500(s string) ActionOpt
- func MinMajor(n int) ActionOpt
- func ModeFor(f func(in any) Mode) ActionOpt
- func Needs(s string) ActionOpt
- func NoRepo() ActionOpt
- func Params(names ...string) ActionOpt
- func Required(names ...string) ActionOpt
- func Summary(s string) ActionOpt
- type Call
- type Env
- type InstructionsInfo
- type Memo
- type Mode
- type Registry
- func (r *Registry) Add(s Spec)
- func (r *Registry) Build(cfg *config.Config) error
- func (r *Registry) CoveredBy(endpoint string) string
- func (r *Registry) DeniedEndpoints() map[string]string
- func (r *Registry) Enabled() []Spec
- func (r *Registry) EnabledToolsets() map[string]bool
- func (r *Registry) Install(srv *mcp.Server, env *Env) error
- func (r *Registry) SideEffectGets() []string
- func (r *Registry) Specs() []Spec
- type Result
- type Spec
Constants ¶
const ( // BudgetTotalBytes caps the tools/list JSON of all non-admin toolsets. BudgetTotalBytes = 75000 // BudgetToolBytes caps the schema JSON of one tool. BudgetToolBytes = 6000 // BudgetDescriptionChars caps Spec.Description. BudgetDescriptionChars = 160 )
Schema-size budget (TestSchemaBudget). Frozen by WP4 after measuring the real tools/list JSON (name + description + inputSchema + annotations) of stub param structs with about 45 properties and action-prefixed descriptions (see TestMeasureStubSchemas):
pr (11 actions) 4.1-4.4 KB issue (18 actions) 4.5-5.0 KB repo (20 actions) 4.9-5.5 KB run (12 actions) 4.3-4.6 KB
(lower figure: 8 params per action, upper: 12). The widest tool therefore needs about 5.5 KB, so 6000 bytes per tool holds with roughly 8% headroom. Measured on the finished server (docs/VERIFIED.md): the 29 default tools are 51,804 bytes of tools/list JSON (about 13k tokens), all 30 tools are 55,529 bytes, and the widest tool (repo) is 4,259 bytes. The limits below keep headroom above those figures; rarely used params belong to forgejo_api instead.
Variables ¶
var Toolsets = []string{
"meta", "repos", "pulls", "issues", "actions", "runners", "settings", "users", "packages", "admin",
}
Toolsets lists every toolset name (a tool belongs to exactly one). "meta" is always on and cannot be disabled; "admin" is off by default.
Functions ¶
func BuildInputSchema ¶
func BuildInputSchema(s Spec, allowed []Action) (*jsonschema.Schema, error)
BuildInputSchema builds the tool input schema (section 2): infer with jsonschema.For from Spec.Params, replace properties.action with {type:string, enum:[allowed + "help"]}, require only `action`, set additionalProperties:false and prefix every property description with the `[actions]` that read it (`*` marks required).
Single tools have no `action` property and no `help`; their required list is the one of their only action and descriptions carry no prefix.
func CheckMinVersion ¶
CheckMinVersion returns the error text of section 5.4 (`<tool>.<action> needs Forgejo >= N (server is X)`) or "" when satisfied.
func HelpText ¶
HelpText renders the implicit `help` action: the action table of the tool (`name [R|W|D] params(required marked *) - summary`) or, when action is non-empty, the full parameter list of that one action. Generated from Action.Params/Required/Summary, never hand-written twice.
func HostOf ¶
HostOf returns the host[:port] of an instance URL (the whole string when it does not parse).
func Instructions ¶
func Instructions(in InstructionsInfo) string
Instructions renders the <= 700 character `instructions` text of section 4.1. Sentences about tools in hidden toolsets are omitted.
func MinMajorFor ¶
MinMajorFor returns the effective minimum major for tool.action: the larger of the table value and the value the Action itself declares.
Types ¶
type Action ¶
type Action struct {
Name string
Mode Mode
Summary string // one line, used by `help`
Params []string // json names of the params this action reads
Required []string // json names; "repo" is added automatically when Spec.RepoScoped and NoRepo is false
NoRepo bool
Endpoints []string // "GET /repos/{owner}/{repo}/pulls" (coverage test + forgejo_endpoints "covered_by")
MinMajor int // 0 = any supported
Needs string // permission text for 403 hints, e.g. "repo admin"
Hint500 string // likely causes when the server hides a 500 message
// ModeFor optionally classifies a call by its params (forgejo_api). The
// registry keeps such an action when read-only is on and applies ModeFor
// at call time.
ModeFor func(in any) Mode
// Run executes the action; in is a *T where T is the Spec.Params type.
Run func(c *Call, in any) (*Result, error)
}
Action is one value of a tool's `action` enum.
type Call ¶
type Call struct {
Ctx context.Context
Limit int // effective output cap for this call (6.6)
Env *Env
Action string
Owner, Repo string // resolved when RepoScoped (empty otherwise)
// Progress sends a progress notification; no-op when the client sent no
// progress token.
Progress func(msg string, done, total float64)
}
Call is the per-invocation context handed to Action.Run.
func (*Call) Cap ¶
Cap is the last-resort cap to Call.Limit, head-keeping, cut at a line boundary; trailer lines survive (see format.CapHead).
func (*Call) Chars ¶
Chars returns the effective per-action size: requested (or def) clamped to [200, Limit-1500] (section 6.6).
type Env ¶
type Env struct {
Client *forgejo.Client
Cfg *config.Config
Repo *gitremote.Detector
Clock clock.Clock
// Memo holds in-process facts shared between tools, for example
// Memo.Set("automerge:o/r#42") after a 201 from pr merge.
Memo *Memo
}
Env is the shared runtime environment of every tool.
type InstructionsInfo ¶
type InstructionsInfo struct {
Host string
Version string // "" before the first tool call
DefaultRepo string // "" = none
Toolsets map[string]bool
WaitMax int // seconds
}
InstructionsInfo carries the values interpolated into the server `instructions` text (section 4.1).
type Memo ¶
type Memo struct {
// contains filtered or unexported fields
}
Memo is a mutex-protected string set.
type Mode ¶
type Mode uint8
Mode classifies an action. Destructive implies Write and requires `confirm`.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds every Spec and builds the filtered tool set.
func (*Registry) Build ¶
Build applies toolsets, FORGEJO_DENY and read-only (section 4 steps 1-4) and computes DeniedEndpoints and SideEffectGets.
func (*Registry) DeniedEndpoints ¶
DeniedEndpoints returns the "METHOD template" strings blocked by deny rules or disabled toolsets (consumed by forgejo_api policy); the value is the "tool.action" that owns the endpoint.
func (*Registry) Enabled ¶
Enabled returns the filtered Specs (only actions that survived). Before Build it returns every Spec.
func (*Registry) EnabledToolsets ¶
EnabledToolsets returns the toolsets selected by the last Build (nil before).
func (*Registry) Install ¶
Install registers every enabled Spec on srv with the raw Server.AddTool (handler order of section 2).
func (*Registry) SideEffectGets ¶
SideEffectGets returns the "GET template" endpoints that belong to non-read actions (sorted).
type Spec ¶
type Spec struct {
Name, Toolset, Description string // Description <= 160 chars
Params any // zero value of the flat params struct (json + jsonschema tags)
Actions []Action
RepoScoped bool // adds `repo` resolution before Run
// Single marks a single-purpose tool: exactly one Action named "run", no
// `action` property in the schema, no `help`.
Single bool
}
Spec describes one MCP tool.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package actions implements the `run` tool: Actions runs, jobs, logs, workflows, dispatch and artifacts (DESIGN.md sections 8.6 and 10.2).
|
Package actions implements the `run` tool: Actions runs, jobs, logs, workflows, dispatch and artifacts (DESIGN.md sections 8.6 and 10.2). |
|
Package admin implements the `admin` tool (DESIGN.md section 8.11).
|
Package admin implements the `admin` tool (DESIGN.md section 8.11). |
|
Package all registers every tool area.
|
Package all registers every tool area. |
|
Command docgen writes docs/TOOLS.md from the tool registry.
|
Command docgen writes docs/TOOLS.md from the tool registry. |
|
Package packages implements the `package` tool (DESIGN.md section 8.10).
|
Package packages implements the `package` tool (DESIGN.md section 8.10). |
|
Package shared holds helpers used by several tool areas (DESIGN.md sections 1, 3.1, 5.6, 5.7, 10.5).
|
Package shared holds helpers used by several tool areas (DESIGN.md sections 1, 3.1, 5.6, 5.7, 10.5). |
|
ci
Package ci holds the CI plumbing shared by the pr, checks, run, ci_failure and ci_wait tools (DESIGN.md sections 10.1-10.4).
|
Package ci holds the CI plumbing shared by the pr, checks, run, ci_failure and ci_wait tools (DESIGN.md sections 10.1-10.4). |
|
ci/wait
Package wait implements the server-side polling of section 10.1 (ci_wait and run dispatch wait=true).
|
Package wait implements the server-side polling of section 10.1 (ci_wait and run dispatch wait=true). |