From 1af26adbb1e91a2d3edb8ee4333031275818add9 Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 6 Aug 2025 22:52:02 +0200 Subject: [PATCH] MCP: better tool naming (#22812) --- server/mcp/mcp.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/mcp/mcp.go b/server/mcp/mcp.go index fbc5fc9ee..13110db0c 100644 --- a/server/mcp/mcp.go +++ b/server/mcp/mcp.go @@ -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