Documentation
¶
Overview ¶
Package source defines the top-level source configuration consumed by the MCP server and the dispatcher that wires per-type Connect implementations into the server.
A Source describes a single named connection to an external system. Source files contain a top-level `sources:` map keyed by the user-chosen source name; for each key, the value is decoded into a Source and the map key is assigned to Source.Name by LoadSources.
The dispatcher in dispatcher.go switches on Source.Type and, in this issue, returns an empty tool.Response for every known type. The per-type Connect implementations land in a follow-up issue.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply connects every source in parallel, runs the prefix and remove middlewares over the returned tools, validates that no two tools end up with the same name, and registers the survivors with server.
Apply is tolerant of per-source failures: every Connect error, unknown source type, or duplicate tool name is logged at error level (with the source name, type, and underlying error) and the surviving sources' tools are still registered. Apply returns a non-nil error only when no source contributed any tool — the signal cmd/main.go uses to refuse to start a server with zero tools to offer. The MCP Go SDK silently replaces a tool of the same name on AddTool; this function surfaces that situation as a logged config error rather than aborting the apply.
The per-type Connect calls fan out via sync.WaitGroup; the validation and registration phases run sequentially. Each Connect writes to a distinct indexed slot in the results slice, so the goroutines don't need locks for the write half.
Types ¶
type Source ¶
type Source struct {
Name string `yaml:"-" json:"-"` // populated by the loader from the map key
Type string `yaml:"type" json:"type"`
Connect map[string]any `yaml:"connect,omitempty" json:"connect,omitempty"`
Tools ToolsConfig `yaml:"tools" json:"tools"`
}
Source describes a single named connection to an external system.
Name is populated by the loader from the surrounding `sources:` map key (e.g. `forgejo:`) — it is not itself a config field. The remaining fields map directly onto the YAML/JSON keys of the same name. Connect is a free-form map so each per-type implementation can decode its own connection schema without the source package having to know about it.
func LoadSources ¶
LoadSources decodes a YAML or JSON document and returns the entries under the top-level `sources:` map as a slice of Source values with each Source.Name populated from its map key.
The document format is auto-detected from the first non-whitespace byte: a leading '{' or '[' is treated as JSON, anything else as YAML. Decoding errors are wrapped with a format-specific prefix so callers can tell which parser failed.
type ToolsConfig ¶
type ToolsConfig struct {
Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"`
Remove []string `yaml:"remove,omitempty" json:"remove,omitempty"`
EnableOnly []string `yaml:"enable_only,omitempty" json:"enable_only,omitempty"`
ReadOnly bool `yaml:"read_only,omitempty" json:"read_only,omitempty"`
}
ToolsConfig governs per-source tool-name and tool-set adjustments applied by the dispatcher middlewares. The fields are consumed by the middlewares added in a follow-up issue; this issue only decodes them so a later pass can mutate them.
Remove and EnableOnly are mutually exclusive: setting both on the same source is a configuration error and LoadSources rejects it. The two fields have opposite intent (drop matching vs keep matching only) and combining them produces ambiguous behavior on tools that match only one of the two pattern sets.