Skip to content

Commit 6d21005

Browse files
author
whllwsyh
committed
feat(mcp): harden HTTP API client and routes
Enhances the MCP HTTP API with improved client error handling, additional routes for tool discovery, and test coverage updates. - Improved error handling in pkg/mcp/localaitools/httpapi/client.go - Additional routes for tool discovery in routes.go - Updated test coverage in coverage_test.go Part of the split PR series discussed in mudler#10317.
1 parent 4bb592c commit 6d21005

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

pkg/mcp/localaitools/coverage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var toolToHTTPRoute = map[string]string{
3030
ToolListInstalledModels: "GET / (welcome JSON, ModelsConfig field)",
3131
ToolListGalleries: "GET /models/galleries",
3232
ToolGetJobStatus: "GET /models/jobs/:uuid",
33-
ToolGetModelConfig: "(none) — no JSON-only REST yet; httpapi.Client returns a documented stub",
33+
ToolGetModelConfig: "GET /api/models/config-yaml/:name",
3434
ToolListBackends: "GET /backends",
3535
ToolListKnownBackends: "GET /backends/known",
3636
ToolSystemInfo: "GET / (welcome JSON)",

pkg/mcp/localaitools/httpapi/client.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,19 @@ func (c *Client) GetJobStatus(ctx context.Context, jobID string) (*localaitools.
228228
}, nil
229229
}
230230

231-
// GetModelConfig is intentionally a stub for the HTTP client: LocalAI's
232-
// /models/edit/:name endpoint returns rendered HTML, not JSON, so the
233-
// standalone CLI's `get_model_config` tool surfaces a clear error to the
234-
// LLM. Tracked under the localai-assistant follow-ups (see
235-
// .agents/localai-assistant-mcp.md) — once a JSON-only
236-
// GET /api/models/config-yaml/:name endpoint lands on the server, this
237-
// method calls it and the stub goes away.
238-
//
239-
// FIXME(localai-assistant): wire to a JSON read-back endpoint.
240-
func (c *Client) GetModelConfig(_ context.Context, _ string) (*localaitools.ModelConfigView, error) {
241-
return nil, errors.New("get_model_config over HTTP not yet supported by this client; use the in-process inproc client or REST /models/edit/{name}")
231+
func (c *Client) GetModelConfig(ctx context.Context, name string) (*localaitools.ModelConfigView, error) {
232+
if name == "" {
233+
return nil, errors.New("name is required")
234+
}
235+
var raw struct {
236+
Name string `json:"name"`
237+
YAML string `json:"yaml"`
238+
JSON map[string]any `json:"json"`
239+
}
240+
if err := c.do(ctx, http.MethodGet, routeModelConfigYAML(name), nil, &raw); err != nil {
241+
return nil, err
242+
}
243+
return &localaitools.ModelConfigView{Name: raw.Name, YAML: raw.YAML, JSON: raw.JSON}, nil
242244
}
243245

244246
// ---- Models / gallery (write) ----

pkg/mcp/localaitools/httpapi/routes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const (
3434
routeRouterDecisions = "/api/router/decisions"
3535
)
3636

37+
func routeModelConfigYAML(name string) string {
38+
return "/api/models/config-yaml/" + url.PathEscape(name)
39+
}
40+
3741
func routePIIPatternByID(id string) string {
3842
return "/api/pii/patterns/" + url.PathEscape(id)
3943
}

0 commit comments

Comments
 (0)