admin

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeStatic

func ServeStatic(w http.ResponseWriter, r *http.Request)

ServeStatic serves static files from the embedded assets

Types

type Admin

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

Admin handles admin UI requests

func New

func New(config *types.Config, getStats func() *Stats, getProviders func() []ProviderInfo, getMCPServers func() []MCPServerInfo, getMCPTools func(string) ([]ToolInfo, error), getMCPResources func(string) ([]ResourceInfo, error), getMCPPrompts func(string) ([]PromptInfo, error), getModels func() []ModelInfo, mcpStorage storage.MCPStorage, mcpStorageWritable bool, onMCPServerChange func(), onMCPCacheRefresh func()) *Admin

New creates a new Admin handler

func (*Admin) ChatPageHandler added in v0.5.0

func (a *Admin) ChatPageHandler() http.HandlerFunc

ChatPageHandler returns the HTTP handler for /chat. Uses requirePageAuth (same admin session as every other page). One password, one role.

func (*Admin) Enabled

func (a *Admin) Enabled() bool

Enabled returns true if admin UI is enabled (admin password set).

func (*Admin) HandleCreateMCPServer

func (a *Admin) HandleCreateMCPServer(w http.ResponseWriter, r *http.Request)

HandleCreateMCPServer creates a new MCP server

func (*Admin) HandleCreateProvider added in v0.5.0

func (a *Admin) HandleCreateProvider(w http.ResponseWriter, r *http.Request)

HandleCreateProvider creates a new provider in storage.

func (*Admin) HandleDashboard

func (a *Admin) HandleDashboard(w http.ResponseWriter, r *http.Request)

HandleDashboard renders the dashboard page

func (*Admin) HandleDeleteMCPServer

func (a *Admin) HandleDeleteMCPServer(w http.ResponseWriter, r *http.Request)

HandleDeleteMCPServer deletes an MCP server

func (*Admin) HandleDeleteProvider added in v0.5.0

func (a *Admin) HandleDeleteProvider(w http.ResponseWriter, r *http.Request)

HandleDeleteProvider deletes a stored provider.

func (*Admin) HandleGetMCPServer

func (a *Admin) HandleGetMCPServer(w http.ResponseWriter, r *http.Request)

HandleGetMCPServer returns a single MCP server

func (*Admin) HandleGetMCPServerPrompts added in v0.5.0

func (a *Admin) HandleGetMCPServerPrompts(w http.ResponseWriter, r *http.Request)

HandleGetMCPServerPrompts returns prompts for an MCP server. Like resources, prompts are read-only in the UI.

func (*Admin) HandleGetMCPServerResources added in v0.5.0

func (a *Admin) HandleGetMCPServerResources(w http.ResponseWriter, r *http.Request)

HandleGetMCPServerResources returns resources (static + templates) for an MCP server. Resources are read-only in the UI — there is no storage-level toggle the way there is for tools.

func (*Admin) HandleGetMCPServerTools

func (a *Admin) HandleGetMCPServerTools(w http.ResponseWriter, r *http.Request)

HandleGetMCPServerTools returns tools for an MCP server

func (*Admin) HandleGetProvider added in v0.5.0

func (a *Admin) HandleGetProvider(w http.ResponseWriter, r *http.Request)

HandleGetProvider returns a single provider's config. Checks storage first, then falls back to static config from runtime info.

func (*Admin) HandleListMCPServers

func (a *Admin) HandleListMCPServers(w http.ResponseWriter, r *http.Request)

func (*Admin) HandleListProviders added in v0.5.0

func (a *Admin) HandleListProviders(w http.ResponseWriter, r *http.Request)

HandleListProviders returns all providers (static + stored) for the management page. Static providers are read-only; stored providers support full CRUD.

func (*Admin) HandleLogin

func (a *Admin) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin handles login requests. One password, one session type.

func (*Admin) HandleLoginPage

func (a *Admin) HandleLoginPage(w http.ResponseWriter, r *http.Request)

HandleLoginPage renders the login page

func (*Admin) HandleLogout

