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

Function BuildWriteArguments

internal/sessions/session_injection.go:224–276  ·  view source on GitHub ↗

BuildWriteArguments constructs the arguments map for a file-write tool invocation.

(sess *Session, toolName, filePath, content string)

Source from the content-addressed store, hash-verified

222
223// BuildWriteArguments constructs the arguments map for a file-write tool invocation.
224func BuildWriteArguments(sess *Session, toolName, filePath, content string) map[string]any {
225 if sess == nil {
226 return map[string]any{"file_path": filePath, "content": content}
227 }
228
229 schema := findToolSchema(sess, toolName)
230 if schema != nil {
231 if props, ok := schema["properties"].(map[string]any); ok {
232 pathKey := ""
233 contentKey := ""
234
235 // Find path parameter.
236 for _, key := range []string{"file_path", "path", "file", "filename"} {
237 if _, exists := props[key]; exists {
238 pathKey = key
239 break
240 }
241 }
242 // Find content parameter.
243 for _, key := range []string{"content", "data", "text", "file_text"} {
244 if _, exists := props[key]; exists {
245 contentKey = key
246 break
247 }
248 }
249
250 if pathKey != "" && contentKey != "" {
251 return map[string]any{pathKey: filePath, contentKey: content}
252 }
253
254 // Fall back: assign first two string properties.
255 if pathKey == "" || contentKey == "" {
256 for key, propRaw := range props {
257 if prop, ok := propRaw.(map[string]any); ok {
258 if t, _ := prop["type"].(string); t == "string" {
259 if pathKey == "" {
260 pathKey = key
261 } else if contentKey == "" && key != pathKey {
262 contentKey = key
263 }
264 }
265 }
266 }
267 }
268
269 if pathKey != "" && contentKey != "" {
270 return map[string]any{pathKey: filePath, contentKey: content}
271 }
272 }
273 }
274
275 return map[string]any{"file_path": filePath, "content": content}
276}
277
278// findToolSchema returns the schema map for a named tool, or nil.
279func findToolSchema(sess *Session, toolName string) map[string]any {

Calls 1

findToolSchemaFunction · 0.85