名称: morph-apply 描述: 通过 Morph Apply API 实现的快速文件编辑(10,500 令牌/秒,98% 准确率) 允许工具: [Bash, Read]
Morph 快速应用
快速、AI 驱动的文件编辑,使用 Morph Apply API。无需先读取整个文件即可编辑文件。处理速度达 10,500 令牌/秒,准确率为 98%。
何时使用
- 无需先读取整个文件的快速文件编辑
- 对文件的批量编辑(一次操作中多个更改)
- 当你知道要更改什么但文件很大时
- 大型文件,读取会消耗太多令牌
关键模式:代码标记
使用 // ... existing code ...(或语言适当的注释)来标记编辑位置:
# ... existing code ...
try:
result = process()
except Exception as e:
log.error(e)
# ... existing code ...
API 智能地将您的编辑放置在正确的位置。
用法
添加错误处理
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 ..."
添加日志记录
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 ..."
TypeScript 示例
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 ..."
参数
| 参数 | 描述 |
|---|---|
--file |
要编辑的文件路径(必需) |
--instruction |
变更的人类描述(必需) |
--code_edit |
带有标记的代码片段,显示编辑位置(必需) |
与 Claude 的编辑工具对比
| 工具 | 最佳用途 |
|---|---|
| morph-apply | 快速编辑,无需先读取文件,大型文件,批量编辑 |
| Claude Edit | 当文件已在上下文中时的小型精确编辑 |
使用 morph-apply 当:
- 文件不在上下文中,读取会很昂贵
- 文件非常大(>500 行)
- 一次进行多个相关编辑
- 你知道变更的上下文(函数名、类等)
使用 Claude Edit 当:
- 文件已从先前的读取中在上下文中
- 需要精确旧/新字符串匹配的非常精确编辑
- 小型文件(<200 行)
MCP 服务器要求
需要在 mcp_config.json 中包含 morph 服务器,并设置 MORPH_API_KEY。
性能
- 速度: 10,500 令牌/秒
- 准确性: 98% 正确放置
- 令牌节省: 无需先读取整个文件