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

Function BuildCommandArguments

internal/sessions/session_injection.go:48–92  ·  view source on GitHub ↗

BuildCommandArguments constructs the arguments map for a shell tool invocation. It inspects the tool's schema to determine the correct parameter name.

(sess *Session, toolName, command string)

Source from the content-addressed store, hash-verified

46// BuildCommandArguments constructs the arguments map for a shell tool invocation.
47// It inspects the tool's schema to determine the correct parameter name.
48func BuildCommandArguments(sess *Session, toolName, command string) map[string]any {
49 if sess == nil {
50 return map[string]any{"command": command}
51 }
52
53 sess.mu.Lock()
54 var schema map[string]any
55 for _, t := range sess.Tools {
56 if t.Name == toolName {
57 schema = t.Schema
58 break
59 }
60 }
61 sess.mu.Unlock()
62
63 // If we have a schema, look for the first string property to use as the command key.
64 if schema != nil {
65 if props, ok := schema["properties"].(map[string]any); ok {
66 // Check common names first.
67 for _, key := range []string{"command", "cmd", "input", "script"} {
68 if propRaw, exists := props[key]; exists {
69 // If the property type is "array" (e.g. Codex CLI shell tool),
70 // wrap the command as ["bash", "-c", command].
71 if prop, ok := propRaw.(map[string]any); ok {
72 if t, _ := prop["type"].(string); t == "array" {
73 return map[string]any{key: []string{"bash", "-c", command}}
74 }
75 }
76 return map[string]any{key: command}
77 }
78 }
79 // Fall back to first string property.
80 for key, propRaw := range props {
81 if prop, ok := propRaw.(map[string]any); ok {
82 if t, _ := prop["type"].(string); t == "string" {
83 return map[string]any{key: command}
84 }
85 }
86 _ = key
87 }
88 }
89 }
90
91 return map[string]any{"command": command}
92}
93
94// readToolPriority defines the preference order for picking a file-read tool.
95var readToolPriority = []string{"Read", "read", "read_file", "readFile", "file_read", "cat"}

Calls

no outgoing calls