mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-01 04:28:59 -04:00
Add a routing middleware stack and a cloud-proxy backend. * cloud-proxy: a Go gRPC backend that forwards OpenAI- and Anthropic-shaped chat requests to upstream providers, with an optional translate mode (OpenAI request -> Anthropic /v1/messages -> OpenAI response) and full tool-calling support. * routing: admission control, content-aware model routing (embedding cache + classifier + rerank + Arch-Router score), PII detection/redaction (regex + NER) with streaming filter and OpenAI/Anthropic adapters, and a per-user/per-key billing recorder backed by GORM or in-memory storage. * middleware: UsageMiddleware records usage via the billing recorder, plus admission, route-model, usage-stamp and trace middlewares. * observability: BackendTrace ring buffer stores full request bodies (capped), MITM proxy emits structured trace events, and router classifier decisions surface at /api/router/decide. * gallery: Arch-Router-1.5B (Q4_K_M and Q8_0). * UI: cloud-proxy model-editor fields, classifier system-prompt and score-normalization config, and a Traces page rendering request bodies. Assisted-by: claude-code:claude-opus-4-7 [Read] [Edit] [Bash] Signed-off-by: Richard Palethorpe <io@richiejp.com>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package localaitools
|
|
|
|
import (
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
|
|
"github.com/mudler/LocalAI/internal"
|
|
)
|
|
|
|
// Options control which tools the server registers and how the embedded
|
|
// skill prompts are surfaced.
|
|
type Options struct {
|
|
// DisableMutating omits all tools that change server state. Used by the
|
|
// "--read-only" flavour of the standalone stdio CLI.
|
|
DisableMutating bool
|
|
|
|
// ServerName overrides the MCP server's advertised Implementation.Name.
|
|
// Defaults to "localai-admin".
|
|
ServerName string
|
|
|
|
// ServerVersion overrides the advertised version. Defaults to the linked
|
|
// internal.PrintableVersion().
|
|
ServerVersion string
|
|
}
|
|
|
|
// NewServer builds an MCP server that exposes LocalAI's admin surface as
|
|
// tools, backed by the supplied LocalAIClient. The same server type is used
|
|
// in-process (paired in-memory transport) and out-of-process (stdio).
|
|
func NewServer(client LocalAIClient, opts Options) *mcp.Server {
|
|
name := opts.ServerName
|
|
if name == "" {
|
|
name = DefaultServerName
|
|
}
|
|
version := opts.ServerVersion
|
|
if version == "" {
|
|
version = internal.PrintableVersion()
|
|
}
|
|
|
|
srv := mcp.NewServer(&mcp.Implementation{
|
|
Name: name,
|
|
Version: version,
|
|
}, &mcp.ServerOptions{
|
|
Instructions: SystemPrompt(opts),
|
|
})
|
|
|
|
registerModelTools(srv, client, opts)
|
|
registerBackendTools(srv, client, opts)
|
|
registerConfigTools(srv, client, opts)
|
|
registerSystemTools(srv, client, opts)
|
|
registerStateTools(srv, client, opts)
|
|
registerBrandingTools(srv, client, opts)
|
|
registerUsageTools(srv, client, opts)
|
|
registerPIITools(srv, client, opts)
|
|
registerMiddlewareTools(srv, client, opts)
|
|
|
|
return srv
|
|
}
|