Always read files before editing to understand the structure:
Copy
Ask AI
{ "name": "read_file", "description": "Read the contents of a file to understand its structure before making edits", "parameters": { "properties": { "target_file": { "type": "string", "description": "The path of the file to read" }, "start_line_one_indexed": { "type": "integer", "description": "Start line number (1-indexed)" }, "end_line_one_indexed_inclusive": { "type": "integer", "description": "End line number (1-indexed, inclusive)" }, "explanation": { "type": "string", "description": "Why you're reading this file" } }, "required": ["target_file", "explanation"] }}
Best practice: Read the relevant sections first, then edit with proper context.
codebase_search: Find What to Edit
Semantic search to locate relevant code:
Copy
Ask AI
{ "name": "codebase_search", "description": "Find snippets of code from the codebase most relevant to the search query", "parameters": { "properties": { "query": { "type": "string", "description": "The search query to find relevant code" }, "target_directories": { "type": "array", "items": {"type": "string"}, "description": "Optional: limit search scope to specific directories" }, "explanation": { "type": "string", "description": "Why you're searching for this" } }, "required": ["query", "explanation"] }}
Best practice: Search first to understand the codebase, then read specific files.
grep_search: Find Exact Matches
When you need exact text or pattern matches:
Copy
Ask AI
{ "name": "grep_search", "description": "Fast text-based regex search that finds exact pattern matches within files", "parameters": { "properties": { "query": { "type": "string", "description": "The regex pattern to search for" }, "include_pattern": { "type": "string", "description": "File types to include (e.g. '*.ts')" }, "explanation": { "type": "string", "description": "Why you're searching for this pattern" } }, "required": ["query", "explanation"] }}
Best practice: Use for finding function names, imports, or specific strings.
list_dir: Explore Directory Structure
Navigate and understand the codebase structure:
Copy
Ask AI
{ "name": "list_dir", "description": "List the contents of a directory to understand project structure", "parameters": { "properties": { "relative_workspace_path": { "type": "string", "description": "Path to list contents of, relative to the workspace root" }, "explanation": { "type": "string", "description": "Why you're listing this directory" } }, "required": ["relative_workspace_path", "explanation"] }}
Best practice: Use to explore unknown codebases or find related files before editing.
Morph is trained to be robust to poor quality update snippets, but you should still follow these steps to ensure the best quality.
When tools fail, follow these steps:
Check file permissions: Ensure the target file is writable
Verify file path: Confirm the file exists and path is correct
Review syntax: Check that your edit snippet follows the // ... existing code ... pattern
Retry with context: Read the file again and provide more context around your changes
Simplify changes: Break complex edits into smaller, focused changes
For complex refactoring across multiple files, consider using multiple
edit_file calls in sequence. For failed edits, read the file again and
provide more context around your changes.