func (a *Admin) HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout invalidates the session

func (*Admin) HandleMCPServersPage

func (a *Admin) HandleMCPServersPage(w http.ResponseWriter, r *http.Request)

HandleMCPServersPage renders the MCP servers page.

func (*Admin) HandleMCPStorageStatus

func (a *Admin) HandleMCPStorageStatus(w http.ResponseWriter, r *http.Request)

HandleMCPStorageStatus returns whether MCP server storage is writable

func (*Admin) HandleModels

func (a *Admin) HandleModels(w http.ResponseWriter, r *http.Request)

HandleModels returns model information

func (*Admin) HandleModelsPage

func (a *Admin) HandleModelsPage(w http.ResponseWriter, r *http.Request)

HandleModelsPage renders the models page

func (*Admin) HandleOAuthCallback

func (a *Admin) HandleOAuthCallback(w http.ResponseWriter, r *http.Request)

HandleOAuthCallback handles the redirect back from the OAuth2 server. GET /admin/oauth/callback

func (*Admin) HandleOAuthStart

func (a *Admin) HandleOAuthStart(w http.ResponseWriter, r *http.Request)

HandleOAuthStart initiates the PKCE flow for a new OAuth2 MCP server. POST /admin/api/mcp-servers/oauth/start

func (*Admin) HandleProviders

func (a *Admin) HandleProviders(w http.ResponseWriter, r *http.Request)

HandleProviders returns provider information

func (*Admin) HandleProvidersPage added in v0.5.0

func (a *Admin) HandleProvidersPage(w http.ResponseWriter, r *http.Request)

HandleProvidersPage renders the providers management page.

func (*Admin) HandleRefreshMCPCache added in v0.1.5

func (a *Admin) HandleRefreshMCPCache(w http.ResponseWriter, r *http.Request)

HandleRefreshMCPCache refreshes the tool cache from all remote MCP servers

func (*Admin) HandleStats

func (a *Admin) HandleStats(w http.ResponseWriter, r *http.Request)

HandleStats returns dashboard statistics

func (*Admin) HandleToggleMCPServer

func (a *Admin) HandleToggleMCPServer(w http.ResponseWriter, r *http.Request)

HandleToggleMCPServer toggles an MCP server's enabled state

func (*Admin) HandleToggleMCPServerTool

func (a *Admin) HandleToggleMCPServerTool(w http.ResponseWriter, r *http.Request)

HandleToggleMCPServerTool toggles a tool's enabled state (lazy write)

func (*Admin) HandleUpdateMCPServer

func (a *Admin) HandleUpdateMCPServer(w http.ResponseWriter, r *http.Request)

HandleUpdateMCPServer updates an MCP server

func (*Admin) HandleUpdateProvider added in v0.5.0

func (a *Admin) HandleUpdateProvider(w http.ResponseWriter, r *http.Request)

HandleUpdateProvider updates a stored provider.

func (*Admin) RegisterRoutes

func (a *Admin) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers admin routes on the given mux

func (*Admin) RequireAuthMiddleware added in v0.5.0

func (a *Admin) RequireAuthMiddleware() func(http.Handler) http.Handler

RequireAuthMiddleware returns an http.Handler middleware that checks for a valid session. Used by webchat to gate its API + asset routes with the same admin session as the rest of the app. Returns nil if no admin password is set (open access — for local dev behind a reverse proxy).

func (*Admin) Serve404 added in v0.1.2

func (a *Admin) Serve404(w http.ResponseWriter, r *http.Request)

Serve404 renders the 404 page

func (*Admin) SetProviderStorage added in v0.5.0

func (a *Admin) SetProviderStorage(ps storage.ProviderStorage, writable bool, onChange func())

SetProviderStorage wires dynamic provider management. Called after New but before RegisterRoutes. If ps is nil, provider management is disabled (config-file providers are still shown read-only).

type MCPServerInfo

