Opencode Morph Fast Apply 标志

Opencode Morph Fast Apply

社区
JRedeker

OpenCode plugin for Morph Fast Apply - 10x faster code editing with lazy edit markers. No MCP server needed.

发布者JRedeker
代码仓库opencode-morph-fast-apply
语言TypeScript
复刻数
7
星标数
170
可用工具
0
传输类型stdio
许可协议MIT
链接
  • 将工具接入 AI 工作流

    Opencode Morph Fast Apply 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 170 个 Star 和 7 个 Fork。

opencode-morph-fast-apply

CI GitHub release License: MIT

OpenCode plugin for Morph Fast Apply - 10x faster code editing with lazy edit markers.

Features

  • 10,500+ tokens/sec code editing via Morph's Fast Apply API
  • Lazy edit markers (// ... existing code ...) - no exact string matching needed
  • 98% accuracy with intelligent code merging
  • Pre-flight validation - prevents accidental file deletions when markers are missing
  • Unified diff output with context for easy review
  • Custom TUI display - branded titles like Morph: src/file.ts +15/-3 (450ms)
  • OpenCode V2 native - registers through the V2 plugin API; edits are confined to the session's directory per invocation
  • Graceful fallback - suggests native edit tool on API failure

Note: This is an OpenCode plugin that wraps Morph's Fast Apply API. For the official Morph MCP server (which includes WarpGrep search), see @morphllm/morphmcp. This plugin uses morph_edit as the tool name to avoid conflicts if you have both installed.

Installation

OpenCode version support

OpenCode versionSupportNotes
V2 (2.x)YesLoads through the V2 plugin API (setup). Edits are confined to the session's directory, resolved per invocation.
V1 1.18.29+YesLoads through the V1 default.server adapter with the same morph_edit behavior.
V1 older than 1.18.29NoThese loaders do not read the dual-entry default export, so the plugin silently does not load. Upgrade OpenCode or pin an older plugin release.

1. Add the plugin and always-on instruction to your OpenCode config

Preferred when your setup syncs packaged instructions into ~/.config/opencode/instructions/:

OpenCode V2 (2.x) reads the plural plugins key. Add to your global config (~/.config/opencode/opencode.json):

json
{
  "instructions": ["~/.config/opencode/instructions/morph-tools.md"],
  "plugins": ["github:JRedeker/opencode-morph-fast-apply"]
}

Pin only a release that contains the V2 entrypoint. Version v1.11.0 contains the V1-only entrypoint and cannot load on V2.

OpenCode V1 (1.18.29+) reads the singular plugin key. Do not use plugin on V2 — V2 ignores it and the plugin will not load:

json
{
  "instructions": ["~/.config/opencode/instructions/morph-tools.md"],
  "plugin": ["github:JRedeker/opencode-morph-fast-apply"]
}

To keep the existing V1 release on OpenCode V1, pin its tag:

json
{
  "plugin": ["github:JRedeker/opencode-morph-fast-apply#v1.11.0"]
}

Recommended setup summary:

  • Prefer the stable synced instruction path: ~/.config/opencode/instructions/morph-tools.md
  • Use the packaged node_modules/.../morph-tools.md path only when your setup does not sync instructions
  • Keep the routing policy in the OpenCode instructions array, not a skill

If you are installing the plugin directly and do not sync packaged instructions into ~/.config/opencode/instructions/, you can point OpenCode at the packaged file instead. Use plugins on V2 and plugin on V1:

json
{
  "instructions": [
    "~/.config/opencode/node_modules/opencode-morph-fast-apply/instructions/morph-tools.md"
  ],
  "plugins": ["github:JRedeker/opencode-morph-fast-apply"]
}
json
{
  "instructions": [
    "~/.config/opencode/node_modules/opencode-morph-fast-apply/instructions/morph-tools.md"
  ],
  "plugin": ["github:JRedeker/opencode-morph-fast-apply"]
}

The morph_edit tool description remains self-contained, but for more reliable tool selection you should also load the packaged always-on instruction file shown above. This avoids agents defaulting to native edit when morph_edit is the better fit for large, scattered, or whitespace-sensitive edits.

Important: the active agent must also expose morph_edit in its tool manifest. If an agent profile marks morph_edit: false, the model cannot choose Morph even when the plugin is installed and the always-on instruction is present.

2. Set your Morph API key

Get an API key at morphllm.com/dashboard, then add it to the environment that starts OpenCode:

bash
export MORPH_API_KEY="sk-your-key-here"

The plugin reads MORPH_API_KEY from the OpenCode process environment when it loads. Setting the variable in an unrelated shell does not update already-running OpenCode sessions.

3. Restart OpenCode

The morph_edit tool will now be available.

Usage

The LLM uses morph_edit for efficient partial file edits:

morph_edit({
  target_filepath: "src/auth.ts",
  instructions: "I am adding error handling for invalid tokens",
  code_edit: `// ... existing code ...
function validateToken(token) {
  if (!token) {
    throw new Error("Token is required");
  }
  // ... existing code ...
}
// ... existing code ...`
})

When to use morph_edit vs edit

SituationToolReason
Small, exact replacementeditFast, no API call
Large file (500+ lines)morph_editHandles partial snippets
Multiple scattered changesmorph_editBatch efficiently
Whitespace-sensitivemorph_editForgiving with formatting

Configuration

VariableDefaultDescription
MORPH_API_KEY(required)Your Morph API key
MORPH_API_URLhttps://api.morphllm.comAPI endpoint
MORPH_MODELmorph-v3-fastModel to use (see below)
MORPH_TIMEOUT30000Request timeout in ms

Available Models

ModelSpeedAccuracyBest For
morph-v3-fast10,500+ tok/sec96%Real-time applications, quick edits
morph-v3-large5,000+ tok/sec98%Complex changes, highest accuracy
auto5,000-10,500 tok/sec~98%Recommended - automatically selects optimal model

How It Works

  1. Reads the original file content
  2. Sends to Morph API:
    • <instruction> - Your intent description
    • <code> - The complete original file
    • <update> - Your partial edit with markers
  3. Morph intelligently merges the lazy edit markers with original code
  4. Writes the merged result back to the file
  5. Returns a unified diff showing what changed

Troubleshooting

"MORPH_API_KEY not configured"

Ensure the environment variable is set and exported in the shell or service that starts OpenCode:

bash
echo $MORPH_API_KEY  # Should show your key

After changing MORPH_API_KEY, restart OpenCode so the plugin reloads with the updated OpenCode process environment.

Timeout errors

Increase the timeout for large files:

bash
export MORPH_TIMEOUT=60000  # 60 seconds

Unexpected deletions

If code is being deleted unexpectedly, ensure your code_edit includes // ... existing code ... markers at the start and end. Omitting these markers tells Morph to replace the entire file.

Safety guards

The plugin blocks unsafe Morph responses before writing files:

  • Marker leakage guard: If merged output contains // ... existing code ... but the original file did not, the write is aborted.
  • Catastrophic truncation guard: If merged output loses more than 60% of characters and more than 50% of lines (for marker-based edits), the write is aborted.
  • Dropped imports guard: If top-level import identifiers present in the original file are missing from the merged output, the write is aborted. This catches silent import loss that can occur when edits fall outside the anchoring context.
  • Path confinement: Target paths stay within the invoking session directory or a validated ADV worktree root. Symlinks are followed and validated; paths that resolve outside that root are rejected.
  • Secret scrubbing: API error messages are automatically scrubbed to prevent leaking your MORPH_API_KEY or Bearer tokens in tool output.

In all guard cases, morph_edit returns a detailed error with recovery options (retry with tighter anchors, use native edit, or split into smaller edits).

Markdown-fenced code_edit input

If an AI agent wraps code_edit in markdown fences (for example, ```typescript ... ```), morph_edit strips the outer fence before sending content to Morph.

Wrong edit location

If edits are applied to the wrong location, add more unique context around your changes and make your instructions more specific about which function/section you're modifying.

Native edit recovery

When a native edit reports an unmatched or ambiguous exact target:

  1. Re-read the target file before any retry.
  2. Do not repeat the unchanged failed edit input.
  3. Make at most one corrected native edit only when the re-read proves the change is still small and exact.
  4. Otherwise use morph_edit for the contextual repair — multi-line, scattered, whitespace-sensitive, or broader anchoring.
  5. Use write only for new-file or intentional full-file replacement.

This recovery sequence is separate from the Morph API-error/timeout fallback, which still recovers to native edit.

Tool blocked in plan/explore mode

The morph_edit tool is disabled in readonly agent modes (plan, explore). Switch to a build/code mode to make edits.

Changelog

Unreleased

  • Native edit recovery policy — The embedded morph_edit description, the packaged always-on instruction, and the README now share the same bounded recovery sequence for a failed native exact edit: re-read the target, do not repeat unchanged input, allow at most one corrected native edit only when still small and exact, otherwise hand off to morph_edit for contextual repair. The existing Morph API-error/timeout → native edit fallback is preserved.
  • Drift regression tests — Content-level tests assert the recovery policy is present and consistent across all three routing surfaces.

v1.8.2

  • Tool exposure requirement docs — instructions/morph-tools.md now documents that agent profiles must expose morph_edit: true in their tool manifest for the routing policy to take effect
  • README alignment — Installation section notes the tool manifest requirement alongside the always-on instruction
  • Test coverage — Tests verify the tool exposure section exists in the instruction file and README

v1.8.1

  • Stable instruction path guidance - README now prefers ~/.config/opencode/instructions/morph-tools.md and keeps the packaged node_modules/... path as a fallback for direct installs
  • Canonical routing policy wording - instructions/morph-tools.md now explicitly says morph routing belongs in always-on instructions, not a skill
  • Docs/test alignment - Tests now verify the stable instruction path and canonical policy wording

v1.8.0

  • Packaged always-on instruction - instructions/morph-tools.md now ships with the plugin so OpenCode can load reliable morph_edit selection guidance through the instructions array
  • Packaging coverage - package metadata now includes the instructions/ directory, and tests verify that the shipped instruction path is documented
  • Installation docs updated - README now recommends adding the packaged always-on instruction to global OpenCode config for more reliable morph_edit selection

v1.7.0

  • Self-contained tool description — Core morph_edit guidance still lives in the tool description so the tool is usable even without extra setup.
  • Packaged always-on instruction — instructions/morph-tools.md can be added to your OpenCode instructions array so agents choose morph_edit more reliably.
  • Removed skill pattern — Deleted skills/morph/SKILL.md and MORPH_INSTRUCTIONS.md. The skill added a round-trip and split-brain problem where guidance lived in multiple places.
  • Removed MORPH_SKILL_LOAD_HINT — Agents no longer need to load a skill before using morph_edit.

v1.6.0

  • Post-merge safety guards - Blocks unsafe Morph output before writing to disk:
    • Marker leakage guard - Detects when merge model treats // ... existing code ... as literal text
    • Truncation guard - Dual-metric validation (>60% char + >50% line loss) prevents silent data loss
  • Input normalization - Strips markdown fences from code_edit to prevent merge confusion
  • TUI guard titles - Shows Morph: blocked (marker leakage) or Morph: blocked (truncation) on guard failures
  • 32 test cases - Comprehensive coverage of normalization, leakage detection, and truncation edge cases

v1.5.0

  • Custom TUI display - Tool output shows branded titles like Morph: src/file.ts +15/-3 (450ms)
  • API timing - Response time tracked and displayed in tool title
  • Structured metadata - Provider, version, model info included for future TUI enhancements

v1.4.0

  • Fixed stdout pollution - Replaced console.log/console.warn with client.app.log() SDK method
  • Readonly agent protection - Blocks morph_edit in plan and explore modes to prevent accidental edits
  • Stderr fallback - Graceful logging if SDK method unavailable

v1.3.0

  • Pre-flight validation prevents accidental deletions - Tool now returns an error if code_edit is missing markers for files >10 lines, preventing catastrophic code loss
  • Improved code_edit parameter description - Changed from "Only the changed lines" to "The code changes wrapped with markers" to emphasize wrapping
  • Added explicit wrapping rule - Tool description now includes "ALWAYS wrap your changes with markers at the start AND end"
  • Restored comprehensive examples - MORPH_INSTRUCTIONS.md now includes all key examples (adding functions, modifying code, deletions)
  • Added Quick Reference - Aligned with Morph's official agent instructions format
  • Added fetch timeout example - From official Morph documentation

v1.2.0

  • Tool schema aligned with Morph official spec - Tool description now matches Morph's recommended format
  • Concise AI agent instructions - MORPH_INSTRUCTIONS.md reduced by 72% (237→67 lines) while keeping critical guidance
  • Added marker validation warning - Server logs warn when code_edit is missing markers (helps debug unexpected deletions)
  • Documentation improvements - Added troubleshooting section, model comparison table, updated config paths

v1.1.0

  • Initial public release
  • Morph Fast Apply integration with lazy edit markers
  • Unified diff output
  • Graceful fallback suggestions

Contributing

Contributions welcome! This plugin could potentially be integrated into OpenCode core.

This project uses Bun. The bun.lock lockfile is tracked in git; pnpm-lock.yaml and package-lock.json are ignored.

License

MIT

将 Opencode Morph Fast Apply MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Opencode Morph Fast Apply 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Opencode Morph Fast Apply 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Opencode Morph Fast Apply MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "opencode-morph-fast-apply": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Opencode Morph Fast Apply MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Opencode Morph Fast Apply MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Opencode Morph Fast Apply 帮我完成这项任务吗?
Opencode Morph Fast Apply
当然。我已阅读。
以下是我使用 Opencode Morph Fast Apply 得到的结果。

常见问题

Opencode Morph Fast Apply MCP 服务器有什么用途?

Opencode Morph Fast Apply 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Opencode Morph Fast Apply MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Opencode Morph Fast Apply,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Opencode Morph Fast Apply MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Opencode Morph Fast Apply 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Opencode Morph Fast Apply MCP 连接到 TypingMind?

Opencode Morph Fast Apply 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Opencode Morph Fast Apply MCP 在 TypingMind 中提供哪些工具?

Opencode Morph Fast Apply 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Opencode Morph Fast Apply MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Opencode Morph Fast Apply 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