morph-apply
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMorph Fast Apply
Morph Fast Apply
Fast, AI-powered file editing using the Morph Apply API. Edit files without reading them first. Processes at 10,500 tokens/sec with 98% accuracy.
借助Morph Apply API实现由AI驱动的快速文件编辑。无需先阅读文件即可进行编辑,处理速度达每秒10500个token,准确率98%。
When to Use
适用场景
- Fast file edits without reading entire file first
- Batch edits to a file (multiple changes in one operation)
- When you know what to change but file is large
- Large files where reading would consume too many tokens
- 无需先阅读整个文件即可快速编辑
- 对文件进行批量编辑(一次操作完成多处修改)
- 明确修改内容但文件体积较大时
- 文件过大,读取会消耗大量token时
Key Pattern: Code Markers
核心模式:代码标记
Use (or language-appropriate comments) to mark where edits go:
// ... existing code ...python
undefined使用(或对应语言的注释格式)标记编辑位置:
// ... existing code ...python
undefined... existing code ...
... existing code ...
try:
result = process()
except Exception as e:
log.error(e)
try:
result = process()
except Exception as e:
log.error(e)
... existing code ...
... existing code ...
The API intelligently places your edit in the right location.
API会智能地将你的编辑内容放置在正确位置。Usage
使用方法
Add error handling
添加错误处理
bash
uv run python -m runtime.harness scripts/mcp/morph_apply.py \
--file "src/auth.py" \
--instruction "Add error handling to login function" \
--code_edit "# ... existing code ...
try:
user = authenticate(credentials)
except AuthError as e:
log.error(f'Auth failed: {e}')
raisebash
uv run python -m runtime.harness scripts/mcp/morph_apply.py \
--file "src/auth.py" \
--instruction "Add error handling to login function" \
--code_edit "# ... existing code ...
try:
user = authenticate(credentials)
except AuthError as e:
log.error(f'Auth failed: {e}')
raise... existing code ..."
... existing code ..."
undefinedundefinedAdd logging
添加日志记录
bash
uv run python -m runtime.harness scripts/mcp/morph_apply.py \
--file "src/api.py" \
--instruction "Add debug logging" \
--code_edit "# ... existing code ...
logger.debug(f'Processing request: {request.id}')bash
uv run python -m runtime.harness scripts/mcp/morph_apply.py \
--file "src/api.py" \
--instruction "Add debug logging" \
--code_edit "# ... existing code ...
logger.debug(f'Processing request: {request.id}')... existing code ..."
... existing code ..."
undefinedundefinedTypeScript example
TypeScript示例
bash
uv run python -m runtime.harness scripts/mcp/morph_apply.py \
--file "src/types.ts" \
--instruction "Add user validation" \
--code_edit "// ... existing code ...
if (!user) throw new Error('User not found');
if (!user.isActive) throw new Error('User inactive');
// ... existing code ..."bash
uv run python -m runtime.harness scripts/mcp/morph_apply.py \
--file "src/types.ts" \
--instruction "Add user validation" \
--code_edit "// ... existing code ...
if (!user) throw new Error('User not found');
if (!user.isActive) throw new Error('User inactive');
// ... existing code ..."Parameters
参数说明
| Parameter | Description |
|---|---|
| File path to edit (required) |
| Human description of the change (required) |
| Code snippet with markers showing where to place edit (required) |
| 参数 | 描述 |
|---|---|
| 待编辑的文件路径(必填) |
| 用自然语言描述修改需求(必填) |
| 包含标记的代码片段,用于指定编辑位置(必填) |
vs Claude's Edit Tool
与Claude编辑工具对比
| Tool | Best For |
|---|---|
| morph-apply | Fast edits, don't need to read file first, large files, batch edits |
| Claude Edit | Small precise edits when file is already in context |
Use morph-apply when:
- File is not in context and reading it would be expensive
- File is very large (>500 lines)
- Making multiple related edits at once
- You know the context of the change (function name, class, etc.)
Use Claude Edit when:
- File is already in context from prior Read
- Very precise edits requiring exact old/new string matching
- Small files (<200 lines)
| 工具 | 最佳适用场景 |
|---|---|
| morph-apply | 快速编辑、无需先读取文件、大文件编辑、批量编辑 |
| Claude Edit | 文件已在上下文环境中时的小型精准编辑 |
优先使用morph-apply的场景:
- 文件不在当前上下文,读取会产生较高token消耗
- 文件体积非常大(超过500行)
- 一次性进行多处相关修改
- 清楚修改的上下文(如函数名、类名等)
优先使用Claude Edit的场景:
- 文件已通过之前的Read操作处于上下文环境中
- 需要精确匹配新旧字符串的极精准编辑
- 小型文件(少于200行)
MCP Server Required
需要MCP服务器
Requires server in mcp_config.json with .
morphMORPH_API_KEY需要在mcp_config.json中配置带有的服务器。
MORPH_API_KEYmorphPerformance
性能表现
- Speed: 10,500 tokens/sec
- Accuracy: 98% correct placement
- Token savings: Don't need to read entire file first
- 速度:每秒10500个token
- 准确率:98%的编辑位置正确率
- token节省:无需先读取整个文件