防护破坏性操作
不可逆操作前要求确认。
防护破坏性操作 是 CoddyKit 上的免费 MCP Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 MCP Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 MCP Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Some Actions Cannot Be Undone
Deleting records, sending emails, charging cards, and pushing code are irreversible operations. These deserve more caution than a harmless read. ⚠️
Reversibility Is the Test
Ask one question of each tool: can I easily undo this? If the answer is no, treat it as high risk and wrap it in extra safeguards before it can run.
Keep a Human in the Loop
For risky actions, pause and ask a person to approve. Human-in-the-loop approval means an injected instruction cannot quietly trigger real damage.
Confirm Before You Commit
A good pattern is to preview the change and require an explicit confirm flag. This tool refuses to act until the caller has clearly opted in.
@mcp.tool()
def delete_user(id: int, confirm: bool = False) -> str:
if not confirm:
return "Set confirm=true to delete."
return remove(id)Show What Will Happen
Before a destructive call, return a clear summary of the exact effect, like which rows vanish. A precise preview lets the approver catch a mistake in time.
Prefer Soft Over Hard
When you can, make actions recoverable: a soft delete that marks a row instead of erasing it lets you reverse a bad call without losing the data.
Make Repeats Safe
Design destructive tools to be idempotent where possible, so calling delete twice does no extra harm. Safe repeats reduce the cost of a confused retry.
Limit Scope and Volume
Cap how much one call can affect. A delete tool that can only remove a single id by id is far safer than one that can wipe a table in one shot.
Use the Sampling Approval Flow
MCP lets a server ask the host to confirm with the user before acting. Routing risky steps through user approval keeps the person in control of the outcome.
Log Every Sensitive Action
Record who triggered each destructive call, with what arguments and when. A clear audit trail lets you detect abuse and recover when something goes wrong.
Default to Caution
When you are unsure whether an action is safe, treat it as if it is not. Defaulting to asking first costs a moment and prevents irreversible mistakes.
Quick Check
Which approach best guards an irreversible delete?
Recap
Treat irreversible actions specially: require confirmation, preview effects, prefer soft deletes, limit scope, and log everything. Default to caution. ✅
常见问题解答
「防护破坏性操作」课时是免费的吗?
是的 — 「防护破坏性操作」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 MCP Academy 课程的其余内容,请升级到 CoddyKit PRO。 MCP Academy 课程共包含 4 节课。
「防护破坏性操作」这节课中我会学到什么?
不可逆操作前要求确认。 你通过在浏览器中直接运行的动手代码来练习 MCP Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 MCP Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 MCP Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「防护破坏性操作」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 MCP Academy 课中编写并运行代码吗?
能。每节 MCP Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。