Documentation
¶
Index ¶
- func NewCallToolProxy(gw *Gateway) tools.BaseTool
- func NewCatalogTool(gw *Gateway) tools.BaseTool
- type CallToolProxy
- type CatalogTool
- type FavoriteConfig
- type Gateway
- func (g *Gateway) CallTool(ctx context.Context, toolID string, params map[string]interface{}, ...) (interface{}, error)
- func (g *Gateway) Close()
- func (g *Gateway) GetAllTools(ctx context.Context) ([]RegisteredTool, error)
- func (g *Gateway) GetFavorites(ctx context.Context) ([]RegisteredTool, error)
- func (g *Gateway) Initialize(ctx context.Context, mcpServers map[string]config.MCPServer) error
- func (g *Gateway) RecordUsage(ctx context.Context, toolID, sessionID string, durationMs int64, success bool)
- func (g *Gateway) SearchTools(ctx context.Context, query string, maxResults int) ([]RegisteredTool, error)
- type MCPClientPool
- type RegisteredTool
- type Registry
- func (r *Registry) DiscoverAll(ctx context.Context, mcpServers map[string]config.MCPServer) error
- func (r *Registry) GetAllTools(ctx context.Context) ([]RegisteredTool, error)
- func (r *Registry) GetTool(ctx context.Context, toolID string) (*RegisteredTool, error)
- func (r *Registry) GetToolsByIDs(ctx context.Context, ids []string) ([]RegisteredTool, error)
- func (r *Registry) SearchTools(ctx context.Context, query string, maxResults int) ([]RegisteredTool, error)
- func (r *Registry) UpsertTool(ctx context.Context, serverName, toolName, description string, ...) error
- type Stats
- type UsageStat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCallToolProxy ¶
NewCallToolProxy returns a BaseTool that proxies arbitrary MCP tool calls.
func NewCatalogTool ¶
NewCatalogTool returns a BaseTool that wraps the catalog search capability.
Types ¶
type CallToolProxy ¶
type CallToolProxy struct {
// contains filtered or unexported fields
}
CallToolProxy implements tools.BaseTool as "mcp_call_tool". It executes any MCP tool by name, using the gateway to route the call.
func (*CallToolProxy) Info ¶
func (t *CallToolProxy) Info() tools.ToolInfo
func (*CallToolProxy) Run ¶
func (t *CallToolProxy) Run(ctx context.Context, params tools.ToolCall) (tools.ToolResponse, error)
type CatalogTool ¶
type CatalogTool struct {
// contains filtered or unexported fields
}
CatalogTool implements tools.BaseTool as "mcp_query_catalog". It searches the MCP tool registry by description/task keyword.
func (*CatalogTool) Info ¶
func (t *CatalogTool) Info() tools.ToolInfo
func (*CatalogTool) Run ¶
func (t *CatalogTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolResponse, error)
type FavoriteConfig ¶
type FavoriteConfig struct {
Threshold int // minimum calls to become a favorite (default 5)
MaxFavorites int // maximum directly-exposed tools (default 15)
WindowDays int // look-back window in days (default 30)
DecayDays int // inactivity days before removal from favorites (default 14)
}
FavoriteConfig controls how favorites are computed from usage statistics.
func DefaultFavoriteConfig ¶
func DefaultFavoriteConfig() FavoriteConfig
DefaultFavoriteConfig returns FavoriteConfig with sensible defaults.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is the main MCP gateway orchestrator, combining the tool registry and usage statistics subsystems.
func NewGateway ¶
func NewGateway(db *sql.DB, cfg FavoriteConfig) *Gateway
NewGateway creates a Gateway with the given database connection and favorites config.
func (*Gateway) CallTool ¶
func (g *Gateway) CallTool(ctx context.Context, toolID string, params map[string]interface{}, sessionID string) (interface{}, error)
CallTool executes a registered MCP tool by its ID ("server/tool" or tool_name). It records usage statistics after the call.
func (*Gateway) GetAllTools ¶
func (g *Gateway) GetAllTools(ctx context.Context) ([]RegisteredTool, error)
GetAllTools returns all tools in the registry.
func (*Gateway) GetFavorites ¶
func (g *Gateway) GetFavorites(ctx context.Context) ([]RegisteredTool, error)
GetFavorites returns the current favorite tools based on usage statistics.
func (*Gateway) Initialize ¶
Initialize discovers all MCP server tools and populates the registry.
func (*Gateway) RecordUsage ¶
func (g *Gateway) RecordUsage(ctx context.Context, toolID, sessionID string, durationMs int64, success bool)
RecordUsage records a tool usage event asynchronously (errors are logged, not returned).
func (*Gateway) SearchTools ¶
func (g *Gateway) SearchTools(ctx context.Context, query string, maxResults int) ([]RegisteredTool, error)
SearchTools performs a keyword search over the registry.
type MCPClientPool ¶
type MCPClientPool struct {
// contains filtered or unexported fields
}
MCPClientPool manages long-lived MCP client connections to avoid creating a new subprocess / HTTP client on every tool call. Clients are keyed by server name and are initialized (handshake done) on first use. A client is evicted when an error occurs, so the next caller will transparently reconnect.
func NewClientPool ¶
func NewClientPool() *MCPClientPool
NewClientPool creates an empty MCPClientPool.
func (*MCPClientPool) Evict ¶
func (p *MCPClientPool) Evict(serverName string)
Evict closes and removes the cached client for a server. Called after a call error so that the next invocation creates a fresh connection.
func (*MCPClientPool) GetOrCreate ¶
func (p *MCPClientPool) GetOrCreate(ctx context.Context, serverName string, srv config.MCPServer) (pooledMCPClient, error)
GetOrCreate returns a cached and already-initialized MCP client for the given server, creating and initializing one if none exists. The caller must NOT close the returned client — the pool owns its lifecycle.
func (*MCPClientPool) StopAll ¶
func (p *MCPClientPool) StopAll()
StopAll closes all pooled clients and resets the pool.
type RegisteredTool ¶
type RegisteredTool struct {
ID string
ServerName string
ToolName string
Description string
InputSchema map[string]interface{}
LastDiscovered time.Time
}
RegisteredTool represents a tool stored in the MCP tool registry.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages the MCP tool catalog in SQLite.
func NewRegistry ¶
NewRegistry creates a new Registry backed by the given database connection.
func (*Registry) DiscoverAll ¶
DiscoverAll iterates the configured MCP servers, calls ListTools on each, and upserts every discovered tool into mcp_tool_registry.
func (*Registry) GetAllTools ¶
func (r *Registry) GetAllTools(ctx context.Context) ([]RegisteredTool, error)
GetAllTools returns all registered tools.
func (*Registry) GetTool ¶
GetTool retrieves a tool by its composite ID ("server/tool") or by tool_name.
func (*Registry) GetToolsByIDs ¶
GetToolsByIDs returns tools matching the given IDs.
func (*Registry) SearchTools ¶
func (r *Registry) SearchTools(ctx context.Context, query string, maxResults int) ([]RegisteredTool, error)
SearchTools performs a keyword search over tool_name and description.
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats manages usage statistics and favorite computation.
func NewStats ¶
func NewStats(db *sql.DB, cfg FavoriteConfig) *Stats
NewStats creates a new Stats instance with the given database and configuration.
func (*Stats) GetFavorites ¶
func (s *Stats) GetFavorites(ctx context.Context) ([]RegisteredTool, error)
GetFavorites returns tools that meet the favorite criteria:
- called at least Threshold times in the last WindowDays days
- active within the last DecayDays days
- capped at MaxFavorites entries
It joins with mcp_tool_registry to return full RegisteredTool records.
func (*Stats) GetTopTools ¶
GetTopTools returns the tool IDs ordered by call count within the configured window.