registry

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 33 Imported by: 1 module, 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 registry has the connectors, which are remote MCP servers, whose definitions are kept in a store, with a client of each, which Run connects to its server

Index

Constants

View Source
const CallbackPath = "/mcp/callback"

CallbackPath is the path of the callback, beneath the API's prefix, which an authorization server redirects to, with its code

View Source
const MaxIconSize = 64 * 1024

MaxIconSize is the largest data URL of an icon, which a server sends, as it's connected, which a connector's status has

View Source
const TemplateIconPath = "icon/connector/"

TemplateIconPath is the path of a template's logo, among the web UI's files, which its icon is the file name of

Variables

View Source
var (
	// RetryInterval is how often Run connects the connectors which aren't
	// connected, such as those whose servers couldn't be, or closed their
	// sessions, and connects, and disconnects, those which another process
	// with the store created, or deleted. A connector which the registry
	// creates, updates, or deletes is connected, or disconnected, at once.
	RetryInterval = 30 * time.Second

	// ConnectTimeout is how long a connector's server is waited for, as it's
	// connected, and its tools are listed, unless the registry is given
	// another, with WithConnectTimeout
	ConnectTimeout = 30 * time.Second

	// ConnectJitter is the most each connector waits, at random, before
	// it's connected, when more than one is, such as as Run starts, so
	// they aren't all connected at once
	ConnectJitter = 2 * time.Second
)
View Source
var AuthorizeTimeout = 10 * time.Minute

AuthorizeTimeout is how long an authorization is waited for, once it's started, until its callback

Functions

func CredentialKey added in v1.6.3

func CredentialKey(name string) string

CredentialKey returns the key which how the connector with the name is signed in to, such as its token, is kept under, with the credentials provider, as JSON. It's an identifier, as go-auth's keys are, of at most 64 characters, as a connector's name is at most 60.

func ParseTemplates

func ParseTemplates(data []byte) ([]schema.ConnectorTemplate, error)

ParseTemplates returns the templates in the YAML, which is a list of them, or ErrBadParameter, when it isn't, or one isn't valid, as it has no name, or its URL, or credentials' names, aren't valid

func Templates

func Templates() ([]schema.ConnectorTemplate, error)

Templates returns the templates of the remote MCP servers which are offered by default, from servers.yaml, which is embedded

Types

type CredentialsProvider

type CredentialsProvider = credential.CredentialProvider

CredentialsProvider expands credentials, such as a connector's client's secret, whose placeholders, such as ${GITHUB_CLIENT_SECRET}, are replaced with the credentials they name, and keeps how each connector's server is signed in to, under its CredentialKey. It's go-auth's CredentialProvider, so one provider is shared by the registry, the toolkit and the connectors.

type Opt

type Opt func(*opt) error

Opt is an option of the registry

func WithAgents added in v1.6.4

func WithAgents(run namespace.RunFunc) Opt

WithAgents makes connectors' MCP prompts agents, which are tools in their namespaces, beside their tools, run with the function, as the registry runs its agents, such as its RunAgentTool. Without it, they aren't.

func WithBroadcaster

func WithBroadcaster(b *broadcaster.Broadcaster) Opt

WithBroadcaster is the broadcaster the registry publishes its connectors' connections to, such as the server's, so its clients see them: a connector whose server is connected is created, with which server it is, and one whose server is disconnected is deleted, with why, when it wasn't disconnected

func WithClientOpts

func WithClientOpts(opts ...client.ClientOpt) Opt

WithClientOpts are options of go-client, such as client.OptTracer, which apply to the requests of the clients of each connector

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Opt

WithConnectTimeout is how long a connector's server is waited for, as it's connected, and its tools are listed, rather than ConnectTimeout

func WithCredentialsProvider

func WithCredentialsProvider(provider CredentialsProvider) Opt

WithCredentialsProvider sets the provider which expands credentials, such as a connector's client secret, whose placeholders, such as ${GITHUB_CLIENT_SECRET}, are replaced with the credentials they name, as the provider registry's are. Without one, or with nil, the credentials are environment variables.

func WithName

func WithName(name, version string) Opt

