Documentation
¶
Index ¶
- Constants
- func CalculateTrustScore(entry RegistryFeedEntry) int
- func FormatInt(v int) string
- func FormatInt64(v int64) string
- func FormatLastRelease(v string) string
- func FormatString(v string) string
- func FormatTrustLabel(score int) string
- func FormatWarning(sid string, score int) string
- func IsLowTrust(score int) bool
- func LeanProxyDir() (string, error)
- func TrustLevel(score int) string
- type DiscoverySignature
- type EventType
- type FeedFetcher
- func (f *FeedFetcher) CacheAge() (time.Duration, error)
- func (f *FeedFetcher) CacheStaleInfo() string
- func (f *FeedFetcher) IndexPath() string
- func (f *FeedFetcher) LoadCache() (*FeedIndex, error)
- func (f *FeedFetcher) OnSync(fn func(entries []RegistryFeedEntry))
- func (f *FeedFetcher) RegistryDir() string
- func (f *FeedFetcher) StartPeriodicRefresh(ctx context.Context)
- func (f *FeedFetcher) Sync(ctx context.Context) error
- func (f *FeedFetcher) SyncSources(ctx context.Context) error
- func (f *FeedFetcher) WaitRefreshDone()
- func (f *FeedFetcher) WithCustomSources(sources []NamedFeedSource) *FeedFetcher
- func (f *FeedFetcher) WithHTTPClient(c *http.Client) *FeedFetcher
- func (f *FeedFetcher) WithInterval(d time.Duration) *FeedFetcher
- func (f *FeedFetcher) WithOfficialClient(c *mcpregistry.Client) *FeedFetcher
- func (f *FeedFetcher) WithURL(url string) *FeedFetcher
- type FeedIndex
- type HealthStatus
- type LifecycleManager
- type MatchCriteria
- type NamedFeedSource
- type Namespace
- type NamespaceConfig
- type NamespaceManager
- type Registry
- type RegistryConfig
- type RegistryEvent
- type RegistryFeedEntry
- type SchemaCache
- type SchemaCacheManager
- func (m *SchemaCacheManager) GetFullSchema(ctx context.Context, toolName string) (json.RawMessage, error)
- func (m *SchemaCacheManager) Invalidate(toolName string)
- func (m *SchemaCacheManager) InvalidateAll()
- func (m *SchemaCacheManager) SetFullSchema(ctx context.Context, toolName string, schema json.RawMessage)
- type ServerConfig
- type ServerEntry
- type ServerHandle
- type ServerState
- type ServerStats
- type ServerStatus
- type Tool
- type ToolEntry
- type ToolEvent
- type ToolEventType
- type ToolMatch
- type ToolRegistry
- type ToolSchemaRegistry
- type TransportType
- type TrustSignal
Constants ¶
const ( // DefaultRegistryURL used to point FeedFetcher at an unowned domain // (registry.mcp.io) by default, which would have handed whoever // controls that domain code execution on every install (issue #313). // LeanProxy does not own that domain, so there is no default NDJSON // feed URL any more: FeedFetcher.Sync uses the official MCP Registry // (see pkg/registry/mcpregistry) unless WithURL configures a specific, // user-chosen custom feed. The constant is kept (empty) only so any // external reference to it still compiles; do not set a URL here. DefaultRegistryURL = "" DefaultSyncInterval = 1 * time.Hour CacheStaleThreshold = 24 * time.Hour )
const ( TransportStdio = migrate.TransportStdio TransportHTTP = migrate.TransportHTTP TransportSSE = migrate.TransportSSE )
const ( // TrustUnverified is the level assigned to a score of 0: no signal // LeanProxy can independently verify was present at all. It is // distinct from TrustLow (some signal was present but weak) so the // display can tell "we checked and it looks risky" apart from "we have // nothing to check". TrustUnverified = "unverified" TrustLow = "low" TrustMedium = "medium" TrustHigh = "high" )
const SourceOfficial = "official"
SourceOfficial tags entries that came from the official MCP Registry.
Variables ¶
This section is empty.
Functions ¶
func CalculateTrustScore ¶ added in v0.8.0
func CalculateTrustScore(entry RegistryFeedEntry) int
CalculateTrustScore computes a trust score from 0-100 using only signals LeanProxy itself can observe or independently verify:
- registry namespace verification status (entry.NamespaceVerified) — the registry API confirmed the publisher owns the namespace (DNS or GitHub verification for the official MCP Registry);
- presence of a license (entry.License);
- recency of the last release;
- open issue count (as a maintenance signal);
- download count.
A feed-provided trust_score (entry.TrustScore) is never used: whoever authors the feed does not get to grade their own homework (issue #313). An entry with no verifiable signal at all scores 0, labeled "unverified" (see TrustLevel), never a high score by default.
func FormatInt ¶ added in v0.8.0
FormatInt renders v as a decimal string, substituting "-" only when v is negative. Zero is a legitimate signal (e.g. zero open issues) and is preserved.
func FormatInt64 ¶ added in v0.8.0
FormatInt64 mirrors FormatInt for int64.
func FormatLastRelease ¶ added in v0.8.0
FormatLastRelease renders a registry last-release string. Empty strings and unparseable dates are both rendered as "-" so the search column does not conflate "missing" with "garbage". Parseable dates are returned verbatim so consumers can apply their own locale formatting later.
func FormatString ¶ added in v0.8.0
FormatString renders v as-is when non-empty, otherwise "-" to signal unavailable data. Used for columns where empty is the natural absence.
func FormatTrustLabel ¶ added in v0.8.0
func FormatWarning ¶ added in v0.8.0
func IsLowTrust ¶ added in v0.8.0
func LeanProxyDir ¶ added in v0.8.0
func TrustLevel ¶ added in v0.8.0
Types ¶
type DiscoverySignature ¶ added in v0.2.0
type DiscoverySignature struct {
Name string `json:"name"`
Description string `json:"description"`
}
func NewDiscoverySignature ¶ added in v0.2.0
func NewDiscoverySignature(name, description string, fullSchema json.RawMessage) (*DiscoverySignature, error)
type FeedFetcher ¶ added in v0.8.0
type FeedFetcher struct {
// contains filtered or unexported fields
}
func NewFeedFetcher ¶ added in v0.8.0
func NewFeedFetcher(logger *slog.Logger, cacheDir string) *FeedFetcher
func (*FeedFetcher) CacheAge ¶ added in v0.8.0
func (f *FeedFetcher) CacheAge() (time.Duration, error)
func (*FeedFetcher) CacheStaleInfo ¶ added in v0.8.0
func (f *FeedFetcher) CacheStaleInfo() string
func (*FeedFetcher) IndexPath ¶ added in v0.8.0
func (f *FeedFetcher) IndexPath() string
func (*FeedFetcher) LoadCache ¶ added in v0.8.0
func (f *FeedFetcher) LoadCache() (*FeedIndex, error)
func (*FeedFetcher) OnSync ¶ added in v0.8.0
func (f *FeedFetcher) OnSync(fn func(entries []RegistryFeedEntry))
func (*FeedFetcher) RegistryDir ¶ added in v0.8.0
func (f *FeedFetcher) RegistryDir() string
func (*FeedFetcher) StartPeriodicRefresh ¶ added in v0.8.0
func (f *FeedFetcher) StartPeriodicRefresh(ctx context.Context)
func (*FeedFetcher) Sync ¶ added in v0.8.0
func (f *FeedFetcher) Sync(ctx context.Context) error
Sync refreshes the local cache. When registryURL is set (via WithURL — used directly by tests and by any caller that wants exactly one custom NDJSON feed), it fetches only that feed, unchanged from prior releases. Otherwise (the default) it syncs from the official MCP Registry plus any configured custom sources (WithCustomSources) — see SyncSources.
func (*FeedFetcher) SyncSources ¶ added in v1.1.1
func (f *FeedFetcher) SyncSources(ctx context.Context) error
SyncSources refreshes the local cache from the official MCP Registry (the default marketplace source) plus every configured custom NDJSON source (registry.sources — opt-in only, issue #313). A failure syncing one custom source is logged and skipped rather than failing the whole sync, so one broken opt-in feed cannot take down the default source; a failure reaching the official registry is returned, since it is the primary source operators expect `marketplace sync` to refresh.
func (*FeedFetcher) WaitRefreshDone ¶ added in v0.8.0
func (f *FeedFetcher) WaitRefreshDone()
func (*FeedFetcher) WithCustomSources ¶ added in v1.1.1
func (f *FeedFetcher) WithCustomSources(sources []NamedFeedSource) *FeedFetcher
WithCustomSources sets the opt-in custom NDJSON feeds to sync alongside the official registry. Only used on the default (no WithURL) sync path.
func (*FeedFetcher) WithHTTPClient ¶ added in v0.8.0
func (f *FeedFetcher) WithHTTPClient(c *http.Client) *FeedFetcher
func (*FeedFetcher) WithInterval ¶ added in v0.8.0
func (f *FeedFetcher) WithInterval(d time.Duration) *FeedFetcher
func (*FeedFetcher) WithOfficialClient ¶ added in v1.1.1
func (f *FeedFetcher) WithOfficialClient(c *mcpregistry.Client) *FeedFetcher
WithOfficialClient overrides the official-registry client (e.g. to point it at a test server, or to disable it by passing nil).
func (*FeedFetcher) WithURL ¶ added in v0.8.0
func (f *FeedFetcher) WithURL(url string) *FeedFetcher
type FeedIndex ¶ added in v0.8.0
type FeedIndex struct {
SyncedAt time.Time `json:"synced_at"`
Entries []RegistryFeedEntry `json:"entries"`
}
type HealthStatus ¶
type HealthStatus string
const ( HealthUnknown HealthStatus = "unknown" HealthHealthy HealthStatus = "healthy" HealthUnhealthy HealthStatus = "unhealthy" )
type LifecycleManager ¶
type LifecycleManager interface {
Start(ctx context.Context, config ServerConfig) (ServerHandle, error)
Stop(ctx context.Context, id string) error
Kill(ctx context.Context, id string) error
Restart(ctx context.Context, id string) error
Status(ctx context.Context, id string) (ServerStatus, error)
List(ctx context.Context) ([]ServerStatus, error)
Close()
}
func NewLifecycleManager ¶
func NewLifecycleManager(logger *slog.Logger) LifecycleManager
type MatchCriteria ¶
type MatchCriteria struct {
Capabilities []string
Transport TransportType
MinHealth HealthStatus
MaxLoad float64
}
type NamedFeedSource ¶ added in v1.1.1
NamedFeedSource is one opt-in custom NDJSON feed the operator configured under registry.sources (pkg/migrate.RegistrySettings).
type NamespaceConfig ¶ added in v0.7.0
type NamespaceManager ¶ added in v0.7.0
type NamespaceManager interface {
Load(ctx context.Context, r io.Reader) error
GetNamespace(ctx context.Context, name string) (*Namespace, error)
GetToolsForNamespace(ctx context.Context, ns string) ([]string, error)
CheckAccess(ctx context.Context, ns, clientID string) error
GetAllNamespaces(ctx context.Context) []*Namespace
GetServerNamespace(ctx context.Context, serverID string) (string, error)
GetChildNamespaces(ctx context.Context, parentName string) ([]string, error)
ListToolsInNamespace(ctx context.Context, nsName string) ([]ToolEntry, error)
}
func NewNamespaceManager ¶ added in v0.7.0
func NewNamespaceManager(logger *slog.Logger) NamespaceManager
type Registry ¶
type Registry interface {
Register(ctx context.Context, entry ServerEntry) error
Unregister(ctx context.Context, id string) error
Update(ctx context.Context, entry ServerEntry) error
Get(ctx context.Context, id string) (*ServerEntry, error)
List(ctx context.Context) ([]*ServerEntry, error)
FindByCapability(ctx context.Context, capability string) ([]*ServerEntry, error)
FindByTransport(ctx context.Context, transport TransportType) ([]*ServerEntry, error)
FindBest(ctx context.Context, criteria MatchCriteria) (*ServerEntry, error)
UpdateHealth(ctx context.Context, id string, health HealthStatus) error
ListUnhealthy(ctx context.Context) ([]*ServerEntry, error)
Save(ctx context.Context) error
Load(ctx context.Context) error
Subscribe(ch chan<- RegistryEvent) func()
}
type RegistryConfig ¶ added in v0.2.0
type RegistryConfig struct {
CompactByDefault bool `yaml:"compact_by_default"`
MaxSignatureBytes int `yaml:"max_signature_bytes"`
}
func LoadRegistryConfig ¶ added in v0.2.0
func LoadRegistryConfig(r io.Reader) (*RegistryConfig, error)
func (*RegistryConfig) Validate ¶ added in v0.2.0
func (c *RegistryConfig) Validate() error
type RegistryEvent ¶
type RegistryEvent struct {
Type EventType
Server *ServerEntry
Details string
}
type RegistryFeedEntry ¶ added in v0.8.0
type RegistryFeedEntry struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
Transport string `json:"transport,omitempty"`
// TrustScore is read from the feed for backward compatibility with old
// cache files only. It is never used by CalculateTrustScore (issue
// #313): a feed cannot be trusted to grade itself.
TrustScore int `json:"trust_score,omitempty"`
LastRelease string `json:"last_release,omitempty"`
OpenIssues int `json:"open_issues,omitempty"`
Downloads int `json:"downloads,omitempty"`
TokensPerTurn int64 `json:"tokens_per_turn,omitempty"`
Categories []string `json:"categories,omitempty"`
// Version is the exact package/image version this entry pins, when
// known. Empty means the source did not publish a version (a legacy
// custom feed entry) — installers must not assume "latest" is safe and
// should pin best-effort (see pkg/migrate.buildServerConfig).
Version string `json:"version,omitempty"`
// PackageRegistry identifies which package registry Command/Args were
// derived from ("npm", "pypi", "oci"), when the entry came from a
// structured source (the official MCP Registry). Empty for legacy
// custom-feed entries that only ever provided a raw Command/Args pair.
PackageRegistry string `json:"package_registry,omitempty"`
// PackageIdentifier is the bare package name or image reference
// (without a version suffix) when PackageRegistry is set.
PackageIdentifier string `json:"package_identifier,omitempty"`
// Source names where this entry came from: "official" for the MCP
// Registry API, or the configured name of a custom NDJSON source
// (registry.sources). Used for provenance display and for
// InstalledFrom.Registry.
Source string `json:"source,omitempty"`
// NamespaceVerified reports whether the source registry verified that
// the publisher owns the server's namespace (DNS/GitHub verification
// on the official MCP Registry). Used only as a trust signal — see
// CalculateTrustScore.
NamespaceVerified bool `json:"namespace_verified,omitempty"`
// License is the SPDX identifier or free-form license name reported by
// the source, when known. Used only as a trust signal.
License string `json:"license,omitempty"`
}
type SchemaCache ¶ added in v0.2.0
type SchemaCache interface {
Get(key string) (json.RawMessage, bool)
Set(key string, schema json.RawMessage)
Delete(key string)
Clear()
}
func NewLRUSchemaCache ¶ added in v0.2.0
func NewLRUSchemaCache(maxSize int, maxAge time.Duration, onEvict func(key string, schema json.RawMessage)) SchemaCache
type SchemaCacheManager ¶ added in v0.2.0
type SchemaCacheManager struct {
// contains filtered or unexported fields
}
func NewSchemaCacheManager ¶ added in v0.2.0
func (*SchemaCacheManager) GetFullSchema ¶ added in v0.2.0
func (m *SchemaCacheManager) GetFullSchema(ctx context.Context, toolName string) (json.RawMessage, error)
func (*SchemaCacheManager) Invalidate ¶ added in v0.2.0
func (m *SchemaCacheManager) Invalidate(toolName string)
func (*SchemaCacheManager) InvalidateAll ¶ added in v0.2.0
func (m *SchemaCacheManager) InvalidateAll()
func (*SchemaCacheManager) SetFullSchema ¶ added in v0.2.0
func (m *SchemaCacheManager) SetFullSchema(ctx context.Context, toolName string, schema json.RawMessage)
type ServerConfig ¶
type ServerEntry ¶
type ServerEntry struct {
ID string
Config *ServerConfig
Address string
Transport TransportType
Capabilities []string
Health HealthStatus
Stats ServerStats
ComplexityTier string
// Timeout is the per-server request timeout (sourced from the
// `timeout` field of the server's stanza in leanproxy_servers.yaml).
// Zero means no override; callers should fall back to a documented
// default. This is the timeout the request layer uses when dispatching
// to this server — see cmd/serve.go handlers and pkg/pool/server.go.
Timeout time.Duration
RegisteredAt time.Time
LastSeenAt time.Time
}
type ServerHandle ¶
type ServerHandle struct {
ID string
Config ServerConfig
PID int
}
type ServerState ¶
type ServerState string
const ( StateRunning ServerState = "running" StateStopped ServerState = "stopped" StateError ServerState = "error" StateStarting ServerState = "starting" )
type ServerStats ¶
type ServerStatus ¶
type Tool ¶ added in v0.2.0
type Tool struct {
Signature DiscoverySignature `json:"signature"`
FullSchema json.RawMessage `json:"full_schema,omitempty"`
ServerID string `json:"server_id"`
}
type ToolEvent ¶
type ToolEvent struct {
Type ToolEventType
ServerID string
ToolName string
Tool ToolEntry
}
type ToolEventType ¶
type ToolEventType int
const ( ToolEventRegistered ToolEventType = iota ToolEventUnregistered )
type ToolRegistry ¶
type ToolRegistry interface {
RegisterTool(ctx context.Context, serverID, toolName string) error
UnregisterTool(ctx context.Context, serverID, toolName string) error
GetToolServer(ctx context.Context, toolName string) (string, error)
SearchTools(ctx context.Context, query string) []ToolMatch
ListAllTools(ctx context.Context) []ToolEntry
SubscribeTools(ch chan<- ToolEvent) func()
}
func NewToolRegistry ¶
func NewToolRegistry(logger interface{ Debug(msg string, args ...any) }) ToolRegistry
type ToolSchemaRegistry ¶ added in v0.2.0
type ToolSchemaRegistry interface {
RegisterTool(ctx context.Context, tool Tool) error
UnregisterTool(ctx context.Context, serverID, toolName string) error
GetDiscoverySignatures() []DiscoverySignature
GetFullSchema(ctx context.Context, toolName string) (json.RawMessage, error)
RefreshManifest(ctx context.Context) error
}
func NewToolSchemaRegistry ¶ added in v0.2.0
func NewToolSchemaRegistry() ToolSchemaRegistry
type TransportType ¶
type TransportType = migrate.TransportType
type TrustSignal ¶ added in v1.1.1
TrustSignal is one individually-displayable input to the trust score.
func TrustSignals ¶ added in v1.1.1
func TrustSignals(entry RegistryFeedEntry) []TrustSignal
TrustSignals returns the individual signals behind entry's trust score, in a fixed display order, so callers can show "why" a score is what it is instead of only the number (issue #313 acceptance criterion: "Display the individual signals, not just a number").
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mcpregistry is a client for the official MCP Registry API (https://registry.modelcontextprotocol.io/, API version v0), used as the default marketplace source (issue #313).
|
Package mcpregistry is a client for the official MCP Registry API (https://registry.modelcontextprotocol.io/, API version v0), used as the default marketplace source (issue #313). |