EncodeToolID namespaces the given tool name with a prefix to identify tools injected by this library. Claude Code, for example, prefixes the tools it includes from defined MCP servers with the "mcp__" prefix. We have to namespace the tools we inject to prevent clashes. We stick to 5 prefix chars ("
(server, tool string)
| 106 | // - https://community.openai.com/t/function-call-description-max-length/529902 |
| 107 | // - https://github.com/anthropics/claude-code/issues/2326 |
| 108 | func EncodeToolID(server, tool string) string { |
| 109 | // strings.Builder writes to in-memory storage and never return errors. |
| 110 | var sb strings.Builder |
| 111 | _, _ = sb.WriteString(injectedToolPrefix) |
| 112 | _, _ = sb.WriteString(injectedToolDelimiter) |
| 113 | _, _ = sb.WriteString(server) |
| 114 | _, _ = sb.WriteString(injectedToolDelimiter) |
| 115 | _, _ = sb.WriteString(tool) |
| 116 | return sb.String() |
| 117 | } |
| 118 | |
| 119 | // FilterAllowedTools filters tools based on the given allow/denylists. |
| 120 | // Filtering acts on tool names, and uses tool IDs for tracking. |
no test coverage detected