WithName is the name, and version, which each connector's MCP server is told, as a client connects to it, rather than schema.DefaultName, and schema.DefaultVersion. The version can be empty.

func WithStore

func WithStore(store Store) Opt

WithStore is the store of the connectors, which keeps them, such as in a file, or a database, rather than in memory

func WithTemplates

func WithTemplates(templates ...schema.ConnectorTemplate) Opt

WithTemplates sets the templates of the remote MCP servers which are offered, as connectors which can be added, rather than those of Templates, or none, with none, of which those whose credentials the credentials provider has, as the registry is created, are

func WithToolTimeout

func WithToolTimeout(timeout time.Duration) Opt

WithToolTimeout is how long one of a connector's server's tools has, as it's called, rather than the toolkit's default, which it has when it's zero

func WithToolkit

func WithToolkit(tk *toolkit.Toolkit) Opt

WithToolkit is the toolkit which a connector's server's tools are added to, as a namespace, once it's connected, and removed from, once it's disconnected, whose name is the connector's, as schema.Namespace makes it, so it doesn't clash with the toolkit's other namespaces

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry has the connectors, whose definitions are kept in its store, which is read each time they're asked for, so they're as the store has them, and a client of each, which Run connects, which is created once, and again once the connector's definition changes, when the session of the one it replaces is closed

func New

func New(opts ...Opt) (*Registry, error)

New returns a registry, with the options, such as its store, with WithStore, which keeps its connectors in memory otherwise

func (*Registry) Authorize

func (r *Registry) Authorize(ctx context.Context, name, callback string) (string, error)

Authorize starts the authorization of the connector's server, as it needs to be authorized, with the callback, which the authorization server redirects to, with its code, and returns the URL a person authorizes it at. Its authorization server is discovered, as its server said, and a client is registered with it, unless one with the callback is already, which the connector's credential has. Returns ErrNotFound when there's no connector with the name, ErrBadParameter when the callback isn't an http, or https, URL, ErrNotImplemented when the authorization server doesn't register clients, or support PKCE's S256, and ErrServiceUnavailable when it can't be discovered.

func (*Registry) Callback

func (r *Registry) Callback(ctx context.Context, state, code, reason string) (*schema.Connector, error)

Callback completes the authorization the state is of, with the code, which the authorization server redirected with, or the error it said, by exchanging the code for a token, which is stored, with the connector's credential, and connecting its server again, with it. Returns the connector, or ErrNotFound, when the state isn't one which is waited for, or ErrBadParameter, when the authorization server said why it wasn't authorized, or the code couldn't be exchanged.

func (*Registry) Close

func (r *Registry) Close() error

Close disconnects every connector's server, such as when the process stops, and returns their errors

func (*Registry) CreateConnector

func (r *Registry) CreateConnector(ctx context.Context, connector schema.Connector) (*schema.Connector, error)

CreateConnector creates the connector, and returns it, with its serial. It's connected by Run. One without a name is named after its server, as it says, once it's connected to, or as the metadata of how it's authorized says, when it needs to be, or else the host of its URL, as an identifier, with a number, such as github-2, when that's another connector's. Returns ErrBadParameter when its name, or its fields, aren't valid, and ErrConflict when there's a connector with its name.

func (*Registry) DeleteConnector

func (r *Registry) DeleteConnector(ctx context.Context, name string) (*schema.Connector, error)

DeleteConnector deletes the connector with the name, and disconnects its server, when it's connected, and returns it, as it was. Returns ErrNotFound when there's no connector with the name, and ErrConflict when it was changed as it was deleted.

func (*Registry) GetConnector

func (r *Registry) GetConnector(ctx context.Context, name string) (*schema.Connector, error)

GetConnector returns the connector with the name, with its status, or ErrNotFound when there's none

func (*Registry) ListConnectors

func (r *Registry) ListConnectors(ctx context.Context) (*schema.ConnectorList, error)

ListConnectors returns the connectors, with their status, in order of their names

func (*Registry) ListTemplates

func (r *Registry) ListTemplates(ctx context.Context) (*schema.ConnectorTemplateList, error)

