MCP: better tool naming (#22812)

This commit is contained in:
andig 2025-08-06 22:52:02 +02:00 • committed by GitHub
parent 360c30a523
commit 1af26adbb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"slices"
"strings"
"github.com/evcc-io/evcc/util"
@ -79,14 +80,17 @@ func NewHandler(host http.Handler, baseUrl, basePath string) (http.Handler, erro
func nameFormat(log *util.Logger) func(name string) string {
return func(name string) string {
// move method to the end
parts := strings.Split(name, "_")
res := strings.Join(parts[:len(parts)-1], "-") + "-" + parts[len(parts)-1]
parts := strings.SplitN(name, "_", 2)
slices.Reverse(parts)
res = strings.TrimPrefix(res, "/")
res := strings.Join(parts, "-")
res = strings.ReplaceAll(res, "/", "-")
res = strings.ReplaceAll(res, "{", "_")
res = strings.ReplaceAll(res, "}", "")
res = strings.ReplaceAll(res, "-_", "_")
res = strings.ReplaceAll(res, "--", "-")
res = strings.TrimLeft(res, "/-_")
res = strings.ToLower(res)
// Claude Code has a 64 character limit for tool names