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 ¶
- type OverwrittenTool
- type Registry
- func (r *Registry) Lookup(toolName string) *ToolEntry
- func (r *Registry) LookupBatch(toolNames []string) map[string]*ToolEntry
- func (r *Registry) PinnedHash(toolName string) (hash string, pinned bool)
- func (r *Registry) Register(serverID, serverType, serverAddr string, tools []ToolInfo) []OverwrittenTool
- func (r *Registry) Remove(serverID string)
- func (r *Registry) ServerAddrs() map[string]string
- func (r *Registry) SetCallbacks(cb RegistryCallbacks)
- type RegistryCallbacks
- type ToolEntry
- type ToolInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OverwrittenTool ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.