ListTemplates returns the templates of the connectors which can be added, whose credentials the registry's credentials provider had, as it was created, and whose server isn't a connector's already, in order of their names

func (*Registry) Run

func (r *Registry) Run(ctx context.Context, logger *slog.Logger) error

Run connects the connectors' servers, as it starts, and disconnects those which are deleted, at once, as the registry's own broadcaster publishes that they're created, updated, or deleted, and every RetryInterval, for those which aren't connected, until the context is cancelled, when it disconnects every one, and returns. What happens is logged, with the logger, or isn't when it's nil.

func (*Registry) SourceAgent added in v1.6.4

func (r *Registry) SourceAgent(_ context.Context, ns, name string) (agentschema.AgentMeta, error)

SourceAgent returns the definition of the connector's MCP prompt, as an agent, by its namespace, which is the connector's tools', and its name as an agent, such as args_prompt, with its namespace as its origin, so the registry runs it as it runs its agents. Returns ErrNotFound when there's no connector in the namespace, it isn't connected, or it has no such prompt.

func (*Registry) SourceMessages added in v1.6.4

func (r *Registry) SourceMessages(ctx context.Context, ns, name string, input json.RawMessage) ([]llm.Message, error)

SourceMessages returns the messages of the connector's MCP prompt, by its namespace, and its name as an agent, with the input, which are its arguments, as its model is sent them. Returns ErrNotFound when there's no such prompt, and ErrBadParameter when the input isn't valid.

func (*Registry) UpdateConnector

func (r *Registry) UpdateConnector(ctx context.Context, name string, meta schema.ConnectorMeta) (*schema.Connector, error)

UpdateConnector replaces the fields of the connector with the name, once its server, as it is now, is connected, within its connect timeout, so a URL which isn't a server's isn't stored, and returns it, with its new serial, and connected. Its server, as it was, is disconnected, once it's replaced. One whose URL, and client, are the same, such as when only its patterns change, isn't connected first, as its server was already: it keeps its session, when it's connected, and has its tools added again, with its patterns, or is stored, and connected again, by Run, when it isn't, so a server which has only one session at once, or needs to be signed in to, isn't connected to twice. Returns ErrNotFound when there's no connector with the name, ErrBadParameter when the fields aren't valid, ErrServiceUnavailable when its server, as it is now, can't be connected, when it's left as it was, and ErrConflict when it was changed as it was updated.

type Store

type Store interface {
	// List returns the connectors, with their serials, in any order
	List(context.Context) ([]schema.Connector, error)

	// Put creates the connector, when its serial is zero, and the store has no
	// connector with its name, or replaces the connector with its name, when its
	// serial is that connector's, and returns it, with its new serial. Returns
	// ErrConflict when its serial isn't the connector's, as the connector was
	// changed, or created, since it was seen.
	Put(context.Context, schema.Connector) (schema.Connector, error)

	// Delete deletes the connector with the name, when the serial is its
	// serial, or does nothing when there's none. Returns ErrConflict when
	// the serial isn't its serial, as it was changed since it was seen.
	Delete(ctx context.Context, name string, serial uint64) error
}

Store has the definitions of connectors, by their names, each with its serial, which the store sets, and changes each time the connector does, so a change is made to the connector as it was last seen, rather than a newer one, such as one which another process made. A serial isn't used again for a name, even once its connector is deleted, and another created with the name, so a change to one isn't made to another.

func NewMemoryStore

func NewMemoryStore() Store

NewMemoryStore returns a store of connectors in memory, which aren't kept once the process ends

Directories

Path Synopsis
Package cmd has the commands, and flags, of the MCP connectors: those which call the connectors' API, and the server's
Package cmd has the commands, and flags, of the MCP connectors: those which call the connectors' API, and the server's
Package httpclient is a client of the HTTP API of the MCP connectors
Package httpclient is a client of the HTTP API of the MCP connectors
Package httphandler has the HTTP API of the MCP connectors, which lists, gets, creates, updates and deletes them
Package httphandler has the HTTP API of the MCP connectors, which lists, gets, creates, updates and deletes them

Jump to

Keyboard shortcuts

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