MCPcopy
hub / github.com/mudler/LocalAI / registerModelTools

Function registerModelTools

pkg/mcp/localaitools/tools_models.go:9–113  ·  view source on GitHub ↗
(s *mcp.Server, client LocalAIClient, opts Options)

Source from the content-addressed store, hash-verified

7)
8
9func registerModelTools(s *mcp.Server, client LocalAIClient, opts Options) {
10 mcp.AddTool(s, &mcp.Tool{
11 Name: ToolGallerySearch,
12 Description: "Search configured galleries for installable models. Returns name, gallery, description, license and tags. Always run this before install_model.",
13 }, func(ctx context.Context, _ *mcp.CallToolRequest, args GallerySearchQuery) (*mcp.CallToolResult, any, error) {
14 hits, err := client.GallerySearch(ctx, args)
15 if err != nil {
16 return errorResult(err), nil, nil
17 }
18 return jsonResult(hits), nil, nil
19 })
20
21 mcp.AddTool(s, &mcp.Tool{
22 Name: ToolListInstalledModels,
23 Description: "List models currently installed on this LocalAI. Optional capability filter (chat, completion, embeddings, image, tts, transcript, rerank, vad).",
24 }, func(ctx context.Context, _ *mcp.CallToolRequest, args struct {
25 Capability Capability `json:"capability,omitempty" jsonschema:"Filter to models advertising this capability. One of: chat, completion, embeddings, image, tts, transcript, rerank, vad. Empty value = no filter."`
26 }) (*mcp.CallToolResult, any, error) {
27 models, err := client.ListInstalledModels(ctx, args.Capability)
28 if err != nil {
29 return errorResult(err), nil, nil
30 }
31 return jsonResult(models), nil, nil
32 })
33
34 mcp.AddTool(s, &mcp.Tool{
35 Name: ToolListGalleries,
36 Description: "List configured model galleries.",
37 }, func(ctx context.Context, _ *mcp.CallToolRequest, _ struct{}) (*mcp.CallToolResult, any, error) {
38 galleries, err := client.ListGalleries(ctx)
39 if err != nil {
40 return errorResult(err), nil, nil
41 }
42 return jsonResult(galleries), nil, nil
43 })
44
45 mcp.AddTool(s, &mcp.Tool{
46 Name: ToolGetJobStatus,
47 Description: "Poll the status of an install/delete/upgrade job by id. Returns processed, progress, message, and error fields.",
48 }, func(ctx context.Context, _ *mcp.CallToolRequest, args struct {
49 JobID string `json:"job_id" jsonschema:"The job id returned by install_model / install_backend / upgrade_backend / delete_model."`
50 }) (*mcp.CallToolResult, any, error) {
51 if args.JobID == "" {
52 return errorResultf("job_id is required"), nil, nil
53 }
54 status, err := client.GetJobStatus(ctx, args.JobID)
55 if err != nil {
56 return errorResult(err), nil, nil
57 }
58 if status == nil {
59 return errorResultf("no job with id %q", args.JobID), nil, nil
60 }
61 return jsonResult(status), nil, nil
62 })
63
64 if opts.DisableMutating {
65 return
66 }

Callers 1

NewServerFunction · 0.85

Calls 10

errorResultFunction · 0.85
jsonResultFunction · 0.85
errorResultfFunction · 0.85
GallerySearchMethod · 0.65
ListInstalledModelsMethod · 0.65
ListGalleriesMethod · 0.65
GetJobStatusMethod · 0.65
InstallModelMethod · 0.65
ImportModelURIMethod · 0.65
DeleteModelMethod · 0.65

Tested by

no test coverage detected