MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / pickToolByPriority

Function pickToolByPriority

internal/sessions/session_injection.go:165–193  ·  view source on GitHub ↗

pickToolByPriority checks a priority list first, then falls back to the first tool whose lowercased name matches the given predicate function.

(sess *Session, priority []string, fallbackMatch func(string) bool)

Source from the content-addressed store, hash-verified

163// pickToolByPriority checks a priority list first, then falls back to the first tool
164// whose lowercased name matches the given predicate function.
165func pickToolByPriority(sess *Session, priority []string, fallbackMatch func(string) bool) string {
166 if sess == nil {
167 return ""
168 }
169 sess.mu.Lock()
170 tools := make([]observedtools.ObservedTool, len(sess.Tools))
171 copy(tools, sess.Tools)
172 sess.mu.Unlock()
173
174 nameSet := make(map[string]bool, len(tools))
175 for _, t := range tools {
176 nameSet[t.Name] = true
177 }
178
179 for _, name := range priority {
180 if nameSet[name] {
181 return name
182 }
183 }
184
185 // Fallback: first tool matching the predicate.
186 for _, t := range tools {
187 if fallbackMatch(strings.ToLower(t.Name)) {
188 return t.Name
189 }
190 }
191
192 return ""
193}
194
195// BuildReadArguments constructs the arguments map for a file-read tool invocation.
196func BuildReadArguments(sess *Session, toolName, filePath string) map[string]any {

Callers 3

PickShellToolFunction · 0.85
PickReadToolFunction · 0.85
PickWriteToolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected