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)
| 241 | // strconv.Unquote so embedded escapes are decoded correctly; the raw |
| 242 | // literal value is returned as a best-effort fallback if unquoting fails. |
| 243 | func 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 | } |
no test coverage detected