MCP: better tool naming (#22812)
This commit is contained in:
parent
360c30a523
commit
1af26adbb1
1 changed files with 7 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue