MCPcopy Index your code
hub / github.com/github/github-mcp-server / extractToolName

Function extractToolName

pkg/toolvalidation/readonlyhint.go:243–256  ·  view source on GitHub ↗

extractToolName returns the literal value of the Name field of an mcp.Tool composite literal, or empty string if the value is not a basic string literal. Interpreted ("...") and raw (`...`) string literals are handled via strconv.Unquote so embedded escapes are decoded correctly; the raw literal val

(cl *ast.CompositeLit)

Source from the content-addressed store, hash-verified

241// strconv.Unquote so embedded escapes are decoded correctly; the raw
242// literal value is returned as a best-effort fallback if unquoting fails.
243func extractToolName(cl *ast.CompositeLit) string {
244 v := findFieldValue(cl, "Name")
245 if v == nil {
246 return ""
247 }
248 bl, ok := v.(*ast.BasicLit)
249 if !ok || bl.Kind != token.STRING {
250 return ""
251 }
252 if unq, err := strconv.Unquote(bl.Value); err == nil {
253 return unq
254 }
255 return bl.Value
256}

Callers 1

checkToolLiteralFunction · 0.85

Calls 1

findFieldValueFunction · 0.85

Tested by

no test coverage detected