mcpregistry

package
v0.0.0-...-230ac96 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 2 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 mcpregistry provides an in-memory registry that maps MCP tool names to their server metadata. It is the central data structure shared by the LLM proxy, shim, and network monitor for tool call interception.

The registry is safe for concurrent use. Lookups use a read lock for minimal contention on the hot path (every LLM response).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OverwrittenTool

type OverwrittenTool struct {
	ToolName         string
	PreviousServerID string
	NewServerID      string
}

OverwrittenTool reports when a tool name is overwritten by a different server.

type Registry

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

Registry maps tool names to their MCP server metadata.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty, ready-to-use registry.

func (*Registry) Lookup

func (r *Registry) Lookup(toolName string) *ToolEntry

Lookup returns the registry entry for a tool name, or nil if not found. This is the hot-path call used by the LLM proxy on every tool_use block. Returns a copy so callers cannot mutate internal state.

func (*Registry) LookupBatch

func (r *Registry) LookupBatch(toolNames []string) map[string]*ToolEntry

LookupBatch returns entries for multiple tool names at once. Only found entries are included in the returned map; missing tools are omitted. Used when an LLM response contains parallel tool calls. Returns copies so callers cannot mutate internal state.

func (*Registry) PinnedHash

func (r *Registry) PinnedHash(toolName string) (hash string, pinned bool)

PinnedHash returns the first-seen hash for a tool name and whether it was pinned. The pinned hash never changes once set, even if the tool is removed and re-registered with a different hash. Used by the proxy for version pinning enforcement.

func (*Registry) Register

func (r *Registry) Register(serverID, serverType, serverAddr string, tools []ToolInfo) []OverwrittenTool

Register bulk-registers tools from a server. If a tool name already exists in the registry (from a different server), the new entry overwrites it (last-write-wins) and the previous entry is reported in the return value.

For network servers (non-empty serverAddr), the address is recorded in the address map so the network monitor can look it up, even if tools is empty.

func (*Registry) Remove

func (r *Registry) Remove(serverID string)

Remove deletes all tools that were registered by the given server and removes the server's address from the address map. Used for cleanup when a server disconnects or is removed from the session.

func (*Registry) ServerAddrs

func (r *Registry) ServerAddrs() map[string]string

ServerAddrs returns a copy of all known network MCP server addresses. The returned map is addr -> serverID. Stdio servers (which have empty addresses) are never included. Used by the network monitor to build its watch list.

func (*Registry) SetCallbacks

func (r *Registry) SetCallbacks(cb RegistryCallbacks)

SetCallbacks configures optional callbacks for registry events. If 2+ servers are already registered and OnMultiServer hasn't fired yet, it fires immediately (outside the lock) so late-attached consumers don't miss the multi-server state. Thread-safe; can be called at any time.

type RegistryCallbacks

type RegistryCallbacks struct {
	OnMultiServer func()                                          // called once when 2nd distinct server registers
	OnOverwrite   func(toolName, oldServerID, newServerID string) // called on tool name collision
}

RegistryCallbacks allows external components to be notified of registry events.

type ToolEntry

type ToolEntry struct {
	ToolName     string
	ServerID     string
	ServerType   string // "stdio" | "http" | "sse"
	ServerAddr   string // "" for stdio, "host:port" for network
	ToolHash     string
	RegisteredAt time.Time
}

ToolEntry describes a single MCP tool and the server that provides it.

type ToolInfo

type ToolInfo struct {
	Name string
	Hash string
}

ToolInfo carries the minimal information needed to register a tool. The server identity fields (serverID, serverType, serverAddr) are provided separately in the Register call.

Jump to

Keyboard shortcuts

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