type MCPServerInfo struct {
	Namespace      string   `json:"namespace"`
	URL            string   `json:"url"`
	AuthType       string   `json:"auth_type,omitempty"`
	Enabled        bool     `json:"enabled"`
	ToolVisibility string   `json:"tool_visibility"`
	ToolAllowlist  []string `json:"tool_allowlist,omitempty"`
	ToolDenylist   []string `json:"tool_denylist,omitempty"`
	StaticServer   bool     `json:"static_server"`
	RemoteSearch   bool     `json:"remote_search"`
}

MCPServerInfo represents MCP server information for the UI

type ModelInfo

type ModelInfo struct {
	ID        string   `json:"id"`
	Providers []string `json:"providers"`
}

ModelInfo represents a model and its providers for the UI

type PromptArgument added in v0.5.0

type PromptArgument struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required"`
}

PromptArgument describes one argument a prompt accepts.

type PromptInfo added in v0.5.0

type PromptInfo struct {
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Arguments   []PromptArgument `json:"arguments,omitempty"`
}

PromptInfo represents a prompt exposed by an MCP server. Arguments is the (possibly empty) list of named arguments the prompt accepts.

type ProviderDetail added in v0.5.0

type ProviderDetail struct {
	Name           string              `json:"name"`
	Provider       string              `json:"provider"`
	BaseURL        string              `json:"base_url,omitempty"`
	Enabled        bool                `json:"enabled"`
	Healthy        bool                `json:"healthy"`
	Weight         float64             `json:"weight"`
	ModelCount     int                 `json:"model_count"`
	Models         []string            `json:"models,omitempty"`
	ModelAllowlist []string            `json:"model_allowlist,omitempty"`
	Tags           []string            `json:"tags,omitempty"`
	ModelDenylist  []string            `json:"model_denylist,omitempty"`
	ModelAliases   map[string]string   `json:"model_aliases,omitempty"`
	ModelTags      map[string][]string `json:"model_tags,omitempty"`
	StaticProvider bool                `json:"static_provider"`
}

ProviderDetail is the full provider config returned by the management API. For static (config-file) providers, only the display fields are populated. For stored providers, all editable fields are included.

type ProviderInfo

type ProviderInfo struct {
	Name           string  `json:"name"`
	Type           string  `json:"type"`
	Healthy        bool    `json:"healthy"`
	ModelCount     int     `json:"model_count"`
	Weight         float64 `json:"weight"`
	StaticProvider bool    `json:"static_provider"` // true = from config file, false = from UI/storage
}

ProviderInfo represents provider information for the UI

type ResourceInfo added in v0.5.0

type ResourceInfo struct {
	URI         string `json:"uri"`
	Template    bool   `json:"template"`
	Name        string `json:"name"`
	Description string `json:"description"`
	MimeType    string `json:"mime_type,omitempty"`
}

ResourceInfo represents a resource (static or template) exposed by an MCP server. Templates carry a URITemplate with {var} placeholders; static resources carry a concrete URI. Both are shown read-only in the UI — the router has no per-resource enable/disable toggle the way it does for tools.

type Session

type Session struct {
	Token     string
	CreatedAt time.Time
}

Session represents an authenticated session.

type Stats

type Stats struct {
	Providers      int `json:"providers"`
	Models         int `json:"models"`
	MCPServers     int `json:"mcp_servers"`
	ActiveRequests int `json:"active_requests"`
}

Stats represents dashboard statistics

type TemplateData

type TemplateData struct {
	CSSFile string
	JSFile  string
	Prefix  string
}

TemplateData contains data passed to templates

type TemplateRenderer

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

TemplateRenderer handles HTML template rendering

func NewTemplateRenderer

func NewTemplateRenderer(fsys fs.FS) *TemplateRenderer

NewTemplateRenderer creates a new template renderer

func (*TemplateRenderer) Render

func (r *TemplateRenderer) Render(w io.Writer, name string, data *TemplateData) error

Render renders a template with the given data

type ToolInfo

type ToolInfo struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"input_schema"`
	Enabled     bool                   `json:"enabled"`
}

ToolInfo represents tool information for the UI

Jump to

Keyboard shortcuts

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