MCPcopy
hub / github.com/HKUDS/DeepCode / write_multiple_files

Function write_multiple_files

tools/code_implementation_server.py:475–680  ·  view source on GitHub ↗

Write multiple files in a single operation (for batch implementation) Args: file_implementations: JSON string mapping file paths to content, e.g., '{"file1.py": "content1", "file2.py": "content2"}' create_dirs: Whether to create directories if th

(
    file_implementations: str,
    create_dirs: bool = True,
    create_backup: bool = False,
    max_files: int = 5,
)

Source from the content-addressed store, hash-verified

473
474@mcp.tool()
475async def write_multiple_files(
476 file_implementations: str,
477 create_dirs: bool = True,
478 create_backup: bool = False,
479 max_files: int = 5,
480) -> str:
481 """
482 Write multiple files in a single operation (for batch implementation)
483
484 Args:
485 file_implementations: JSON string mapping file paths to content, e.g.,
486 '{"file1.py": "content1", "file2.py": "content2"}'
487 create_dirs: Whether to create directories if they don't exist
488 create_backup: Whether to create backup files if they already exist
489 max_files: Maximum number of files to write in one operation (default: 5)
490
491 Returns:
492 JSON string of operation results for all files
493 """
494 try:
495 # Parse the file implementations
496 try:
497 files_dict = json.loads(file_implementations)
498 except json.JSONDecodeError as e:
499 return json.dumps(
500 {
501 "status": "error",
502 "message": f"Invalid JSON format for file_implementations: {str(e)}",
503 "operation_type": "multi_file",
504 "timestamp": datetime.now().isoformat(),
505 },
506 ensure_ascii=False,
507 indent=2,
508 )
509
510 # Validate input
511 if not isinstance(files_dict, dict):
512 return json.dumps(
513 {
514 "status": "error",
515 "message": "file_implementations must be a JSON object mapping file paths to content",
516 "operation_type": "multi_file",
517 "timestamp": datetime.now().isoformat(),
518 },
519 ensure_ascii=False,
520 indent=2,
521 )
522
523 if len(files_dict) == 0:
524 return json.dumps(
525 {
526 "status": "error",
527 "message": "No files provided for writing",
528 "operation_type": "multi_file",
529 "timestamp": datetime.now().isoformat(),
530 },
531 ensure_ascii=False,
532 indent=2,

Callers

nothing calls this directly

Calls 2

validate_pathFunction · 0.85
log_operationFunction · 0.85

Tested by

no test coverage detected